# Path: pyLIMA/microltoolbox.py
# MAGNITUDE_CONSTANT = 27.4
# def chichi(residuals_fn, fit_process_parameters):
# def magnitude_to_flux(magnitude):
# def flux_to_magnitude(flux):
# def error_magnitude_to_error_flux(error_magnitude, flux):
# def error_flux_to_error_magnitude(error_flux, flux):
# def MCMC_compute_fs_g(fit, mcmc_chains):
# def align_the_data_to_the_reference_telescope(fit, telescope_index = 0, parameters = None) :


import numpy as np
import scipy.signal as ss
from pyLIMA import microltoolbox
       This assumes no blending.

    :param object event: the event object on which you perform the fit on. More details on the
                            event module.

    :return: the PSPL guess for this event. A list of parameters associated to the PSPL model + the source flux of
    :return: the PSPL guess for this event. A list of parameters associated to the PSPL model + the source flux of
                the survey telescope.
    :rtype: list,float
    """

    # to estimation
    to_estimations = []
    maximum_flux_estimations = []
    errors_magnitude = []

    for telescope in event.telescopes:
        # Lot of process here, if one fails, just skip
        lightcurve_magnitude = telescope.lightcurve_magnitude
        mean_error_magnitude = np.mean(lightcurve_magnitude[:, 2])
        try:

            # only the best photometry
            good_photometry_indexes = np.where((lightcurve_magnitude[:, 2] <
                                                max(0.1, mean_error_magnitude)))[0]
            lightcurve_bis = lightcurve_magnitude[good_photometry_indexes]

            lightcurve_bis = lightcurve_bis[lightcurve_bis[:, 0].argsort(), :]

            mag = lightcurve_bis[:, 1]

# Path: pyLIMA/microltoolbox.py
# MAGNITUDE_CONSTANT = 27.4
# def chichi(residuals_fn, fit_process_parameters):
# def magnitude_to_flux(magnitude):
# def flux_to_magnitude(flux):
# def error_magnitude_to_error_flux(error_magnitude, flux):
# def error_flux_to_error_magnitude(error_flux, flux):
# def MCMC_compute_fs_g(fit, mcmc_chains):
# def align_the_data_to_the_reference_telescope(fit, telescope_index = 0, parameters = None) :


# Path: pyLIMA/microlguess.py
import numpy as np
import scipy.signal as ss
from pyLIMA import microltoolbox

       This assumes no blending.

    :param object event: the event object on which you perform the fit on. More details on the
                            event module.

    :return: the PSPL guess for this event. A list of parameters associated to the PSPL model + the source flux of
    :return: the PSPL guess for this event. A list of parameters associated to the PSPL model + the source flux of
                the survey telescope.
    :rtype: list,float
    """

    # to estimation
    to_estimations = []
    maximum_flux_estimations = []
    errors_magnitude = []

    for telescope in event.telescopes:
        # Lot of process here, if one fails, just skip
        lightcurve_magnitude = telescope.lightcurve_magnitude
        mean_error_magnitude = np.mean(lightcurve_magnitude[:, 2])
        try:

            # only the best photometry
            good_photometry_indexes = np.where((lightcurve_magnitude[:, 2] <
                                                max(0.1, mean_error_magnitude)))[0]
            lightcurve_bis = lightcurve_magnitude[good_photometry_indexes]

            lightcurve_bis = lightcurve_bis[lightcurve_bis[:, 0].argsort(), :]

            mag = lightcurve_bis[:, 1]

            flux = microltoolbox.magnitude_to_flux(mag)