Exemplo n.º 1
0
 def calculate_ifar(self, newsnr, duration):
     if self.fit_info['fixed_ifar']:
         return self.fit_info['fixed_ifar']
     dur_bin = self.fit_info['bins'][duration]
     rate = self.fit_info['rates'][dur_bin]
     coeff = self.fit_info['coeffs'][dur_bin]
     rate_louder = rate * fits.cum_fit('exponential', [newsnr], coeff,
                                       self.fit_info['thresh'])[0]
     # apply a trials factor of the number of duration bins
     rate_louder *= len(self.fit_info['rates'])
     return conv.sec_to_year(1. / rate_louder)
Exemplo n.º 2
0
    def calculate_ifar(self, sngl_ranking, duration):
        if self.fixed_ifar:
            return self.fixed_ifar[self.ifo]

        with h5py.File(self.fit_file, 'r') as fit_file:
            bin_edges = fit_file['bins_edges'][:]
            live_time = fit_file[self.ifo].attrs['live_time']
            thresh = fit_file.attrs['fit_threshold']

            dist_grp = fit_file[self.ifo][self.sngl_ifar_est_dist]
            rates = dist_grp['counts'][:] / live_time
            coeffs = dist_grp['fit_coeff'][:]

        bins = bin_utils.IrregularBins(bin_edges)
        dur_bin = bins[duration]

        rate = rates[dur_bin]
        coeff = coeffs[dur_bin]
        rate_louder = rate * fits.cum_fit('exponential', [sngl_ranking], coeff,
                                          thresh)[0]
        # apply a trials factor of the number of duration bins
        rate_louder *= len(rates)
        return conv.sec_to_year(1. / rate_louder)
Exemplo n.º 3
0
def n_louder_from_fit(back_stat,
                      fore_stat,
                      dec_facs,
                      fit_func='exponential',
                      fit_thresh=0):
    """
    Use a fit to events in back_stat in order to estimate the
    distribution for use in recovering the estimate count of louder
    background events. Below the fit threshold, use the n_louder
    method for these triggers

    back_stat: numpy.ndarray
        Array of the background statistic values
    fore_stat: numpy.ndarray or scalar
        Array of the foreground statistic values or single value
    dec_facs: numpy.ndarray
        Array of the decimation factors for the background statistics
    fit_func: str
        Name of the function to be used for the fit to background
        statistic values
    fit_thresh: float
        Threshold above which triggers use the fitted value, below this
        the counted number of louder events will be used

    Returns
    -------
    back_cnum: numpy.ndarray
        The estimated number of background events louder than each
        background event
    fn_louder: numpy.ndarray
        The estimated number of background events louder than each
        foreground event
    """

    # Calculate the fitting factor of the ranking statistic distribution
    alpha, _ = trstats.fit_above_thresh(fit_func,
                                        back_stat,
                                        thresh=fit_thresh,
                                        weights=dec_facs)

    # Count background events above threshold as the cum_fit is
    # normalised to 1
    bg_above = back_stat > fit_thresh
    bg_above_thresh = np.sum(dec_facs[bg_above])
    fg_above = fore_stat > fit_thresh

    # These will be overwritten, but just to silence a warning
    # in the case where trstats.cum_fit returns zero
    back_cnum = np.zeros_like(back_stat)
    fnlouder = np.zeros_like(fore_stat)

    # Ue the fit above the threshold
    back_cnum[bg_above] = trstats.cum_fit(fit_func, back_stat[bg_above], alpha,
                                          fit_thresh) * bg_above_thresh
    fnlouder[fg_above] = trstats.cum_fit(fit_func, fore_stat[fg_above], alpha,
                                         fit_thresh) * bg_above_thresh

    # Below the fit threshold, we expect there to be sufficient events
    # to use the count_n_louder method, and the distribution may deviate
    # from the fit function
    fg_below = np.logical_not(fg_above)
    bg_below = np.logical_not(bg_above)

    back_cnum[bg_below], fnlouder[fg_below] = \
        count_n_louder(back_stat, fore_stat, dec_facs)

    return back_cnum, fnlouder