Commit 11aeb6eb authored by moritz's avatar moritz
Browse files

Moritz Huebner: Implemented time_duration and sampling_frequency as properties with setters

* Flags are now used to signal if the frequency_array and time_array properties need to be calculated again
* Should bring significant speed improvement
parent bbdc2079
...@@ -2,6 +2,7 @@ import inspect ...@@ -2,6 +2,7 @@ import inspect
from . import utils from . import utils
class WaveformGenerator(object): class WaveformGenerator(object):
""" A waveform generator """ A waveform generator
...@@ -28,25 +29,40 @@ class WaveformGenerator(object): ...@@ -28,25 +29,40 @@ class WaveformGenerator(object):
self.sampling_frequency = sampling_frequency self.sampling_frequency = sampling_frequency
self.source_model = source_model self.source_model = source_model
self.parameters = parameters self.parameters = parameters
self.__frequency_array_updated = False
self.__time_array_updated = False
def frequency_domain_strain(self):
""" Wrapper to source_model """
return self.source_model(self.frequency_array, **self.parameters)
@property @property
def frequency_array(self): def frequency_array(self):
return utils.create_fequency_series(self.sampling_frequency, if self.__frequency_array_updated:
self.time_duration) return self.__frequency_array
else:
self.__frequency_array = utils.create_fequency_series(
self.sampling_frequency,
self.time_duration)
self.__frequency_array_updated = True
return self.__frequency_array
@property @property
def time_array(self): def time_array(self):
return utils.create_time_series(self.sampling_frequency, if self.__time_array_updated:
return self.__time_array
else:
self.__time_array = utils.create_time_series(
self.sampling_frequency,
self.time_duration) self.time_duration)
self.__time_array_updated = True
return self.__time_array
@property @property
def parameters(self): def parameters(self):
return self.__parameters return self.__parameters
@property
def source_model(self):
return self.__source_model
@parameters.setter @parameters.setter
def parameters(self, parameters): def parameters(self, parameters):
if parameters is None: if parameters is None:
...@@ -67,12 +83,31 @@ class WaveformGenerator(object): ...@@ -67,12 +83,31 @@ class WaveformGenerator(object):
raise TypeError('Parameters must either be set as a list of keys or' raise TypeError('Parameters must either be set as a list of keys or'
' a dictionary of key-value pairs.') ' a dictionary of key-value pairs.')
@property
def source_model(self):
return self.__source_model
@source_model.setter @source_model.setter
def source_model(self, source_model): def source_model(self, source_model):
self.__source_model = source_model self.__source_model = source_model
self.parameters = inspect.getargspec(source_model).args self.parameters = inspect.getargspec(source_model).args
def frequency_domain_strain(self): @property
""" Wrapper to source_model """ def time_duration(self):
return self.source_model(self.frequency_array, **self.parameters) return self.__time_duration
@time_duration.setter
def time_duration(self, time_duration):
self.__time_duration = time_duration
self.__frequency_array_updated = False
self.__time_array_updated = False
@property
def sampling_frequency(self):
return self.__sampling_frequency
@sampling_frequency.setter
def sampling_frequency(self, sampling_frequency):
self.__sampling_frequency = sampling_frequency
self.__frequency_array_updated = False
self.__time_array_updated = False
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