from astropy.modeling import models, fitting from .utils import get_hist def fit_line(x, y, model): """ Line fitting kx+b Parameters ---------- x/y : array x/y data Returns ------- fitted_model : astropy fitting model fitting gaussian model """ fitter = fitting.LevMarLSQFitter() fitted_model = fitter(model, x, y) return fitted_model def fit_hist_gaussian(x): """ Gaussian fitting is performed on the histogram Parameters ---------- x : array data point Returns ------- fitted_model : astropy fitting model fitting gaussian model """ fitter = fitting.LMLSQFitter() count, center = get_hist(x) model = models.Gaussian1D(amplitude=count.max(), mean=x.mean(), stddev=x.std()) fitted_model = fitter(model, center, count) return fitted_model