Commit 34b47e16 authored by moritz's avatar moritz
Browse files

Moritz Huebner: Moved the WaveformGenerator into a separate file

parent d1584202
......@@ -7,5 +7,6 @@ import peyote.prior as prior
import peyote.parameter as parameter
import peyote.source as source
import peyote.likelihood as likelihood
import peyote.waveform_generator as waveform_generator
from peyote.sampler import run_sampler
from peyote.utils import setup_logger
......@@ -2,7 +2,6 @@ from __future__ import division, print_function
import peyote
import numpy as np
import os.path
import inspect
import os
......@@ -46,56 +45,6 @@ def LALBinaryBlackHole(
return {'plus': h_plus, 'cross': h_cross}
class WaveformGenerator:
""" A waveform generator
Parameters
----------
sampling_frequency: float
The sampling frequency to sample at
time_duration: float
Time duration of data
source_model: func
A python function taking some arguments and returning the frequency
domain strain. Note the first argument must be the frequencies at
which to compute the strain
Note: the arguments of source_model (except the first, which is the
frequencies at which to compute the strain) will be added to the
WaveformGenerator object and initialised to `None`.
"""
def __init__(self, name, sampling_frequency, time_duration, source_model):
self.parameter_keys = inspect.getargspec(source_model).args
self.parameter_keys.pop(0)
for a in self.parameter_keys:
setattr(self, a, None)
self.name = name
self.sampling_frequency = sampling_frequency
self.time_duration = time_duration
self.time_array = peyote.utils.create_time_series(
sampling_frequency, time_duration)
self.frequency_array = peyote.utils.create_fequency_series(
sampling_frequency, time_duration)
self.source_model = source_model
def frequency_domain_strain(self):
""" Wrapper to source_model """
kwargs = {k: self.__dict__[k] for k in self.parameter_keys}
return self.source_model(self.frequency_array, **kwargs)
def set_values(self, dictionary):
""" Given a dictionary of values, set the class attributes """
for k in self.parameter_keys:
try:
setattr(self, k, dictionary[k])
except KeyError:
raise KeyError(
'The provided dictionary did not contain key {}'.format(k))
class Source:
def __init__(self):
pass
......
import inspect
import peyote
class WaveformGenerator:
""" A waveform generator
Parameters
----------
sampling_frequency: float
The sampling frequency to sample at
time_duration: float
Time duration of data
source_model: func
A python function taking some arguments and returning the frequency
domain strain. Note the first argument must be the frequencies at
which to compute the strain
Note: the arguments of source_model (except the first, which is the
frequencies at which to compute the strain) will be added to the
WaveformGenerator object and initialised to `None`.
"""
def __init__(self, name, sampling_frequency, time_duration, source_model):
self.parameter_keys = inspect.getargspec(source_model).args
self.parameter_keys.pop(0)
for a in self.parameter_keys:
setattr(self, a, None)
self.name = name
self.sampling_frequency = sampling_frequency
self.time_duration = time_duration
self.time_array = peyote.utils.create_time_series(
sampling_frequency, time_duration)
self.frequency_array = peyote.utils.create_fequency_series(
sampling_frequency, time_duration)
self.source_model = source_model
def frequency_domain_strain(self):
""" Wrapper to source_model """
kwargs = {k: self.__dict__[k] for k in self.parameter_keys}
return self.source_model(self.frequency_array, **kwargs)
def set_values(self, dictionary):
""" Given a dictionary of values, set the class attributes """
for k in self.parameter_keys:
try:
setattr(self, k, dictionary[k])
except KeyError:
raise KeyError(
'The provided dictionary did not contain key {}'.format(k))
\ No newline at end of file
......@@ -27,7 +27,7 @@ simulation_parameters = dict(
)
# Create the waveformgenerator using a LAL BinaryBlackHole source function
waveformgenerator = peyote.source.WaveformGenerator(
waveformgenerator = peyote.waveform_generator.WaveformGenerator(
'BBH', sampling_frequency, time_duration, peyote.source.LALBinaryBlackHole)
waveformgenerator.set_values(simulation_parameters)
hf_signal = waveformgenerator.frequency_domain_strain()
......
......@@ -2,6 +2,8 @@ import peyote
import os
import numpy as np
import waveform_generator
np.random.seed(10)
time_duration = 1.
......@@ -23,7 +25,7 @@ simulation_parameters = dict(
psi=2.659
)
waveformgenerator = peyote.source.WaveformGenerator(
waveformgenerator = waveform_generator.WaveformGenerator(
'BBH', sampling_frequency, time_duration, peyote.source.LALBinaryBlackHole)
waveformgenerator.set_values(simulation_parameters)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment