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.
Files changed (66) hide show
  1. redback/__init__.py +4 -0
  2. redback/constraints.py +46 -25
  3. redback/eos.py +1 -0
  4. redback/get_data/fink.py +1 -1
  5. redback/get_data/lasair.py +3 -4
  6. redback/get_data/swift.py +7 -7
  7. redback/interaction_processes.py +1 -4
  8. redback/likelihoods.py +207 -21
  9. redback/model_library.py +2 -2
  10. redback/plotting.py +10 -10
  11. redback/priors/bazin_sne.prior +5 -0
  12. redback/priors/csm_interaction.prior +6 -7
  13. redback/priors/csm_nickel.prior +3 -3
  14. redback/priors/csm_shock_and_arnett.prior +11 -0
  15. redback/priors/csm_shock_and_arnett_bolometric.prior +10 -0
  16. redback/priors/csm_shock_breakout.prior +7 -0
  17. redback/priors/nicholl_bns.prior +2 -1
  18. redback/priors/one_comp_kne_rosswog_heatingrate.prior +5 -0
  19. redback/priors/pwn.prior +7 -0
  20. redback/priors/shocked_cocoon.prior +6 -6
  21. redback/priors/sn_fallback.prior +8 -0
  22. redback/priors/stream_stream_tde.prior +10 -0
  23. redback/priors/stream_stream_tde_bolometric.prior +9 -0
  24. redback/priors/tde_analytical.prior +5 -5
  25. redback/priors/tde_analytical_bolometric.prior +6 -4
  26. redback/priors/tde_fallback.prior +9 -0
  27. redback/priors/tde_fallback_bolometric.prior +6 -0
  28. redback/priors/tde_synchrotron.prior +6 -0
  29. redback/priors/tophat_from_emulator.prior +9 -0
  30. redback/priors/two_comp_kne_rosswog_heatingrate.prior +9 -0
  31. redback/priors/two_layer_stratified_kilonova.prior +1 -1
  32. redback/priors/villar_sne.prior +7 -0
  33. redback/priors.py +12 -1
  34. redback/sed.py +194 -2
  35. redback/simulate_transients.py +71 -35
  36. redback/tables/GRBs_w_redshift.txt +430 -413
  37. redback/tables/LGRB_table.txt +70 -6
  38. redback/tables/SGRB_table.txt +139 -135
  39. redback/tables/filters.csv +14 -0
  40. redback/tables/qdot_rosswogkorobkin24.pck +0 -0
  41. redback/tables/ztf.tar.gz +0 -0
  42. redback/transient/afterglow.py +17 -7
  43. redback/transient/kilonova.py +6 -3
  44. redback/transient/prompt.py +14 -4
  45. redback/transient/supernova.py +7 -3
  46. redback/transient/tde.py +6 -3
  47. redback/transient/transient.py +29 -12
  48. redback/transient_models/afterglow_models.py +152 -146
  49. redback/transient_models/combined_models.py +69 -48
  50. redback/transient_models/extinction_models.py +6 -6
  51. redback/transient_models/general_synchrotron_models.py +518 -0
  52. redback/transient_models/integrated_flux_afterglow_models.py +2 -2
  53. redback/transient_models/kilonova_models.py +310 -61
  54. redback/transient_models/magnetar_driven_ejecta_models.py +2 -2
  55. redback/transient_models/magnetar_models.py +1 -1
  56. redback/transient_models/phenomenological_models.py +69 -1
  57. redback/transient_models/shock_powered_models.py +159 -110
  58. redback/transient_models/supernova_models.py +211 -43
  59. redback/transient_models/tde_models.py +975 -5
  60. redback/utils.py +309 -16
  61. {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/METADATA +46 -6
  62. {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/RECORD +65 -49
  63. {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/WHEEL +1 -1
  64. redback/tables/ztf_obslog.csv +0 -106649
  65. {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/LICENCE.md +0 -0
  66. {redback-1.0.1.dist-info → redback-1.0.3.dist-info}/top_level.txt +0 -0
@@ -14,11 +14,11 @@ datadir = os.path.join(os.path.dirname(redback.__file__), 'tables')
14
14
 
15
15
  class SimulateGenericTransient(object):
16
16
  def __init__(self, model, parameters, times, model_kwargs, data_points,
17
- seed=1234, multiwavelength_transient=False, noise_term=0.2):
17
+ seed=1234, multiwavelength_transient=False, noise_term=0.2, noise_type='gaussianmodel', extra_scatter=0.0):
18
18
  """
19
19
  A generic interface to simulating transients
20
20
 
21
- :param model: String corresponding to redback model
21
+ :param model: String corresponding to redback model or a python function that can evaluate an SED.
22
22
  :param parameters: Dictionary of parameters describing a single transient
23
23
  :param times: Time values that the model is evaluated from
24
24
  :param model_kwargs: Additional keyword arguments, must include all the keyword arguments required by the model.
@@ -31,9 +31,17 @@ class SimulateGenericTransient(object):
31
31
  and the data points are sampled in bands/frequency as well,
32
32
  rather than just corresponding to one wavelength/filter.
33
33
  This also allows the same time value to be sampled multiple times.
34
- :param noise_term: Float. Factor which is multiplied by the model flux/magnitude to give the sigma.
35
- """
36
- self.model = redback.model_library.all_models_dict[model]
34
+ :param noise_type: String. Type of noise to add to the model.
35
+ Default is 'gaussianmodel' where sigma is noise_term * model.
36
+ Another option is 'gaussian' i.e., a simple Gaussian noise with sigma = noise_term.
37
+ :param noise_term: Float. Factor which is multiplied by the model flux/magnitude to give the sigma
38
+ or is sigma itself for 'gaussian' noise. Or the SNR for 'SNRbased' noise.
39
+ :param extra_scatter: Float. Sigma of normal added to output for additional scatter.
40
+ """
41
+ if model in redback.model_library.all_models_dict:
42
+ self.model = redback.model_library.all_models_dict[model]
43
+ else:
44
+ self.model = model
37
45
  self.parameters = parameters
38
46
  self.all_times = times
39
47
  self.model_kwargs = model_kwargs
@@ -44,20 +52,25 @@ class SimulateGenericTransient(object):
44
52
  self.noise_term = noise_term
45
53
  random.seed(self.seed)
46
54
 
47
- if multiwavelength_transient:
48
- self.all_bands = self.model_kwargs.get('bands', None)
49
- self.all_frequency = self.model_kwargs.get('frequency', None)
50
- if self.all_bands is None and self.all_frequency is None:
51
- raise ValueError('Must supply either bands or frequency to sample data points for an optical transient')
52
- if self.all_bands is not None and self.all_frequency is None:
53
- self.subset_bands = np.array(random.choices(self.all_bands, k=self.data_points))
54
- if self.all_bands is None and self.all_frequency is not None:
55
- self.subset_frequency = np.array(random.choices(self.all_frequency, k=self.data_points))
56
- self.replacement = True
57
- # allow times to be chosen repeatedly
55
+ self.all_bands = self.model_kwargs.get('bands', None)
56
+ self.all_frequency = self.model_kwargs.get('frequency', None)
57
+ if self.all_bands is None and self.all_frequency is None:
58
+ raise ValueError('Must supply either bands or frequency to sample data points for an optical transient')
58
59
  else:
59
- # allow times to be chosen only once.
60
- self.replacement = False
60
+ if multiwavelength_transient:
61
+ if self.all_bands is not None and self.all_frequency is None:
62
+ self.subset_bands = np.array(random.choices(self.all_bands, k=self.data_points))
63
+ if self.all_bands is None and self.all_frequency is not None:
64
+ self.subset_frequency = np.array(random.choices(self.all_frequency, k=self.data_points))
65
+ self.replacement = True
66
+ # allow times to be chosen repeatedly
67
+ else:
68
+ if self.all_bands is not None and self.all_frequency is None:
69
+ self.subset_bands = self.data_points * [self.all_bands]
70
+ if self.all_bands is None and self.all_frequency is not None:
71
+ self.subset_frequency = np.ones(self.data_points) * self.all_frequency
72
+ # allow times to be chosen only once.
73
+ self.replacement = False
61
74
  self.subset_times = np.sort(np.random.choice(self.all_times, size=self.data_points, replace=self.replacement))
62
75
 
63
76
  injection_kwargs = self.parameters.copy()
@@ -76,24 +89,47 @@ class SimulateGenericTransient(object):
76
89
  if 'frequency' in model_kwargs.keys():
77
90
  data['frequency'] = self.subset_frequency
78
91
  data['true_output'] = true_output
79
- data['output'] = np.random.normal(true_output, self.noise_term * true_output)
80
- data['output_error'] = self.noise_term * true_output
92
+
93
+ if noise_type == 'gaussianmodel':
94
+ noise = np.random.normal(0, self.noise_term * true_output, len(true_output))
95
+ output = true_output + noise
96
+ output_error = self.noise_term * true_output
97
+ elif noise_type == 'gaussian':
98
+ noise = np.random.normal(0, self.noise_term, len(true_output))
99
+ output = true_output + noise
100
+ output_error = self.noise_term
101
+ elif noise_type == 'SNRbased':
102
+ sigma = np.sqrt(true_output + np.min(true_output)/self.noise_term)
103
+ output_error = sigma
104
+ output = true_output + np.random.normal(0, sigma, len(true_output))
105
+ else:
106
+ logger.warning(f"noise_type {noise_type} not implemented.")
107
+ raise ValueError('noise_type must be either gaussianmodel, gaussian, or SNRBased')
108
+
109
+ if extra_scatter > 0:
110
+ extra_noise = np.random.normal(0, extra_scatter, len(true_output))
111
+ output = output + extra_noise
112
+ output_error = np.sqrt(output_error**2 + extra_noise**2)
113
+
114
+ data['output'] = output
115
+ data['output_error'] = output_error
81
116
  self.data = data
82
117
 
83
- def save_transient(self, name):
84
- """
85
- Save the transient observations to a csv file.
86
- This will save the full observational dataframe including non-detections etc.
87
- This will save the data to a folder called 'simulated'
88
- with the name of the transient and a csv file of the injection parameters
89
-
90
- :param name: name to save transient.
91
- """
92
- bilby.utils.check_directory_exists_and_if_not_mkdir('simulated')
93
- path = 'simulated/' + name + '.csv'
94
- injection_path = 'simulated/' + name + '_injection_parameters.csv'
95
- self.observations.to_csv(path, index=False)
96
- self.parameters.to_csv(injection_path, index=False)
118
+ def save_transient(self, name):
119
+ """
120
+ Save the transient observations to a csv file.
121
+ This will save the full observational dataframe including non-detections etc.
122
+ This will save the data to a folder called 'simulated'
123
+ with the name of the transient and a csv file of the injection parameters
124
+
125
+ :param name: name to save transient.
126
+ """
127
+ bilby.utils.check_directory_exists_and_if_not_mkdir('simulated')
128
+ path = 'simulated/' + name + '.csv'
129
+ injection_path = 'simulated/' + name + '_injection_parameters.csv'
130
+ self.data.to_csv(path, index=False)
131
+ self.parameters=pd.DataFrame.from_dict([self.parameters])
132
+ self.parameters.to_csv(injection_path, index=False)
97
133
 
98
134
  class SimulateOpticalTransient(object):
99
135
  def __init__(self, model, parameters, pointings_database=None,
@@ -415,7 +451,7 @@ class SimulateOpticalTransient(object):
415
451
  Convert the circular field of view to a radius in radians.
416
452
  :return: survey_radius in radians
417
453
  """
418
- survey_fov_sqrad = self.survey_fov_sqdeg*(np.pi/180.0)
454
+ survey_fov_sqrad = self.survey_fov_sqdeg*(np.pi/180.0)**2
419
455
  survey_radius = np.sqrt(survey_fov_sqrad/np.pi)
420
456
  # survey_radius = np.sqrt(self.survey_fov_sqdeg*((np.pi/180.0)**2.0)/np.pi)
421
457
  return survey_radius