redback 1.0.0__py3-none-any.whl → 1.0.2__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.
Files changed (43) hide show
  1. redback/__init__.py +4 -0
  2. redback/constraints.py +31 -25
  3. redback/ejecta_relations.py +8 -8
  4. redback/get_data/lasair.py +3 -4
  5. redback/get_data/swift.py +7 -7
  6. redback/interaction_processes.py +1 -4
  7. redback/likelihoods.py +207 -21
  8. redback/plotting.py +11 -11
  9. redback/priors/csm_interaction.prior +6 -7
  10. redback/priors/csm_nickel.prior +3 -3
  11. redback/priors/one_comp_kne_rosswog_heatingrate.prior +5 -0
  12. redback/priors/one_component_nsbh_ejecta_relation.prior +1 -1
  13. redback/priors/tde_analytical.prior +5 -5
  14. redback/priors/tde_analytical_bolometric.prior +6 -4
  15. redback/priors/tophat_from_emulator.prior +9 -0
  16. redback/priors/two_comp_kne_rosswog_heatingrate.prior +9 -0
  17. redback/priors/two_component_nsbh_ejecta_relation.prior +1 -1
  18. redback/priors/two_layer_stratified_kilonova.prior +1 -1
  19. redback/priors.py +11 -0
  20. redback/sed.py +194 -2
  21. redback/simulate_transients.py +61 -32
  22. redback/tables/filters.csv +15 -1
  23. redback/tables/ztf.tar.gz +0 -0
  24. redback/transient/afterglow.py +3 -2
  25. redback/transient/kilonova.py +1 -1
  26. redback/transient/supernova.py +1 -1
  27. redback/transient/tde.py +1 -1
  28. redback/transient/transient.py +2 -2
  29. redback/transient_models/afterglow_models.py +42 -0
  30. redback/transient_models/combined_models.py +47 -32
  31. redback/transient_models/extinction_models.py +12 -5
  32. redback/transient_models/kilonova_models.py +247 -14
  33. redback/transient_models/magnetar_driven_ejecta_models.py +2 -2
  34. redback/transient_models/phenomenological_models.py +13 -0
  35. redback/transient_models/supernova_models.py +50 -36
  36. redback/transient_models/tde_models.py +126 -1
  37. redback/utils.py +283 -6
  38. {redback-1.0.0.dist-info → redback-1.0.2.dist-info}/METADATA +7 -4
  39. {redback-1.0.0.dist-info → redback-1.0.2.dist-info}/RECORD +42 -40
  40. {redback-1.0.0.dist-info → redback-1.0.2.dist-info}/WHEEL +1 -1
  41. redback/tables/ztf_obslog.csv +0 -106649
  42. {redback-1.0.0.dist-info → redback-1.0.2.dist-info}/LICENCE.md +0 -0
  43. {redback-1.0.0.dist-info → redback-1.0.2.dist-info}/top_level.txt +0 -0
redback/__init__.py CHANGED
@@ -2,3 +2,7 @@ from redback import analysis, constants, get_data, redback_errors, priors, resul
2
2
  transient_models, utils, photosphere, sed, interaction_processes, constraints, plotting, model_library, simulate_transients
3
3
  from redback.transient import afterglow, kilonova, prompt, supernova, tde
4
4
  from redback.sampler import fit_model
5
+ from redback.utils import setup_logger
6
+
7
+ __version__ = "1.0.2"
8
+ setup_logger(log_level='info')
redback/constraints.py CHANGED
@@ -2,6 +2,7 @@ import numpy as np
2
2
  import redback.eos as eos
3
3
  from redback.constants import *
4
4
  from redback.utils import calc_tfb
5
+ from scipy.interpolate import interp1d
5
6
 
6
7
  def slsn_constraint(parameters):
7
8
  """
@@ -23,7 +24,7 @@ def slsn_constraint(parameters):
23
24
  neutrino_energy = 1e51
24
25
  total_energy = kinetic_energy + neutrino_energy
25
26
  # ensure rotational energy is greater than total output energy
26
- converted_parameters['erot_constraint'] = rotational_energy - total_energy
27
+ converted_parameters['erot_constraint'] = total_energy/rotational_energy
27
28
  # ensure t_nebula is greater than 100 days
28
29
  converted_parameters['t_nebula_min'] = tnebula - 100
29
30
  return converted_parameters
@@ -43,7 +44,7 @@ def basic_magnetar_powered_sn_constraints(parameters):
43
44
  kinetic_energy = 0.5 * mej * vej**2
44
45
  rotational_energy = 2.6e52 * (mass_ns/1.4)**(3./2.) * p0**(-2)
45
46
  # ensure rotational energy is greater than total output energy
46
- converted_parameters['erot_constraint'] = rotational_energy - kinetic_energy
47
+ converted_parameters['erot_constraint'] = kinetic_energy/rotational_energy
47
48
  return converted_parameters
48
49
 
49
50
  def general_magnetar_powered_sn_constraints(parameters):
@@ -61,7 +62,7 @@ def general_magnetar_powered_sn_constraints(parameters):
61
62
  tau = parameters['tsd']
62
63
  rotational_energy = 2*l0*tau
63
64
  # ensure rotational energy is greater than total output energy
64
- converted_parameters['erot_constraint'] = rotational_energy - kinetic_energy
65
+ converted_parameters['erot_constraint'] = kinetic_energy/rotational_energy
65
66
  return converted_parameters
66
67
 
67
68
  def general_magnetar_powered_supernova_constraints(parameters):
@@ -77,7 +78,7 @@ def general_magnetar_powered_supernova_constraints(parameters):
77
78
  nn = parameters['nn']
78
79
  rotational_energy = (nn-1)*l0*tau/2.0
79
80
  # ensure rotational energy is less than the maximum spin down energy
80
- converted_parameters['erot_constraint'] = 1e53 - rotational_energy
81
+ converted_parameters['erot_constraint'] = rotational_energy/1e53
81
82
  return converted_parameters
82
83
 
83
84
  def tde_constraints(parameters):
@@ -91,7 +92,7 @@ def tde_constraints(parameters):
91
92
  rp = parameters['pericenter_radius']
92
93
  mass_bh = parameters['mass_bh']
93
94
  schwarzchild_radius = (2 * graviational_constant * mass_bh * solar_mass /(speed_of_light**2))/au_cgs
94
- converted_parameters['disruption_radius'] = rp - schwarzchild_radius
95
+ converted_parameters['disruption_radius'] = schwarzchild_radius/rp
95
96
  return converted_parameters
96
97
 
97
98
  def gaussianrise_tde_constraints(parameters):
@@ -103,13 +104,11 @@ def gaussianrise_tde_constraints(parameters):
103
104
  converted_parameters = parameters.copy()
104
105
  ms = parameters['stellar_mass']
105
106
  mbh6 = parameters['mbh_6']
106
- etamin = 0.01*(ms**(-7./15.))*(mbh6**(2./3.))
107
107
  betamax = 12.*(ms**(7./15.))*(mbh6**(-2./3.))
108
108
  tfb = calc_tfb(binding_energy_const=0.8, mbh_6=mbh6,stellar_mass=ms)/86400
109
109
  tfb_obs = tfb * (1 + parameters['redshift'])
110
- converted_parameters['eta_low'] = converted_parameters['eta'] - etamin
111
- converted_parameters['beta_high'] = betamax - converted_parameters['beta']
112
- converted_parameters['tfb_max'] = tfb_obs - converted_parameters['peak_time']
110
+ converted_parameters['beta_high'] = converted_parameters['beta']/betamax
111
+ converted_parameters['tfb_max'] = converted_parameters['peak_time']/tfb_obs
113
112
  return converted_parameters
114
113
 
115
114
  def nuclear_burning_constraints(parameters):
@@ -126,7 +125,7 @@ def nuclear_burning_constraints(parameters):
126
125
  kinetic_energy = 0.5 * mej * (vej / 2.0) ** 2
127
126
  excess_constant = -(56.0 / 4.0 * 2.4249 - 53.9037) / proton_mass * mev_cgs
128
127
  emax = excess_constant * mej * fnickel
129
- converted_parameters['emax_constraint'] = emax - kinetic_energy
128
+ converted_parameters['emax_constraint'] = kinetic_energy/emax
130
129
  return converted_parameters
131
130
 
132
131
  def simple_fallback_constraints(parameters):
@@ -149,7 +148,7 @@ def simple_fallback_constraints(parameters):
149
148
  neutrino_energy = 1e51
150
149
  total_energy = e_fallback + neutrino_energy
151
150
  # ensure total energy is greater than kinetic energy
152
- converted_parameters['en_constraint'] = total_energy - kinetic_energy
151
+ converted_parameters['en_constraint'] = kinetic_energy/total_energy
153
152
  # ensure t_nebula is greater than 100 days
154
153
  converted_parameters['t_nebula_min'] = tnebula - 100
155
154
  return converted_parameters
@@ -162,15 +161,18 @@ def csm_constraints(parameters):
162
161
  :param parameters: dictionary of parameters
163
162
  :return: converted_parameters dictionary where the violated samples are thrown out
164
163
  """
165
- from redback.utils import get_csm_properties
166
164
  converted_parameters = parameters.copy()
167
165
  mej = parameters['mej']
168
166
  csm_mass = parameters['csm_mass']
169
167
  kappa = parameters['kappa']
170
168
  r0 = parameters['r0']
171
169
  vej = parameters['vej']
172
- nn = parameters.get('nn', np.ones(len(mej)) * 12.)
173
- delta = parameters.get('delta', np.ones(len(mej)))
170
+ if hasattr(parameters['mej'], "__len__"):
171
+ nn = parameters.get('nn', np.ones(len(mej)) * 8.)
172
+ delta = parameters.get('delta', np.ones(len(mej)))
173
+ else:
174
+ nn = parameters.get('nn', 12.)
175
+ delta = parameters.get('delta', 0.)
174
176
  eta = parameters['eta']
175
177
  rho = parameters['rho']
176
178
 
@@ -180,12 +182,16 @@ def csm_constraints(parameters):
180
182
  vej = vej * km_cgs
181
183
  Esn = 3. * vej ** 2 * mej / 10.
182
184
 
183
- AA = np.zeros(len(mej))
184
- Bf = np.zeros(len(mej))
185
- for x in range(len(mej)):
186
- csm_properties = get_csm_properties(nn[x], eta[x])
187
- AA[x] = csm_properties.AA
188
- Bf[x] = csm_properties.Bf
185
+ ns = [6, 7, 8, 9, 10, 12, 14]
186
+ Bfs = [1.377, 1.299, 1.267, 1.250, 1.239, 1.226, 1.218]
187
+ As = [0.62, 0.27, 0.15, 0.096, 0.067, 0.038, 0.025]
188
+
189
+ Bf_func = interp1d(ns, Bfs)
190
+ A_func = interp1d(ns, As)
191
+
192
+ Bf = Bf_func(nn)
193
+ AA = A_func(nn)
194
+
189
195
  qq = rho * r0 ** eta
190
196
  # outer CSM shell radius
191
197
  radius_csm = ((3.0 - eta) / (4.0 * np.pi * qq) * csm_mass + r0 ** (3.0 - eta)) ** (
@@ -203,14 +209,14 @@ def csm_constraints(parameters):
203
209
  (3.0 - delta) * (nn - 3.0) * mej) ** ((nn - 5.0) / 2.0))
204
210
 
205
211
  tshock = ((radius_csm - r0) / Bf / (AA * g_n / qq) ** (
206
- 1. / (nn - eta))) ** ((nn - eta) /(nn - 3))
212
+ 1. / (nn - eta))) ** ((nn - eta) / (nn - 3))
207
213
 
208
- diffusion_time = np.sqrt(2. * kappa * mass_csm_threshold /(vej * 13.7 * 3.e10))
214
+ diffusion_time = np.sqrt(2. * kappa * mass_csm_threshold / (vej * 13.7 * 3.e10))
209
215
  # ensure shock crossing time is greater than diffusion time
210
- # converted_parameters['shock_time'] = tshock - diffusion_time
216
+ converted_parameters['shock_time'] = diffusion_time/tshock
211
217
  # ensure photospheric radius is within the csm i.e., r_photo < radius_csm and r_photo > r0
212
- converted_parameters['photosphere_constraint_1'] = radius_csm - r_photosphere
213
- converted_parameters['photosphere_constraint_2'] = r_photosphere - r0
218
+ converted_parameters['photosphere_constraint_1'] = r_photosphere/radius_csm
219
+ converted_parameters['photosphere_constraint_2'] = r0/r_photosphere
214
220
  return converted_parameters
215
221
 
216
222
  def piecewise_polytrope_eos_constraints(parameters):
@@ -288,7 +288,7 @@ class TwoComponentBNS(object):
288
288
 
289
289
 
290
290
  class TwoComponentNSBH(object):
291
- def __init__(self, mass_bh, mass_ns, chi_eff, lambda_ns, zeta):
291
+ def __init__(self, mass_bh, mass_ns, chi_bh, lambda_ns, zeta):
292
292
  """
293
293
  Relations to connect intrinsic GW parameters to extrinsic kilonova parameters
294
294
  for a neutron star black hole merger with two components using relations from Kawaguchi et al. 2016.
@@ -296,14 +296,14 @@ class TwoComponentNSBH(object):
296
296
 
297
297
  :param mass_bh: mass of black hole
298
298
  :param mass_2: mass of neutron star
299
- :param chi_eff: effective spin of black hole
299
+ :param chi_bh: spin of black hole along Z axis
300
300
  :param lambda_ns: tidal deformability of neutron star
301
301
  :param zeta: fraction of disk that gets unbound
302
302
  """
303
303
  self.mass_bh = mass_bh
304
304
  self.mass_ns = mass_ns
305
305
  self.mass_ratio = mass_bh/mass_ns
306
- self.chi_eff = chi_eff
306
+ self.chi_bh = chi_bh
307
307
  self.lambda_ns = lambda_ns
308
308
  self.zeta = zeta
309
309
  self.reference = ['https://ui.adsabs.harvard.edu/abs/2016ApJ...825...52K/abstract',
@@ -320,7 +320,7 @@ class TwoComponentNSBH(object):
320
320
 
321
321
  :return: Normalized radius of the Innermost Stable Circular Orbit
322
322
  """
323
- chi_bh = self.chi_eff
323
+ chi_bh = self.chi_bh
324
324
  z1 = 1 + (1 - chi_bh ** 2) ** (1 / 3) * (
325
325
  (1 + chi_bh) ** (1 / 3) + (1 - chi_bh) ** (1 / 3))
326
326
  z2 = np.sqrt(3 * chi_bh ** 2 + z1 ** 2)
@@ -378,20 +378,20 @@ class TwoComponentNSBH(object):
378
378
  return mej_disk_wind
379
379
 
380
380
  class OneComponentNSBH(object):
381
- def __init__(self, mass_bh, mass_ns, chi_eff, lambda_ns):
381
+ def __init__(self, mass_bh, mass_ns, chi_bh, lambda_ns):
382
382
  """
383
383
  Relations to connect intrinsic GW parameters to extrinsic kilonova parameters
384
384
  for a neutron star black hole merger with one component (zone) from Kawaguchi et al. 2016.
385
385
 
386
386
  :param mass_bh: mass of black hole
387
387
  :param mass_2: mass of neutron star
388
- :param chi_eff: effective spin of black hole
388
+ :param chi_bh: spin of black hole along z axis
389
389
  :param lambda_ns: tidal deformability of neutron star
390
390
  """
391
391
  self.mass_bh = mass_bh
392
392
  self.mass_ns = mass_ns
393
393
  self.mass_ratio = mass_bh/mass_ns
394
- self.chi_eff = chi_eff
394
+ self.chi_bh = chi_bh
395
395
  self.lambda_ns = lambda_ns
396
396
  self.reference = 'https://ui.adsabs.harvard.edu/abs/2016ApJ...825...52K/abstract'
397
397
  self.risco = self.isco_radius
@@ -405,7 +405,7 @@ class OneComponentNSBH(object):
405
405
 
406
406
  :return: isco radius
407
407
  """
408
- chi = self.chi_eff
408
+ chi = self.chi_bh
409
409
  z1 = 1 + ((1 - chi * chi) ** (1 / 3.0)) * (((1 + chi) ** (1 / 3.0)) + (1 - chi) ** (1 / 3.0))
410
410
  z2 = (3 * chi * chi + z1 * z1) ** (1 / 2.0)
411
411
  risco = 3 + z2 - np.sign(chi) * ((3 - z1) * (3 + z1 + 2 * z2)) ** (1 / 2.0)
@@ -58,8 +58,8 @@ class LasairDataGetter(DataGetter):
58
58
  f"Are you sure you are using the right alias?")
59
59
  data = pd.read_html(self.url)
60
60
  data = data[1]
61
- data['diff_magnitude'] = [data['magpsf'].iloc[x].split(" ")[0] for x in range(len(data))]
62
- data['diff_magnitude_error'] = [data['magpsf'].iloc[x].split(" ")[-1] for x in range(len(data))]
61
+ data['diff_magnitude'] = [data['unforced mag'].iloc[x].split(" ")[0] for x in range(len(data))]
62
+ data['diff_magnitude_error'] = [data['unforced mag'].iloc[x].split(" ")[-1] for x in range(len(data))]
63
63
 
64
64
  logger.warning('Using the difference magnitude to calculate quantities. '
65
65
  'Reduce the data yourself if you would like to use a reference magnitude')
@@ -67,7 +67,6 @@ class LasairDataGetter(DataGetter):
67
67
  # Change the dataframe to the correct raw dataframe format
68
68
  del data['UTC']
69
69
  del data['images']
70
- del data['magpsf']
71
70
  data.to_csv(self.raw_file_path, index=False)
72
71
  logger.info(f"Retrieved data for {self.transient}.")
73
72
 
@@ -83,7 +82,7 @@ class LasairDataGetter(DataGetter):
83
82
  return pd.read_csv(self.processed_file_path)
84
83
 
85
84
  raw_data = pd.read_csv(self.raw_file_path)
86
- raw_data = raw_data[raw_data['difference flux status'] != 'limit']
85
+ raw_data = raw_data[raw_data['unforced mag status'] != 'limit']
87
86
  lasair_to_general_bands = {"g": "ztfg", "r": "ztfr", "i":'ztfi'}
88
87
  processed_data = pd.DataFrame()
89
88
 
redback/get_data/swift.py CHANGED
@@ -199,9 +199,9 @@ class SwiftDataGetter(GRBDataGetter):
199
199
  driver = fetch_driver()
200
200
  try:
201
201
  driver.get(self.grb_website)
202
- driver.find_element_by_xpath("//select[@name='xrtsub']/option[text()='no']").click()
202
+ driver.find_element("xpath", "//select[@name='xrtsub']/option[text()='no']").click()
203
203
  time.sleep(20)
204
- driver.find_element_by_id("xrt_DENSITY_makeDownload").click()
204
+ driver.find_element("id","xrt_DENSITY_makeDownload").click()
205
205
  time.sleep(20)
206
206
  grb_url = driver.current_url
207
207
  # scrape the data
@@ -227,19 +227,19 @@ class SwiftDataGetter(GRBDataGetter):
227
227
  # select option for BAT bin_size
228
228
  bat_binning = 'batxrtbin'
229
229
  if check_element(driver, bat_binning):
230
- driver.find_element_by_xpath("//select[@name='batxrtbin']/option[text()='SNR 4']").click()
230
+ driver.find_element("xpath", "//select[@name='batxrtbin']/option[text()='SNR 4']").click()
231
231
  # select option for subplot
232
232
  subplot = "batxrtsub"
233
233
  if check_element(driver, subplot):
234
- driver.find_element_by_xpath("//select[@name='batxrtsub']/option[text()='no']").click()
234
+ driver.find_element("xpath","//select[@name='batxrtsub']/option[text()='no']").click()
235
235
  # Select option for flux density
236
236
  flux_density1 = "batxrtband1"
237
237
  flux_density0 = "batxrtband0"
238
238
  if (check_element(driver, flux_density1)) and (check_element(driver, flux_density0)):
239
- driver.find_element_by_xpath(".//*[@id='batxrtband1']").click()
240
- driver.find_element_by_xpath(".//*[@id='batxrtband0']").click()
239
+ driver.find_element("xpath",".//*[@id='batxrtband1']").click()
240
+ driver.find_element("xpath",".//*[@id='batxrtband0']").click()
241
241
  # Generate data file
242
- driver.find_element_by_xpath(".//*[@id='batxrt_XRTBAND_makeDownload']").click()
242
+ driver.find_element("xpath",".//*[@id='batxrt_XRTBAND_makeDownload']").click()
243
243
  time.sleep(20)
244
244
  grb_url = driver.current_url
245
245
  driver.quit()
@@ -165,8 +165,6 @@ class CSMDiffusion(object):
165
165
  # photosphere radius
166
166
  r_photosphere = self.r_photosphere
167
167
 
168
- tau_diff = (self.kappa * self.csm_mass) / (13.8 * speed_of_light * r_photosphere) / day_to_s
169
-
170
168
  # mass of the optically thick CSM (tau > 2/3).
171
169
  mass_csm_threshold = self.mass_csm_threshold
172
170
 
@@ -180,7 +178,7 @@ class CSMDiffusion(object):
180
178
  lu = len(uniq_times)
181
179
 
182
180
  num = int(round(timesteps / 2.0))
183
- lsp = np.logspace(np.log10(tau_diff /self.dense_times[-1]) + minimum_log_spacing, 0, num)
181
+ lsp = np.logspace(np.log10(t0 /self.dense_times[-1]) + minimum_log_spacing, 0, num)
184
182
  xm = np.unique(np.concatenate((lsp, 1 - lsp)))
185
183
 
186
184
  int_times = tb + (uniq_times.reshape(lu, 1) - tb) * xm
@@ -192,7 +190,6 @@ class CSMDiffusion(object):
192
190
 
193
191
  uniq_lums = np.trapz(int_args, int_times, axis=1)
194
192
  uniq_lums *= np.exp(-int_tes/t0)/t0
195
-
196
193
  new_lums = uniq_lums[np.searchsorted(uniq_times, self.time)]
197
194
  return new_lums
198
195