Commit e6750cbc authored by moritz's avatar moritz
Browse files

Moritz Huebner: Added FFT/IFFT functionality to create strain data for both...

Moritz Huebner: Added FFT/IFFT functionality to create strain data for both domains even if only one source model is given.
parent ef6e8151
......@@ -38,7 +38,9 @@ class WaveformGenerator(object):
if self.frequency_domain_source_model is not None:
return self.frequency_domain_source_model(self.frequency_array, **self.parameters)
elif self.time_domain_source_model is not None:
fft_data, self.frequency_array = utils.nfft(self.time_domain_source_model(self.time_array, **self.parameters), self.sampling_frequency)
fft_data = dict()
fft_data['cross'], self.frequency_array = utils.nfft(self.time_domain_source_model(self.time_array, **self.parameters)['cross'], self.sampling_frequency)
fft_data['plus'], _ = utils.nfft(self.time_domain_source_model(self.time_array, **self.parameters)['plus'], self.sampling_frequency)
return fft_data
else:
raise RuntimeError("No source model given")
......@@ -47,7 +49,10 @@ class WaveformGenerator(object):
if self.time_domain_source_model is not None:
return self.time_domain_source_model(self.time_array, **self.parameters)
elif self.frequency_domain_source_model is not None:
return utils.infft(self.frequency_domain_source_model(self.frequency_array, **self.parameters))
ifft_data = dict()
ifft_data['cross'] = utils.infft(self.frequency_domain_source_model(self.frequency_array, **self.parameters)['cross'], self.sampling_frequency)
ifft_data['plus'] = utils.infft(self.frequency_domain_source_model(self.frequency_array, **self.parameters)['plus'], self.sampling_frequency)
return ifft_data
else:
raise RuntimeError("No source model given")
......@@ -81,16 +86,23 @@ class WaveformGenerator(object):
@parameters.setter
def parameters(self, parameters):
if parameters is None:
parameters = inspect.getargspec(self.frequency_domain_source_model).args
parameters.pop(0)
self.__parameters = dict.fromkeys(parameters)
if self.frequency_domain_source_model is not None:
parameters = inspect.getargspec(self.frequency_domain_source_model).args
parameters.pop(0)
self.__parameters = dict.fromkeys(parameters)
elif self.time_domain_source_model is not None:
parameters = inspect.getargspec(self.time_domain_source_model).args
parameters.pop(0)
self.__parameters = dict.fromkeys(parameters)
elif isinstance(parameters, list):
parameters.pop(0)
self.__parameters = dict.fromkeys(parameters)
elif isinstance(parameters, dict):
for key in self.__parameters.keys():
if key in parameters.keys():
self.__parameters[key] = parameters[key]
self.__parameters = parameters
# for key in self.__parameters.keys():
#
# if key in parameters.keys():
# self.__parameters[key] = parameters[key]
# else:
# raise KeyError('The provided dictionary did not '
# 'contain key {}'.format(key))
......@@ -98,15 +110,6 @@ class WaveformGenerator(object):
raise TypeError('Parameters must either be set as a list of keys or'
' a dictionary of key-value pairs.')
@property
def frequency_domain_source_model(self):
return self.__source_model
@frequency_domain_source_model.setter
def frequency_domain_source_model(self, source_model):
self.__source_model = source_model
self.parameters = inspect.getargspec(source_model).args
@property
def time_duration(self):
return self.__time_duration
......
import tupak
import matplotlib.pyplot as plt
import numpy as np
def frequency_domain_sine_gaussian(f, A, f0, tau, phi0, geocent_time, ra, dec, psi):
arg = -(np.pi * tau * (f-f0))**2 + 1j * phi0
plus = np.sqrt(np.pi) * A * tau * np.exp(arg) / 2.
cross = plus * np.exp(1j*np.pi/2)
return {'plus': plus, 'cross': cross}
def time_domain_sine_gaussian(t, A, t0, f0, tau, phi0, geocent_time, ra, dec, psi):
arg = -(-(t-t0)/tau)**2
plus = A * np.exp(arg) *np.cos(2*np.pi*f0*t + phi0)
cross = plus * np.exp(1j*np.pi/2)
return {'plus': plus, 'cross': cross}
parameters = dict()
parameters['A'] = 10000
parameters['f0'] = 5
parameters['t0'] = 10
parameters['tau'] = 3
parameters['geocent_time'] = 0
parameters['phi0'] = 0
parameters['ra'] = 0
parameters['dec'] = 0
parameters['psi'] = 0
wg = tupak.waveform_generator.WaveformGenerator(time_domain_source_model=time_domain_sine_gaussian, time_duration=2000, sampling_frequency=1000)
wg.parameters = parameters
plt.plot(wg.frequency_array, wg.frequency_domain_strain()['plus'])
plt.xlim(4, 6)
plt.show()
plt.plot(wg.frequency_array, wg.frequency_domain_strain()['cross'])
plt.xlim(4, 6)
plt.show()
plt.plot(wg.time_array, wg.time_domain_strain()['plus'])
plt.xlim(0, 20)
plt.show()
plt.plot(wg.time_array, wg.time_domain_strain()['cross'])
plt.xlim(0, 20)
plt.show()
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