Exemple #1
0
    def low_pass_filter(self, filter_freq=None):
        """ Low pass filter the data """
        from gwpy.signal.filter_design import lowpass
        from gwpy.timeseries import TimeSeries

        if filter_freq is None:
            logger.debug(
                "Setting low pass filter_freq using given maximum frequency")
            filter_freq = self.maximum_frequency

        if 2 * filter_freq >= self.sampling_frequency:
            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))
            return

        logger.debug(
            "Applying low pass filter with filter frequency {}".format(
                filter_freq))
        bp = lowpass(filter_freq, self.sampling_frequency)
        strain = TimeSeries(self.time_domain_strain,
                            sample_rate=self.sampling_frequency)
        strain = strain.filter(bp, filtfilt=True)
        self._time_domain_strain = strain.value
def filter_gwe(data:TimeSeries):
    from gwpy.signal import filter_design

    bp = filter_design.bandpass(50, 250, data.sample_rate)
    notches = [filter_design.notch(line, data.sample_rate) for line in (60, 120, 180)]
    zpk = filter_design.concatenate_zpks(bp, *notches)
    filt = data.filter(zpk, filtfilt=True)
    data = data.crop(*data.span.contract(1))
    filt = filt.crop(*filt.span.contract(1))
    return filt
    def plot_time_domain_data(self,
                              outdir='.',
                              label=None,
                              bandpass_frequencies=(50, 250),
                              notches=None,
                              start_end=None,
                              t0=None):
        """ Plots the strain data in the time domain

        Parameters
        ==========
        outdir, label: str
            Used in setting the saved filename.
        bandpass: tuple, optional
            A tuple of the (low, high) frequencies to use when bandpassing the
            data, if None no bandpass is applied.
        notches: list, optional
            A list of frequencies specifying any lines to notch
        start_end: tuple
            A tuple of the (start, end) range of GPS times to plot
        t0: float
            If given, the reference time to subtract from the time series before
            plotting.

        """
        import matplotlib.pyplot as plt
        from gwpy.timeseries import TimeSeries
        from gwpy.signal.filter_design import bandpass, concatenate_zpks, notch

        # We use the gwpy timeseries to perform bandpass and notching
        if notches is None:
            notches = list()
        timeseries = TimeSeries(data=self.strain_data.time_domain_strain,
                                times=self.strain_data.time_array)
        zpks = []
        if bandpass_frequencies is not None:
            zpks.append(
                bandpass(bandpass_frequencies[0], bandpass_frequencies[1],
                         self.strain_data.sampling_frequency))
        if notches is not None:
            for line in notches:
                zpks.append(notch(line, self.strain_data.sampling_frequency))
        if len(zpks) > 0:
            zpk = concatenate_zpks(*zpks)
            strain = timeseries.filter(zpk, filtfilt=False)
        else:
            strain = timeseries

        fig, ax = plt.subplots()

        if t0:
            x = self.strain_data.time_array - t0
            xlabel = 'GPS time [s] - {}'.format(t0)
        else:
            x = self.strain_data.time_array
            xlabel = 'GPS time [s]'

        ax.plot(x, strain)
        ax.set_xlabel(xlabel)
        ax.set_ylabel('Strain')

        if start_end is not None:
            ax.set_xlim(*start_end)

        fig.tight_layout()

        if label is None:
            fig.savefig('{}/{}_time_domain_data.png'.format(outdir, self.name))
        else:
            fig.savefig('{}/{}_{}_time_domain_data.png'.format(
                outdir, self.name, label))
        plt.close(fig)