diff --git a/slsim/Sources/SourceVariability/accretion_disk_reprocessing.py b/slsim/Sources/SourceVariability/accretion_disk_reprocessing.py index 27550cd2..2fa933b0 100644 --- a/slsim/Sources/SourceVariability/accretion_disk_reprocessing.py +++ b/slsim/Sources/SourceVariability/accretion_disk_reprocessing.py @@ -69,6 +69,10 @@ def __init__(self, reprocessing_model, **kwargs_agn_model): self.time_array = None self.magnitude_array = None + if "redshift" in self.kwargs_model: + self.redshift = self.kwargs_model["redshift"] + else: + self.redshift = 0 def define_new_response_function(self, rest_frame_wavelength_in_nanometers): """Define a response function of the agn accretion disk to the flaring corona in @@ -261,13 +265,27 @@ def reprocess_signal( interpolated_signal, (interpolated_response_function), mode="full" ) + # bring the reprocessed signal to the observer frame + interpolation_of_reprocessed_signal = interpolate.interp1d( + signal_time_axis, + reprocessed_signal[: len(signal_time_axis)], + bounds_error=False, + fill_value=0, + ) + redshifted_time_axis = signal_time_axis / (1 + self.redshift) + reprocessed_signal_in_observed_frame = interpolation_of_reprocessed_signal( + redshifted_time_axis + ) + normalization = np.nansum(interpolated_response_function) if normalization == 0: - reprocessed_signal = interpolated_signal + reprocessed_signal_in_observed_frame = intrinsic_signal.magnitude( + redshifted_time_axis + ) else: - reprocessed_signal /= normalization + reprocessed_signal_in_observed_frame /= normalization - return reprocessed_signal[: len(self.time_array)] + return reprocessed_signal_in_observed_frame[: len(self.time_array)] def determine_agn_luminosity_from_known_luminosity( self, diff --git a/slsim/Sources/SourceVariability/variability.py b/slsim/Sources/SourceVariability/variability.py index ac0411a6..50777e00 100644 --- a/slsim/Sources/SourceVariability/variability.py +++ b/slsim/Sources/SourceVariability/variability.py @@ -80,6 +80,7 @@ def __init__(self, variability_model, **kwargs_variability_model): self.accretion_disk_reprocessor = AccretionDiskReprocessing( "lamppost", **self.agn_kwargs ) + self.accretion_disk_reprocessor.redshift = self.redshift if ( "time_array" in self.signal_kwargs @@ -231,6 +232,10 @@ def reprocess_with_lamppost_model(variability): reprocessed_signal = variability.accretion_disk_reprocessor.reprocess_signal( response_function_amplitudes=response_function ) + # set the mean magnitude from reprocessing kwargs if present + if "mean_magnitude" in variability.reprocessing_kwargs.keys(): + reprocessed_signal -= np.mean(reprocessed_signal) + reprocessed_signal += variability.reprocessing_kwargs["mean_magnitude"] light_curve = { "MJD": variability.signal_kwargs["time_array"], "ps_mag_" + str(speclite_filter): reprocessed_signal, diff --git a/slsim/Sources/agn.py b/slsim/Sources/agn.py index 3941cf3c..f0773c8e 100644 --- a/slsim/Sources/agn.py +++ b/slsim/Sources/agn.py @@ -99,6 +99,7 @@ def __init__( self.kwargs_model["magnitude_array"] = driving_variability.variability_at_time( self.kwargs_model["time_array"] ) + self.kwargs_model["redshift"] = self.redshift # Create the lamppost reprocessor with a driving light curve that remains static self.variable_disk = Variability("lamppost_reprocessed", **self.kwargs_model) diff --git a/slsim/Sources/source.py b/slsim/Sources/source.py index 0ed684e9..ef7e1078 100644 --- a/slsim/Sources/source.py +++ b/slsim/Sources/source.py @@ -253,7 +253,7 @@ def kwargs_variability_extracted(self): ] = speclite_names[index] # Set the mean magnitude of this filter - self.agn_class.variable_disk.driving_signal_kwargs[ + self.agn_class.variable_disk.reprocessing_kwargs[ "mean_magnitude" ] = mean_magnitudes[index] diff --git a/tests/test_Source/test_accretion_disk_reprocessing.py b/tests/test_Source/test_accretion_disk_reprocessing.py index 04a75d45..191fc057 100644 --- a/tests/test_Source/test_accretion_disk_reprocessing.py +++ b/tests/test_Source/test_accretion_disk_reprocessing.py @@ -23,6 +23,14 @@ def test_initialization(self): } reprocessor = AccretionDiskReprocessing("lamppost", **kwargs_agn_model) assert reprocessor.reprocessing_model == "lamppost" + assert reprocessor.redshift == 0 + + kwargs_agn_model["redshift"] = 3.1 + redshifted_reprocessor = AccretionDiskReprocessing( + "lamppost", **kwargs_agn_model + ) + assert redshifted_reprocessor.redshift == 3.1 + with pytest.raises(ValueError): AccretionDiskReprocessing("other", **kwargs_agn_model) @@ -43,6 +51,9 @@ def test_initialization_invalid_model(self): "Given model is not supported. Currently supported model is lamppost." ) in str(excinfo.value) + kwargs_agn_model["redshift"] = 3.1 + AccretionDiskReprocessing("lamppost", **kwargs_agn_model) + def test_default_initialization_lamppost_model(self): kwargs_agn_model = {"r_out": 1000} reprocessor = AccretionDiskReprocessing("lamppost", **kwargs_agn_model) diff --git a/tests/test_Source/test_source_variability.py b/tests/test_Source/test_source_variability.py index c05647a9..f1c46668 100644 --- a/tests/test_Source/test_source_variability.py +++ b/tests/test_Source/test_source_variability.py @@ -125,6 +125,10 @@ def test_lamppost_reprocessed(self): error_reprocessing_kwargs = { "response_function_amplitudes": badly_defined_transfer_function_amplitudes } + reprocessing_kwargs_6 = { + "speclite_filter": "lsst2016-z", + "mean_magnitude": 21, + } single_reprocessing_kwargs = { "response_function_amplitudes": single_transfer_function_amplitudes } @@ -184,6 +188,15 @@ def test_lamppost_reprocessed(self): ]: for key in dictionary: full_kwargs_5[key] = dictionary[key] + full_kwargs_6 = {} + for dictionary in [ + agn_kwargs, + bpl_kwargs, + reprocessing_kwargs_6, + other_kwargs, + ]: + for key in dictionary: + full_kwargs_6[key] = dictionary[key] full_error_kwargs = {} for dictionary in [ agn_kwargs, @@ -208,6 +221,7 @@ def test_lamppost_reprocessed(self): Variability("lamppost_reprocessed", **full_kwargs_3) Variability("lamppost_reprocessed", **full_kwargs_4) Variability("lamppost_reprocessed", **full_kwargs_5) + Variability("lamppost_reprocessed", **full_kwargs_6) Variability("lamppost_reprocessed", **single_response_kwargs) with pytest.raises(ValueError): Variability("lamppost_reprocessed", **full_error_kwargs)