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

**URL:** <https://ask.igwn.org/t/how-to-use-my-own-waveforms-or-interferometer-in-bilby-and-pbilby/1114>\
**Category:** Data Analysis\
**Created:** [October 6, 2024, 4:50am UTC](https://ask.igwn.org/t/how-to-use-my-own-waveforms-or-interferometer-in-bilby-and-pbilby/1114 "2024-10-06T04:50:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CalTNG](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@CalTNG](https://ask.igwn.org/u/CalTNG)\
**Post date:** [October 6, 2024, 4:50am UTC](https://ask.igwn.org/t/how-to-use-my-own-waveforms-or-interferometer-in-bilby-and-pbilby/1114/1 "2024-10-06T04:50:05Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![martinberoiz](https://yyz1.discourse-cdn.com/flex031/user_avatar/ask.igwn.org/martinberoiz/32/11_2.png) [@martinberoiz](https://ask.igwn.org/u/martinberoiz)\
**Post date:** [October 6, 2024, 4:00pm UTC](https://ask.igwn.org/t/how-to-use-my-own-waveforms-or-interferometer-in-bilby-and-pbilby/1114/2 "2024-10-06T16:00:54Z")

</div>

Hello,

If you’re having trouble with bilby, you can try asking specific questions on their [github repo](https://github.com/bilby-dev/bilby) 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.

---

<div class="post-metadata">

**Author:** ![CalTNG](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@CalTNG](https://ask.igwn.org/u/CalTNG)\
**Post date:** [October 6, 2024, 4:33pm UTC](https://ask.igwn.org/t/how-to-use-my-own-waveforms-or-interferometer-in-bilby-and-pbilby/1114/3 "2024-10-06T16:33:44Z")

</div>

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:

```auto
# 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:

```auto
(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

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![martinberoiz](https://yyz1.discourse-cdn.com/flex031/user_avatar/ask.igwn.org/martinberoiz/32/11_2.png) [@martinberoiz](https://ask.igwn.org/u/martinberoiz)\
**Post date:** [October 7, 2024, 4:39pm UTC](https://ask.igwn.org/t/how-to-use-my-own-waveforms-or-interferometer-in-bilby-and-pbilby/1114/4 "2024-10-07T16:39:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CalTNG](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@CalTNG](https://ask.igwn.org/u/CalTNG)\
**Post date:** [October 8, 2024, 7:04am UTC](https://ask.igwn.org/t/how-to-use-my-own-waveforms-or-interferometer-in-bilby-and-pbilby/1114/5 "2024-10-08T07:04:29Z")

</div>

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