def spline_fit_magseries(times, mags, errs, period,<EOL>knotfraction=<NUM_LIT>,<EOL>maxknots=<NUM_LIT:30>,<EOL>sigclip=<NUM_LIT>,<EOL>plotfit=False,<EOL>ignoreinitfail=False,<EOL>magsarefluxes=False,<EOL>verbose=True):
<EOL>if errs is None:<EOL><INDENT>errs = npfull_like(mags, <NUM_LIT>)<EOL><DEDENT>stimes, smags, serrs = sigclip_magseries(times, mags, errs,<EOL>sigclip=sigclip,<EOL>magsarefluxes=magsarefluxes)<EOL>nzind = npnonzero(serrs)<EOL>stimes, smags, serrs = stimes[nzind], smags[nzind], serrs[nzind]<EOL>phase, pmags, perrs, ptimes, mintime = (<EOL>get_phased_quantities(stimes, smags, serrs, period)<EOL>)<EOL>nobs = len(phase)<EOL>nknots = int(npfloor(knotfraction*nobs))<EOL>nknots = maxknots if nknots > maxknots else nknots<EOL>splineknots = nplinspace(phase[<NUM_LIT:0>] + <NUM_LIT>,<EOL>phase[-<NUM_LIT:1>] - <NUM_LIT>,<EOL>num=nknots)<EOL>phase_diffs_ind = npdiff(phase) > <NUM_LIT:0.0><EOL>incphase_ind = npconcatenate((nparray([True]), phase_diffs_ind))<EOL>phase, pmags, perrs = (phase[incphase_ind],<EOL>pmags[incphase_ind],<EOL>perrs[incphase_ind])<EOL>spl = LSQUnivariateSpline(phase, pmags, t=splineknots, w=<NUM_LIT:1.0>/perrs)<EOL>fitmags = spl(phase)<EOL>fitchisq = npsum(<EOL>((fitmags - pmags)*(fitmags - pmags)) / (perrs*perrs)<EOL>)<EOL>fitredchisq = fitchisq/(len(pmags) - nknots - <NUM_LIT:1>)<EOL>if verbose:<EOL><INDENT>LOGINFO(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(nknots, fitchisq, fitredchisq)<EOL>)<EOL><DEDENT>if not magsarefluxes:<EOL><INDENT>fitmagminind = npwhere(fitmags == npmax(fitmags))<EOL><DEDENT>else:<EOL><INDENT>fitmagminind = npwhere(fitmags == npmin(fitmags))<EOL><DEDENT>if len(fitmagminind[<NUM_LIT:0>]) > <NUM_LIT:1>:<EOL><INDENT>fitmagminind = (fitmagminind[<NUM_LIT:0>][<NUM_LIT:0>],)<EOL><DEDENT>magseriesepoch = ptimes[fitmagminind]<EOL>returndict = {<EOL>'<STR_LIT>':'<STR_LIT>',<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':nknots,<EOL>'<STR_LIT>':fitmags,<EOL>'<STR_LIT>':magseriesepoch<EOL>},<EOL>'<STR_LIT>':fitchisq,<EOL>'<STR_LIT>':fitredchisq,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':ptimes,<EOL>'<STR_LIT>':phase,<EOL>'<STR_LIT>':pmags,<EOL>'<STR_LIT>':perrs,<EOL>'<STR_LIT>':magsarefluxes<EOL>},<EOL>}<EOL>if plotfit and isinstance(plotfit, str):<EOL><INDENT>make_fit_plot(phase, pmags, perrs, fitmags,<EOL>period, mintime, magseriesepoch,<EOL>plotfit,<EOL>magsarefluxes=magsarefluxes)<EOL>returndict['<STR_LIT>'] = plotfit<EOL><DEDENT>return returndict<EOL>
This fits a univariate cubic spline to the phased light curve.

    This fit may be better than the Fourier fit for sharply variable objects,
    like EBs, so can be used to distinguish them from other types of variables.

    Parameters
    ----------

    times,mags,errs : np.array
        The input mag/flux time-series to fit a spline to.

    period : float
        The period to use for the spline fit.

    knotfraction : float
        The knot fraction is the number of internal knots to use for the
        spline. A value of 0.01 (or 1%) of the total number of non-nan
        observations appears to work quite well, without over-fitting. maxknots
        controls the maximum number of knots that will be allowed.

    maxknots : int
        The maximum number of knots that will be used even if `knotfraction`
        gives a value to use larger than `maxknots`. This helps dealing with
        over-fitting to short time-scale variations.

    sigclip : float or int or sequence of two floats/ints or None
        If a single float or int, a symmetric sigma-clip will be performed using
        the number provided as the sigma-multiplier to cut out from the input
        time-series.

        If a list of two ints/floats is provided, the function will perform an
        'asymmetric' sigma-clip. The first element in this list is the sigma
        value to use for fainter flux/mag values; the second element in this
        list is the sigma value to use for brighter flux/mag values. For
        example, `sigclip=[10., 3.]`, will sigclip out greater than 10-sigma
        dimmings and greater than 3-sigma brightenings. Here the meaning of
        "dimming" and "brightening" is set by *physics* (not the magnitude
        system), which is why the `magsarefluxes` kwarg must be correctly set.

        If `sigclip` is None, no sigma-clipping will be performed, and the
        time-series (with non-finite elems removed) will be passed through to
        the output.

    magsarefluxes : bool
        If True, will treat the input values of `mags` as fluxes for purposes of
        plotting the fit and sig-clipping.

    plotfit : str or False
        If this is a string, this function will make a plot for the fit to the
        mag/flux time-series and writes the plot to the path specified here.

    ignoreinitfail : bool
        If this is True, ignores the initial failure to find a set of optimized
        Fourier parameters using the global optimization function and proceeds
        to do a least-squares fit anyway.

    verbose : bool
        If True, will indicate progress and warn of any problems.

    Returns
    -------

    dict
        This function returns a dict containing the model fit parameters, the
        minimized chi-sq value and the reduced chi-sq value. The form of this
        dict is mostly standardized across all functions in this module::

            {
                'fittype':'spline',
                'fitinfo':{
                    'nknots': the number of knots used for the fit
                    'fitmags': the model fit mags,
                    'fitepoch': the epoch of minimum light for the fit,
                },
                'fitchisq': the minimized value of the fit's chi-sq,
                'fitredchisq':the reduced chi-sq value,
                'fitplotfile': the output fit plot if fitplot is not None,
                'magseries':{
                    'times':input times in phase order of the model,
                    'phase':the phases of the model mags,
                    'mags':input mags/fluxes in the phase order of the model,
                    'errs':errs in the phase order of the model,
                    'magsarefluxes':input value of magsarefluxes kwarg
                }
            }