# Path: pyleoclim/utils/tsbase.py
# def is_evenly_spaced(ts, tol=1e-4):
#     ''' Check if a time axis is evenly spaced, within a given tolerance
# 
#     Parameters
#     ----------
# 
#     ts : array
#         the time axis of a time series
#         
#     tol : float64
#         numerical tolerance for the relative difference
# 
#     Returns
#     -------
# 
#     check : bool
#         True - evenly spaced; False - unevenly spaced.
# 
#     '''
#     if ts is None:
#         check = True
#     else:
#         dts = np.diff(ts)
#         dt_mean = dts.mean()   
#         check = all(np.abs((dt - dt_mean)/dt_mean) < tol for dt in np.diff(ts)) # compare relative spacing to the mean
#         
#     return check


import numpy as np
import statsmodels.api as sm
from scipy import signal
from .tsbase import (
    is_evenly_spaced
)
    Parameters
    ----------

    ys : numpy array
        Evenly-spaced timeseries
    ts : numpy array
        Time axis
    method : string
        The method to use to pad the series
        - ARIMA: uses a fitted ARIMA model
        - reflect (default): Reflects the time series around either end.
    params : tuple ARIMA model order parameters (p,d,q), Default corresponds to an AR(1) model
    reflect_type : string
         {‘even’, ‘odd’}, optional
         Used in ‘reflect’, and ‘symmetric’. The ‘even’ style is the default with an unaltered reflection around the edge value.
         For the ‘odd’ style, the extented part of the array is created by subtracting the reflected values from two times the edge value.
         For more details, see np.lib.pad()
    padFrac : float
        padding fraction (scalar) such that padLength = padFrac*length(series)

    Returns
    -------

    yp : array
        padded timeseries
    tp : array
        augmented time axis
    """
    padLength =  np.round(len(ts)*padFrac).astype(np.int64)


# Path: pyleoclim/utils/tsbase.py
# def is_evenly_spaced(ts, tol=1e-4):
#     ''' Check if a time axis is evenly spaced, within a given tolerance
# 
#     Parameters
#     ----------
# 
#     ts : array
#         the time axis of a time series
#         
#     tol : float64
#         numerical tolerance for the relative difference
# 
#     Returns
#     -------
# 
#     check : bool
#         True - evenly spaced; False - unevenly spaced.
# 
#     '''
#     if ts is None:
#         check = True
#     else:
#         dts = np.diff(ts)
#         dt_mean = dts.mean()   
#         check = all(np.abs((dt - dt_mean)/dt_mean) < tol for dt in np.diff(ts)) # compare relative spacing to the mean
#         
#     return check


# Path: pyleoclim/utils/filter.py
import numpy as np
import statsmodels.api as sm
from scipy import signal
from .tsbase import (
    is_evenly_spaced
)

    Parameters
    ----------

    ys : numpy array
        Evenly-spaced timeseries
    ts : numpy array
        Time axis
    method : string
        The method to use to pad the series
        - ARIMA: uses a fitted ARIMA model
        - reflect (default): Reflects the time series around either end.
    params : tuple ARIMA model order parameters (p,d,q), Default corresponds to an AR(1) model
    reflect_type : string
         {‘even’, ‘odd’}, optional
         Used in ‘reflect’, and ‘symmetric’. The ‘even’ style is the default with an unaltered reflection around the edge value.
         For the ‘odd’ style, the extented part of the array is created by subtracting the reflected values from two times the edge value.
         For more details, see np.lib.pad()
    padFrac : float
        padding fraction (scalar) such that padLength = padFrac*length(series)

    Returns
    -------

    yp : array
        padded timeseries
    tp : array
        augmented time axis
    """
    padLength =  np.round(len(ts)*padFrac).astype(np.int64)


    if is_evenly_spaced(ts)==False: