Beispiel #1
0
    def filtered(self,freq_range,filt_type='stop',order=4):
        """
        Filter the data using a Butterworth filter and return a new
        TimeSeries instance.

        Parameters
        ----------
        freq_range : {array_like}
            The range of frequencies to filter.
        filt_type = {scipy.signal.band_dict.keys()},optional
            Filter type.
        order = {int}
            The order of the filter.

        Returns
        -------
        ts : {TimeSeries}
            A TimeSeries instance with the filtered data.
        """

        filtered_array = filt.buttfilt(np.asarray(self),
                                       freq_range,self.samplerate,filt_type,
                                       order,axis=self.taxis)
        attrs = self._attrs.copy()
        for k in self._required_attrs.keys():
            attrs.pop(k,None)
        return TimeSeries(filtered_array,self.tdim, self.samplerate,
                          dims=self.dims.copy(), **attrs)
Beispiel #2
0
    def filtered(self,freq_range,filt_type='stop',order=4):
        """
        Filter the data using a Butterworth filter and return a new
        TimeSeries instance.

        Parameters
        ----------
        freq_range : {array_like}
            The range of frequencies to filter.
        filt_type = {scipy.signal.band_dict.keys()},optional
            Filter type.
        order = {int}
            The order of the filter.

        Returns
        -------
        ts : {TimeSeries}
            A TimeSeries instance with the filtered data.
        """

        filtered_array = filt.buttfilt(np.asarray(self),
                                       freq_range,self.samplerate,filt_type,
                                       order,axis=self.taxis)
        attrs = self._attrs.copy()
        for k in self._required_attrs.keys():
            attrs.pop(k,None)
        return TimeSeries(filtered_array,self.tdim, self.samplerate,
                          dims=self.dims.copy(), **attrs)
Beispiel #3
0
    def filter(self):

        from ptsa.filt  import buttfilt

        # find index  of the  axis called 'time'
        if self.time_axis<0:

            time_index_array = np.where(np.array(self.time_series.dims) == 'time')
            if len(time_index_array)>0:
                self.time_axis =time_index_array[0] # picking first index that corresponds to the dimension
            else:
                raise RuntimeError("Could not locate 'time' axis in your time series."
                                   " Make sure to either label appropriate axis of your time series 'time' or specify"
                                   "time axis explicitely as a non-negative integer '")

        filtered_array = buttfilt(self.time_series,
                                       self.freq_range, self.samplerate, self.filt_type,
                                       self.order,axis=self.time_axis)


        self.filtered_time_series = xray.DataArray(
            filtered_array,
            coords = [xray.DataArray(coord.copy()) for coord_name, coord in self.time_series.coords.items() ]
        )


        # l = [xray.DataArray(coord.copy()) for coord_name, coord in self.time_series.coords.items() ]

        return self.filtered_time_series

        # attrs = self._attrs.copy()
        # for k in self._required_attrs.keys():
        #     attrs.pop(k,None)
        # return TimeSeries(filtered_array,self.tdim, self.samplerate,
        #                   dims=self.dims.copy(), **attrs)
    def filtered(self, freq_range, filt_type='stop', order=4):
        """
        Filter the data using a Butterworth filter and return a new
        TimeSeries instance.

        Parameters
        ----------
        freq_range : array-like
            The range of frequencies to filter.
        filt_type : str
            Filter type (default: ``'stop'``).
        order : int
            The order of the filter (default: 4).

        Returns
        -------
        ts : TimeSeriesX
            A TimeSeriesX instance with the filtered data.

        """
        warnings.warn("The filtered method is not very flexible. "
                      "Consider using filters in ptsa.data.filters instead.")
        time_axis_index = get_axis_index(self, axis_name='time')
        filtered_array = buttfilt(self.values, freq_range, float(self['samplerate']), filt_type,
                                  order, axis=time_axis_index)
        new_ts = self.copy()
        new_ts.data = filtered_array
        return new_ts
    def filter(self):
        """
        Applies Butterwoth filter to input time series and returns filtered TimeSeriesX object

        Returns
        -------
        filtered: TimeSeriesX
            The filtered time series

        """
        time_axis_index = get_axis_index(self.time_series, axis_name='time')
        filtered_array = buttfilt(self.time_series,
                                  self.freq_range,
                                  float(self.time_series['samplerate']),
                                  self.filt_type,
                                  self.order,
                                  axis=time_axis_index)

        coords_dict = {
            coord_name: DataArray(coord.copy())
            for coord_name, coord in list(self.time_series.coords.items())
        }
        coords_dict['samplerate'] = self.time_series['samplerate']
        dims = [dim_name for dim_name in self.time_series.dims]
        filtered_time_series = TimeSeriesX(filtered_array,
                                           dims=dims,
                                           coords=coords_dict)

        # filtered_time_series = TimeSeriesX(filtered_time_series)
        filtered_time_series.attrs = self.time_series.attrs.copy()
        return filtered_time_series
Beispiel #6
0
    def filtered(self,freq_range,filt_type='stop',order=4):
        """
        Filter the data using a Butterworth filter and return a new
        TimeSeries instance.

        Parameters
        ----------
        freq_range : {array_like}
            The range of frequencies to filter.
        filt_type = {scipy.signal.band_dict.keys()},optional
            Filter type.
        order = {int}
            The order of the filter.

        Returns
        -------
        ts : {TimeSeries}
            A TimeSeries instance with the filtered data.
        """

        from ptsa.filt  import buttfilt

        filtered_array = buttfilt(self.values, freq_range, self.attrs['samplerate'], filt_type,
                                       order,axis=self.time_axis_index)

        filtered_time_series = TimeSeriesXray(
            filtered_array,
            coords = [xr.DataArray(coord.copy()) for coord_name, coord in list(self.coords.items())]
        )


        filtered_time_series.attrs = self.attrs.copy()

        return filtered_time_series
Beispiel #7
0
    def filter(self):
        """
        Applies Butterwoth filter to input time series and returns filtered TimeSeriesX object

        Returns
        -------
        filtered: TimeSeriesX
            The filtered time series

        """
        time_axis_index = get_axis_index(self.time_series, axis_name='time')
        filtered_array = buttfilt(self.time_series,
                                  self.freq_range, float(self.time_series['samplerate']), self.filt_type,
                                  self.order, axis=time_axis_index)

        coords_dict = {coord_name: DataArray(coord.copy()) for coord_name, coord in list(self.time_series.coords.items())}
        coords_dict['samplerate'] = self.time_series['samplerate']
        dims = [dim_name for dim_name in self.time_series.dims]
        filtered_time_series = TimeSeriesX(
            filtered_array,
            dims=dims,
            coords=coords_dict
        )

        # filtered_time_series = TimeSeriesX(filtered_time_series)
        filtered_time_series.attrs = self.time_series.attrs.copy()
        return filtered_time_series
Beispiel #8
0
 def test_filter(self):
     samplerate = 200
     filtType='stop'
     freqRange = [10,20]
     order = 4
     ts = TimeSeries(self.dat200,'time',samplerate,dims=self.dims200)
     ts_filt = ts.filtered(freqRange, filtType, order)
     test = filt.buttfilt(self.dat200,freqRange,samplerate,filtType,
                          order,axis=ts.taxis)
     np.testing.assert_array_almost_equal(ts_filt[:],test[:],decimal=6)
Beispiel #9
0
 def test_filter(self):
     samplerate = 200
     filtType='stop'
     freqRange = [10,20]
     order = 4
     ts = TimeSeries(self.dat200,'time',samplerate,dims=self.dims200)
     ts_filt = ts.filtered(freqRange, filtType, order)
     test = filt.buttfilt(self.dat200,freqRange,samplerate,filtType,
                          order,axis=ts.taxis)
     np.testing.assert_array_almost_equal(ts_filt[:],test[:],decimal=6)
Beispiel #10
0
    def filtered(self, freq_range, filt_type='stop', order=4):
        """
        Filter the data using a Butterworth filter and return a new
        TimeSeries instance.

        Parameters
        ----------
        freq_range : {array_like}
            The range of frequencies to filter.
        filt_type = {scipy.signal.band_dict.keys()},optional
            Filter type.
        order = {int}
            The order of the filter.

        Returns
        -------
        ts : {TimeSeries}
            A TimeSeries instance with the filtered data.
        """

        from ptsa.filt import buttfilt

        filtered_array = buttfilt(self.values,
                                  freq_range,
                                  self.attrs['samplerate'],
                                  filt_type,
                                  order,
                                  axis=self.time_axis_index)

        # filtered_time_series = xray.DataArray(
        #     filtered_array,
        #     coords = [xray.DataArray(coord.copy()) for coord_name, coord in self.coords.items() ]
        # )

        filtered_time_series = TimeSeriesXray(
            filtered_array,
            coords=[
                xray.DataArray(coord.copy())
                for coord_name, coord in self.coords.items()
            ])

        filtered_time_series.attrs = self.attrs.copy()

        return filtered_time_series
Beispiel #11
0
    def filtered(self, freq_range, filt_type='stop', order=4):
        """
        Filter the data using a Butterworth filter and return a new
        TimeSeries instance.

        Parameters
        ----------
        freq_range : {array_like}
            The range of frequencies to filter.
        filt_type = {scipy.signal.band_dict.keys()},optional
            Filter type.
        order = {int}
            The order of the filter.

        Returns
        -------
        ts : {TimeSeries}
            A TimeSeries instance with the filtered data.
        """

        from ptsa.filt import buttfilt
        time_axis_index = get_axis_index(self, axis_name='time')
        filtered_array = buttfilt(self.values,
                                  freq_range,
                                  float(self['samplerate']),
                                  filt_type,
                                  order,
                                  axis=time_axis_index)

        coords = {}

        for coord_name, coord in self.coords.items():
            if len(coord.shape):
                coords[coord_name] = coord

        filtered_time_series = TimeSeriesX(
            filtered_array,
            dims=[dim_name for dim_name in self.dims],
            coords=coords)

        filtered_time_series.attrs = self.attrs.copy()

        return filtered_time_series
Beispiel #12
0
    def filtered(self, freq_range, filt_type='stop', order=4):
        """
        Filter the data using a Butterworth filter and return a new
        TimeSeries instance.

        Parameters
        ----------
        freq_range : {array_like}
            The range of frequencies to filter.
        filt_type = {scipy.signal.band_dict.keys()},optional
            Filter type.
        order = {int}
            The order of the filter.

        Returns
        -------
        ts : {TimeSeries}
            A TimeSeries instance with the filtered data.
        """

        from ptsa.filt import buttfilt
        time_axis_index = get_axis_index(self, axis_name='time')
        filtered_array = buttfilt(self.values, freq_range, float(self['samplerate']), filt_type,
                                  order, axis=time_axis_index)


        coords={}


        for coord_name, coord in self.coords.items():
            if len(coord.shape):
                coords[coord_name] = coord

        filtered_time_series = TimeSeriesX(
            filtered_array,
            dims=[dim_name for dim_name in self.dims],
            coords=coords
        )

        filtered_time_series.attrs = self.attrs.copy()

        return filtered_time_series