Skip to content

Commit

Permalink
Merge pull request #256 from Henry-Best-01/agn_sources
Browse files Browse the repository at this point in the history
Adding a short check to see if mean magnitude is passed into variable signal
  • Loading branch information
nkhadka21 authored Sep 23, 2024
2 parents 2369db8 + 149032d commit d687c43
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
24 changes: 21 additions & 3 deletions slsim/Sources/SourceVariability/accretion_disk_reprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions slsim/Sources/SourceVariability/variability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions slsim/Sources/agn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion slsim/Sources/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
11 changes: 11 additions & 0 deletions tests/test_Source/test_accretion_disk_reprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_Source/test_source_variability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit d687c43

Please sign in to comment.