How to use my own waveforms or interferometer in bilby and pbilby?

Hi, I am using some waveforms not included in LALsuite (as well as LALsuite-extra) to analyze several GW events. However, I encountered some troubles when trying to use them in bilby as I am following the example create_own_time_source_model since it doesn’t make use of the parameters conversion function and other things related to real waveforms like SEOBNRv4PHM.
Thanks!

Hello,

If you’re having trouble with bilby, you can try asking specific questions on their github repo or the other web sites listed there in the README file. When you do, I would suggest try including a short working example that reproduces the errors you see or results that are not working for you and explain what are you trying to accomplish and why it’s not working.

Thank you! I will post an issue on github as well:)
Actually, I am trying to use SEOBNRE in bilby. I followed the create_own_time_source_model example and try to make use of conversion function as well, but it seems that something went wrong.
Here’s my code:

# Add the geocent time prior
priors["geocent_time"] = bilby.core.prior.Uniform(
    trigger_time - 0.1, trigger_time + 0.1, name="geocent_time"
)

def SEOBNRE_waveform(time,mass_1,mass_2,spin_1x,spin_1y,spin_1z,spin_2x,spin_2y,spin_2z,eccentricity,luminosity_distance,iota,phase,):
    params = (mass_1,mass_2,spin_1x,spin_1y,spin_1z,spin_2x,spin_2y,spin_2z,eccentricity,luminosity_distance,0,iota,phase,0)
    fMin = minimum_frequency
    srate=sampling_frequency
    Mf_ref=0.002
    waveform, dynamics = calculate_waveform_ep(params, fMin, Mf_ref = Mf_ref, srate=srate, is_coframe=False)
    hpc = waveform.hpc
    plus = hpc.real
    cross = -hpc.imag
    tpeak = waveform.hpc.time[waveform.h22.argpeak]
    plus = TimeSeries(plus,epoch=-tpeak)
    cross = TimeSeries(cross,epoch=-tpeak)
    return {'plus':plus,'cross':cross}


# In this step we define a `waveform_generator`. This is the object which
# creates the frequency-domain strain. In this instance, we are using the
# `lal_binary_black_hole model` source model. We also pass other parameters:
# the waveform approximant and reference frequency and a parameter conversion
# which allows us to sample in chirp mass and ratio rather than component mass
waveform_generator = bilby.gw.WaveformGenerator(
    sampling_frequency=sampling_frequency,
    duration = duration,
    time_domain_source_model=SEOBNRE_waveform,
    parameter_conversion=bilby.gw.conversion.convert_to_lal_binary_black_hole_parameters,
    waveform_arguments={
        "waveform_approximant": "SEOBNRE",
        "reference_frequency": 11,
    },
)

and here’s (part of) my output:

(base) [tanghonglue@swarm01 SEOBNRE]$ vim slurm-8126090.out 

  File "/project/tanghonglue/Injection/SEOBNRE/GW150914.py", line 124, in <module>
    result = bilby.run_sampler(
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/__init__.py", line 264, in run_sampler
    sampler = sampler_class(
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/dynesty.py", line 221, in __init__
    super(Dynesty, self).__init__(
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/base_sampler.py", line 262, in __init__
    self._verify_parameters()
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/base_sampler.py", line 431, in _verify_parameters
    self.log_likelihood(theta)
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/base_sampler.py", line 889, in log_likelihood
    return Sampler.log_likelihood(self, theta)
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/base_sampler.py", line 551, in log_likelihood
    return self.likelihood.log_likelihood()
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/likelihood/base.py", line 853, in log_likelihood
    return self.log_likelihood_ratio() + self.noise_log_likelihood()
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/likelihood/base.py", line 408, in log_likelihood_ratio
    self.waveform_generator.frequency_domain_strain(self.parameters)
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/waveform_generator.py", line 131, in frequency_domain_strain
    return self._calculate_strain(model=self.frequency_domain_source_model,
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/waveform_generator.py", line 171, in _calculate_strain
    self.parameters = parameters
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/waveform_generator.py", line 237, in parameters
00:20 bilby INFO    : Analysis priors:
    new_parameters.pop(key)
KeyError: 'spin_1y'
00:20 bilby INFO    : a_1=Uniform(minimum=0, maximum=0.99, name='a_1', latex_label='$a_1$', unit=None, boundary=None)

and

Traceback (most recent call last):
  File "/project/tanghonglue/Injection/SEOBNRE/GW150914.py", line 124, in <module>
    result = bilby.run_sampler(
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/__init__.py", line 264, in run_sampler
    sampler = sampler_class(
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/dynesty.py", line 221, in __init__
    super(Dynesty, self).__init__(
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/base_sampler.py", line 262, in __init__
    self._verify_parameters()
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/base_sampler.py", line 431, in _verify_parameters
    self.log_likelihood(theta)
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/base_sampler.py", line 889, in log_likelihood
    return Sampler.log_likelihood(self, theta)
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/core/sampler/base_sampler.py", line 551, in log_likelihood
    return self.likelihood.log_likelihood()
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/likelihood/base.py", line 853, in log_likelihood
    return self.log_likelihood_ratio() + self.noise_log_likelihood()
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/likelihood/base.py", line 408, in log_likelihood_ratio
    self.waveform_generator.frequency_domain_strain(self.parameters)
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/waveform_generator.py", line 131, in frequency_domain_strain
    return self._calculate_strain(model=self.frequency_domain_source_model,
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/waveform_generator.py", line 171, in _calculate_strain
    self.parameters = parameters
  File "/home/tanghonglue/project/miniconda3/envs/bilby_mp/lib/python3.9/site-packages/bilby/gw/waveform_generator.py", line 237, in parameters
    new_parameters.pop(key)
KeyError: 'iota'
00:20 bilby INFO    : Analysis priors:
00:20 bilby INFO    : a_1=Uniform(minimum=0, maximum=0.99, name='a_1', latex_label='$a_1$', unit=None, boundary=None)
00:20 bilby INFO    : a_2=Uniform(minimum=0, maximum=0.99, name='a_2', latex_label='$a_2$', unit=None, boundary=None)
00:20 bilby INFO    : chirp_mass=bilby.gw.prior.UniformInComponentsChirpMass(minimum=50, maximum=150, name='chirp_mass', latex_label='$\\mathcal{M}$', unit='$M_{\\odot}$', boundary=None)
00:20 bilby INFO    : eccentricity=LogUniform(minimum=0.0001, maximum=0.4, name='eccentricity', latex_label='$e$', unit=None, boundary=None)

I’m not a user of Bilby, so I can’t give you advice on this one, but maybe someone else in the forum can. From a cursory look at the output logs, it seems it has trouble finding the spin_1y and iota keys, but I would not know what it means in practice.

thanks for reply!I have posted an issue on github and I will check the documents to see whether I can solve this issue;)

1 Like