redback 1.0.1__py3-none-any.whl → 1.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- redback/__init__.py +4 -0
- redback/constraints.py +46 -25
- redback/eos.py +1 -0
- redback/get_data/fink.py +1 -1
- redback/get_data/lasair.py +3 -4
- redback/get_data/swift.py +7 -7
- redback/interaction_processes.py +1 -4
- redback/likelihoods.py +207 -21
- redback/model_library.py +2 -2
- redback/plotting.py +10 -10
- redback/priors/bazin_sne.prior +5 -0
- redback/priors/csm_interaction.prior +6 -7
- redback/priors/csm_nickel.prior +3 -3
- redback/priors/csm_shock_and_arnett.prior +11 -0
- redback/priors/csm_shock_and_arnett_bolometric.prior +10 -0
- redback/priors/csm_shock_breakout.prior +7 -0
- redback/priors/nicholl_bns.prior +2 -1
- redback/priors/one_comp_kne_rosswog_heatingrate.prior +5 -0
- redback/priors/pwn.prior +7 -0
- redback/priors/shocked_cocoon.prior +6 -6
- redback/priors/sn_fallback.prior +8 -0
- redback/priors/stream_stream_tde.prior +10 -0
- redback/priors/stream_stream_tde_bolometric.prior +9 -0
- redback/priors/tde_analytical.prior +5 -5
- redback/priors/tde_analytical_bolometric.prior +6 -4
- redback/priors/tde_fallback.prior +9 -0
- redback/priors/tde_fallback_bolometric.prior +6 -0
- redback/priors/tde_synchrotron.prior +6 -0
- redback/priors/tophat_from_emulator.prior +9 -0
- redback/priors/two_comp_kne_rosswog_heatingrate.prior +9 -0
- redback/priors/two_layer_stratified_kilonova.prior +1 -1
- redback/priors/villar_sne.prior +7 -0
- redback/priors.py +12 -1
- redback/sed.py +194 -2
- redback/simulate_transients.py +71 -35
- redback/tables/GRBs_w_redshift.txt +430 -413
- redback/tables/LGRB_table.txt +70 -6
- redback/tables/SGRB_table.txt +139 -135
- redback/tables/filters.csv +14 -0
- redback/tables/qdot_rosswogkorobkin24.pck +0 -0
- redback/tables/ztf.tar.gz +0 -0
- redback/transient/afterglow.py +17 -7
- redback/transient/kilonova.py +6 -3
- redback/transient/prompt.py +14 -4
- redback/transient/supernova.py +7 -3
- redback/transient/tde.py +6 -3
- redback/transient/transient.py +29 -12
- redback/transient_models/afterglow_models.py +152 -146
- redback/transient_models/combined_models.py +69 -48
- redback/transient_models/extinction_models.py +6 -6
- redback/transient_models/general_synchrotron_models.py +518 -0
- redback/transient_models/integrated_flux_afterglow_models.py +2 -2
- redback/transient_models/kilonova_models.py +310 -61
- redback/transient_models/magnetar_driven_ejecta_models.py +2 -2
- redback/transient_models/magnetar_models.py +1 -1
- redback/transient_models/phenomenological_models.py +69 -1
- redback/transient_models/shock_powered_models.py +159 -110
- redback/transient_models/supernova_models.py +211 -43
- redback/transient_models/tde_models.py +975 -5
- redback/utils.py +309 -16
- {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/METADATA +46 -6
- {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/RECORD +65 -49
- {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/WHEEL +1 -1
- redback/tables/ztf_obslog.csv +0 -106649
- {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/LICENCE.md +0 -0
- {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from astropy.cosmology import Planck18 as cosmo # noqa
|
|
2
2
|
from inspect import isfunction
|
|
3
|
-
from redback.utils import logger, citation_wrapper, calc_ABmag_from_flux_density, lambda_to_nu
|
|
3
|
+
from redback.utils import logger, citation_wrapper, calc_ABmag_from_flux_density, lambda_to_nu, bands_to_frequency
|
|
4
4
|
from redback.constants import day_to_s, speed_of_light, solar_mass, proton_mass, electron_mass, sigma_T
|
|
5
5
|
from redback.sed import get_correct_output_format_from_spectra
|
|
6
6
|
import astropy.units as uu
|
|
@@ -285,16 +285,16 @@ class RedbackAfterglows():
|
|
|
285
285
|
te = np.arcsin(cs / (self.cc * (G2 - 1.) ** 0.5)) # equivalent form for angle due to spreading
|
|
286
286
|
# prepare ex and OmG in this function
|
|
287
287
|
if self.is_expansion:
|
|
288
|
-
ex = te
|
|
288
|
+
ex = te / (G2) # expansion
|
|
289
289
|
fac = 0.5 * latstep
|
|
290
|
-
OmG = rotstep * (np.cos(thi - fac) - np.cos(ex + thi + fac)) # equivalent form for linear spacing
|
|
290
|
+
OmG = rotstep * (np.cos(thi - fac) - np.cos(ex/self.res + thi + fac)) # equivalent form for linear spacing
|
|
291
291
|
else:
|
|
292
|
-
|
|
292
|
+
ex = np.ones(te.size) # no expansion
|
|
293
293
|
fac = 0.5 * latstep
|
|
294
294
|
OmG = rotstep * (np.cos(thi - fac) - np.cos(thi + fac)) # equivalent form for linear spacing
|
|
295
295
|
# prepare R
|
|
296
296
|
size = G.size
|
|
297
|
-
exponent = ((1 - np.cos(
|
|
297
|
+
exponent = ((1 - np.cos(latstep + ex[0])) / (1 - np.cos(latstep + ex[:size]))) ** (1/2)
|
|
298
298
|
R = ((3. - k) * Ne[:size] / (self.fourpi * n)) ** (1. / (3. - k))
|
|
299
299
|
R[1:] = np.diff(R) * exponent[1:size] ** (1. / (3. - k))
|
|
300
300
|
R = np.cumsum(R)
|
|
@@ -688,150 +688,10 @@ def _get_kn_dynamics(n0, Eej, Mej):
|
|
|
688
688
|
# convert from lab frame to observer time. Approximate expression acounting for radial+azimuthal time-of-flight effect
|
|
689
689
|
# (eq. 26 from Nava et al. 2013; see also Waxman 1997)
|
|
690
690
|
tobs = R / (Gamma ** 2 * (1.0 + beta) * speed_of_light) + np.insert(
|
|
691
|
-
integrate.
|
|
691
|
+
integrate.cumulative_trapezoid((1.0 - beta_sh) / beta_sh, x=R) / speed_of_light, 0, 0.0)
|
|
692
692
|
|
|
693
693
|
return t, R, beta, Gamma, eden, tobs, beta_sh, Gamma_sh
|
|
694
694
|
|
|
695
|
-
@citation_wrapper('https://ui.adsabs.harvard.edu/abs/2022MNRAS.516.4949S/abstract')
|
|
696
|
-
def kilonova_afterglow_redback(time, redshift, loge0, mej, logn0, logepse, logepsb, p,
|
|
697
|
-
**kwargs):
|
|
698
|
-
"""
|
|
699
|
-
Calculate the afterglow emission from a kilonova remnant, following the model of Sarin et al. 2022.
|
|
700
|
-
This model was modified by Nikhil Sarin following code provided by Ben Margalit.
|
|
701
|
-
|
|
702
|
-
:param time: time in observer frame (days) in observer frame
|
|
703
|
-
:param redshift: source redshift
|
|
704
|
-
:param loge0: log10 of the initial kinetic energy of the ejecta (erg)
|
|
705
|
-
:param mej: ejecta mass (solar masses)
|
|
706
|
-
:param logn0: log10 of the circumburst density (cm^-3)
|
|
707
|
-
:param logepse: log10 of the fraction of shock energy given to electrons
|
|
708
|
-
:param logepsb: log10 of the fraction of shock energy given to magnetic field
|
|
709
|
-
:param p: power-law index of the electron energy distribution
|
|
710
|
-
:param kwargs: Additional keyword arguments
|
|
711
|
-
:param zeta_e: fraction of electrons participating in diffusive shock acceleration. Default is 1.
|
|
712
|
-
:param output_format: Whether to output flux density or AB mag
|
|
713
|
-
:param frequency: frequency in Hz for the flux density calculation
|
|
714
|
-
:param cosmology: Cosmology to use for luminosity distance calculation. Defaults to Planck18. Must be a astropy.cosmology object.
|
|
715
|
-
:return: flux density or AB mag. Note this is going to give the monochromatic magnitude at the effective frequency for the band.
|
|
716
|
-
For a proper calculation of the magntitude use the sed variant models.
|
|
717
|
-
"""
|
|
718
|
-
Eej = 10 ** loge0
|
|
719
|
-
Mej = mej * solar_mass
|
|
720
|
-
cosmology = kwargs.get('cosmology', cosmo)
|
|
721
|
-
epsilon_e = 10 ** logepse
|
|
722
|
-
epsilon_B = 10 ** logepsb
|
|
723
|
-
n0 = 10 ** logn0
|
|
724
|
-
zeta_e = kwargs.get('zeta_e', 1.0)
|
|
725
|
-
qe = 4.803e-10
|
|
726
|
-
|
|
727
|
-
dl = cosmology.luminosity_distance(redshift).cgs.value
|
|
728
|
-
# calculate blast-wave dynamics
|
|
729
|
-
t, R, beta, Gamma, eden, tobs, beta_sh, Gamma_sh = _get_kn_dynamics(n0=n0, Eej=Eej, Mej=Mej)
|
|
730
|
-
|
|
731
|
-
# shock-amplified magnetic field, minimum & cooling Lorentz factors
|
|
732
|
-
B = (8.0 * np.pi * epsilon_B * eden) ** 0.5
|
|
733
|
-
gamma_m = 1.0 + (epsilon_e / zeta_e) * ((p - 2.0) / (p - 1.0)) * (proton_mass / electron_mass) * (Gamma - 1.0)
|
|
734
|
-
gamma_c = 6.0 * np.pi * electron_mass * speed_of_light / (sigma_T * Gamma * t * B ** 2)
|
|
735
|
-
|
|
736
|
-
# number of emitting electrons, where zeta_DN is an approximate smooth interpolation between the "standard"
|
|
737
|
-
# and deep-Newtonian regime discussed by Sironi & Giannios (2013)
|
|
738
|
-
zeta_DN = (gamma_m - 1.0) / gamma_m
|
|
739
|
-
Ne = zeta_DN * zeta_e * (4.0 * np.pi / 3.0) * R ** 3 * n0
|
|
740
|
-
|
|
741
|
-
# LOS approximation
|
|
742
|
-
mu = 1.0
|
|
743
|
-
blueshift = Gamma * (1.0 - beta * mu)
|
|
744
|
-
|
|
745
|
-
frequency = kwargs['frequency']
|
|
746
|
-
if isinstance(frequency, float):
|
|
747
|
-
frequency = np.ones(len(time)) * frequency
|
|
748
|
-
fnu_func = {}
|
|
749
|
-
for nu in frequency:
|
|
750
|
-
Fnu_opt_thin = _pnu_synchrotron(nu * blueshift * (1.0 + redshift), B, gamma_m, gamma_c, Ne, p) * (1.0 + redshift) / (
|
|
751
|
-
4.0 * np.pi * dl ** 2 * blueshift)
|
|
752
|
-
|
|
753
|
-
# correct for synchrotron self-absorption (approximate treatment, correct up to factors of order unity)
|
|
754
|
-
Fnu_opt_thick = Gamma * (8 * np.pi ** 2 * (nu * blueshift * (1.0 + redshift)) ** 2 / speed_of_light ** 2) * R ** 2 * (
|
|
755
|
-
1.0 / 3.0) * electron_mass * speed_of_light ** 2 * np.maximum(gamma_m, (
|
|
756
|
-
2 * np.pi * electron_mass * speed_of_light * nu * blueshift * (1.0 + redshift) / (qe * B)) ** 0.5) * (1.0 + redshift) / (
|
|
757
|
-
4.0 * np.pi * dl ** 2 * blueshift)
|
|
758
|
-
# new prescription:
|
|
759
|
-
Fnu = Fnu_opt_thick * (1e0 - np.exp(-Fnu_opt_thin / Fnu_opt_thick))
|
|
760
|
-
# add brute-force optically-thin case to avoid roundoff error in 1e0-np.exp(-x) term (above) when x->0
|
|
761
|
-
Fnu[Fnu == 0.0] = Fnu_opt_thin[Fnu == 0.0]
|
|
762
|
-
|
|
763
|
-
fnu_func[nu] = interp1d(tobs/day_to_s, Fnu, bounds_error=False, fill_value='extrapolate')
|
|
764
|
-
|
|
765
|
-
# interpolate onto actual observed frequency and time values
|
|
766
|
-
flux_density = []
|
|
767
|
-
for freq, tt in zip(frequency, time):
|
|
768
|
-
flux_density.append(fnu_func[freq](tt))
|
|
769
|
-
|
|
770
|
-
fmjy = np.array(flux_density) / 1e-26
|
|
771
|
-
if kwargs['output_format'] == 'flux_density':
|
|
772
|
-
return fmjy
|
|
773
|
-
elif kwargs['output_format'] == 'magnitude':
|
|
774
|
-
return calc_ABmag_from_flux_density(fmjy).value
|
|
775
|
-
|
|
776
|
-
@citation_wrapper('https://ui.adsabs.harvard.edu/abs/2011Natur.478...82N/abstract')
|
|
777
|
-
def kilonova_afterglow_nakarpiran(time, redshift, loge0, mej, logn0, logepse, logepsb, p, **kwargs):
|
|
778
|
-
"""
|
|
779
|
-
A kilonova afterglow model based on Nakar & Piran 2011
|
|
780
|
-
|
|
781
|
-
:param time: time in days in the observer frame
|
|
782
|
-
:param redshift: source redshift
|
|
783
|
-
:param loge0: initial kinetic energy in erg of ejecta
|
|
784
|
-
:param mej: mass of ejecta in solar masses
|
|
785
|
-
:param logn0: log10 of the number density of the circumburst medium in cm^-3
|
|
786
|
-
:param logepse: log10 of the fraction of energy given to electrons
|
|
787
|
-
:param logepsb: log10 of the fraction of energy given to the magnetic field
|
|
788
|
-
:param p: electron power law index
|
|
789
|
-
:param kwargs: Additional keyword arguments
|
|
790
|
-
:param output_format: Whether to output flux density or AB mag
|
|
791
|
-
:param frequency: frequency in Hz for the flux density calculation
|
|
792
|
-
:param cosmology: Cosmology to use for luminosity distance calculation. Defaults to Planck18. Must be a astropy.cosmology object.
|
|
793
|
-
:return: flux density or AB mag. Note this is going to give the monochromatic magnitude at the effective frequency for the band.
|
|
794
|
-
For a proper calculation of the magntitude use the sed variant models.
|
|
795
|
-
:return:
|
|
796
|
-
"""
|
|
797
|
-
Eej = 10 ** loge0
|
|
798
|
-
Mej = mej * solar_mass
|
|
799
|
-
Gamma0 = 1.0 + Eej / (Mej * speed_of_light ** 2)
|
|
800
|
-
vej = speed_of_light * (1.0 - Gamma0 ** (-2)) ** 0.5
|
|
801
|
-
cosmology = kwargs.get('cosmology', cosmo)
|
|
802
|
-
epsilon_e = 10 ** logepse
|
|
803
|
-
epsilon_B = 10 ** logepsb
|
|
804
|
-
n0 = 10 ** logn0
|
|
805
|
-
dl = cosmology.luminosity_distance(redshift).cgs.value
|
|
806
|
-
|
|
807
|
-
# in days
|
|
808
|
-
t_dec = 30 * (Eej / 1e49) ** (1.0 / 3.0) * (n0 / 1e0) ** (-1.0 / 3.0) * (vej / speed_of_light) ** (-5.0 / 3.0)
|
|
809
|
-
|
|
810
|
-
fnu_dec_dict = {}
|
|
811
|
-
fnu_func = {}
|
|
812
|
-
temp_time = np.linspace(0.1, 100, 200) * t_dec
|
|
813
|
-
frequency = kwargs['frequency']
|
|
814
|
-
if isinstance(frequency, float):
|
|
815
|
-
frequency = np.ones(len(time)) * frequency
|
|
816
|
-
for freq in frequency:
|
|
817
|
-
# Eq. 11 in Nakar & Piran 2011 (in Mjy)
|
|
818
|
-
fnu_dec_dict[freq] = 0.3 * (Eej / 1e49) * n0 ** (0.25 * (p + 1)) * (epsilon_B / 1e-1) ** (0.25 * (p + 1)) * (
|
|
819
|
-
epsilon_e / 1e-1) ** (p - 1) * (vej / speed_of_light) ** (0.5 * (5 * p - 7)) * (freq / 1.4e9) ** (
|
|
820
|
-
-0.5 * (p - 1)) * (dl / 1e27) ** (-2)
|
|
821
|
-
fnu = fnu_dec_dict[freq] * (temp_time / t_dec) ** 3
|
|
822
|
-
fnu[temp_time > t_dec] = fnu_dec_dict[freq] * (temp_time[temp_time > t_dec] / t_dec) ** (-0.3 * (5 * p - 7))
|
|
823
|
-
fnu_func[freq] = interp1d(temp_time, fnu, bounds_error=False, fill_value='extrapolate')
|
|
824
|
-
|
|
825
|
-
# interpolate onto actual observed frequency and time values
|
|
826
|
-
flux_density = []
|
|
827
|
-
for freq, tt in zip(frequency, time):
|
|
828
|
-
flux_density.append(fnu_func[freq](tt))
|
|
829
|
-
fmjy = flux_density * uu.mJy
|
|
830
|
-
if kwargs['output_format'] == 'flux_density':
|
|
831
|
-
return fmjy.value
|
|
832
|
-
elif kwargs['output_format'] == 'magnitude':
|
|
833
|
-
return calc_ABmag_from_flux_density(fmjy.value).value
|
|
834
|
-
|
|
835
695
|
@citation_wrapper('redback, https://ui.adsabs.harvard.edu/abs/2018MNRAS.481.2581L/abstract')
|
|
836
696
|
def tophat_redback(time, redshift, thv, loge0, thc, logn0, p, logepse, logepsb, g0, xiN, **kwargs):
|
|
837
697
|
"""
|
|
@@ -2092,6 +1952,48 @@ def tophat(time, redshift, thv, loge0, thc, logn0, p, logepse, logepsb, ksin, g0
|
|
|
2092
1952
|
elif kwargs['output_format'] == 'magnitude':
|
|
2093
1953
|
return calc_ABmag_from_flux_density(flux_density).value
|
|
2094
1954
|
|
|
1955
|
+
|
|
1956
|
+
def tophat_from_emulator(time, redshift, thv, loge0, thc, logn0, p, logepse, logepsb, g0, **kwargs):
|
|
1957
|
+
"""
|
|
1958
|
+
Evaluate a tophat afterglow model using an mpl regressor. Note that this model predicts for a fixed redshift = 0.01 and fixed ksin = 1.
|
|
1959
|
+
This tophat model does not include all of the ususal kwargs
|
|
1960
|
+
|
|
1961
|
+
:param time: time in days in observer frame, should be in range 0.1 to 300
|
|
1962
|
+
:param redshift: source redshift
|
|
1963
|
+
:param thv: viewing angle in radians
|
|
1964
|
+
:param loge0: log10 on axis isotropic equivalent energy
|
|
1965
|
+
:param thc: half width of jet core/jet opening angle in radians
|
|
1966
|
+
:param logn0: log10 number density of ISM in cm^-3
|
|
1967
|
+
:param p: electron distribution power law index. Must be greater than 2.
|
|
1968
|
+
:param logepse: log10 fraction of thermal energy in electrons
|
|
1969
|
+
:param logepsb: log10 fraction of thermal energy in magnetic field
|
|
1970
|
+
:param g0: initial lorentz factor
|
|
1971
|
+
:param kwargs: Additional keyword arguments
|
|
1972
|
+
:param frequency: frequency of the band to view in- single number or same length as time array
|
|
1973
|
+
:param output_format: Whether to output flux density or AB mag, specified by 'flux_density' or 'magnitude'
|
|
1974
|
+
:return: flux density or AB mag predicted by emulator. Note this is going to give the monochromatic magnitude at the effective frequency for the band.
|
|
1975
|
+
For a proper calculation of the magntitude use the sed variant models
|
|
1976
|
+
"""
|
|
1977
|
+
|
|
1978
|
+
from redback_surrogates.afterglowmodels import tophat_emulator
|
|
1979
|
+
|
|
1980
|
+
z1=0.01
|
|
1981
|
+
z2= redshift
|
|
1982
|
+
frequency= np.log10(kwargs['frequency'])
|
|
1983
|
+
flux_density = tophat_emulator(new_time=time/(1+z2), thv=thv, loge0=loge0, thc=thc, logn0=logn0, p=p,
|
|
1984
|
+
logepse=logepse, logepsb=logepsb, g0=g0,frequency=frequency)
|
|
1985
|
+
|
|
1986
|
+
#scaling flux density with redshift
|
|
1987
|
+
dl1 = cosmo.luminosity_distance(z1)
|
|
1988
|
+
dl2 = cosmo.luminosity_distance(z2)
|
|
1989
|
+
scale_factor = ((dl1**2)*(1+z1)) / (dl2**2)
|
|
1990
|
+
flux_density=flux_density*scale_factor
|
|
1991
|
+
|
|
1992
|
+
if kwargs['output_format'] == 'flux_density':
|
|
1993
|
+
return flux_density
|
|
1994
|
+
elif kwargs['output_format'] == 'magnitude':
|
|
1995
|
+
return calc_ABmag_from_flux_density(flux_density).value
|
|
1996
|
+
|
|
2095
1997
|
@citation_wrapper('https://ui.adsabs.harvard.edu/abs/2020ApJ...896..166R/abstract')
|
|
2096
1998
|
def afterglow_models_with_energy_injection(time, **kwargs):
|
|
2097
1999
|
"""
|
|
@@ -2211,4 +2113,108 @@ def afterglow_models_sed(time, **kwargs):
|
|
|
2211
2113
|
spectra=spectra, lambda_array=lambda_observer_frame,
|
|
2212
2114
|
**kwargs)
|
|
2213
2115
|
|
|
2116
|
+
@citation_wrapper('https://ui.adsabs.harvard.edu/abs/2024ApJS..273...17W/abstract')
|
|
2117
|
+
def jetsimpy_tophat(time, redshift, thv, loge0, thc, nism, A, p, logepse, logepsb, g0, **kwargs):
|
|
2118
|
+
"""
|
|
2119
|
+
A tophat jet model from jetsimpy
|
|
2120
|
+
:param time: time in days in observer frame
|
|
2121
|
+
:param redshift: source redshift
|
|
2122
|
+
:param thv: viewing angle in radians
|
|
2123
|
+
:param loge0: log10 on axis isotropic equivalent energy
|
|
2124
|
+
:param thc: half width of jet core/jet opening angle in radians
|
|
2125
|
+
:param nism: number density of ISM in cm^-3 (ntot = A * (r / 1e17)^-2 + nism (cm^-3))
|
|
2126
|
+
:param A: wind density scale (ntot = A * (r / 1e17)^-2 + nism (cm^-3))
|
|
2127
|
+
:param p: electron distribution power law index.
|
|
2128
|
+
:param logepse: log10 fraction of thermal energy in electrons
|
|
2129
|
+
:param logepsb: log10 fraction of thermal energy in magnetic field
|
|
2130
|
+
:param g0: initial lorentz factor
|
|
2131
|
+
:param kwargs: Additional keyword arguments
|
|
2132
|
+
:param output_format: Whether to output flux density or AB mag
|
|
2133
|
+
:param frequency: frequency in Hz for the flux density calculation
|
|
2134
|
+
:param cosmology: Cosmology to use for luminosity distance calculation. Defaults to Planck18. Must be a astropy.cosmology object.
|
|
2135
|
+
:return: flux density or AB mag. Note this is going to give the monochromatic magnitude at the effective frequency for the band.
|
|
2136
|
+
"""
|
|
2137
|
+
import jetsimpy #Can not use models unless jetsimpy is downloaded
|
|
2138
|
+
time = time * day_to_s
|
|
2139
|
+
cosmology = kwargs.get('cosmology', cosmo)
|
|
2140
|
+
dl = cosmology.luminosity_distance(redshift).cgs.value
|
|
2141
|
+
P = dict(Eiso = 10 ** loge0, lf = g0, theta_c = thc, n0 = nism, A = A, eps_e = 10 ** logepse, eps_b = 10 ** logepsb, p = p, theta_v = thv, d = dl*3.24078e-25, z = redshift) #make a param dict
|
|
2142
|
+
if kwargs['output_format'] == 'flux_density':
|
|
2143
|
+
frequency = kwargs['frequency']
|
|
2144
|
+
flux_density = jetsimpy.FluxDensity_tophat(time, frequency, P)
|
|
2145
|
+
return flux_density
|
|
2146
|
+
else:
|
|
2147
|
+
frequency = bands_to_frequency(kwargs['bands'])
|
|
2148
|
+
flux_density = jetsimpy.FluxDensity_tophat(time, frequency, P)
|
|
2149
|
+
return calc_ABmag_from_flux_density(flux_density).value
|
|
2150
|
+
|
|
2151
|
+
@citation_wrapper('https://ui.adsabs.harvard.edu/abs/2024ApJS..273...17W/abstract')
|
|
2152
|
+
def jetsimpy_gaussian(time, redshift, thv, loge0, thc, nism, A, p, logepse, logepsb, g0, **kwargs):
|
|
2153
|
+
"""
|
|
2154
|
+
A gaussian jet model from jetsimpy
|
|
2155
|
+
:param time: time in days in observer frame
|
|
2156
|
+
:param redshift: source redshift
|
|
2157
|
+
:param thv: viewing angle in radians
|
|
2158
|
+
:param loge0: log10 on axis isotropic equivalent energy
|
|
2159
|
+
:param thc: half width of jet core/jet opening angle in radians
|
|
2160
|
+
:param nism: number density of ISM in cm^-3 (ntot = A * (r / 1e17)^-2 + nism (cm^-3))
|
|
2161
|
+
:param A: wind density scale (ntot = A * (r / 1e17)^-2 + nism (cm^-3))
|
|
2162
|
+
:param p: electron distribution power law index.
|
|
2163
|
+
:param logepse: log10 fraction of thermal energy in electrons
|
|
2164
|
+
:param logepsb: log10 fraction of thermal energy in magnetic field
|
|
2165
|
+
:param g0: initial lorentz factor
|
|
2166
|
+
:param kwargs: Additional keyword arguments
|
|
2167
|
+
:param output_format: Whether to output flux density or AB mag
|
|
2168
|
+
:param frequency: frequency in Hz for the flux density calculation
|
|
2169
|
+
:param cosmology: Cosmology to use for luminosity distance calculation. Defaults to Planck18. Must be a astropy.cosmology object.
|
|
2170
|
+
:return: flux density or AB mag. Note this is going to give the monochromatic magnitude at the effective frequency for the band.
|
|
2171
|
+
"""
|
|
2172
|
+
import jetsimpy #Can not use models unless jetsimpy is downloaded
|
|
2173
|
+
time = time * day_to_s
|
|
2174
|
+
cosmology = kwargs.get('cosmology', cosmo)
|
|
2175
|
+
dl = cosmology.luminosity_distance(redshift).cgs.value
|
|
2176
|
+
P = dict(Eiso = 10 ** loge0, lf = g0, theta_c = thc, n0 = nism, A = A, eps_e = 10 ** logepse, eps_b = 10 ** logepsb, p = p, theta_v = thv, d = dl*3.24078e-25, z = redshift) #make a param dict
|
|
2177
|
+
if kwargs['output_format'] == 'flux_density':
|
|
2178
|
+
frequency = kwargs['frequency']
|
|
2179
|
+
flux_density = jetsimpy.FluxDensity_gaussian(time, frequency, P)
|
|
2180
|
+
return flux_density
|
|
2181
|
+
else:
|
|
2182
|
+
frequency = bands_to_frequency(kwargs['bands'])
|
|
2183
|
+
flux_density = jetsimpy.FluxDensity_gaussian(time, frequency, P)
|
|
2184
|
+
return calc_ABmag_from_flux_density(flux_density).value
|
|
2214
2185
|
|
|
2186
|
+
@citation_wrapper('https://ui.adsabs.harvard.edu/abs/2024ApJS..273...17W/abstract')
|
|
2187
|
+
def jetsimpy_powerlaw(time, redshift, thv, loge0, thc, nism, A, p, logepse, logepsb, g0, s, **kwargs):
|
|
2188
|
+
"""
|
|
2189
|
+
A power-law jet model from jetsimpy
|
|
2190
|
+
:param time: time in days in observer frame
|
|
2191
|
+
:param redshift: source redshift
|
|
2192
|
+
:param thv: viewing angle in radians
|
|
2193
|
+
:param loge0: log10 on axis isotropic equivalent energy
|
|
2194
|
+
:param thc: half width of jet core/jet opening angle in radians
|
|
2195
|
+
:param nism: number density of ISM in cm^-3 (ntot = A * (r / 1e17)^-2 + nism (cm^-3))
|
|
2196
|
+
:param A: wind density scale (ntot = A * (r / 1e17)^-2 + nism (cm^-3))
|
|
2197
|
+
:param p: electron distribution power law index.
|
|
2198
|
+
:param logepse: log10 fraction of thermal energy in electrons
|
|
2199
|
+
:param logepsb: log10 fraction of thermal energy in magnetic field
|
|
2200
|
+
:param g0: initial lorentz factor
|
|
2201
|
+
:param s: power-law jet slope
|
|
2202
|
+
:param kwargs: Additional keyword arguments
|
|
2203
|
+
:param output_format: Whether to output flux density or AB mag
|
|
2204
|
+
:param frequency: frequency in Hz for the flux density calculation
|
|
2205
|
+
:param cosmology: Cosmology to use for luminosity distance calculation. Defaults to Planck18. Must be a astropy.cosmology object.
|
|
2206
|
+
:return: flux density or AB mag. Note this is going to give the monochromatic magnitude at the effective frequency for the band.
|
|
2207
|
+
"""
|
|
2208
|
+
import jetsimpy #Can not use models unless jetsimpy is downloaded
|
|
2209
|
+
time = time * day_to_s
|
|
2210
|
+
cosmology = kwargs.get('cosmology', cosmo)
|
|
2211
|
+
dl = cosmology.luminosity_distance(redshift).cgs.value
|
|
2212
|
+
P = dict(Eiso = 10 ** loge0, lf = g0, theta_c = thc, n0 = nism, A = A, eps_e = 10 ** logepse, eps_b = 10 ** logepsb, p = p, theta_v = thv, d = dl*3.24078e-25, z = redshift, s = s) #make a param dict
|
|
2213
|
+
if kwargs['output_format'] == 'flux_density':
|
|
2214
|
+
frequency = kwargs['frequency']
|
|
2215
|
+
flux_density = jetsimpy.FluxDensity_powerlaw(time, frequency, P)
|
|
2216
|
+
return flux_density
|
|
2217
|
+
else:
|
|
2218
|
+
frequency = bands_to_frequency(kwargs['bands'])
|
|
2219
|
+
flux_density = jetsimpy.FluxDensity_powerlaw(time, frequency, P)
|
|
2220
|
+
return calc_ABmag_from_flux_density(flux_density).value
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import redback.transient_models.extinction_models
|
|
2
|
-
|
|
1
|
+
import redback.transient_models.extinction_models as em
|
|
2
|
+
import redback.transient_models as tm
|
|
3
|
+
from redback.utils import nu_to_lambda
|
|
4
|
+
from redback.utils import citation_wrapper
|
|
5
|
+
|
|
6
|
+
@citation_wrapper('https://ui.adsabs.harvard.edu/abs/2020ApJ...896..166R/abstract, https://ui.adsabs.harvard.edu/abs/2020ApJ...891..152H/abstract')
|
|
7
|
+
def tophat_and_twolayerstratified(time, redshift, av, thv, loge0, thc, logn0, p, logepse,
|
|
8
|
+
logepsb, ksin, g0, mej, vej_1, vej_2, kappa, beta, **kwargs):
|
|
3
9
|
|
|
4
10
|
"""
|
|
5
11
|
function to combine the flux density signals of a tophat afterglow and a two layer stratified kilonova with extinction
|
|
@@ -34,20 +40,22 @@ def tophat_and_twolayerstratified(time, redshift, av, thv, loge0, thc, logn0, p,
|
|
|
34
40
|
:return: flux density signal with extinction added
|
|
35
41
|
|
|
36
42
|
"""
|
|
37
|
-
kwargs['output_format']='flux_density'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
kwargs['base_model']='two_layer_stratified_kilonova'
|
|
43
|
-
kilonova = redback.transient_models.extinction_models.extinction_with_kilonova_base_model(time=time, redshift=redshift, av=av,
|
|
44
|
-
mej=mej, vej_1=vej_1, vej_2=vej_2, kappa=kappa, beta=beta, **kwargs)
|
|
45
|
-
|
|
43
|
+
kwargs['output_format'] = 'flux_density'
|
|
44
|
+
afterglow = tm.afterglow_models.tophat(time=time, redshift=redshift, thv=thv, loge0=loge0, thc=thc, logn0=logn0,
|
|
45
|
+
p=p, logepse=logepse, logepsb=logepsb, ksin=ksin, g0=g0, **kwargs)
|
|
46
|
+
kilonova = tm.kilonova_models.two_layer_stratified_kilonova(time=time, redshift=redshift, mej=mej, vej_1=vej_1,
|
|
47
|
+
vej_2=vej_2, kappa=kappa, beta=beta, **kwargs)
|
|
46
48
|
combined = afterglow+kilonova
|
|
49
|
+
r_v = kwargs.get('r_v', 3.1)
|
|
50
|
+
# correct for extinction
|
|
51
|
+
angstroms = nu_to_lambda(kwargs['frequency'])
|
|
52
|
+
combined = em._perform_extinction(flux_density=combined, angstroms=angstroms, av=av, r_v=r_v)
|
|
47
53
|
return combined
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
def tophat_and_twocomponent(time, redshift, av, thv, loge0, thc, logn0,
|
|
55
|
+
@citation_wrapper('https://ui.adsabs.harvard.edu/abs/2020ApJ...896..166R/abstract, redback')
|
|
56
|
+
def tophat_and_twocomponent(time, redshift, av, thv, loge0, thc, logn0,
|
|
57
|
+
p, logepse, logepsb, ksin, g0, mej_1, vej_1,
|
|
58
|
+
temperature_floor_1, kappa_1, mej_2, vej_2, temperature_floor_2, kappa_2, **kwargs):
|
|
51
59
|
|
|
52
60
|
"""
|
|
53
61
|
function to combine the flux density signals of a tophat afterglow and a two component kilonova with extinction added
|
|
@@ -85,19 +93,22 @@ def tophat_and_twocomponent(time, redshift, av, thv, loge0, thc, logn0, p, logep
|
|
|
85
93
|
:return: flux density signal with extinction added
|
|
86
94
|
"""
|
|
87
95
|
|
|
88
|
-
kwargs['output_format']='flux_density'
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
mej_1=mej_1, vej_1=vej_2, temperature_floor_1=temperature_floor_1, kappa_1=kappa_1, mej_2=mej_2, vej_2=vej_2, temperature_floor_2=temperature_floor_2, kappa_2=kappa_2, **kwargs)
|
|
96
|
+
kwargs['output_format'] = 'flux_density'
|
|
97
|
+
afterglow = tm.afterglow_models.tophat(time=time, redshift=redshift, thv=thv, loge0=loge0, thc=thc, logn0=logn0,
|
|
98
|
+
p=p, logepse=logepse, logepsb=logepsb, ksin=ksin, g0=g0, **kwargs)
|
|
99
|
+
kilonova = tm.kilonova_models.two_component_kilonova_model(time=time, redshift=redshift, av=av,
|
|
100
|
+
mej_1=mej_1, vej_1=vej_1, temperature_floor_1=temperature_floor_1,
|
|
101
|
+
kappa_1=kappa_1, mej_2=mej_2, vej_2=vej_2,
|
|
102
|
+
temperature_floor_2=temperature_floor_2, kappa_2=kappa_2, **kwargs)
|
|
96
103
|
|
|
97
104
|
combined = afterglow + kilonova
|
|
105
|
+
r_v = kwargs.get('r_v', 3.1)
|
|
106
|
+
# correct for extinction
|
|
107
|
+
angstroms = nu_to_lambda(kwargs['frequency'])
|
|
108
|
+
combined = em._perform_extinction(flux_density=combined, angstroms=angstroms, av=av, r_v=r_v)
|
|
98
109
|
return combined
|
|
99
110
|
|
|
100
|
-
|
|
111
|
+
@citation_wrapper('https://ui.adsabs.harvard.edu/abs/2020ApJ...896..166R/abstract, https://ui.adsabs.harvard.edu/abs/1982ApJ...253..785A/abstract')
|
|
101
112
|
def tophat_and_arnett(time, av, redshift, thv, loge0, thc, logn0, p, logepse, logepsb, ksin, g0, f_nickel, mej, **kwargs):
|
|
102
113
|
|
|
103
114
|
"""
|
|
@@ -137,46 +148,56 @@ def tophat_and_arnett(time, av, redshift, thv, loge0, thc, logn0, p, logepse, lo
|
|
|
137
148
|
:return: flux density with extinction added
|
|
138
149
|
"""
|
|
139
150
|
|
|
140
|
-
kwargs['output_format']='flux_density'
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
kwargs['base_model']='arnett'
|
|
146
|
-
supernova = redback.transient_models.extinction_models.extinction_with_supernova_base_model(time=time, redshift=redshift, av=av,
|
|
147
|
-
f_nickel=f_nickel, mej=mej, **kwargs)
|
|
148
|
-
|
|
151
|
+
kwargs['output_format'] = 'flux_density'
|
|
152
|
+
afterglow = tm.afterglow_models.tophat(time=time, redshift=redshift, thv=thv, loge0=loge0, thc=thc, logn0=logn0,
|
|
153
|
+
p=p, logepse=logepse, logepsb=logepsb, ksin=ksin, g0=g0, **kwargs)
|
|
154
|
+
kwargs['base_model'] = 'arnett'
|
|
155
|
+
supernova = tm.supernova_models.arnett(time=time, redshift=redshift, f_nickel=f_nickel, mej=mej, **kwargs)
|
|
149
156
|
combined = afterglow + supernova
|
|
157
|
+
r_v = kwargs.get('r_v', 3.1)
|
|
158
|
+
# correct for extinction
|
|
159
|
+
angstroms = nu_to_lambda(kwargs['frequency'])
|
|
160
|
+
combined = em._perform_extinction(flux_density=combined, angstroms=angstroms, av=av, r_v=r_v)
|
|
150
161
|
return combined
|
|
151
162
|
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
@citation_wrapper('redback, and any citations for the specific model you use')
|
|
164
|
+
def afterglow_and_optical(time, redshift, av, **model_kwargs):
|
|
154
165
|
"""
|
|
155
166
|
function to combine the signals of any afterglow and any other optical transient with extinction added
|
|
156
167
|
|
|
157
168
|
:param time: time in days in observer frame
|
|
158
169
|
:param redshift: source redshift
|
|
159
170
|
:param av: absolute mag extinction
|
|
160
|
-
:param
|
|
171
|
+
:param model_kwargs: kwargs shared by models frequency and r_v (extinction paramater defaults to 3.1)
|
|
161
172
|
:param afterglow_kwargs: dictionary of parameters required by the afterglow transient model specified by 'base_model'
|
|
162
173
|
and any additional keyword arguments. Refer to model documentation for details.
|
|
163
174
|
:param optical_kwargs: dictionary of parameters required by the optical transient model specifed by 'base_model'
|
|
164
175
|
and any additional keyword arguments. Note the base model must correspond to the given model type. Refer to model documentation
|
|
165
176
|
for details.
|
|
166
|
-
:
|
|
167
|
-
:return: set by shared_kwargs output format - 'flux_density' or 'magnitude' with extinction added
|
|
168
|
-
note that only afterglow_models_sed allow for magnitude outputs
|
|
177
|
+
:return: flux density signal with extinction added
|
|
169
178
|
"""
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
optical_kwargs
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
|
|
180
|
+
from redback.model_library import all_models_dict
|
|
181
|
+
optical_kwargs = model_kwargs['optical_kwargs']
|
|
182
|
+
afterglow_kwargs = model_kwargs['afterglow_kwargs']
|
|
183
|
+
model_kwargs['output_format']= model_kwargs.get('output_format', 'flux_density')
|
|
184
|
+
|
|
185
|
+
_afterglow_kwargs = afterglow_kwargs.copy()
|
|
186
|
+
_afterglow_kwargs.update(model_kwargs)
|
|
187
|
+
|
|
188
|
+
_optical_kwargs = optical_kwargs.copy()
|
|
189
|
+
_optical_kwargs.update(model_kwargs)
|
|
190
|
+
|
|
191
|
+
afterglow_function = all_models_dict[_afterglow_kwargs['base_model']]
|
|
192
|
+
afterglow = afterglow_function(time=time, redshift=redshift, **_afterglow_kwargs)
|
|
193
|
+
|
|
194
|
+
optical_function = all_models_dict[_optical_kwargs['base_model']]
|
|
195
|
+
optical = optical_function(time=time, redshift=redshift, **_optical_kwargs)
|
|
196
|
+
|
|
197
|
+
combined = afterglow + optical
|
|
198
|
+
r_v = model_kwargs.get('r_v', 3.1)
|
|
199
|
+
# correct for extinction
|
|
200
|
+
angstroms = nu_to_lambda(model_kwargs['frequency'])
|
|
201
|
+
combined = em._perform_extinction(flux_density=combined, angstroms=angstroms, av=av, r_v=r_v)
|
|
181
202
|
return combined
|
|
182
203
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from inspect import isfunction
|
|
2
2
|
import numpy as np
|
|
3
|
-
|
|
4
3
|
import redback.utils
|
|
5
4
|
from redback.transient_models.fireball_models import predeceleration
|
|
6
5
|
from redback.utils import logger, calc_ABmag_from_flux_density, citation_wrapper, lambda_to_nu
|
|
@@ -12,30 +11,32 @@ extinction_afterglow_base_models = ['tophat', 'cocoon', 'gaussian',
|
|
|
12
11
|
'kn_afterglow', 'cone_afterglow',
|
|
13
12
|
'gaussiancore', 'gaussian',
|
|
14
13
|
'smoothpowerlaw', 'powerlawcore',
|
|
14
|
+
'tophat','tophat_from_emulator',
|
|
15
15
|
'kilonova_afterglow_redback', 'kilonova_afterglow_nakarpiran',
|
|
16
16
|
'tophat_redback', 'gaussian_redback', 'twocomponent_redback',
|
|
17
17
|
'powerlaw_redback', 'alternativepowerlaw_redback', 'doublegaussian_redback',
|
|
18
18
|
'tophat_redback_refreshed', 'gaussian_redback_refreshed',
|
|
19
19
|
'twocomponent_redback_refreshed','powerlaw_redback_refreshed',
|
|
20
20
|
'alternativepowerlaw_redback_refreshed', 'doublegaussian_redback_refreshed']
|
|
21
|
+
|
|
21
22
|
extinction_integrated_flux_afterglow_models = extinction_afterglow_base_models
|
|
22
23
|
extinction_supernova_base_models = ['sn_exponential_powerlaw', 'arnett', 'shock_cooling_and_arnett',
|
|
23
24
|
'basic_magnetar_powered', 'slsn', 'magnetar_nickel',
|
|
24
25
|
'csm_interaction', 'csm_nickel', 'type_1a', 'type_1c',
|
|
25
|
-
'general_magnetar_slsn','general_magnetar_driven_supernova']
|
|
26
|
+
'general_magnetar_slsn','general_magnetar_driven_supernova', 'sn_fallback']
|
|
26
27
|
extinction_kilonova_base_models = ['nicholl_bns', 'mosfit_rprocess', 'mosfit_kilonova',
|
|
27
28
|
'power_law_stratified_kilonova','bulla_bns_kilonova',
|
|
28
|
-
'bulla_nsbh_kilonova', '
|
|
29
|
+
'bulla_nsbh_kilonova', 'kasen_bns_kilonova','two_layer_stratified_kilonova',
|
|
29
30
|
'three_component_kilonova_model', 'two_component_kilonova_model',
|
|
30
31
|
'one_component_kilonova_model', 'one_component_ejecta_relation',
|
|
31
32
|
'one_component_ejecta_relation_projection', 'two_component_bns_ejecta_relation',
|
|
32
33
|
'polytrope_eos_two_component_bns', 'one_component_nsbh_ejecta_relation',
|
|
33
34
|
'two_component_nsbh_ejecta_relation','metzger_kilonova_model']
|
|
34
35
|
extinction_tde_base_models = ['tde_analytical', 'tde_semianalytical', 'gaussianrise_cooling_envelope',
|
|
35
|
-
'cooling_envelope']
|
|
36
|
+
'cooling_envelope', 'bpl_cooling_envelope']
|
|
36
37
|
extinction_magnetar_driven_base_models = ['basic_mergernova', 'general_mergernova', 'general_mergernova_thermalisation',
|
|
37
38
|
'general_mergernova_evolution', 'metzger_magnetar_driven_kilonova_model',
|
|
38
|
-
'general_metzger_magnetar_driven', '
|
|
39
|
+
'general_metzger_magnetar_driven', 'general_metzger_magnetar_driven_thermalisation',
|
|
39
40
|
'general_metzger_magnetar_driven_evolution']
|
|
40
41
|
extinction_shock_powered_base_models = ['shocked_cocoon', 'shock_cooling']
|
|
41
42
|
|
|
@@ -86,7 +87,6 @@ def _perform_extinction(flux_density, angstroms, av, r_v):
|
|
|
86
87
|
:return: flux
|
|
87
88
|
"""
|
|
88
89
|
import extinction # noqa
|
|
89
|
-
import numpy.ma as ma
|
|
90
90
|
if isinstance(angstroms, float):
|
|
91
91
|
angstroms = np.array([angstroms])
|
|
92
92
|
mag_extinction = extinction.fitzpatrick99(angstroms, av, r_v=r_v)
|