# 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
from statsmodels.tsa.arima_process import arma_generate_sample
from statsmodels.tsa.arima.model import ARIMA
from .tsbase import (
    is_evenly_spaced
)
from scipy import optimize
    y[0] = 0  # initializing

    for i in range(1, n):
        scaled_dt = (t[i] - t[i-1]) / tau
        rho = np.exp(-scaled_dt)
        err = np.random.normal(0, np.sqrt(1 - rho**2)*output_sigma, 1)
        y[i] = y[i-1]*rho + err

    return y


def ar1_fit(y, t=None):
    ''' Returns the lag-1 autocorrelation from AR(1) fit OR persistence from tauest.

    Parameters
    ----------

    y : array
        the time series
    t : array
        the time axis of that series

    Returns
    -------

    g : float
        lag-1 autocorrelation coefficient (for evenly-spaced time series)
        OR estimated persistence (for unevenly-spaced time series)
    '''


# 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/tsmodel.py
import numpy as np
from statsmodels.tsa.arima_process import arma_generate_sample
from statsmodels.tsa.arima.model import ARIMA
from .tsbase import (
    is_evenly_spaced
)
from scipy import optimize

    y[0] = 0  # initializing

    for i in range(1, n):
        scaled_dt = (t[i] - t[i-1]) / tau
        rho = np.exp(-scaled_dt)
        err = np.random.normal(0, np.sqrt(1 - rho**2)*output_sigma, 1)
        y[i] = y[i-1]*rho + err

    return y


def ar1_fit(y, t=None):
    ''' Returns the lag-1 autocorrelation from AR(1) fit OR persistence from tauest.

    Parameters
    ----------

    y : array
        the time series
    t : array
        the time axis of that series

    Returns
    -------

    g : float
        lag-1 autocorrelation coefficient (for evenly-spaced time series)
        OR estimated persistence (for unevenly-spaced time series)
    '''


    if is_evenly_spaced(t):