Commit b6a91b48 authored by Marc Arene's avatar Marc Arene
Browse files

Using "pre-masked" arrays and "pre-masked-windowed" psd-array in nwip.

parent d8ec30a8
......@@ -377,7 +377,7 @@ class GWTransientLikelihoodGradient(LikelihoodGradient):
# # [DEBUG]: old way of computing inner products which does not use the strain_data.window_factor
# ifo.s_inner_h_at_point = nwip(ifo.fd_strain, ifo.template_at_point, ifo.psd_array, ifo.strain_data.duration)
# ifo.h_inner_h_at_point = np.real(nwip(ifo.template_at_point, ifo.template_at_point, ifo.psd_array, ifo.strain_data.duration))
ifo.s_inner_h_at_point = ifo.inner_product(ifo.template_at_point)
ifo.s_inner_h_at_point = ifo.inner_product_mask_fixed(ifo.template_at_point)
ifo.h_inner_h_at_point = np.real(ifo.optimal_snr_squared(ifo.template_at_point))
ifo.matched_filter_snr_at_point = np.real(ifo.s_inner_h_at_point) / ifo.h_inner_h_at_point**0.5
self.s_inner_h_at_point += ifo.s_inner_h_at_point
......@@ -509,8 +509,8 @@ class GWTransientLikelihoodGradient(LikelihoodGradient):
# ifo.s_inner_h_plus = nwip(ifo.fd_strain, template_plus, ifo.psd_array, ifo.strain_data.duration)
# ifo.s_inner_h_minus = nwip(ifo.fd_strain, template_minus, ifo.psd_array, ifo.strain_data.duration)
# ifo.h_inner_dh = nwip(ifo.template_at_point, dh, ifo.psd_array, ifo.strain_data.duration)
ifo.s_inner_h_plus = ifo.inner_product(template_plus)
ifo.s_inner_h_minus = ifo.inner_product(template_minus)
ifo.s_inner_h_plus = ifo.inner_product_mask_fixed(template_plus)
ifo.s_inner_h_minus = ifo.inner_product_mask_fixed(template_minus)
ifo.h_inner_dh = ifo.noise_weighted_inner_product(ifo.template_at_point, dh)
return dh
......@@ -560,7 +560,7 @@ class GWTransientLikelihoodGradient(LikelihoodGradient):
# # [DEBUG]: old way of computing inner products which does not use the strain_data.window_factor
# ifo.s_inner_h_plus = nwip(ifo.fd_strain, template_plus, ifo.psd_array, ifo.strain_data.duration)
# ifo.h_inner_dh = nwip(ifo.template_at_point, dh, ifo.psd_array, ifo.strain_data.duration)
ifo.s_inner_h_plus = ifo.inner_product(template_plus)
ifo.s_inner_h_plus = ifo.inner_product_mask_fixed(template_plus)
ifo.h_inner_dh = ifo.noise_weighted_inner_product(ifo.template_at_point, dh)
return dh
......@@ -608,7 +608,7 @@ class GWTransientLikelihoodGradient(LikelihoodGradient):
# # [DEBUG]: old way of computing inner products which does not use the strain_data.window_factor
# ifo.s_inner_h_minus = nwip(ifo.fd_strain, template_minus, ifo.psd_array, ifo.strain_data.duration)
# ifo.h_inner_dh = nwip(ifo.template_at_point, dh, ifo.psd_array, ifo.strain_data.duration)
ifo.s_inner_h_minus = ifo.inner_product(template_minus)
ifo.s_inner_h_minus = ifo.inner_product_mask_fixed(template_minus)
ifo.h_inner_dh = ifo.noise_weighted_inner_product(ifo.template_at_point, dh)
return dh
......
......@@ -17,6 +17,8 @@ class Interferometer(BilbyInterferometer):
"""
def __init__(self, name, power_spectral_density, minimum_frequency, maximum_frequency, length, latitude, longitude, elevation, xarm_azimuth, yarm_azimuth, xarm_tilt=0., yarm_tilt=0., calibration_model=None):
BilbyInterferometer.__init__(self, name, power_spectral_density, minimum_frequency, maximum_frequency, length, latitude, longitude, elevation, xarm_azimuth, yarm_azimuth, xarm_tilt, yarm_tilt, calibration_model)
self._power_spectral_density_array_masked_windowed = None
self.frequency_domain_strain_masked = None
def get_detector_response_geocent(self, waveform_polarizations, parameters):
""" Get the detector response for a particular waveform before timeshifting it from geocent, ie it is the response of and identically oriented detector but located at the center of the earth.
......@@ -100,5 +102,35 @@ class Interferometer(BilbyInterferometer):
return gwutilsnwip(
aa=aa[self.strain_data.frequency_mask],
bb=bb[self.strain_data.frequency_mask],
power_spectral_density=self.power_spectral_density_array[self.strain_data.frequency_mask],
power_spectral_density=self.power_spectral_density_array_masked_windowed,
duration=self.strain_data.duration)
@property
def power_spectral_density_array_masked_windowed(self):
"""
Pre-compute the masked and windowed psd array and cache it in this property to avoid unnecessary computations in the noise-weighted-inner-products.
"""
if self._power_spectral_density_array_masked_windowed is None:
self._power_spectral_density_array_masked_windowed = self.power_spectral_density_array[self.strain_data.frequency_mask]
return self._power_spectral_density_array_masked_windowed
def inner_product_mask_fixed(self, signal):
"""
Same as Bilby's original `interferometer.inner_product()` method but using "pre-masked" arrays and "pre-masked-windowed" psd-array to save some computation time.
Parameters
----------
signal: array_like
Array containing the signal
Returns
-------
float: The optimal signal to noise ratio possible squared
"""
if self.frequency_domain_strain_masked is None:
self.frequency_domain_strain_masked = self.strain_data.frequency_domain_strain[self.strain_data.frequency_mask]
return gwutilsnwip(
aa=signal[self.strain_data.frequency_mask],
bb=self.frequency_domain_strain_masked,
power_spectral_density=self.power_spectral_density_array_masked_windowed,
duration=self.strain_data.duration)
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