Beispiel #1
0
    def detrend(self, method='none', nbins=None, order=None, knee=None):
        """
        A method to detrend the light curve using a Savitsky-Golay filter (:func:`.savitzky_golay`),
        a running median filter (:func:`.running_median`), or a high-pass filter
        (:func:`.highpass_filter_lightcurve`).

        Parameters
        ----------
        method : string, default: 'none'
           The detrending method. Either 'savitzkygolay', 'runningmedian', or
           'highpassfilter'.
        nbins : int, default: None
           The number of bins in the Savitsky-Golay, or running median detrend window
        order : int, default: None
           The polynomial order of the Savitsky-Golay detrending fit.
        knee : float, default: None
           The high-pass filter knee frequency (Hz).

        """

        self.set_detrend(method=method, nbins=nbins, order=order, knee=knee)
        self.detrended = True

        # store un-detrending light curve
        self.ulc = np.copy(self.clc)

        if method == 'savitzkygolay':
            if nbins is None or order is None:
                raise ValueError("Number of bins, or polynomial order, for Savitsky-Golay filter not set")

            ffit = bf.savitzky_golay(self.clc, nbins, order)
            self.clc = (self.clc - ffit)
            self.detrend_fit = np.copy(ffit)
        elif method == 'runningmedian':
            if nbins is None:
                raise ValueError("Number of bins for running median filter not set")

            ffit = bf.running_median(self.clc, nbins)
            self.clc = (self.clc - ffit)
            self.detrend_fit = np.copy(ffit)
        elif method == 'highpassfilter':
            if knee is None:
                raise ValueError("Knee frequency for high-pass filter not set.")

            dlc = bf.highpass_filter_lightcurve(self, knee=knee)
            self.clc = np.copy(dlc.clc)
        else:
            raise ValueError("No detrend method set")
Beispiel #2
0
    def detrend(self, method='none', nbins=None, order=None, knee=None):
        """
        A method to detrend the light curve using a Savitsky-Golay filter (:func:`.savitzky_golay`),
        a running median filter (:func:`.running_median`), or a high-pass filter
        (:func:`.highpass_filter_lightcurve`).

        Parameters
        ----------
        method : string, default: 'none'
           The detrending method. Either 'savitzkygolay', 'runningmedian', or
           'highpassfilter'.
        nbins : int, default: None
           The number of bins in the Savitsky-Golay, or running median detrend window
        order : int, default: None
           The polynomial order of the Savitsky-Golay detrending fit.
        knee : float, default: None
           The high-pass filter knee frequency (Hz).

        """

        self.set_detrend(method=method, nbins=nbins, order=order, knee=knee)
        self.detrended = True

        # store un-detrending light curve
        self.ulc = np.copy(self.clc)
        
        if method == 'savitzkygolay':
            if nbins is None or order is None:
                raise ValueError("Number of bins, or polynomial order, for Savitsky-Golay filter not set")
          
            ffit = bf.savitzky_golay(self.clc, nbins, order)
            self.clc = (self.clc - ffit)
            self.detrend_fit = np.copy(ffit)
        elif method == 'runningmedian':
            if nbins is None:
                raise ValueError("Number of bins for running median filter not set")
          
            ffit = bf.running_median(self.clc, nbins)
            self.clc = (self.clc - ffit)
            self.detrend_fit = np.copy(ffit)
        elif method == 'highpassfilter':
            if knee is None:
                raise ValueError("Knee frequency for high-pass filter not set.")
          
            dlc = bf.highpass_filter_lightcurve(self, knee=knee)
            self.clc = np.copy(dlc.clc)
        else:
            raise ValueError("No detrend method set")
Beispiel #3
0
    def filter_model(self,
                     m,
                     filtermethod='savitzkygolay',
                     nbins=101,
                     order=3,
                     filterknee=(1. / (0.3 * 86400.))):
        """
        Use the Savitzky-Golay smoothing (:func:`.savitzky_golay`) to high-pass filter the model m.

        Parameters
        ----------
        m : :class:`numpy.ndarray`
           An array containing the model.
        filtermethod : string, default: 'savitzkygolay'
           The method for filtering/detrending the model function. The default is
           the Savitzky-Golay method, but this can also be 'runningmedian' to use
           a running median detrending, or 'highpass' for a high-pass 3rd order Butterworth
           filter.
        nbins : int, optional, default: 101
           An odd integer width (in bins) for the Savitzky-Golay, or running median, filtering.
        order : int, optional, default: 3
           The polynomial order for the Savitzky-Golay filtering.
        filterknee : float, default: 1/(0.3*86400) Hz
           The filter knee frequency (in Hz) for the high-pass filter method.

        Returns
        -------
        The filtered model time series

        """
        if filtermethod == 'savitzkygolay':
            return (m - bf.savitzky_golay(m, nbins, order))
        elif filtermethod == 'runningmedian':
            return (m - bf.running_median(m, nbins))
        elif filtermethod == 'highpass':
            ml = bf.Lightcurve()
            ml.clc = np.copy(m)
            ml.cts = np.copy(self.ts)
            filtm = bf.highpass_filter_lightcurve(ml, knee=filterknee)
            del ml
            return filtm
        else:
            raise ValueError('Unrecognised filter method (%s) given' %
                             filtermethod)
Beispiel #4
0
    def filter_model(self, m, filtermethod='savitzkygolay', nbins=101, order=3, filterknee=(1./(0.3*86400.))):
        """
        Use the Savitzky-Golay smoothing (:func:`.savitzky_golay`) to high-pass filter the model m.

        Parameters
        ----------
        m : :class:`numpy.ndarray`
           An array containing the model.
        filtermethod : string, default: 'savitzkygolay'
           The method for filtering/detrending the model function. The default is
           the Savitzky-Golay method, but this can also be 'runningmedian' to use
           a running median detrending, or 'highpass' for a high-pass 3rd order Butterworth
           filter.
        nbins : int, optional, default: 101
           An odd integer width (in bins) for the Savitzky-Golay, or running median, filtering.
        order : int, optional, default: 3
           The polynomial order for the Savitzky-Golay filtering.
        filterknee : float, default: 1/(0.3*86400) Hz
           The filter knee frequency (in Hz) for the high-pass filter method.
        
        Returns
        -------
        The filtered model time series
        
        """
        if filtermethod == 'savitzkygolay':
            return (m - bf.savitzky_golay(m, nbins, order))
        elif filtermethod == 'runningmedian':
            return (m - bf.running_median(m, nbins))
        elif filtermethod == 'highpass':
            ml = bf.Lightcurve()
            ml.clc = np.copy(m)
            ml.cts = np.copy(self.ts)
            filtm = bf.highpass_filter_lightcurve(ml, knee=filterknee)
            del ml
            return filtm 
        else:
            raise ValueError('Unrecognised filter method (%s) given' % filtermethod)