diff --git a/test/detector_tests.py b/test/detector_tests.py new file mode 100644 index 0000000000000000000000000000000000000000..fe30b523427461123812ec53680ea3cf39147e7f --- /dev/null +++ b/test/detector_tests.py @@ -0,0 +1,391 @@ +from context import tupak +from tupak import detector +import unittest +import mock +from mock import MagicMock +import numpy as np +import logging + + +class TestDetector(unittest.TestCase): + + def setUp(self): + self.name = 'name' + self.power_spectral_density = MagicMock() + self.minimum_frequency = 10 + self.maximum_frequency = 20 + self.length = 30 + self.latitude = 1 + self.longitude = 2 + self.elevation = 3 + self.xarm_azimuth = 4 + self.yarm_azimuth = 5 + self.xarm_tilt = 0. + self.yarm_tilt = 0. + # noinspection PyTypeChecker + self.ifo = detector.Interferometer(name=self.name, power_spectral_density=self.power_spectral_density, + minimum_frequency=self.minimum_frequency, + maximum_frequency=self.maximum_frequency, length=self.length, + latitude=self.latitude, longitude=self.longitude, elevation=self.elevation, + xarm_azimuth=self.xarm_azimuth, yarm_azimuth=self.yarm_azimuth, + xarm_tilt=self.xarm_tilt, yarm_tilt=self.yarm_tilt) + + def tearDown(self): + del self.name + del self.power_spectral_density + del self.minimum_frequency + del self.maximum_frequency + del self.length + del self.latitude + del self.longitude + del self.elevation + del self.xarm_azimuth + del self.yarm_azimuth + del self.xarm_tilt + del self.yarm_tilt + del self.ifo + + def test_name_setting(self): + self.assertEqual(self.ifo.name, self.name) + + def test_psd_setting(self): + self.assertEqual(self.ifo.power_spectral_density, self.power_spectral_density) + + def test_min_freq_setting(self): + self.assertEqual(self.ifo.minimum_frequency, self.minimum_frequency) + + def test_max_freq_setting(self): + self.assertEqual(self.ifo.maximum_frequency, self.maximum_frequency) + + def test_length_setting(self): + self.assertEqual(self.ifo.length, self.length) + + def test_latitude_setting(self): + self.assertEqual(self.ifo.latitude, self.latitude) + + def test_longitude_setting(self): + self.assertEqual(self.ifo.longitude, self.longitude) + + def test_elevation_setting(self): + self.assertEqual(self.ifo.elevation, self.elevation) + + def test_xarm_azi_setting(self): + self.assertEqual(self.ifo.xarm_azimuth, self.xarm_azimuth) + + def test_yarm_azi_setting(self): + self.assertEqual(self.ifo.yarm_azimuth, self.yarm_azimuth) + + def test_xarm_tilt_setting(self): + self.assertEqual(self.ifo.xarm_tilt, self.xarm_tilt) + + def test_yarm_tilt_setting(self): + self.assertEqual(self.ifo.yarm_tilt, self.yarm_tilt) + + def test_data_init(self): + self.assertTrue(np.array_equal(self.ifo.data, np.array([]))) + + def test_frequency_array_init(self): + self.assertTrue(np.array_equal(self.ifo.frequency_array, np.array([]))) + + def test_sampling_frequency_init(self): + self.assertIsNone(self.ifo.sampling_frequency) + + def test_sampling_duration_init(self): + self.assertIsNone(self.ifo.duration) + + def test_epoch_init(self): + self.assertEqual(self.ifo.epoch, 0) + + def test_frequency_mask(self): + self.ifo.frequency_array = np.array([8, 10, 13, 15, 20, 22]) + self.assertTrue(np.array_equal(self.ifo.frequency_mask, [False, False, True, True, False, False])) + + def test_vertex_without_update(self): + _ = self.ifo.vertex + with mock.patch('tupak.utils.get_vertex_position_geocentric') as m: + m.return_value = np.array([1]) + self.assertFalse(np.array_equal(self.ifo.vertex, np.array([1]))) + + def test_vertex_with_latitude_update(self): + with mock.patch('tupak.utils.get_vertex_position_geocentric') as m: + m.return_value = np.array([1]) + self.ifo.latitude = 5 + self.assertEqual(self.ifo.vertex, np.array([1])) + + def test_vertex_with_longitude_update(self): + with mock.patch('tupak.utils.get_vertex_position_geocentric') as m: + m.return_value = np.array([1]) + self.ifo.longitude = 5 + self.assertEqual(self.ifo.vertex, np.array([1])) + + def test_vertex_with_elevation_update(self): + with mock.patch('tupak.utils.get_vertex_position_geocentric') as m: + m.return_value = np.array([1]) + self.ifo.elevation = 5 + self.assertEqual(self.ifo.vertex, np.array([1])) + + def test_x_without_update(self): + _ = self.ifo.x + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + + self.assertFalse(np.array_equal(self.ifo.x, + np.array([1]))) + + def test_x_with_xarm_tilt_update(self): + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + self.ifo.xarm_tilt = 0 + self.assertTrue(np.array_equal(self.ifo.x, + np.array([1]))) + + def test_x_with_xarm_azimuth_update(self): + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + self.ifo.xarm_azimuth = 0 + self.assertTrue(np.array_equal(self.ifo.x, + np.array([1]))) + + def test_x_with_longitude_update(self): + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + self.ifo.longitude = 0 + self.assertTrue(np.array_equal(self.ifo.x, + np.array([1]))) + + def test_x_with_latitude_update(self): + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + self.ifo.latitude = 0 + self.assertTrue(np.array_equal(self.ifo.x, + np.array([1]))) + + def test_y_without_update(self): + _ = self.ifo.y + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + + self.assertFalse(np.array_equal(self.ifo.y, + np.array([1]))) + + def test_y_with_yarm_tilt_update(self): + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + self.ifo.yarm_tilt = 0 + self.assertTrue(np.array_equal(self.ifo.y, + np.array([1]))) + + def test_y_with_yarm_azimuth_update(self): + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + self.ifo.yarm_azimuth = 0 + self.assertTrue(np.array_equal(self.ifo.y, + np.array([1]))) + + def test_y_with_longitude_update(self): + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + self.ifo.longitude = 0 + self.assertTrue(np.array_equal(self.ifo.y, + np.array([1]))) + + def test_y_with_latitude_update(self): + self.ifo.unit_vector_along_arm = MagicMock(return_value=np.array([1])) + self.ifo.latitude = 0 + self.assertTrue(np.array_equal(self.ifo.y, + np.array([1]))) + + def test_detector_tensor_without_update(self): + _ = self.ifo.detector_tensor + with mock.patch('numpy.einsum') as m: + m.return_value = 1 + self.assertIsInstance(self.ifo.detector_tensor, np.ndarray) + + def test_detector_tensor_with_x_update(self): + with mock.patch('numpy.einsum') as m: + m.return_value = 1 + self.ifo.xarm_azimuth = 12 + self.assertEqual(self.ifo.detector_tensor, 0) + + def test_detector_tensor_with_y_update(self): + with mock.patch('numpy.einsum') as m: + m.return_value = 1 + self.ifo.yarm_azimuth = 12 + self.assertEqual(self.ifo.detector_tensor, 0) + + def test_amplitude_spectral_density_array(self): + self.ifo.power_spectral_density.power_spectral_density_interpolated = MagicMock(return_value=np.array([1, 4])) + self.assertTrue(np.array_equal(self.ifo.amplitude_spectral_density_array, np.array([1, 2]))) + + def test_power_spectral_density_array(self): + self.ifo.power_spectral_density.power_spectral_density_interpolated = MagicMock(return_value=np.array([1, 4])) + self.assertTrue(np.array_equal(self.ifo.power_spectral_density_array, np.array([1, 4]))) + + def test_antenna_response_default(self): + with mock.patch('tupak.utils.get_polarization_tensor') as m: + with mock.patch('numpy.einsum') as n: + m.return_value = 0 + n.return_value = 1 + self.assertEqual(self.ifo.antenna_response(234, 52, 54, 76, 'plus'), 1) + + def test_antenna_response_einsum(self): + with mock.patch('tupak.utils.get_polarization_tensor') as m: + m.return_value = np.ones((3, 3)) + self.assertAlmostEqual(self.ifo.antenna_response(234, 52, 54, 76, 'plus'), self.ifo.detector_tensor.sum()) + + def test_get_detector_response_default_behaviour(self): + self.ifo.antenna_response = MagicMock(return_value=1) + self.ifo.time_delay_from_geocenter = MagicMock(return_value = 0) + self.ifo.epoch = 0 + self.minimum_frequency = 10 + self.maximum_frequency = 20 + self.ifo.frequency_array = np.array([8, 12, 16, 20, 24]) + plus = np.array([1, 2, 3, 4, 5]) + response = self.ifo.get_detector_response( + waveform_polarizations=dict(plus=plus), + parameters=dict(ra=0, dec=0, geocent_time=0, psi=0)) + self.assertTrue(np.array_equal(response, plus*self.ifo.frequency_mask*np.exp(-0j))) + + def test_get_detector_response_with_dt(self): + self.ifo.antenna_response = MagicMock(return_value=1) + self.ifo.time_delay_from_geocenter = MagicMock(return_value = 0) + self.ifo.epoch = 1 + self.minimum_frequency = 10 + self.maximum_frequency = 20 + self.ifo.frequency_array = np.array([8, 12, 16, 20, 24]) + plus = np.array([1, 2, 3, 4, 5]) + response = self.ifo.get_detector_response( + waveform_polarizations=dict(plus=plus), + parameters=dict(ra=0, dec=0, geocent_time=0, psi=0)) + self.assertTrue(np.array_equal(response, plus*self.ifo.frequency_mask*np.exp(-1j*2*np.pi*self.ifo.frequency_array))) + + def test_get_detector_response_multiple_modes(self): + self.ifo.antenna_response = MagicMock(return_value=1) + self.ifo.time_delay_from_geocenter = MagicMock(return_value = 0) + self.ifo.epoch = 0 + self.minimum_frequency = 10 + self.maximum_frequency = 20 + self.ifo.frequency_array = np.array([8, 12, 16, 20, 24]) + plus = np.array([1, 2, 3, 4, 5]) + cross = np.array([6, 7, 8, 9, 10]) + response = self.ifo.get_detector_response( + waveform_polarizations=dict(plus=plus, cross=cross), + parameters=dict(ra=0, dec=0, geocent_time=0, psi=0)) + self.assertTrue(np.array_equal(response, (plus+cross)*self.ifo.frequency_mask*np.exp(-0j))) + + def test_inject_signal_no_waveform_polarizations(self): + with mock.patch('logging.warning') as m: + m.side_effect = KeyError('foo') + with self.assertRaises(KeyError): + self.ifo.inject_signal(waveform_polarizations=None, parameters=None) + + def test_inject_signal_sets_data_with_existing_data_array(self): + self.ifo.get_detector_response = MagicMock(return_value=np.array([1])) + self.ifo.frequency_array = np.array([0, 1]) + with mock.patch('tupak.utils.optimal_snr_squared') as m: + with mock.patch('tupak.utils.matched_filter_snr_squared') as n: + m.return_value = 0 + n.return_value = 0 + self.ifo.data = np.array([1]) + self.ifo.inject_signal(waveform_polarizations='foo', parameters=None) + self.assertEqual(self.ifo.data, np.array([2])) + + def test_inject_signal_sets_data_without_data_array(self): + self.ifo.get_detector_response = MagicMock(return_value=np.array([1])) + self.ifo.frequency_array = np.array([0, 1]) + with mock.patch('tupak.utils.optimal_snr_squared') as m: + with mock.patch('tupak.utils.matched_filter_snr_squared') as n: + m.return_value = 0 + n.return_value = 0 + self.ifo.data = 1 + self.ifo.data = np.array([]) + self.ifo.inject_signal(waveform_polarizations='foo', parameters=None) + self.assertEqual(self.ifo.data, np.array([1])) + + def test_unit_vector_along_arm_default(self): + with mock.patch('logging.warning') as m: + m.side_effect = KeyError('foo') + with self.assertRaises(KeyError): + self.ifo.unit_vector_along_arm('z') + + def test_unit_vector_along_arm_x(self): + with mock.patch('numpy.array') as m: + m.return_value = 1 + self.ifo.xarm_tilt = 0 + self.ifo.xarm_azimuth = 0 + self.ifo.yarm_tilt = 0 + self.ifo.yarm_azimuth = np.pi + self.assertAlmostEqual(self.ifo.unit_vector_along_arm('x'), 1) + + def test_unit_vector_along_arm_y(self): + with mock.patch('numpy.array') as m: + m.return_value = 1 + self.ifo.xarm_tilt = 0 + self.ifo.xarm_azimuth = 0 + self.ifo.yarm_tilt = 0 + self.ifo.yarm_azimuth = np.pi + self.assertAlmostEqual(self.ifo.unit_vector_along_arm('y'), -1) + + def test_set_data_raises_value_error(self): + with self.assertRaises(ValueError): + self.ifo.set_data(sampling_frequency=1, duration=1) + + def test_set_data_sets_data_from_frequency_domain_strain(self): + with mock.patch('tupak.utils.create_frequency_series') as m: + m.return_value = np.array([1]) + self.ifo.minimum_frequency = 0 + self.ifo.maximum_frequency = 3 + self.ifo.power_spectral_density.get_noise_realisation = MagicMock(return_value=(1, np.array([2]))) + self.ifo.set_data(sampling_frequency=1, duration=1, frequency_domain_strain=np.array([1])) + self.assertTrue(np.array_equal(self.ifo.data, np.array([1]))) + + def test_set_data_sets_frequencies_from_frequency_domain_strain(self): + with mock.patch('tupak.utils.create_frequency_series') as m: + m.return_value = np.array([1]) + self.ifo.minimum_frequency = 0 + self.ifo.maximum_frequency = 3 + self.ifo.power_spectral_density.get_noise_realisation = MagicMock(return_value=(1, np.array([2]))) + self.ifo.set_data(sampling_frequency=1, duration=1, frequency_domain_strain=np.array([1])) + self.assertTrue(np.array_equal(self.ifo.frequency_array, np.array([1]))) + + def test_set_data_sets_frequencies_from_spectral_density(self): + with mock.patch('tupak.utils.create_frequency_series') as m: + m.return_value = np.array([1]) + self.ifo.minimum_frequency = 0 + self.ifo.maximum_frequency = 3 + self.ifo.power_spectral_density.get_noise_realisation = MagicMock(return_value=(1, np.array([2]))) + self.ifo.set_data(sampling_frequency=1, duration=1, from_power_spectral_density=True) + self.assertTrue(np.array_equal(self.ifo.frequency_array, np.array([2]))) + + def test_set_data_sets_epoch(self): + with mock.patch('tupak.utils.create_frequency_series') as m: + m.return_value = np.array([1]) + self.ifo.minimum_frequency = 0 + self.ifo.maximum_frequency = 3 + self.ifo.power_spectral_density.get_noise_realisation = MagicMock(return_value=(1, np.array([2]))) + self.ifo.set_data(sampling_frequency=1, duration=1, from_power_spectral_density=True, epoch=4) + self.assertEqual(self.ifo.epoch, 4) + + def test_set_data_sets_sampling_frequency(self): + with mock.patch('tupak.utils.create_frequency_series') as m: + m.return_value = np.array([1]) + self.ifo.minimum_frequency = 0 + self.ifo.maximum_frequency = 3 + self.ifo.power_spectral_density.get_noise_realisation = MagicMock(return_value=(1, np.array([2]))) + self.ifo.set_data(sampling_frequency=1, duration=1, from_power_spectral_density=True, epoch=4) + self.assertEqual(self.ifo.sampling_frequency, 1) + + def test_set_data_sets_duration(self): + with mock.patch('tupak.utils.create_frequency_series') as m: + m.return_value = np.array([1]) + self.ifo.minimum_frequency = 0 + self.ifo.maximum_frequency = 3 + self.ifo.power_spectral_density.get_noise_realisation = MagicMock(return_value=(1, np.array([2]))) + self.ifo.set_data(sampling_frequency=1, duration=1, from_power_spectral_density=True, epoch=4) + self.assertEqual(self.ifo.duration, 1) + + def test_time_delay_from_geocenter(self): + with mock.patch('tupak.utils.time_delay_geocentric') as m: + m.return_value = 1 + self.assertEqual(self.ifo.time_delay_from_geocenter(1, 2, 3), 1) + + def test_vertex_position_geocentric(self): + with mock.patch('tupak.utils.vertex_position_geocentric') as m: + m.return_value = 1 + self.assertEqual(self.ifo.vertex_position_geocentric(), 1) + + def test_whitened_data(self): + self.ifo.data = np.array([2]) + self.ifo.power_spectral_density.power_spectral_density_interpolated = MagicMock(return_value=np.array([1])) + self.assertTrue(np.array_equal(self.ifo.whitened_data, np.array([2]))) diff --git a/test/make_standard_data.py b/test/make_standard_data.py index e01f86c9af429d126f4c81aef233a568cc28f76a..d4407acb5c7fa5713e4c6fedde9189b7545574b5 100644 --- a/test/make_standard_data.py +++ b/test/make_standard_data.py @@ -44,7 +44,7 @@ IFO = tupak.detector.get_interferometer_with_fake_noise_and_injection(name='H1', sampling_frequency=sampling_frequency) hf_signal_and_noise = IFO.data -frequencies = tupak.utils.create_fequency_series( +frequencies = tupak.utils.create_frequency_series( sampling_frequency=sampling_frequency, duration=time_duration) if __name__ == '__main__': diff --git a/tupak/detector.py b/tupak/detector.py index d2aff36ccf0dd1b7bec83a4672f1577ff173beda..32206a4e2ef3b3ae7ffc363278c1dcde79cbf971 100644 --- a/tupak/detector.py +++ b/tupak/detector.py @@ -1,14 +1,15 @@ from __future__ import division, print_function, absolute_import -import numpy as np -import tupak + import logging import os -from scipy.interpolate import interp1d + import matplotlib.pyplot as plt -from scipy import signal -from gwpy.timeseries import TimeSeries +import numpy as np from gwpy.signal import filter_design +from scipy import signal +from scipy.interpolate import interp1d +import tupak from . import utils @@ -51,7 +52,7 @@ class Interferometer(object): self.__x_updated = False self.__y_updated = False self.__vertex_updated = False - self.__detector_tensor_update = False + self.__detector_tensor_updated = False self.name = name self.minimum_frequency = minimum_frequency @@ -66,10 +67,11 @@ class Interferometer(object): self.yarm_tilt = yarm_tilt self.power_spectral_density = power_spectral_density self.data = np.array([]) - self.frequency_array = [] + self.frequency_array = np.array([]) self.sampling_frequency = None self.duration = None self.time_marginalization = False + self.epoch = 0 @property def minimum_frequency(self): @@ -171,7 +173,7 @@ class Interferometer(object): if self.__x_updated is False: self.__x = self.unit_vector_along_arm('x') self.__x_updated = True - self.__detector_tensor_update = False + self.__detector_tensor_updated = False return self.__x @property @@ -179,7 +181,7 @@ class Interferometer(object): if self.__y_updated is False: self.__y = self.unit_vector_along_arm('y') self.__y_updated = True - self.__detector_tensor_update = False + self.__detector_tensor_updated = False return self.__y @property @@ -189,9 +191,9 @@ class Interferometer(object): See Eq. B6 of arXiv:gr-qc/0008066 """ - if self.__detector_tensor_update is False: + if self.__detector_tensor_updated is False: self.__detector_tensor = 0.5 * (np.einsum('i,j->ij', self.x, self.x) - np.einsum('i,j->ij', self.y, self.y)) - self.__detector_tensor_update = True + self.__detector_tensor_updated = True return self.__detector_tensor def antenna_response(self, ra, dec, time, psi, mode): @@ -227,7 +229,7 @@ class Interferometer(object): det_response = self.antenna_response( parameters['ra'], parameters['dec'], - self.epoch,#parameters['geocent_time'], + parameters['geocent_time'], parameters['psi'], mode) signal[mode] = waveform_polarizations[mode] * det_response @@ -247,7 +249,7 @@ class Interferometer(object): dt = self.epoch - (parameters['geocent_time'] - time_shift) signal_ifo = signal_ifo * np.exp( - -1j * 2 * np.pi * dt * self.frequency_array) + -1j * 2 * np.pi * dt * self.frequency_array) return signal_ifo @@ -264,9 +266,9 @@ class Interferometer(object): logging.warning('Trying to inject signal which is None.') else: signal_ifo = self.get_detector_response(waveform_polarizations, parameters) - try: + if np.shape(self.data).__eq__(np.shape(signal_ifo)): self.data += signal_ifo - except TypeError: + else: logging.info('Injecting into zero noise.') self.data = signal_ifo opt_snr = np.sqrt(tupak.utils.optimal_snr_squared(signal=signal_ifo, interferometer=self, @@ -289,21 +291,24 @@ class Interferometer(object): Output: n - unit vector along arm in cartesian Earth-based coordinates """ - e_long = np.array([-np.sin(self.__longitude), np.cos(self.__longitude), 0]) - e_lat = np.array([-np.sin(self.__latitude) * np.cos(self.__longitude), - -np.sin(self.__latitude) * np.sin(self.__longitude), np.cos(self.__latitude)]) - e_h = np.array([np.cos(self.__latitude) * np.cos(self.__longitude), - np.cos(self.__latitude) * np.sin(self.__longitude), np.sin(self.__latitude)]) if arm == 'x': - n = np.cos(self.__xarm_tilt) * np.cos(self.__xarm_azimuth) * e_long + np.cos(self.__xarm_tilt) \ - * np.sin(self.__xarm_azimuth) * e_lat + np.sin(self.__xarm_tilt) * e_h + return self.__calculate_arm(self.xarm_tilt, self.xarm_azimuth) elif arm == 'y': - n = np.cos(self.__yarm_tilt) * np.cos(self.__yarm_azimuth) * e_long + np.cos(self.__yarm_tilt) \ - * np.sin(self.__yarm_azimuth) * e_lat + np.sin(self.__yarm_tilt) * e_h + return self.__calculate_arm(self.yarm_tilt, self.yarm_azimuth) else: logging.warning('Not a recognized arm, aborting!') return - return n + + def __calculate_arm(self, arm_tilt, arm_azimuth): + e_long = np.array([-np.sin(self.__longitude), np.cos(self.__longitude), 0]) + e_lat = np.array([-np.sin(self.__latitude) * np.cos(self.__longitude), + -np.sin(self.__latitude) * np.sin(self.__longitude), np.cos(self.__latitude)]) + e_h = np.array([np.cos(self.__latitude) * np.cos(self.__longitude), + np.cos(self.__latitude) * np.sin(self.__longitude), np.sin(self.__latitude)]) + + return np.cos(arm_tilt) * np.cos(arm_azimuth) * e_long +\ + np.cos(arm_tilt) * np.sin(arm_azimuth) * e_lat + \ + np.sin(arm_tilt) * e_h @property def amplitude_spectral_density_array(self): @@ -318,7 +323,7 @@ class Interferometer(object): return self.power_spectral_density.power_spectral_density_interpolated(self.frequency_array) def set_data(self, sampling_frequency, duration, epoch=0, - from_power_spectral_density=None, + from_power_spectral_density=False, frequency_domain_strain=None): """ Set the interferometer frequency-domain stain and accompanying PSD values. @@ -343,8 +348,8 @@ class Interferometer(object): if frequency_domain_strain is not None: logging.info( 'Setting {} data using provided frequency_domain_strain'.format(self.name)) - frequencies = utils.create_fequency_series(sampling_frequency, duration) - elif from_power_spectral_density is not None: + frequencies = utils.create_frequency_series(sampling_frequency, duration) + elif from_power_spectral_density is True: logging.info( 'Setting {} data using noise realization from provided' 'power_spectal_density'.format(self.name)) @@ -599,13 +604,13 @@ def get_interferometer_with_open_data( utils.check_directory_exists_and_if_not_mkdir(outdir) strain = utils.get_open_strain_data( - name, center_time-T/2, center_time+T/2, outdir=outdir, cache=cache, - raw_data_file=raw_data_file, **kwargs) + name, center_time - T / 2, center_time + T / 2, outdir=outdir, cache=cache, + raw_data_file=raw_data_file, **kwargs) strain_psd = utils.get_open_strain_data( - name, center_time+psd_offset, center_time+psd_offset+psd_duration, - raw_data_file=raw_data_file, - outdir=outdir, cache=cache, **kwargs) + name, center_time + psd_offset, center_time + psd_offset + psd_duration, + raw_data_file=raw_data_file, + outdir=outdir, cache=cache, **kwargs) sampling_frequency = int(strain.sample_rate.value) @@ -618,10 +623,10 @@ def get_interferometer_with_open_data( # Create and save PSDs NFFT = int(sampling_frequency * T) - window = signal.tukey(NFFT, alpha=alpha) + window = signal.windows.tukey(NFFT, alpha=alpha) psd = strain_psd.psd(fftlength=T, window=window) psd_file = '{}/{}_PSD_{}_{}.txt'.format( - outdir, name, center_time+psd_offset, psd_duration) + outdir, name, center_time + psd_offset, psd_duration) with open('{}'.format(psd_file), 'w+') as file: for f, p in zip(psd.frequencies.value, psd.value): file.write('{} {}\n'.format(f, p)) @@ -631,7 +636,7 @@ def get_interferometer_with_open_data( # Apply Tukey window N = len(time_series) - strain = strain * signal.tukey(N, alpha=alpha) + strain = strain * signal.windows.tukey(N, alpha=alpha) interferometer = get_empty_interferometer(name) interferometer.power_spectral_density = PowerSpectralDensity( @@ -648,7 +653,7 @@ def get_interferometer_with_open_data( '-C0', label=name) ax.loglog(interferometer.frequency_array, interferometer.amplitude_spectral_density_array, - '-C1', lw=0.5, label=name+' ASD') + '-C1', lw=0.5, label=name + ' ASD') ax.grid('on') ax.set_ylabel(r'strain [strain/$\sqrt{\rm Hz}$]') ax.set_xlabel(r'frequency [Hz]') @@ -713,7 +718,7 @@ def get_interferometer_with_fake_noise_and_injection( '-C0', label=name) ax.loglog(interferometer.frequency_array, interferometer.amplitude_spectral_density_array, - '-C1', lw=0.5, label=name+' ASD') + '-C1', lw=0.5, label=name + ' ASD') ax.loglog(interferometer.frequency_array, abs(interferometer_signal), '-C2', label='Signal') ax.grid('on') diff --git a/tupak/utils.py b/tupak/utils.py index fbb4bfe4882bccc33e1add1c4a72aae9ace2b91a..6b6f575ae53843ff279d8d6a076d224b1c4b467b 100644 --- a/tupak/utils.py +++ b/tupak/utils.py @@ -65,7 +65,7 @@ def gps_time_to_gmst(gps_time): return gmst -def create_fequency_series(sampling_frequency, duration): +def create_frequency_series(sampling_frequency, duration): """ Create a frequency series with the correct length and spacing. @@ -105,7 +105,7 @@ def create_white_noise(sampling_frequency, duration): delta_freq = 1./duration - frequencies = create_fequency_series(sampling_frequency, duration) + frequencies = create_frequency_series(sampling_frequency, duration) norm1 = 0.5*(1./delta_freq)**0.5 re1 = np.random.normal(0, norm1, len(frequencies)) diff --git a/tupak/waveform_generator.py b/tupak/waveform_generator.py index 7ffb7c84e394514addd5d49eb7325c6b63a1538b..c53a8fd80fba4e6af6a6c2440c02b9c02ed445b3 100644 --- a/tupak/waveform_generator.py +++ b/tupak/waveform_generator.py @@ -94,7 +94,7 @@ class WaveformGenerator(object): @property def frequency_array(self): if self.__frequency_array_updated is False: - self.__frequency_array = utils.create_fequency_series( + self.__frequency_array = utils.create_frequency_series( self.sampling_frequency, self.time_duration) self.__frequency_array_updated = True