Update sources to be functions
An idea inspired by discussion with @paul-lasky and @moritz.huebner.
Users should be able to input a function alone for the source and shouldn't have to worry about subclassing something. This enables this for the current implementation, and could easily be modified for the changes suggested in !13 (merged). Additionally I think it solves (my) issue with !13 (merged) - namely that user defined sources are subject to errors.
Key changes
- The
Source
class is replaced by aWaveformGenerator
class
This is really just a more accurate name for what is currently implemented. As noted by Moritz, semantically the Source
(i.e. a BBH) doesn't care about the frequencies or time-series it is computed at.
- The
WaveformGenerator
take a functionsource_model
which returns the frequency-domain strain. It then does the introspection to work out what parameters thesource_model
needs and defaults them toNone
.
Currently, it still uses "the pass in the parameters" when calculating the frequency domain strain approach. But can easily be modified to fit with !13 (merged) . We can also add functions to set the values (if for example one wants to inject a signal).
Example
Here is psuedo-code example of how it will eventually work (the BasicTutorial.py
currently does work but is missing some of the functionality described here).
def BBH(frequency_array, mass_1, mass_2, luminosity_distance, spin_1, spin_2,
iota, phase, waveform_approximant, reference_frequency, ra, dec,
geocent_time, psi):
.... #The usual stuff using lalsim
return {'plus': h_plus, 'cross': h_cross}
time_duration = 1.
sampling_frequency = 4096.
waveformgenerator = peyote.source.WaveformGenerator('BBH', sampling_frequency, time_duration, BBH)
# Inject a signal
waveformgenerator.set_parameters(mass_1=10, mass_2=5, ....)
hf_signal = waveformgenerator.frequency_domain_strain(simulation_parameters)
# Simulate the data in H1
...
IFOs = [H1, L1]
likelihood = peyote.likelihood.likelihood(IFOs, waveformgenerator)
# Pass this likelihood and a prior to the sampler
Advantages
- Can satisfy !13 (merged)
- Easy for users to define their own models
- Instance variables (i.e.
mass_1
etc) not required at initialisation, but explicitly set before using (either for an injection or inference).
TO DO
-
Add a default waveform generator (e.g. waveformgenerator = peyote.BBH
) -
If accepted, should source.py be renamed? -
Figure out how to specify if it is a time-domain and frequency-domain and add the approach FFTing functions -
Update to work with !13 (merged)
Thoughts?