pyacs.gts.lib.filters package

Submodules

pyacs.gts.lib.filters.el1_trend module

Taken from https://github.com/wudingcheng/TSAnalyzer/blob/master/TSAnalyzer/algorithms/l1extensive.py

pyacs.gts.lib.filters.el1_trend.el1_trend(self, lam, rho, periods=None, in_place=False, return_offset=False, return_periodic=False, verbose=True, component='NEU')[source]

extensive l1 trend filtering

Parameters
  • lam – weight of regularization of filtered data

  • rho – weight of regularization of offsets

  • period – tuple, periods to be estimated (1.,0.5) will estimate annual and semi-annual terms

  • in_place – if True then replace the current time series

  • return_offset – if True also return offset time serie

  • return_periodic – if True also return periodic time serie

  • verbose – boolean, verbose mode

  • component – string. Default ‘NEU’

Returns

the filtered time series

pyacs.gts.lib.filters.el1_trend.gen_d2(n)[source]

Generate the 2nd difference matrix. :param n: int, length of time series :return: csr_matrix, sparse matrix

pyacs.gts.lib.filters.el1_trend.gen_d1(n)[source]

Generate the 1st difference matrix :param n: int, length of time series :return: csr_matrix, sparse matrix

pyacs.gts.lib.filters.el1_trend.get_max_lam(y)[source]

Calculate the max lambda value for given time series y :param y: np.array, time series given :return: float, max lambda value

pyacs.gts.lib.filters.el1_trend.get_max_rho(y)[source]

Calculate the max rho value for given time series y, :param y: np.array, time series given :return: float, max rho value

pyacs.gts.lib.filters.el1_trend.l1filter(t, y, lam=1200, rho=80, periods=365.25, 182.625, solver='MOSEK', verbose=False)[source]

Do l1 regularize for given time series. :param t: np.array, time :param y: np.array, time series value :param lam: lambda value :param rho: rho value :param periods: list, periods, same unit as t :param solver: cvx.solver :param verbose: bool, show verbose or not :return: x, w, s, if periods is not None, else return x, w

pyacs.gts.lib.filters.l1_trend module

L1 trend filter

The L1 trend filtering method produces trend estimates that are piecewise linear from the time series 𝑦. :credit: https://www.cvxpy.org/examples/applications/l1_trend_filter.html :reference: http://stanford.edu/~boyd/papers/l1_trend_filter.html

pyacs.gts.lib.filters.l1_trend.l1_trend(self, vlambda, gap=10, in_place=False, verbose=True, component='NEU')[source]

return a piecewise linear filtered Gts

Parameters
  • vlambda – weight of regularization

  • gap – gap in days to split the time series before applying the filter.default is 10.

  • in_place – if True then replace the current time series

  • verbose – boolean, verbose mode

  • component – string. Default ‘NEU’

Returns

the filtered time series

Note

if there are less than 4 points in a segment, return an L1 estimated trend

pyacs.gts.lib.filters.median module

Median filter for Gts based on scipy.signal.medfilt.

pyacs.gts.lib.filters.median.median_filter(self, n, in_place=False, verbose=True)[source]

returns a filtered time series using scipy.signal.medfilt

Parameters
  • n – size of the median filter window (must be odd)

  • in_place – if True then replace the current time series

  • verbose – boolean, verbose mode

Returns

the filtered time series

Note

the filter is applied to .data and .data_xyz is set to None

pyacs.gts.lib.filters.minimum_component module

Minimum component filter for Gts.

pyacs.gts.lib.filters.minimum_component.minimum_component(self, mask_period=[], p=1, fcut=None, Q=None, in_place=False, verbose=True)[source]

Minimum component filtering for Gts. Minimum component filtering is useful for determining the background component of a signal in the presence of spikes :param mask_periods: periods (list or list of lists) which should be ignored for smoothing :param p: integer (optional). polynomial degree to be used for the fit (default = 1) :param fcut: float (optional). the cutoff frequency for the low-pass filter. Default value is f_nyq / sqrt(N) :param Q: float (optional). the strength of the low-pass filter. Larger Q means a steeper cutoff. default value is 0.1 * fcut :param in_place: if True then replace the current time series :param verbose: boolean, verbose mode :return: the filtered time series :note: This code follows the procedure explained in the book “Practical Statistics for Astronomers” by Wall & Jenkins book, as well as in Wall, J, A&A 122:371, 1997

pyacs.gts.lib.filters.piecewise_linear module

Piecewise linear approximation of time series. Based on https://pypi.org/project/pwlf.

pyacs.gts.lib.filters.piecewise_linear.pwlf(self, component, n, in_place=False, verbose=False, output=False)[source]

Perform a piecewise approximation of a time series. Since it the routine is 1D, the component E,N, or U needs to be specified.

Parameters
  • component – component used for the decomposition. Must be ‘E’,’N’ or ‘U’

  • n – number of segments

  • in_place – if True then replace the current time series

  • verbose – boolean, verbose mode

Output

if False, the predicted time series is returned. If True, then a list of dates is returned.

pyacs.gts.lib.filters.savitzky_golay module

Savitzky-Golay filter for Gts based on scipy.signal.medfilt. http://https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter Additional information on Savitzky-Golay filter from https://scipy-cookbook.readthedocs.io/items/SavitzkyGolay.html

The Savitzky Golay filter is a particular type of low-pass filter, well adapted for data smoothing. For further information see: http://www.wire.tu-bs.de/OLDWEB/mameyer/cmr/savgol.pdf (or http://www.dalkescientific.com/writings/NBN/data/savitzky_golay.py for a pre-numpy implementation).

It has the advantage of preserving the original shape and features of the signal better than other types of filtering approaches, such as moving averages techniques.

The Savitzky-Golay is a type of low-pass filter, particularly suited for smoothing noisy data. The main idea behind this approach is to make for each point a least-square fit with a polynomial of high order over a odd-sized window centered at the point.

pyacs.gts.lib.filters.savitzky_golay.savitzky_golay(self, in_place=False, verbose=True, window_length=15, polyorder=3, deriv=0, delta=1.0, mode='interp', cval=0.0)[source]

returns a filtered time series using scipy.signal.savgol_filter

See documentation for the filter parameters. http://https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter

Parameters
  • in_place – if True then replace the current time series

  • verbose – boolean, verbose mode

Returns

the filtered time series

pyacs.gts.lib.filters.smooth module

pyacs.gts.lib.filters.smooth.smooth(self, window_len=11, window='hanning', in_place=False, verbose=False, component='NEU')[source]

smooth a time series

pyacs.gts.lib.filters.spline module

pyacs.gts.lib.filters.spline.spline(self, smoothing=1, degree=5, date=None)[source]
Parameters

smoothing – Positive smoothing factor used to choose the number of knots. Number of knots will be increased

until the smoothing condition is satisfied:

sum((w[i] * (y[i]-spl(x[i])))**2, axis=0) <= s

Parameters
  • degree – Degree of the smoothing spline. Must be <= 5. Default is k=3, a cubic spline.

  • date – 1D array of interpolation dates in decimal year, or ‘day’ for every day. defualt None will interpolate

at data date only. :return: new gts instance

pyacs.gts.lib.filters.total_variation module

Total variation filters from https://github.com/albarji/proxTV Total variation filters are useful to preserve edges in a signal (edge filter).

pyacs.gts.lib.filters.total_variation.edge(self, lbda, in_place=False, verbose=True)[source]

Edge Gts filter using a L1 total variation filter. The signal is assumed to be piecewise constant.

Parameters
  • lbda – lambda parameter

  • in_place – if True then replace the current time series

  • verbose – boolean, verbose mode

Returns

the filtered time series

Reference

https://github.com/albarji/proxTV

pyacs.gts.lib.filters.total_variation.edge_l2(self, lbda, in_place=False, verbose=True)[source]

Gts filter using a L2 total variation filter. The signal is assumed to be detrended.

Parameters
  • lbda – lambda parameter

  • in_place – if True then replace the current time series

  • verbose – boolean, verbose mode

Returns

the filtered time series

Reference

https://github.com/albarji/proxTV

pyacs.gts.lib.filters.vondrak module

Vondrak filter

pyacs.gts.lib.filters.vondrak.vondrak(self, fc, in_place=False, verbose=True, component='NEU')[source]

returned a filtered Gts using a Vondrak filter

Parameters
  • fc – cutoff frequence in cycle per year

  • in_place – if True then replace the current time series

  • verbose – boolean, verbose mode

Returns

the filtered time series

pyacs.gts.lib.filters.wiener module

Wiener filter for Gts based on scipy.signal.wiener.

https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.wiener.html

pyacs.gts.lib.filters.wiener.wiener(self, in_place=False, verbose=True, my_size=15, noise=None)[source]

returns a filtered time series using scipy.signal.wiener

See documentation for the filter parameters.

Parameters
  • in_place – if True then replace the current time series

  • verbose – boolean, verbose mode

Returns

the filtered time series

Module contents