diff --git a/test/detector_tests.py b/test/detector_tests.py index aefff9ef2ab074fca50c1223a4a96735684921f6..e31265d15764c67e0a3ffa83bd5601fc009c2452 100644 --- a/test/detector_tests.py +++ b/test/detector_tests.py @@ -8,6 +8,8 @@ from mock import patch import numpy as np import scipy.signal.windows import gwpy +import os +import logging class TestDetector(unittest.TestCase): @@ -191,14 +193,6 @@ class TestDetector(unittest.TestCase): 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.gw.utils.get_polarization_tensor') as m: with mock.patch('numpy.einsum') as n: @@ -790,5 +784,201 @@ class TestInterferometerList(unittest.TestCase): self.assertListEqual([self.ifo1.name, new_ifo.name, self.ifo2.name], names) +class TestPowerSpectralDensityWithoutFiles(unittest.TestCase): + + def setUp(self): + self.frequency_array = np.array([1., 2., 3.]) + self.psd_array = np.array([16., 25., 36.]) + self.asd_array = np.array([4., 5., 6.]) + + def tearDown(self): + del self.frequency_array + del self.psd_array + del self.asd_array + + def test_init_with_asd_array(self): + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array, asd_array=self.asd_array) + self.assertTrue(np.array_equal(self.frequency_array, psd.frequency_array)) + self.assertTrue(np.array_equal(self.asd_array, psd.asd_array)) + self.assertTrue(np.array_equal(self.psd_array, psd.psd_array)) + + def test_init_with_psd_array(self): + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array, psd_array=self.psd_array) + self.assertTrue(np.array_equal(self.frequency_array, psd.frequency_array)) + self.assertTrue(np.array_equal(self.asd_array, psd.asd_array)) + self.assertTrue(np.array_equal(self.psd_array, psd.psd_array)) + + def test_setting_asd_array_after_init(self): + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array) + psd.asd_array = self.asd_array + self.assertTrue(np.array_equal(self.frequency_array, psd.frequency_array)) + self.assertTrue(np.array_equal(self.asd_array, psd.asd_array)) + self.assertTrue(np.array_equal(self.psd_array, psd.psd_array)) + + def test_setting_psd_array_after_init(self): + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array) + psd.psd_array = self.psd_array + self.assertTrue(np.array_equal(self.frequency_array, psd.frequency_array)) + self.assertTrue(np.array_equal(self.asd_array, psd.asd_array)) + self.assertTrue(np.array_equal(self.psd_array, psd.psd_array)) + + def test_power_spectral_density_interpolated_from_asd_array(self): + expected = np.array([25.]) + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array, asd_array = self.asd_array) + self.assertEqual(expected, psd.power_spectral_density_interpolated(2)) + + def test_power_spectral_density_interpolated_from_psd_array(self): + expected = np.array([25.]) + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array, psd_array = self.psd_array) + self.assertEqual(expected, psd.power_spectral_density_interpolated(2)) + + def test_from_amplitude_spectral_density_array(self): + actual = tupak.gw.detector.PowerSpectralDensity.from_amplitude_spectral_density_array( + frequency_array=self.frequency_array, asd_array=self.asd_array) + self.assertTrue(np.array_equal(self.psd_array, actual.psd_array)) + self.assertTrue(np.array_equal(self.asd_array, actual.asd_array)) + + def test_from_power_spectral_density_array(self): + actual = tupak.gw.detector.PowerSpectralDensity.from_power_spectral_density_array( + frequency_array=self.frequency_array, psd_array=self.psd_array) + self.assertTrue(np.array_equal(self.psd_array, actual.psd_array)) + self.assertTrue(np.array_equal(self.asd_array, actual.asd_array)) + + def test_repr(self): + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array, psd_array=self.psd_array) + expected = 'PowerSpectralDensity(frequency_array={}, psd_array={}, asd_array={})'.format(self.frequency_array, + self.psd_array, + self.asd_array) + self.assertEqual(expected, repr(psd)) + + +class TestPowerSpectralDensityWithFiles(unittest.TestCase): + + def setUp(self): + self.dir = os.path.join(os.path.dirname(__file__), 'noise_curves') + os.mkdir(self.dir) + self.asd_file = os.path.join(os.path.dirname(__file__), 'noise_curves', 'asd_test_file.txt') + self.psd_file = os.path.join(os.path.dirname(__file__), 'noise_curves', 'psd_test_file.txt') + with open(self.asd_file, 'w') as f: + f.write('1.\t1.0e-21\n2.\t2.0e-21\n3.\t3.0e-21') + with open(self.psd_file, 'w') as f: + f.write('1.\t1.0e-42\n2.\t4.0e-42\n3.\t9.0e-42') + self.frequency_array = np.array([1.0, 2.0, 3.0]) + self.asd_array = np.array([1.0e-21, 2.0e-21, 3.0e-21]) + self.psd_array = np.array([1.0e-42, 4.0e-42, 9.0e-42]) + + def tearDown(self): + os.remove(self.asd_file) + os.remove(self.psd_file) + os.rmdir(self.dir) + del self.dir + del self.asd_array + del self.psd_array + del self.asd_file + del self.psd_file + + def test_init_with_psd_file(self): + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array, psd_file=self.psd_file) + self.assertEqual(self.psd_file, psd.psd_file) + self.assertTrue(np.array_equal(self.psd_array, psd.psd_array)) + self.assertTrue(np.allclose(self.asd_array, psd.asd_array, atol=1e-30)) + + def test_init_with_asd_file(self): + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array, asd_file=self.asd_file) + self.assertEqual(self.asd_file, psd.asd_file) + self.assertTrue(np.allclose(self.psd_array, psd.psd_array, atol=1e-60)) + self.assertTrue(np.array_equal(self.asd_array, psd.asd_array)) + + def test_setting_psd_array_after_init(self): + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array) + psd.psd_file = self.psd_file + self.assertEqual(self.psd_file, psd.psd_file) + self.assertTrue(np.array_equal(self.psd_array, psd.psd_array)) + self.assertTrue(np.allclose(self.asd_array, psd.asd_array, atol=1e-30)) + + def test_init_with_asd_array_after_init(self): + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array) + psd.asd_file = self.asd_file + self.assertEqual(self.asd_file, psd.asd_file) + self.assertTrue(np.allclose(self.psd_array, psd.psd_array, atol=1e-60)) + self.assertTrue(np.array_equal(self.asd_array, psd.asd_array)) + + def test_power_spectral_density_interpolated_from_asd_file(self): + expected = np.array([4.0e-42]) + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array, asd_file=self.asd_file) + self.assertTrue(np.allclose(expected, psd.power_spectral_density_interpolated(2), atol=1e-60)) + + def test_power_spectral_density_interpolated_from_psd_file(self): + expected = np.array([4.0e-42]) + psd = tupak.gw.detector.PowerSpectralDensity(frequency_array=self.frequency_array, psd_file=self.psd_file) + self.assertAlmostEqual(expected, psd.power_spectral_density_interpolated(2)) + + def test_from_amplitude_spectral_density_file(self): + psd = tupak.gw.detector.PowerSpectralDensity.from_amplitude_spectral_density_file(asd_file=self.asd_file) + self.assertEqual(self.asd_file, psd.asd_file) + self.assertTrue(np.allclose(self.psd_array, psd.psd_array, atol=1e-60)) + self.assertTrue(np.array_equal(self.asd_array, psd.asd_array)) + + def test_from_power_spectral_density_file(self): + psd = tupak.gw.detector.PowerSpectralDensity.from_power_spectral_density_file(psd_file=self.psd_file) + self.assertEqual(self.psd_file, psd.psd_file) + self.assertTrue(np.array_equal(self.psd_array, psd.psd_array)) + self.assertTrue(np.allclose(self.asd_array, psd.asd_array, atol=1e-30)) + + def test_from_aligo(self): + psd = tupak.gw.detector.PowerSpectralDensity.from_aligo() + expected_filename = 'aLIGO_ZERO_DET_high_P_psd.txt' + expected = tupak.gw.detector.PowerSpectralDensity(psd_file=expected_filename) + actual_filename = psd.psd_file.split('/')[-1] + self.assertEqual(expected_filename, actual_filename) + self.assertTrue(np.allclose(expected.psd_array, psd.psd_array, atol=1e-60)) + self.assertTrue(np.array_equal(expected.asd_array, psd.asd_array)) + + def test_check_file_psd_file_set_to_asd_file(self): + logger = logging.getLogger('tupak') + m = MagicMock() + logger.warning = m + psd = tupak.gw.detector.PowerSpectralDensity(psd_file=self.asd_file) + self.assertEqual(4, m.call_count) + + def test_check_file_not_called_psd_file_set_to_psd_file(self): + logger = logging.getLogger('tupak') + m = MagicMock() + logger.warning = m + psd = tupak.gw.detector.PowerSpectralDensity(psd_file=self.psd_file) + self.assertEqual(0, m.call_count) + + def test_check_file_asd_file_set_to_psd_file(self): + logger = logging.getLogger('tupak') + m = MagicMock() + logger.warning = m + psd = tupak.gw.detector.PowerSpectralDensity(asd_file=self.psd_file) + self.assertEqual(4, m.call_count) + + def test_check_file_not_called_asd_file_set_to_asd_file(self): + logger = logging.getLogger('tupak') + m = MagicMock() + logger.warning = m + psd = tupak.gw.detector.PowerSpectralDensity(asd_file=self.asd_file) + self.assertEqual(0, m.call_count) + + def test_from_frame_file(self): + expected_frequency_array = np.array([1., 2., 3.]) + expected_psd_array = np.array([16., 25., 36.]) + with mock.patch('tupak.gw.detector.InterferometerStrainData.set_from_frame_file') as m: + with mock.patch('tupak.gw.detector.InterferometerStrainData.create_power_spectral_density') as n: + n.return_value = expected_frequency_array, expected_psd_array + psd = tupak.gw.detector.PowerSpectralDensity.from_frame_file(frame_file=self.asd_file, + psd_start_time=0, + psd_duration=4) + self.assertTrue(np.array_equal(expected_frequency_array, psd.frequency_array)) + self.assertTrue(np.array_equal(expected_psd_array, psd.psd_array)) + + def test_repr(self): + psd = tupak.gw.detector.PowerSpectralDensity(psd_file=self.psd_file) + expected = 'PowerSpectralDensity(psd_file=\'{}\', asd_file=\'{}\')'.format(self.psd_file, None) + self.assertEqual(expected, repr(psd)) + + if __name__ == '__main__': unittest.main() diff --git a/tupak/gw/detector.py b/tupak/gw/detector.py index 3dcfecdd6c8307a30fb5621a4534b76b6970f19d..1edd20848302fadd3709fd92a3ac510c687bb82f 100644 --- a/tupak/gw/detector.py +++ b/tupak/gw/detector.py @@ -427,7 +427,7 @@ class InterferometerStrainData(object): logger.info( "Low pass filter frequency of {}Hz requested, this is equal" " or greater than the Nyquist frequency so no filter applied" - .format(filter_freq)) + .format(filter_freq)) return logger.debug("Applying low pass filter with filter frequency {}".format(filter_freq)) @@ -1331,8 +1331,8 @@ 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.power_spectral_density_interpolated(self.frequency_array) * \ + self.strain_data.window_factor @property def frequency_array(self): @@ -1512,61 +1512,54 @@ class TriangularInterferometer(InterferometerList): class PowerSpectralDensity(object): - def __init__(self, **kwargs): + def __init__(self, frequency_array=None, psd_array=None, asd_array=None, + psd_file=None, asd_file=None): """ Instantiate a new PowerSpectralDensity object. - If called with no argument, `PowerSpectralDensity()` will return an - empty instance which can be filled with one of the `set_from` methods. - You can also initialise a new PowerSpectralDensity object giving the - arguments of any `set_from` method and an attempt will be made to use - this information to load/create the power spectral density. - Example ------- - Using the `set_from` method directly (here `psd_file` is a string + Using the `from` method directly (here `psd_file` is a string containing the path to the file to load): - >>> power_spectral_density = PowerSpectralDensity() - >>> power_spectral_density.set_from_power_spectral_density_file(psd_file) + >>> power_spectral_density = PowerSpectralDensity.from_power_spectral_density_file(psd_file) Alternatively (and equivalently) setting the psd_file directly: >>> power_spectral_density = PowerSpectralDensity(psd_file=psd_file) - Note: for the "direct" method to work, you must provide the input - as a keyword argument as above. - Attributes ---------- - amplitude_spectral_density: array_like + asd_array: array_like Array representation of the ASD - amplitude_spectral_density_file: str + asd_file: str Name of the ASD file frequency_array: array_like Array containing the frequencies of the ASD/PSD values - power_spectral_density: array_like + psd_array: array_like Array representation of the PSD - power_spectral_density_file: str + psd_file: str Name of the PSD file power_spectral_density_interpolated: scipy.interpolated.interp1d Interpolated function of the PSD """ - self.__power_spectral_density = None - self.__amplitude_spectral_density = None + self.frequency_array = np.array(frequency_array) + if psd_array is not None: + self.psd_array = psd_array + if asd_array is not None: + self.asd_array = asd_array + self.psd_file = psd_file + self.asd_file = asd_file - self.frequency_array = [] - self.power_spectral_density_interpolated = None - - for key in kwargs: - try: - expanded_key = (key.replace('psd', 'power_spectral_density') - .replace('asd', 'amplitude_spectral_density')) - m = getattr(self, 'set_from_{}'.format(expanded_key)) - m(**kwargs) - except AttributeError: - logger.info("Tried setting PSD from init kwarg {} and failed".format(key)) + def __repr__(self): + if self.asd_file is not None or self.psd_file is not None: + return self.__class__.__name__ + '(psd_file=\'{}\', asd_file=\'{}\')'\ + .format(self.psd_file, self.asd_file) + else: + return self.__class__.__name__ + '(frequency_array={}, psd_array={}, asd_array={})' \ + .format(self.frequency_array, self.psd_array, self.asd_array) - def set_from_amplitude_spectral_density_file(self, asd_file): + @staticmethod + def from_amplitude_spectral_density_file(asd_file): """ Set the amplitude spectral density from a given file Parameters @@ -1575,18 +1568,10 @@ class PowerSpectralDensity(object): File containing amplitude spectral density, format 'f h_f' """ + return PowerSpectralDensity(asd_file=asd_file) - self.amplitude_spectral_density_file = asd_file - self.import_amplitude_spectral_density() - if min(self.amplitude_spectral_density) < 1e-30: - logger.warning("You specified an amplitude spectral density file.") - logger.warning("{} WARNING {}".format("*" * 30, "*" * 30)) - logger.warning("The minimum of the provided curve is {:.2e}.".format( - min(self.amplitude_spectral_density))) - logger.warning( - "You may have intended to provide this as a power spectral density.") - - def set_from_power_spectral_density_file(self, psd_file): + @staticmethod + def from_power_spectral_density_file(psd_file): """ Set the power spectral density from a given file Parameters @@ -1595,20 +1580,12 @@ class PowerSpectralDensity(object): File containing power spectral density, format 'f h_f' """ + return PowerSpectralDensity(psd_file=psd_file) - self.power_spectral_density_file = psd_file - self.import_power_spectral_density() - if min(self.power_spectral_density) > 1e-30: - logger.warning("You specified a power spectral density file.") - logger.warning("{} WARNING {}".format("*" * 30, "*" * 30)) - logger.warning("The minimum of the provided curve is {:.2e}.".format( - min(self.power_spectral_density))) - logger.warning( - "You may have intended to provide this as an amplitude spectral density.") - - def set_from_frame_file(self, frame_file, psd_start_time, psd_duration, - fft_length=4, sampling_frequency=4096, roll_off=0.2, - channel=None): + @staticmethod + def from_frame_file(frame_file, psd_start_time, psd_duration, + fft_length=4, sampling_frequency=4096, roll_off=0.2, + channel=None): """ Generate power spectral density from a frame file Parameters @@ -1630,103 +1607,123 @@ class PowerSpectralDensity(object): Name of channel to use to generate PSD. """ - strain = InterferometerStrainData(roll_off=roll_off) strain.set_from_frame_file( frame_file, start_time=psd_start_time, duration=psd_duration, channel=channel, sampling_frequency=sampling_frequency) + frequency_array, psd_array = strain.create_power_spectral_density(fft_length=fft_length) + return PowerSpectralDensity(frequency_array=frequency_array, psd_array=psd_array) - f, psd = strain.create_power_spectral_density(fft_length=fft_length) - self.frequency_array = f - self.power_spectral_density = psd + @staticmethod + def from_amplitude_spectral_density_array(frequency_array, asd_array): + return PowerSpectralDensity(frequency_array=frequency_array, asd_array=asd_array) - def set_from_amplitude_spectral_density_array(self, frequency_array, - asd_array): - self.frequency_array = frequency_array - self.amplitude_spectral_density = asd_array + @staticmethod + def from_power_spectral_density_array(frequency_array, psd_array): + return PowerSpectralDensity(frequency_array=frequency_array, psd_array=psd_array) - def set_from_power_spectral_density_array(self, frequency_array, psd_array): - self.frequency_array = frequency_array - self.power_spectral_density = psd_array - - def set_from_aLIGO(self): - psd_file = 'aLIGO_ZERO_DET_high_P_psd.txt' + @staticmethod + def from_aligo(): logger.info("No power spectral density provided, using aLIGO," "zero detuning, high power.") - self.set_from_power_spectral_density_file(psd_file) + return PowerSpectralDensity.from_power_spectral_density_file(psd_file='aLIGO_ZERO_DET_high_P_psd.txt') @property - def power_spectral_density(self): - if self.__power_spectral_density is not None: - return self.__power_spectral_density - else: - self.set_to_aLIGO() - return self.__power_spectral_density + def psd_array(self): + return self.__psd_array - @power_spectral_density.setter - def power_spectral_density(self, power_spectral_density): - self._check_frequency_array_matches_density_array(power_spectral_density) - self.__power_spectral_density = power_spectral_density - self._interpolate_power_spectral_density() - self.__amplitude_spectral_density = power_spectral_density ** 0.5 + @psd_array.setter + def psd_array(self, psd_array): + self.__check_frequency_array_matches_density_array(psd_array) + self.__psd_array = np.array(psd_array) + self.__asd_array = psd_array ** 0.5 + self.__interpolate_power_spectral_density() @property - def amplitude_spectral_density(self): - return self.__amplitude_spectral_density - - @amplitude_spectral_density.setter - def amplitude_spectral_density(self, amplitude_spectral_density): - self._check_frequency_array_matches_density_array(amplitude_spectral_density) - self.__amplitude_spectral_density = amplitude_spectral_density - self.__power_spectral_density = amplitude_spectral_density ** 2 - self._interpolate_power_spectral_density() - - def import_amplitude_spectral_density(self): + def asd_array(self): + return self.__asd_array + + @asd_array.setter + def asd_array(self, asd_array): + self.__check_frequency_array_matches_density_array(asd_array) + self.__asd_array = np.array(asd_array) + self.__psd_array = asd_array ** 2 + self.__interpolate_power_spectral_density() + + def __check_frequency_array_matches_density_array(self, density_array): + if len(self.frequency_array) != len(density_array): + raise ValueError('Provided spectral density does not match frequency array. Not updating.\n' + 'Length spectral density {}\n Length frequency array {}\n' + .format(density_array, self.frequency_array)) + + def __interpolate_power_spectral_density(self): + """Interpolate the loaded power spectral density so it can be resampled + for arbitrary frequency arrays. """ - Automagically load one of the amplitude spectral density curves - contained in the noise_curves directory. + self.__power_spectral_density_interpolated = interp1d(self.frequency_array, + self.psd_array, + bounds_error=False, + fill_value=np.inf) - Test if the file contains a path (i.e., contains '/'). - If not assume the file is in the default directory. - """ + @property + def power_spectral_density_interpolated(self): + return self.__power_spectral_density_interpolated - if '/' not in self.amplitude_spectral_density_file: - self.amplitude_spectral_density_file = os.path.join( - os.path.dirname(__file__), 'noise_curves', - self.amplitude_spectral_density_file) + @property + def asd_file(self): + return self.__asd_file + + @asd_file.setter + def asd_file(self, asd_file): + asd_file = self.__validate_file_name(file=asd_file) + self.__asd_file = asd_file + if asd_file is not None: + self.__import_amplitude_spectral_density() + self.__check_file_was_asd_file() + + def __check_file_was_asd_file(self): + if min(self.asd_array) < 1e-30: + logger.warning("You specified an amplitude spectral density file.") + logger.warning("{} WARNING {}".format("*" * 30, "*" * 30)) + logger.warning("The minimum of the provided curve is {:.2e}.".format(min(self.asd_array))) + logger.warning("You may have intended to provide this as a power spectral density.") - self.frequency_array, self.amplitude_spectral_density = np.genfromtxt( - self.amplitude_spectral_density_file).T + @property + def psd_file(self): + return self.__psd_file + + @psd_file.setter + def psd_file(self, psd_file): + psd_file = self.__validate_file_name(file=psd_file) + self.__psd_file = psd_file + if psd_file is not None: + self.__import_power_spectral_density() + self.__check_file_was_psd_file() + + def __check_file_was_psd_file(self): + if min(self.psd_array) > 1e-30: + logger.warning("You specified a power spectral density file.") + logger.warning("{} WARNING {}".format("*" * 30, "*" * 30)) + logger.warning("The minimum of the provided curve is {:.2e}.".format(min(self.psd_array))) + logger.warning("You may have intended to provide this as an amplitude spectral density.") - def import_power_spectral_density(self): + @staticmethod + def __validate_file_name(file): """ - Automagically load one of the power spectral density curves contained - in the noise_curves directory. - Test if the file contains a path (i.e., contains '/'). If not assume the file is in the default directory. """ - if '/' not in self.power_spectral_density_file: - self.power_spectral_density_file = os.path.join( - os.path.dirname(__file__), 'noise_curves', - self.power_spectral_density_file) - self.frequency_array, self.power_spectral_density = np.genfromtxt( - self.power_spectral_density_file).T + if file is not None and '/' not in file: + file = os.path.join(os.path.dirname(__file__), 'noise_curves', file) + return file - def _check_frequency_array_matches_density_array(self, density_array): - """Check the provided frequency and spectral density arrays match.""" - try: - self.frequency_array - density_array - except ValueError as e: - raise (e, 'Provided spectral density does not match frequency array. Not updating.') + def __import_amplitude_spectral_density(self): + """ Automagically load an amplitude spectral density curve """ + self.frequency_array, self.asd_array = np.genfromtxt(self.asd_file).T - def _interpolate_power_spectral_density(self): - """Interpolate the loaded power spectral density so it can be resampled - for arbitrary frequency arrays. - """ - self.power_spectral_density_interpolated = interp1d( - self.frequency_array, self.power_spectral_density, bounds_error=False, - fill_value=np.inf) + def __import_power_spectral_density(self): + """ Automagically load a power spectral density curve """ + self.frequency_array, self.psd_array = np.genfromtxt(self.psd_file).T def get_noise_realisation(self, sampling_frequency, duration): """ @@ -1746,7 +1743,7 @@ class PowerSpectralDensity(object): """ white_noise, frequencies = utils.create_white_noise(sampling_frequency, duration) - frequency_domain_strain = self.power_spectral_density_interpolated(frequencies) ** 0.5 * white_noise + frequency_domain_strain = self.__power_spectral_density_interpolated(frequencies) ** 0.5 * white_noise out_of_bounds = (frequencies < min(self.frequency_array)) | (frequencies > max(self.frequency_array)) frequency_domain_strain[out_of_bounds] = 0 * (1 + 1j) return frequency_domain_strain, frequencies @@ -1954,7 +1951,7 @@ def get_interferometer_with_fake_noise_and_injection( start_time = injection_parameters['geocent_time'] + 2 - duration interferometer = get_empty_interferometer(name) - interferometer.power_spectral_density.set_from_aLIGO() + interferometer.power_spectral_density = PowerSpectralDensity.from_aligo() if zero_noise: interferometer.set_strain_data_from_zero_noise( sampling_frequency=sampling_frequency, duration=duration,