示例#1
0
    def test_noise_weighted_inner_product(self):
        aa = np.array([1e-23, 2e-23, 3e-23])
        bb = np.array([5e-23, 6e-23, 7e-23])
        frequency = np.array([100, 101, 102])
        PSD = bilby.gw.detector.PowerSpectralDensity.from_aligo()
        psd = PSD.power_spectral_density_interpolated(frequency)
        duration = 4
        nwip = gwutils.noise_weighted_inner_product(aa, bb, psd, duration)
        self.assertEqual(nwip, 239.87768033598326)

        self.assertEqual(
            gwutils.optimal_snr_squared(aa, psd, duration),
            gwutils.noise_weighted_inner_product(aa, aa, psd, duration))
示例#2
0
    def test_absolute_overlap(self):
        priors = BBHPriorDict(aligned_spin=True)
        del priors["mass_1"], priors["mass_2"]
        priors["total_mass"] = Uniform(5, 50)
        priors["mass_ratio"] = Uniform(0.5, 1)
        priors["geocent_time"] = Uniform(-10, 10)

        n_samples = 100
        all_parameters = pd.DataFrame(priors.sample(n_samples))
        overlaps = list()

        for ii in range(n_samples):
            parameters = dict(all_parameters.iloc[ii])
            bilby_pols = self.bilby_wfg.frequency_domain_strain(parameters)
            gpu_pols = self.gpu_wfg.frequency_domain_strain(parameters)
            bilby_strain = self.ifo.get_detector_response(
                waveform_polarizations=bilby_pols, parameters=parameters)
            gpu_strain = self.ifo.get_detector_response(
                waveform_polarizations=gpu_pols, parameters=parameters)
            inner_product = noise_weighted_inner_product(
                aa=bilby_strain,
                bb=gpu_strain,
                power_spectral_density=self.ifo.power_spectral_density_array,
                duration=self.duration)
            overlap = (inner_product /
                       self.ifo.optimal_snr_squared(signal=bilby_strain)**0.5 /
                       self.ifo.optimal_snr_squared(signal=gpu_strain)**0.5)
            overlaps.append(overlap)
        self.assertTrue(min(np.abs(overlaps)) > 0.995)
def overlap_function(a,
                     b,
                     frequency_array,
                     psd,
                     minimum_frequency=20,
                     maximum_frequency=1024):
    """
    Calculate the overlap between two waveforms.
    :param a: dict
        frequency-domain waveform polarisations of one waveform
    :param b: dict
        frequency-domain waveform polarisations of the other waveform
    :param frequency_array: array
        frequency array
    :param psd: array
        power spectral density array
    :param minimum_frequency: int
        minimum frequency at which to perform the calculation
    :param maximum_frequency: int
        maximum frequency at which to perform the calculation
    :return:
        overlap: float
            value of the overlap between the two waveforms
    """
    psd_interp = psd.power_spectral_density_interpolated(frequency_array)
    duration = 1.0 / (frequency_array[1] - frequency_array[0])
    minimum_frequency_index = np.where(
        frequency_array >= minimum_frequency)[0][0]
    maximum_frequency_index = np.where(
        frequency_array >= maximum_frequency)[0][0]
    # Defining temporary arrays to use
    _psd_interp = psd_interp[minimum_frequency_index:maximum_frequency_index]
    _a = {
        key: a[key][minimum_frequency_index:maximum_frequency_index]
        for key in a.keys()
    }
    _b = {
        key: b[key][minimum_frequency_index:maximum_frequency_index]
        for key in b.keys()
    }
    # Doing the calculation
    inner_a = utils.noise_weighted_inner_product(_a["plus"], _a["plus"],
                                                 _psd_interp, duration)
    inner_a += utils.noise_weighted_inner_product(_a["cross"], _a["cross"],
                                                  _psd_interp, duration)
    inner_b = utils.noise_weighted_inner_product(_b["plus"], _b["plus"],
                                                 _psd_interp, duration)
    inner_b += utils.noise_weighted_inner_product(_b["cross"], _b["cross"],
                                                  _psd_interp, duration)
    inner_ab = utils.noise_weighted_inner_product(_a["plus"], _b["plus"],
                                                  _psd_interp, duration)
    inner_ab += utils.noise_weighted_inner_product(_a["cross"], _b["cross"],
                                                   _psd_interp, duration)
    overlap = inner_ab / np.sqrt(inner_a * inner_b)
    return overlap.real