def epd_kepler_lightcurve(lcdict,<EOL>xccol='<STR_LIT>',<EOL>yccol='<STR_LIT>',<EOL>timestoignore=None,<EOL>filterflags=True,<EOL>writetodict=True,<EOL>epdsmooth=<NUM_LIT:5>):
times, fluxes, background, background_err = (lcdict['<STR_LIT:time>'],<EOL>lcdict['<STR_LIT>']['<STR_LIT>'],<EOL>lcdict['<STR_LIT>']['<STR_LIT>'],<EOL>lcdict['<STR_LIT>']['<STR_LIT>'])<EOL>xcc = lcdict[xccol]<EOL>ycc = lcdict[yccol]<EOL>flags = lcdict['<STR_LIT>']<EOL>if filterflags:<EOL><INDENT>nbefore = times.size<EOL>filterind = flags == <NUM_LIT:0><EOL>times = times[filterind]<EOL>fluxes = fluxes[filterind]<EOL>background = background[filterind]<EOL>background_err = background_err[filterind]<EOL>xcc = xcc[filterind]<EOL>ycc = ycc[filterind]<EOL>flags = flags[filterind]<EOL>nafter = times.size<EOL>LOGINFO('<STR_LIT>'<EOL>% (nbefore, nafter))<EOL><DEDENT>find = (npisfinite(xcc) & npisfinite(ycc) &<EOL>npisfinite(times) & npisfinite(fluxes) &<EOL>npisfinite(background) & npisfinite(background_err))<EOL>nbefore = times.size<EOL>times = times[find]<EOL>fluxes = fluxes[find]<EOL>background = background[find]<EOL>background_err = background_err[find]<EOL>xcc = xcc[find]<EOL>ycc = ycc[find]<EOL>flags = flags[find]<EOL>nafter = times.size<EOL>LOGINFO('<STR_LIT>'<EOL>% (nbefore, nafter))<EOL>if (timestoignore and<EOL>isinstance(timestoignore, list) and<EOL>len(timestoignore) > <NUM_LIT:0>):<EOL><INDENT>exclind = npfull_like(times,True)<EOL>nbefore = times.size<EOL>for ignoretime in timestoignore:<EOL><INDENT>time0, time1 = ignoretime[<NUM_LIT:0>], ignoretime[<NUM_LIT:1>]<EOL>thismask = (times > time0) & (times < time1)<EOL>exclind = exclind & thismask<EOL><DEDENT>times = times[exclind]<EOL>fluxes = fluxes[exclind]<EOL>background = background[exclind]<EOL>background_err = background_err[exclind]<EOL>xcc = xcc[exclind]<EOL>ycc = ycc[exclind]<EOL>flags = flags[exclind]<EOL>nafter = times.size<EOL>LOGINFO('<STR_LIT>'<EOL>% (nbefore, nafter))<EOL><DEDENT>smoothedfluxes = median_filter(fluxes, size=epdsmooth)<EOL>initcoeffs = npones(<NUM_LIT:11>)<EOL>leastsqfit = leastsq(_epd_residual,<EOL>initcoeffs,<EOL>args=(smoothedfluxes,<EOL>xcc, ycc,<EOL>background, background_err))<EOL>if leastsqfit[-<NUM_LIT:1>] in (<NUM_LIT:1>,<NUM_LIT:2>,<NUM_LIT:3>,<NUM_LIT:4>):<EOL><INDENT>fitcoeffs = leastsqfit[<NUM_LIT:0>]<EOL>epdfit = _epd_function(fitcoeffs,<EOL>fluxes,<EOL>xcc,<EOL>ycc,<EOL>background,<EOL>background_err)<EOL>epdfluxes = npmedian(fluxes) + fluxes - epdfit<EOL>if writetodict:<EOL><INDENT>lcdict['<STR_LIT>'] = {}<EOL>lcdict['<STR_LIT>']['<STR_LIT:time>'] = times<EOL>lcdict['<STR_LIT>']['<STR_LIT>'] = fluxes<EOL>lcdict['<STR_LIT>']['<STR_LIT>'] = epdfluxes<EOL>lcdict['<STR_LIT>']['<STR_LIT>'] = epdfit<EOL>lcdict['<STR_LIT>']['<STR_LIT>'] = background<EOL>lcdict['<STR_LIT>']['<STR_LIT>'] = background_err<EOL>lcdict['<STR_LIT>']['<STR_LIT>'] = xcc<EOL>lcdict['<STR_LIT>']['<STR_LIT>'] = ycc<EOL>lcdict['<STR_LIT>']['<STR_LIT>'] = flags<EOL>for newcol in ['<STR_LIT>','<STR_LIT>',<EOL>'<STR_LIT>','<STR_LIT>',<EOL>'<STR_LIT>','<STR_LIT>',<EOL>'<STR_LIT>','<STR_LIT>',<EOL>'<STR_LIT>']:<EOL><INDENT>if newcol not in lcdict['<STR_LIT>']:<EOL><INDENT>lcdict['<STR_LIT>'].append(newcol)<EOL><DEDENT><DEDENT><DEDENT>return times, epdfluxes, fitcoeffs, epdfit<EOL><DEDENT>else:<EOL><INDENT>LOGERROR('<STR_LIT>')<EOL>return None, None, None, None<EOL><DEDENT>
This runs EPD on the Kepler light curve.

    Following Huang et al. 2015, we fit the following EPD function to a smoothed
    light curve, and then subtract it to obtain EPD corrected magnitudes::

        f = c0 +
            c1*sin(2*pi*x) + c2*cos(2*pi*x) + c3*sin(2*pi*y) + c4*cos(2*pi*y) +
            c5*sin(4*pi*x) + c6*cos(4*pi*x) + c7*sin(4*pi*y) + c8*cos(4*pi*y) +
            c9*bgv + c10*bge

    By default, this function removes points in the Kepler LC that have ANY
    quality flags set.

    Parameters
    ----------

    lcdict : lcdict
        An `lcdict` produced by `consolidate_kepler_fitslc` or
        `read_kepler_fitslc`.

    xcol,ycol : str
        Indicates the x and y coordinate column names to use from the Kepler LC
        in the EPD fit.

    timestoignore : list of tuples
        This is of the form::

            [(time1_start, time1_end), (time2_start, time2_end), ...]

        and indicates the start and end times to mask out of the final
        lcdict. Use this to remove anything that wasn't caught by the quality
        flags.

    filterflags : bool
        If True, will remove any measurements that have non-zero quality flags
        present. This usually indicates an issue with the instrument or
        spacecraft.

    writetodict : bool
        If writetodict is True, adds the following columns to the lcdict::

            epd_time = time array
            epd_sapflux = uncorrected flux before EPD
            epd_epdsapflux = corrected flux after EPD
            epd_epdsapcorr = EPD flux corrections
            epd_bkg = background array
            epd_bkg_err = background errors array
            epd_xcc = xcoord array
            epd_ycc = ycoord array
            epd_quality = quality flag array

        and updates the 'columns' list in the lcdict as well.

    epdsmooth : int
        Sets the number of light curve points to smooth over when generating the
        EPD fit function.

    Returns
    -------

    tuple
        Returns a tuple of the form: (times, epdfluxes, fitcoeffs, epdfit)