Пример #1
0
def detrend_discontinuous_linear(t, x, max_gap=0, recenter=True):
    """
    Just removed the linear signal

    Args:
        t: time data (should be continuous)
        x: x data. may be gappy (has nans)
        max_gap: the largest gap allowable for interpolation
        recenter: if True, with output will have the same mean as the input

    Returns:
        The detrended data as a pd Series. if the original data was discontinuous, there will be fewer entries in the
        returned Series, but the index will still match up

    """

    sub_tees, sub_exes = continuous_subsets(t, x, max_gap=max_gap, repair=True)
    d_exes = [dt(sub) for sub in sub_exes]

    tees = []
    exes = []
    for sub_t, sub_x in zip(sub_tees, d_exes):
        tees.extend(sub_t)
        exes.extend(sub_x)

    if recenter:
        exes = exes + (np.nanmean(x) - np.mean(exes))

    c = crush_series(t, x, tees, exes)
    return c
Пример #2
0
def detrend(image):
    '''
    Remove linear trends from an image.

    Performs a 2 axis linear detrend using scipy.signal.detrend

    Parameters
    ----------
    image : xarray.DataArray
       Image to process

    Returns
    -------
    image : xarray.DataArray
       Image with linear trends removed
    '''
    return copy_metadata(image, dt(dt(image, image.dims.index('x')), image.dims.index('y')))
Пример #3
0
    def __init__(self, ts, detrend=False):

        if len(ts) != 0:
            m, n = ts.shape[0], ts.shape[2]

            if detrend:
                for i in range(m):
                    for j in range(n):
                        ts[i, :, j] = dt(ts[i, :, j])

        self.ts = ts