Skip to content
Snippets Groups Projects
Commit 87454beb authored by Colm Talbot's avatar Colm Talbot
Browse files

add psd caching

parent f65c3654
No related branches found
No related tags found
1 merge request!483add psd caching
Pipeline #60743 failed
......@@ -619,7 +619,10 @@ class Interferometer(object):
array_like: An array representation of the ASD
"""
return self.power_spectral_density_array ** 0.5
return (
self.power_spectral_density.get_amplitude_spectral_density_array(
frequency_array=self.frequency_array) *
self.strain_data.window_factor**0.5)
@property
def power_spectral_density_array(self):
......@@ -632,8 +635,10 @@ class Interferometer(object):
array_like: An array representation of the PSD
"""
return (self.power_spectral_density.power_spectral_density_interpolated(self.frequency_array) *
self.strain_data.window_factor)
return (
self.power_spectral_density.get_power_spectral_density_array(
frequency_array=self.frequency_array) *
self.strain_data.window_factor)
@property
def frequency_array(self):
......
......@@ -47,6 +47,15 @@ class PowerSpectralDensity(object):
self.asd_array = asd_array
self.psd_file = psd_file
self.asd_file = asd_file
self._cache = dict(
frequency_array=np.array([]), psd_array=None, asd_array=None)
self._update_cache(self.frequency_array)
def _update_cache(self, frequency_array):
psd_array = self.power_spectral_density_interpolated(frequency_array)
self._cache['psd_array'] = psd_array
self._cache['asd_array'] = psd_array**0.5
self._cache['frequency_array'] = frequency_array
def __eq__(self, other):
if self.psd_file == other.psd_file \
......@@ -183,6 +192,16 @@ class PowerSpectralDensity(object):
bounds_error=False,
fill_value=np.inf)
def get_power_spectral_density_array(self, frequency_array):
if not np.array_equal(frequency_array, self._cache['frequency_array']):
self._update_cache(frequency_array=frequency_array)
return self._cache['psd_array']
def get_amplitude_spectral_density_array(self, frequency_array):
if not np.array_equal(frequency_array, self._cache['frequency_array']):
self._update_cache(frequency_array=frequency_array)
return self._cache['asd_array']
@property
def power_spectral_density_interpolated(self):
return self.__power_spectral_density_interpolated
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment