# Path: data_cube_utilities/plotter_utils_consts.py



import numpy as np
from numpy import fft
from .plotter_utils_consts import n_pts_smooth, default_fourier_n_harm
    from scipy.optimize import curve_fit
    from .scale import np_scale
    from scipy.interpolate import CubicSpline
    from scipy.ndimage.filters import gaussian_filter1d

    Parameters
    ----------
    x: list-like
        The x values of the data to fit to.
    y: list-like
        The y values of the data to fit to.
    x_smooth: list-like, optional
        The exact x values to interpolate for. Supercedes `n_pts`.
    n_pts: int, optional
        The number of evenly spaced points spanning the range of `x` to interpolate for.
    sigma: numeric, optional
        The standard deviation of the Gaussian kernel. A larger value yields a smoother curve,
        but also reduced the closeness of the fit. By default, it is `0.75`.

    Returns
    -------
    x_smooth, y_smooth: numpy.ndarray
        The smoothed x and y values of the curve fit.
    """

    if x_smooth is None:
        x_smooth_inds = np.linspace(0, len(x)-1, n_pts)
        x_smooth = np.interp(x_smooth_inds, np.arange(len(x)), x)
    gauss_filter_y = gaussian_filter1d(y, sigma)
    cs = CubicSpline(x, gauss_filter_y)
    y_smooth = cs(x_smooth)
    return x_smooth, y_smooth



# Path: data_cube_utilities/plotter_utils_consts.py



# Path: data_cube_utilities/curve_fitting.py
import numpy as np
from numpy import fft
from .plotter_utils_consts import n_pts_smooth, default_fourier_n_harm
    from scipy.optimize import curve_fit
    from .scale import np_scale
    from scipy.interpolate import CubicSpline
    from scipy.ndimage.filters import gaussian_filter1d


    Parameters
    ----------
    x: list-like
        The x values of the data to fit to.
    y: list-like
        The y values of the data to fit to.
    x_smooth: list-like, optional
        The exact x values to interpolate for. Supercedes `n_pts`.
    n_pts: int, optional
        The number of evenly spaced points spanning the range of `x` to interpolate for.
    sigma: numeric, optional
        The standard deviation of the Gaussian kernel. A larger value yields a smoother curve,
        but also reduced the closeness of the fit. By default, it is `0.75`.

    Returns
    -------
    x_smooth, y_smooth: numpy.ndarray
        The smoothed x and y values of the curve fit.
    """

    if x_smooth is None:
        x_smooth_inds = np.linspace(0, len(x)-1, n_pts)
        x_smooth = np.interp(x_smooth_inds, np.arange(len(x)), x)
    gauss_filter_y = gaussian_filter1d(y, sigma)
    cs = CubicSpline(x, gauss_filter_y)
    y_smooth = cs(x_smooth)
    return x_smooth, y_smooth



def poly_fit(x, y, degree, x_smooth=None, n_pts=n_pts_smooth):