예제 #1
0
    def gate(self,
             time,
             window=0.25,
             method='taper',
             copy=True,
             taper_width=0.25,
             invpsd=None):
        """ Gate out portion of time series

        Parameters
        ----------
        time: float
            Central time of the gate in seconds
        window: float
            Half-length in seconds to remove data around gate time.
        method: str
            Method to apply gate, options are 'hard', 'taper', and 'paint'.
        copy: bool
            If False, do operations inplace to this time series, else return
            new time series.
        taper_width: float
            Length of tapering region on either side of excized data. Only
            applies to the taper gating method.
        invpsd: pycbc.types.FrequencySeries
            The inverse PSD to use for painting method. If not given,
            a PSD is generated using default settings.

        Returns
        -------
        data: pycbc.types.TimeSeris
            Gated time series
        """
        data = self.copy() if copy else self
        if method == 'taper':
            from pycbc.strain import gate_data
            return gate_data(data, [(time, window, taper_width)])
        elif method == 'paint':
            # Uses the hole-filling method of
            # https://arxiv.org/pdf/1908.05644.pdf
            from pycbc.strain.gate import gate_and_paint
            if invpsd is None:
                # These are some bare minimum settings, normally you
                # should probably provide a psd
                invpsd = 1. / self.filter_psd(self.duration / 32, self.delta_f,
                                              0)
            lindex = int((time - window - self.start_time) / self.delta_t)
            rindex = lindex + int(2 * window / self.delta_t)
            lindex = lindex if lindex >= 0 else 0
            rindex = rindex if rindex <= len(self) else len(self)
            return gate_and_paint(data, lindex, rindex, invpsd, copy=False)
        elif method == 'hard':
            tslice = data.time_slice(time - window, time + window)
            tslice[:] = 0
            return data
        else:
            raise ValueError('Invalid method name: {}'.format(method))
예제 #2
0
    def gate(self, time, zero_width=0.25, taper_width=0.25):
        """ Gate out portion of time series

        Parameters
        ----------
        time: float
            Central time of the gate in seconds
        zero_width: float
            Half-length in seconds of zeros around gate.
        taper_width: float
            Lenght of tapering region on either side of zero'd data

        Returns
        -------
        data: pycbc.types.TimeSeris
            Gated time series
        """
        from pycbc.strain import gate_data
        return gate_data(self.copy(), [(time, zero_width, taper_width)])
예제 #3
0
def apply_gates_to_td(strain_dict, gates):
    """Applies the given dictionary of gates to the given dictionary of
    strain.

    Parameters
    ----------
    strain_dict : dict
        Dictionary of time-domain strain, keyed by the ifos.
    gates : dict
        Dictionary of gates. Keys should be the ifo to apply the data to,
        values are a tuple giving the central time of the gate, the half
        duration, and the taper duration.

    Returns
    -------
    dict
        Dictionary of time-domain strain with the gates applied.
    """
    # copy data to new dictionary
    outdict = dict(strain_dict.items())
    for ifo in gates:
        outdict[ifo] = strain.gate_data(outdict[ifo], gates[ifo])
    return outdict