cpd = _read_checkplot_picklefile(cpf)<EOL>if cpd['<STR_LIT>']['<STR_LIT>'] is not None:<EOL><INDENT>objecttags = cpd['<STR_LIT>']['<STR_LIT>'][::]<EOL><DEDENT>else:<EOL><INDENT>objecttags = None<EOL><DEDENT>varinfo = deepcopy(cpd['<STR_LIT>'])<EOL>if '<STR_LIT>' in cpd and cpd['<STR_LIT>'] is not None:<EOL><INDENT>comments = cpd['<STR_LIT>'][::]<EOL><DEDENT>else:<EOL><INDENT>comments = None<EOL><DEDENT>newcpd = _pkl_finder_objectinfo(cpd['<STR_LIT>'],<EOL>varinfo,<EOL>findercmap,<EOL>finderconvolve,<EOL>cpd['<STR_LIT>'],<EOL>cpd['<STR_LIT>'],<EOL>cpd['<STR_LIT>'],<EOL>fast_mode=fast_mode,<EOL>deredden_object=deredden_object,<EOL>custom_bandpasses=custom_bandpasses,<EOL>gaia_submit_timeout=gaia_submit_timeout,<EOL>gaia_submit_tries=gaia_submit_tries,<EOL>gaia_max_timeout=gaia_max_timeout,<EOL>gaia_mirror=gaia_mirror,<EOL>complete_query_later=complete_query_later,<EOL>lclistpkl=lclistpkl,<EOL>nbrradiusarcsec=nbrradiusarcsec,<EOL>maxnumneighbors=maxnumneighbors,<EOL>plotdpi=plotdpi,<EOL>findercachedir=findercachedir,<EOL>verbose=verbose)<EOL>if (newcpd['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']<EOL>)<EOL><DEDENT>if (('<STR_LIT>' in newcpd['<STR_LIT>']['<STR_LIT>'] or<EOL>('<STR_LIT>' in newcpd['<STR_LIT>'] and<EOL>newcpd['<STR_LIT>']['<STR_LIT>'] is None)) and<EOL>'<STR_LIT>' in cpd['<STR_LIT>']['<STR_LIT>']):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>if '<STR_LIT>' in cpd['<STR_LIT>']:<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (not np.isfinite(newcpd['<STR_LIT>']['<STR_LIT>']) and<EOL>np.isfinite(cpd['<STR_LIT>']['<STR_LIT>'])):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (not np.isfinite(newcpd['<STR_LIT>']['<STR_LIT>']) and<EOL>np.isfinite(cpd['<STR_LIT>']['<STR_LIT>'])):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (not np.isfinite(newcpd['<STR_LIT>']['<STR_LIT>']) and<EOL>np.isfinite(cpd['<STR_LIT>']['<STR_LIT>'])):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' in newcpd['<STR_LIT>']['<STR_LIT>'] and<EOL>'<STR_LIT>' in cpd['<STR_LIT>']['<STR_LIT>']):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>if (newcpd['<STR_LIT>']['<STR_LIT>'] is None and<EOL>cpd['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>newcpd['<STR_LIT>']['<STR_LIT>'] = deepcopy(<EOL>cpd['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>cpd.update(newcpd)<EOL>cpd['<STR_LIT>']['<STR_LIT>'] = objecttags<EOL>cpd['<STR_LIT>'] = comments<EOL>newcpf = _write_checkplot_picklefile(cpd, outfile=cpf)<EOL>return newcpf<EOL>

This updates a checkplot objectinfo dict.

    Useful in cases where a previous round of GAIA/finderchart/external catalog
    acquisition failed. This will preserve the following keys in the checkplot
    if they exist::

        comments
        varinfo
        objectinfo.objecttags

    Parameters
    ----------

    cpf : str
        The path to the checkplot pickle to update.

    fast_mode : bool or float
        This runs the external catalog operations in a "fast" mode, with short
        timeouts and not trying to hit external catalogs that take a long time
        to respond. See the docstring for
        :py:func:`astrobase.checkplot.pkl_utils._pkl_finder_objectinfo` for
        details on how this works. If this is True, will run in "fast" mode with
        default timeouts (5 seconds in most cases). If this is a float, will run
        in "fast" mode with the provided timeout value in seconds.

    findercmap : str or matplotlib.cm.ColorMap object
        The Colormap object to use for the finder chart image.

    finderconvolve : astropy.convolution.Kernel object or None
        If not None, the Kernel object to use for convolving the finder image.

    deredden_objects : bool
        If this is True, will use the 2MASS DUST service to get extinction
        coefficients in various bands, and then try to deredden the magnitudes
        and colors of the object already present in the checkplot's objectinfo
        dict.

    custom_bandpasses : dict
        This is a dict used to provide custom bandpass definitions for any
        magnitude measurements in the objectinfo dict that are not automatically
        recognized by the `varclass.starfeatures.color_features` function. See
        its docstring for details on the required format.

    gaia_submit_timeout : float
        Sets the timeout in seconds to use when submitting a request to look up
        the object's information to the GAIA service. Note that if `fast_mode`
        is set, this is ignored.

    gaia_submit_tries : int
        Sets the maximum number of times the GAIA services will be contacted to
        obtain this object's information. If `fast_mode` is set, this is
        ignored, and the services will be contacted only once (meaning that a
        failure to respond will be silently ignored and no GAIA data will be
        added to the checkplot's objectinfo dict).

    gaia_max_timeout : float
        Sets the timeout in seconds to use when waiting for the GAIA service to
        respond to our request for the object's information. Note that if
        `fast_mode` is set, this is ignored.

    gaia_mirror : str
        This sets the GAIA mirror to use. This is a key in the
        :py:data:`astrobase.services.gaia.GAIA_URLS` dict which defines the URLs
        to hit for each mirror.

    complete_query_later : bool
        If this is True, saves the state of GAIA queries that are not yet
        complete when `gaia_max_timeout` is reached while waiting for the GAIA
        service to respond to our request. A later call for GAIA info on the
        same object will attempt to pick up the results from the existing query
        if it's completed. If `fast_mode` is True, this is ignored.

    lclistpkl : dict or str
        If this is provided, must be a dict resulting from reading a catalog
        produced by the `lcproc.catalogs.make_lclist` function or a str path
        pointing to the pickle file produced by that function. This catalog is
        used to find neighbors of the current object in the current light curve
        collection. Looking at neighbors of the object within the radius
        specified by `nbrradiusarcsec` is useful for light curves produced by
        instruments that have a large pixel scale, so are susceptible to
        blending of variability and potential confusion of neighbor variability
        with that of the actual object being looked at. If this is None, no
        neighbor lookups will be performed.

    nbrradiusarcsec : float
        The radius in arcseconds to use for a search conducted around the
        coordinates of this object to look for any potential confusion and
        blending of variability amplitude caused by their proximity.

    maxnumneighbors : int
        The maximum number of neighbors that will have their light curves and
        magnitudes noted in this checkplot as potential blends with the target
        object.

    plotdpi : int
        The resolution in DPI of the plots to generate in this function
        (e.g. the finder chart, etc.)

    findercachedir : str
        The path to the astrobase cache directory for finder chart downloads
        from the NASA SkyView service.

    verbose : bool
        If True, will indicate progress and warn about potential problems.

    Returns
    -------

    str
        Path to the updated checkplot pickle file.


This is used to prevent any further changes to the checkplot.

    TODO: finish this.

    Use this function after all variable classification, period-finding, and
    object xmatches are done. This function will add a 'final' key to the
    checkplot, which will contain:

    - a phased LC plot with the period and epoch set after review using the
      times, mags, errs after any appropriate filtering and sigclip was done in
      the checkplotserver UI

    - The unphased LC using the times, mags, errs after any appropriate
      filtering and sigclip was done in the checkplotserver UI

    - the same plots for any LC collection neighbors

    - the survey cutout for the object if objfits is provided and checks out

    - a redone neighbor search using GAIA and all light curves in the collection
      even if they don't have at least 1000 observations.

    These items will be shown in a special 'Final' tab in the `checkplotserver`
    webapp (this should be run in `readonly` mode as well). The final tab will
    also contain downloadable links for the checkplot pickle in pkl and PNG
    format, as well as the final times, mags, errs as a gzipped CSV with a
    header containing all of this info.

    Parameters
    ----------

    cpx : dict or str
        This is the path to the checkplot dict or pickle file to process.

    outdir : str
        This is the directory to where the final pickle will be written. If this
        is set to the same dir as `cpx` and `cpx` is a pickle, the function will
        return a failure. This is meant to keep the in-process checkplots
        separate from the finalized versions.

    all_lclistpkl : str or dict
        This is the path to the pickle or the dict created by
        :py:func:`astrobase.lcproc.catalogs.make_lclist` with no restrictions on
        the number of observations (so ALL light curves in the collection). This
        is used to make sure all neighbors of this object in the light curve
        collection have had their proximity to this object noted.

    objfits : str or None
        If this is not None, should be a file path to a FITS file containing a
        WCS header and this object from the instrument that was used to observe
        it. This will be used to make a stamp cutout of the object using the
        actual image it was detected on. This will be a useful comparison to the
        usual DSS POSS-RED2 image used by the checkplots.

    Returns
    -------

    str
        The path to the updated checkplot pickle file with a 'final' key added
        to it , as described above.


This is a parallel driver for `finalize_checkplot`, operating on a list
    of checkplots.

    Parameters
    ----------

    cplist : list of str
        This is a list of paths of all checkplot pickles to process and run
        through the finalization process.

    outdir : str
        The directory to where the finalized checkplot pickles will be written.

    objfits : str
        Path to the FITS file containing a WCS header and detections of all
        objects observed by the actual instrument that obtained the light
        curves. This should generally be a high quality 'reference' frame so
        that all of the objects whose checkplots we're finalizing (in `cplist`)
        can be seen on the frame.

    Returns
    -------

    dict
        Dict indicating the success/failure (as True/False) of the checkplot
        finalize operations for each checkplot pickle provided in `cplist`.


This is a parallel driver for `finalize_checkplot`, operating on a
    directory of checkplots.

    Parameters
    ----------

    cpdir : str
        This is the path to the directory containing all the checkplot pickles
        to process and run through the finalization process.

    outdir : str
        The directory to where the finalized checkplot pickles will be written.

    objfits : str
        Path to the FITS file containing a WCS header and detections of all
        objects observed by the actual instrument that obtained the light
        curves. This should generally be a high quality 'reference' frame so
        that all of the objects whose checkplots we're finalizing (in `cplist`)
        can be seen on the frame.

    Returns
    -------

    dict
        Dict indicating the success/failure (as True/False) of the checkplot
        finalize operations for each checkplot pickle provided in `cplist`.


def _base64_to_file(b64str, outfpath, writetostrio=False):

try:<EOL><INDENT>filebytes = base64.b64decode(b64str)<EOL>if writetostrio:<EOL><INDENT>outobj = StrIO(filebytes)<EOL>return outobj<EOL><DEDENT>else:<EOL><INDENT>with open(outfpath,'<STR_LIT:wb>') as outfd:<EOL><INDENT>outfd.write(filebytes)<EOL><DEDENT>if os.path.exists(outfpath):<EOL><INDENT>return outfpath<EOL><DEDENT>else:<EOL><INDENT>LOGERROR('<STR_LIT>' % outfpath)<EOL>return None<EOL><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>'<EOL>'<STR_LIT>' % outfpath)<EOL>return None<EOL><DEDENT>

This converts the base64 encoded string to a file.

    Parameters
    ----------

    b64str : str
        A base64 encoded strin that is the output of `base64.b64encode`.

    outfpath : str
        The path to where the file will be written. This should include an
        appropriate extension for the file (e.g. a base64 encoded string that
        represents a PNG should have its `outfpath` end in a '.png') so the OS
        can open these files correctly.

    writetostrio : bool
        If this is True, will return a StringIO object with the binary stream
        decoded from the base64-encoded input string `b64str`. This can be
        useful to embed these into other files without having to write them to
        disk.

    Returns
    -------

    str or StringIO object
        If `writetostrio` is False, will return the output file's path as a
        str. If it is True, will return a StringIO object directly. If writing
        the file fails in either case, will return None.


if checkplotpickle.endswith('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>with gzip.open(checkplotpickle,'<STR_LIT:rb>') as infd:<EOL><INDENT>cpdict = pickle.load(infd)<EOL><DEDENT><DEDENT>except UnicodeDecodeError:<EOL><INDENT>with gzip.open(checkplotpickle,'<STR_LIT:rb>') as infd:<EOL><INDENT>cpdict = pickle.load(infd, encoding='<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>with open(checkplotpickle,'<STR_LIT:rb>') as infd:<EOL><INDENT>cpdict = pickle.load(infd)<EOL><DEDENT><DEDENT>except UnicodeDecodeError:<EOL><INDENT>with open(checkplotpickle,'<STR_LIT:rb>') as infd:<EOL><INDENT>cpdict = pickle.load(infd, encoding='<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>return cpdict<EOL>

This reads a checkplot gzipped pickle file back into a dict.

    NOTE: the try-except is for Python 2 pickles that have numpy arrays in
    them. Apparently, these aren't compatible with Python 3. See here:

    http://stackoverflow.com/q/11305790

    The workaround is noted in this answer:

    http://stackoverflow.com/a/41366785

    Parameters
    ----------

    checkplotpickle : str
        The path to a checkplot pickle file. This can be a gzipped file (in
        which case the file extension should end in '.gz')

    Returns
    -------

    dict
        This returns a checkplotdict.


<EOL>if ((sys.version_info[<NUM_LIT:0>:<NUM_LIT:2>] >= (<NUM_LIT:3>,<NUM_LIT:4>) and not protocol) or<EOL>(protocol > <NUM_LIT:2>)):<EOL><INDENT>protocol = <NUM_LIT:4><EOL><DEDENT>elif ((sys.version_info[<NUM_LIT:0>:<NUM_LIT:2>] >= (<NUM_LIT:3>,<NUM_LIT:0>) and not protocol) or<EOL>(protocol > <NUM_LIT:2>)):<EOL><INDENT>protocol = <NUM_LIT:3><EOL><DEDENT>elif sys.version_info[<NUM_LIT:0>:<NUM_LIT:2>] == (<NUM_LIT:2>,<NUM_LIT:7>) and not protocol:<EOL><INDENT>protocol = <NUM_LIT:2><EOL><DEDENT>elif not protocol:<EOL><INDENT>protocol = <NUM_LIT:0><EOL><DEDENT>if outgzip:<EOL><INDENT>if not outfile:<EOL><INDENT>outfile = (<EOL>'<STR_LIT>'.format(<EOL>objectid=squeeze(checkplotdict['<STR_LIT>']).replace('<STR_LIT:U+0020>','<STR_LIT:->')<EOL>)<EOL>)<EOL><DEDENT>with gzip.open(outfile,'<STR_LIT:wb>') as outfd:<EOL><INDENT>pickle.dump(checkplotdict,outfd,protocol=protocol)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not outfile:<EOL><INDENT>outfile = (<EOL>'<STR_LIT>'.format(<EOL>objectid=squeeze(checkplotdict['<STR_LIT>']).replace('<STR_LIT:U+0020>','<STR_LIT:->')<EOL>)<EOL>)<EOL><DEDENT>if outfile.endswith('<STR_LIT>'):<EOL><INDENT>LOGWARNING('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>with gzip.open(outfile,'<STR_LIT:wb>') as outfd:<EOL><INDENT>pickle.dump(checkplotdict,outfd,protocol=protocol)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>with open(outfile,'<STR_LIT:wb>') as outfd:<EOL><INDENT>pickle.dump(checkplotdict,outfd,protocol=protocol)<EOL><DEDENT><DEDENT><DEDENT>return os.path.abspath(outfile)<EOL>

This writes the checkplotdict to a (gzipped) pickle file.

    Parameters
    ----------

    checkplotdict : dict
        This the checkplotdict to write to the pickle file.

    outfile : None or str
        The path to the output pickle file to write. If `outfile` is None,
        writes a (gzipped) pickle file of the form:

        checkplot-{objectid}.pkl(.gz)

        to the current directory.

    protocol : int
        This sets the pickle file protocol to use when writing the pickle:

        If None, will choose a protocol using the following rules:

        - 4 -> default in Python >= 3.4 - fast but incompatible with Python 2
        - 3 -> default in Python 3.0-3.3 - mildly fast
        - 2 -> default in Python 2 - very slow, but compatible with Python 2/3

        The default protocol kwarg is None, this will make an automatic choice
        for pickle protocol that's best suited for the version of Python in
        use. Note that this will make pickles generated by Py3 incompatible with
        Py2.

    outgzip : bool
        If this is True, will gzip the output file. Note that if the `outfile`
        str ends in a gzip, this will be automatically turned on.

    Returns
    -------

    str
        The absolute path to the written checkplot pickle file. None if writing
        fails.


catdef = []<EOL>if xc.endswith('<STR_LIT>'):<EOL><INDENT>infd = gzip.open(xc,'<STR_LIT:rb>')<EOL><DEDENT>else:<EOL><INDENT>infd = open(xc,'<STR_LIT:rb>')<EOL><DEDENT>for line in infd:<EOL><INDENT>if line.decode().startswith('<STR_LIT:#>'):<EOL><INDENT>catdef.append(<EOL>line.decode().replace('<STR_LIT:#>','<STR_LIT>').strip().rstrip('<STR_LIT:\n>')<EOL>)<EOL><DEDENT>if not line.decode().startswith('<STR_LIT:#>'):<EOL><INDENT>break<EOL><DEDENT><DEDENT>if not len(catdef) > <NUM_LIT:0>:<EOL><INDENT>LOGERROR("<STR_LIT>"<EOL>"<STR_LIT>" % xc)<EOL>return None<EOL><DEDENT>catdef = '<STR_LIT:U+0020>'.join(catdef)<EOL>catdefdict = json.loads(catdef)<EOL>catdefkeys = [x['<STR_LIT:key>'] for x in catdefdict['<STR_LIT>']]<EOL>catdefdtypes = [x['<STR_LIT>'] for x in catdefdict['<STR_LIT>']]<EOL>catdefnames = [x['<STR_LIT:name>'] for x in catdefdict['<STR_LIT>']]<EOL>catdefunits = [x['<STR_LIT>'] for x in catdefdict['<STR_LIT>']]<EOL>catcolinds = []<EOL>catcoldtypes = []<EOL>catcolnames = []<EOL>catcolunits = []<EOL>for xkcol in xk:<EOL><INDENT>if xkcol in catdefkeys:<EOL><INDENT>xkcolind = catdefkeys.index(xkcol)<EOL>catcolinds.append(xkcolind)<EOL>catcoldtypes.append(catdefdtypes[xkcolind])<EOL>catcolnames.append(catdefnames[xkcolind])<EOL>catcolunits.append(catdefunits[xkcolind])<EOL><DEDENT><DEDENT>return (infd, catdefdict,<EOL>catcolinds, catcoldtypes, catcolnames, catcolunits)<EOL>

This parses the header for a catalog file and returns it as a file object.

Parameters
----------

xc : str
    The file name of an xmatch catalog prepared previously.

xk : list of str
    This is a list of column names to extract from the xmatch catalog.

Returns
-------

tuple
    The tuple returned is of the form::

        (infd: the file object associated with the opened xmatch catalog,
         catdefdict: a dict describing the catalog column definitions,
         catcolinds: column number indices of the catalog,
         catcoldtypes: the numpy dtypes of the catalog columns,
         catcolnames: the names of each catalog column,
         catcolunits: the units associated with each catalog column)


def load_xmatch_external_catalogs(xmatchto, xmatchkeys, outfile=None):

outdict = {}<EOL>for xc, xk in zip(xmatchto, xmatchkeys):<EOL><INDENT>parsed_catdef = _parse_xmatch_catalog_header(xc, xk)<EOL>if not parsed_catdef:<EOL><INDENT>continue<EOL><DEDENT>(infd, catdefdict,<EOL>catcolinds, catcoldtypes,<EOL>catcolnames, catcolunits) = parsed_catdef<EOL>catarr = np.genfromtxt(infd,<EOL>usecols=catcolinds,<EOL>names=xk,<EOL>dtype='<STR_LIT:U+002C>'.join(catcoldtypes),<EOL>comments='<STR_LIT:#>',<EOL>delimiter='<STR_LIT:|>',<EOL>autostrip=True)<EOL>infd.close()<EOL>catshortname = os.path.splitext(os.path.basename(xc))[<NUM_LIT:0>]<EOL>catshortname = catshortname.replace('<STR_LIT>','<STR_LIT>')<EOL>objra, objdecl = (catarr[catdefdict['<STR_LIT>']],<EOL>catarr[catdefdict['<STR_LIT>']])<EOL>cosdecl = np.cos(np.radians(objdecl))<EOL>sindecl = np.sin(np.radians(objdecl))<EOL>cosra = np.cos(np.radians(objra))<EOL>sinra = np.sin(np.radians(objra))<EOL>xyz = np.column_stack((cosra*cosdecl,sinra*cosdecl, sindecl))<EOL>kdt = cKDTree(xyz,copy_data=True)<EOL>catoutdict = {'<STR_LIT>':kdt,<EOL>'<STR_LIT:data>':catarr,<EOL>'<STR_LIT>':xk,<EOL>'<STR_LIT>':catcolnames,<EOL>'<STR_LIT>':catcolunits,<EOL>'<STR_LIT:name>':catdefdict['<STR_LIT:name>'],<EOL>'<STR_LIT>':catdefdict['<STR_LIT:description>']}<EOL>outdict[catshortname] = catoutdict<EOL><DEDENT>if outfile is not None:<EOL><INDENT>if sys.platform == '<STR_LIT>':<EOL><INDENT>dumpbytes = pickle.dumps(outdict, protocol=pickle.HIGHEST_PROTOCOL)<EOL>max_bytes = <NUM_LIT:2>**<NUM_LIT> - <NUM_LIT:1><EOL>with open(outfile, '<STR_LIT:wb>') as outfd:<EOL><INDENT>for idx in range(<NUM_LIT:0>, len(dumpbytes), max_bytes):<EOL><INDENT>outfd.write(dumpbytes[idx:idx+max_bytes])<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>with open(outfile, '<STR_LIT:wb>') as outfd:<EOL><INDENT>pickle.dump(outdict, outfd, pickle.HIGHEST_PROTOCOL)<EOL><DEDENT><DEDENT>return outfile<EOL><DEDENT>else:<EOL><INDENT>return outdict<EOL><DEDENT>

This loads the external xmatch catalogs into a dict for use in an xmatch.

    Parameters
    ----------

    xmatchto : list of str
        This is a list of paths to all the catalog text files that will be
        loaded.

        The text files must be 'CSVs' that use the '|' character as the
        separator betwen columns. These files should all begin with a header in
        JSON format on lines starting with the '#' character. this header will
        define the catalog and contains the name of the catalog and the column
        definitions. Column definitions must have the column name and the numpy
        dtype of the columns (in the same format as that expected for the
        numpy.genfromtxt function). Any line that does not begin with '#' is
        assumed to be part of the columns in the catalog. An example is shown
        below::

            # {"name":"NSVS catalog of variable stars",
            #  "columns":[
            #   {"key":"objectid", "dtype":"U20", "name":"Object ID", "unit": null},
            #   {"key":"ra", "dtype":"f8", "name":"RA", "unit":"deg"},
            #   {"key":"decl","dtype":"f8", "name": "Declination", "unit":"deg"},
            #   {"key":"sdssr","dtype":"f8","name":"SDSS r", "unit":"mag"},
            #   {"key":"vartype","dtype":"U20","name":"Variable type", "unit":null}
            #  ],
            #  "colra":"ra",
            #  "coldec":"decl",
            #  "description":"Contains variable stars from the NSVS catalog"}
            objectid1 | 45.0  | -20.0 | 12.0 | detached EB
            objectid2 | 145.0 | 23.0  | 10.0 | RRab
            objectid3 | 12.0  | 11.0  | 14.0 | Cepheid
            .
            .
            .

    xmatchkeys : list of lists
        This is the list of lists of column names (as str) to get out of each
        `xmatchto` catalog. This should be the same length as `xmatchto` and
        each element here will apply to the respective file in `xmatchto`.

    outfile : str or None
        If this is not None, set this to the name of the pickle to write the
        collected xmatch catalogs to. this pickle can then be loaded
        transparently by the :py:func:`astrobase.checkplot.pkl.checkplot_dict`,
        :py:func:`astrobase.checkplot.pkl.checkplot_pickle` functions to provide
        xmatch info to the
        :py:func:`astrobase.checkplot.pkl_xmatch.xmatch_external_catalogs`
        function below.

        If this is None, will return the loaded xmatch catalogs directly. This
        will be a huge dict, so make sure you have enough RAM.

    Returns
    -------

    str or dict
        Based on the `outfile` kwarg, will either return the path to a collected
        xmatch pickle file or the collected xmatch dict.


<EOL>if isinstance(xmatchinfo, str) and os.path.exists(xmatchinfo):<EOL><INDENT>with open(xmatchinfo,'<STR_LIT:rb>') as infd:<EOL><INDENT>xmatchdict = pickle.load(infd)<EOL><DEDENT><DEDENT>elif isinstance(xmatchinfo, dict):<EOL><INDENT>xmatchdict = xmatchinfo<EOL><DEDENT>else:<EOL><INDENT>LOGERROR("<STR_LIT>")<EOL>return checkplotdict<EOL><DEDENT>objra = checkplotdict['<STR_LIT>']['<STR_LIT>']<EOL>objdecl = checkplotdict['<STR_LIT>']['<STR_LIT>']<EOL>cosdecl = np.cos(np.radians(objdecl))<EOL>sindecl = np.sin(np.radians(objdecl))<EOL>cosra = np.cos(np.radians(objra))<EOL>sinra = np.sin(np.radians(objra))<EOL>objxyz = np.column_stack((cosra*cosdecl,<EOL>sinra*cosdecl,<EOL>sindecl))<EOL>xyzdist = <NUM_LIT> * np.sin(np.radians(xmatchradiusarcsec/<NUM_LIT>)/<NUM_LIT>)<EOL>xmatchresults = {}<EOL>extcats = sorted(list(xmatchdict.keys()))<EOL>for ecat in extcats:<EOL><INDENT>kdt = xmatchdict[ecat]['<STR_LIT>']<EOL>kdt_dist, kdt_ind = kdt.query(objxyz,<EOL>k=<NUM_LIT:1>,<EOL>distance_upper_bound=xyzdist)<EOL>mdsorted = np.argsort(kdt_dist)<EOL>matchdists = kdt_dist[mdsorted]<EOL>matchinds = kdt_ind[mdsorted]<EOL>if matchdists[np.isfinite(matchdists)].size == <NUM_LIT:0>:<EOL><INDENT>xmatchresults[ecat] = {'<STR_LIT:name>':xmatchdict[ecat]['<STR_LIT:name>'],<EOL>'<STR_LIT>':xmatchdict[ecat]['<STR_LIT>'],<EOL>'<STR_LIT>':False,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT:info>':None}<EOL><DEDENT>else:<EOL><INDENT>for md, mi in zip(matchdists, matchinds):<EOL><INDENT>if np.isfinite(md) and md < xyzdist:<EOL><INDENT>infodict = {}<EOL>distarcsec = _xyzdist_to_distarcsec(md)<EOL>for col in xmatchdict[ecat]['<STR_LIT>']:<EOL><INDENT>coldata = xmatchdict[ecat]['<STR_LIT:data>'][col][mi]<EOL>if isinstance(coldata, str):<EOL><INDENT>coldata = coldata.strip()<EOL><DEDENT>infodict[col] = coldata<EOL><DEDENT>xmatchresults[ecat] = {<EOL>'<STR_LIT:name>':xmatchdict[ecat]['<STR_LIT:name>'],<EOL>'<STR_LIT>':xmatchdict[ecat]['<STR_LIT>'],<EOL>'<STR_LIT>':True,<EOL>'<STR_LIT>':distarcsec,<EOL>'<STR_LIT:info>':infodict,<EOL>'<STR_LIT>':xmatchdict[ecat]['<STR_LIT>'],<EOL>'<STR_LIT>':xmatchdict[ecat]['<STR_LIT>'],<EOL>'<STR_LIT>':xmatchdict[ecat]['<STR_LIT>'],<EOL>}<EOL>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if returndirect:<EOL><INDENT>return xmatchresults<EOL><DEDENT>else:<EOL><INDENT>if updatexmatch and '<STR_LIT>' in checkplotdict:<EOL><INDENT>checkplotdict['<STR_LIT>'].update(xmatchresults)<EOL><DEDENT>else:<EOL><INDENT>checkplotdict['<STR_LIT>'] = xmatchresults<EOL><DEDENT>if savepickle:<EOL><INDENT>cpf = _write_checkplot_picklefile(checkplotdict,<EOL>outfile=savepickle,<EOL>protocol=<NUM_LIT:4>)<EOL>return cpf<EOL><DEDENT>else:<EOL><INDENT>return checkplotdict<EOL><DEDENT><DEDENT>

This matches the current object in the checkplotdict to all of the
    external match catalogs specified.

    Parameters
    ----------

    checkplotdict : dict
        This is a checkplotdict, generated by either the `checkplot_dict`
        function, or read in from a `_read_checkplot_picklefile` function. This
        must have a structure somewhat like the following, where the indicated
        keys below are required::

            {'objectid': the ID assigned to this object
             'objectinfo': {'objectid': ID assigned to this object,
                            'ra': right ascension of the object in decimal deg,
                            'decl': declination of the object in decimal deg}}

    xmatchinfo : str or dict
        This is either the xmatch dict produced by the function
        :py:func:`astrobase.checkplot.pkl_xmatch.load_xmatch_external_catalogs`
        above, or the path to the xmatch info pickle file produced by that
        function.

    xmatchradiusarcsec : float
        This is the cross-matching radius to use in arcseconds.

    returndirect : bool
        If this is True, will only return the xmatch results as a dict. If this
        False, will return the checkplotdict with the xmatch results added in as
        a key-val pair.

    updatexmatch : bool
        This function will look for an existing 'xmatch' key in the input
        checkplotdict indicating that an xmatch has been performed before. If
        `updatexmatch` is set to True, the xmatch results will be added onto
        (e.g. when xmatching to additional catalogs after the first run). If
        this is set to False, the xmatch key-val pair will be completely
        overwritten.

    savepickle : str or None
        If this is None, it must be a path to where the updated checkplotdict
        will be written to as a new checkplot pickle. If this is False, only the
        updated checkplotdict is returned.

    Returns
    -------

    dict or str
        If `savepickle` is False, this returns a checkplotdict, with the xmatch
        results added in. An 'xmatch' key will be added to this dict, with
        something like the following dict as the value::

            {'xmatchradiusarcsec':xmatchradiusarcsec,
             'catalog1':{'name':'Catalog of interesting things',
                        'found':True,
                        'distarcsec':0.7,
                        'info':{'objectid':...,'ra':...,'decl':...,'desc':...}},
             'catalog2':{'name':'Catalog of more interesting things',
                         'found':False,
                         'distarcsec':nan,
                         'info':None},
            .
            .
            .
            ....}

        This will contain the matches of the object in the input checkplotdict
        to all of the catalogs provided in `xmatchinfo`.

        If `savepickle` is True, will return the path to the saved checkplot
        pickle file.


<EOL>pgramylabel = PLOTYLABELS[lspinfo['<STR_LIT>']]<EOL>periods = lspinfo['<STR_LIT>']<EOL>lspvals = lspinfo['<STR_LIT>']<EOL>bestperiod = lspinfo['<STR_LIT>']<EOL>nbestperiods = lspinfo['<STR_LIT>']<EOL>nbestlspvals = lspinfo['<STR_LIT>']<EOL>axes.plot(periods,lspvals)<EOL>axes.set_xscale('<STR_LIT>',basex=<NUM_LIT:10>)<EOL>axes.set_xlabel('<STR_LIT>')<EOL>axes.set_ylabel(pgramylabel)<EOL>plottitle = '<STR_LIT>' % (METHODLABELS[lspinfo['<STR_LIT>']],<EOL>bestperiod)<EOL>axes.set_title(plottitle)<EOL>for bestperiod, bestpeak in zip(nbestperiods,<EOL>nbestlspvals):<EOL><INDENT>axes.annotate('<STR_LIT>' % bestperiod,<EOL>xy=(bestperiod, bestpeak), xycoords='<STR_LIT:data>',<EOL>xytext=(<NUM_LIT:0.0>,<NUM_LIT>), textcoords='<STR_LIT>',<EOL>arrowprops=dict(arrowstyle="<STR_LIT>"),fontsize='<STR_LIT>')<EOL><DEDENT>axes.grid(color='<STR_LIT>',<EOL>alpha=<NUM_LIT>,<EOL>zorder=<NUM_LIT:0>,<EOL>linewidth=<NUM_LIT:1.0>,<EOL>linestyle='<STR_LIT::>')<EOL>if (objectinfo and isinstance(objectinfo, dict) and<EOL>('<STR_LIT>' in objectinfo or '<STR_LIT>' in objectinfo) and<EOL>'<STR_LIT>' in objectinfo and '<STR_LIT>' in objectinfo and<EOL>objectinfo['<STR_LIT>'] and objectinfo['<STR_LIT>']):<EOL><INDENT>if '<STR_LIT>' not in objectinfo:<EOL><INDENT>objectid = objectinfo['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>objectid = objectinfo['<STR_LIT>']<EOL><DEDENT>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(objectid, objectinfo['<STR_LIT>'], objectinfo['<STR_LIT>']))<EOL><DEDENT>if ('<STR_LIT>' in objectinfo and '<STR_LIT>' in objectinfo and<EOL>'<STR_LIT>' in objectinfo and '<STR_LIT>' in objectinfo and<EOL>'<STR_LIT>' in objectinfo and<EOL>objectinfo['<STR_LIT>'] and objectinfo['<STR_LIT>'] and<EOL>objectinfo['<STR_LIT>'] and objectinfo['<STR_LIT>'] and<EOL>objectinfo['<STR_LIT>']):<EOL><INDENT>bvcolor = objectinfo['<STR_LIT>'] - objectinfo['<STR_LIT>']<EOL>jkcolor = objectinfo['<STR_LIT>'] - objectinfo['<STR_LIT>']<EOL>ijcolor = objectinfo['<STR_LIT>'] - objectinfo['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>bvcolor = None<EOL>jkcolor = None<EOL>ijcolor = None<EOL><DEDENT>if ('<STR_LIT>' in objectinfo and '<STR_LIT>' in objectinfo and<EOL>objectinfo['<STR_LIT>'] and objectinfo['<STR_LIT>']):<EOL><INDENT>teff_val = objectinfo['<STR_LIT>']<EOL>gmag = objectinfo['<STR_LIT>']<EOL><DEDENT>lspylim = axes.get_ylim()<EOL>axes.set_ylim(lspylim[<NUM_LIT:0>], lspylim[<NUM_LIT:1>]+<NUM_LIT>*(lspylim[<NUM_LIT:1>]-lspylim[<NUM_LIT:0>]))<EOL>try:<EOL><INDENT>dss, dssheader = skyview_stamp(objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>'],<EOL>convolvewith=finderconvolve,<EOL>flip=False,<EOL>cachedir=findercachedir,<EOL>verbose=verbose)<EOL>stamp = dss<EOL>inset = inset_axes(axes, width="<STR_LIT>", height="<STR_LIT>", loc=<NUM_LIT:1>)<EOL>inset.imshow(stamp, cmap=findercmap, origin='<STR_LIT>')<EOL>inset.set_xticks([])<EOL>inset.set_yticks([])<EOL>inset.set_frame_on(False)<EOL>inset.axvline(x=<NUM_LIT>,ymin=<NUM_LIT>,ymax=<NUM_LIT>,linewidth=<NUM_LIT>,color='<STR_LIT:b>')<EOL>inset.axhline(y=<NUM_LIT>,xmin=<NUM_LIT>,xmax=<NUM_LIT>,linewidth=<NUM_LIT>,color='<STR_LIT:b>')<EOL><DEDENT>except OSError as e:<EOL><INDENT>LOGERROR('<STR_LIT>')<EOL>dss, dssheader = skyview_stamp(objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>'],<EOL>convolvewith=finderconvolve,<EOL>flip=False,<EOL>forcefetch=True,<EOL>cachedir=findercachedir,<EOL>verbose=verbose)<EOL>stamp = dss<EOL>inset = inset_axes(axes, width="<STR_LIT>", height="<STR_LIT>", loc=<NUM_LIT:1>)<EOL>inset.imshow(stamp, cmap=findercmap, origin='<STR_LIT>')<EOL>inset.set_xticks([])<EOL>inset.set_yticks([])<EOL>inset.set_frame_on(False)<EOL>inset.axvline(x=<NUM_LIT>,ymin=<NUM_LIT>,ymax=<NUM_LIT>,linewidth=<NUM_LIT>,color='<STR_LIT:b>')<EOL>inset.axhline(y=<NUM_LIT>,xmin=<NUM_LIT>,xmax=<NUM_LIT>,linewidth=<NUM_LIT>,color='<STR_LIT:b>')<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(objectid, objectinfo['<STR_LIT>'], objectinfo['<STR_LIT>']))<EOL><DEDENT>axes.text(<EOL><NUM_LIT>,<NUM_LIT>,<EOL>'<STR_LIT:%s>' % objectid,<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT><EOL>)<EOL>axes.text(<EOL><NUM_LIT>,<NUM_LIT>,<EOL>'<STR_LIT>' % (objectinfo['<STR_LIT>'], objectinfo['<STR_LIT>']),<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT><EOL>)<EOL>if bvcolor:<EOL><INDENT>axes.text(<NUM_LIT>,<NUM_LIT>,<EOL>'<STR_LIT>' % (bvcolor,<EOL>objectinfo['<STR_LIT>']),<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL><DEDENT>elif '<STR_LIT>' in objectinfo and objectinfo['<STR_LIT>']:<EOL><INDENT>axes.text(<NUM_LIT>,<NUM_LIT>,<EOL>'<STR_LIT>' % (objectinfo['<STR_LIT>'],),<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL><DEDENT>if ijcolor:<EOL><INDENT>axes.text(<NUM_LIT>,<NUM_LIT>,<EOL>'<STR_LIT>' % (ijcolor,<EOL>objectinfo['<STR_LIT>']),<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL><DEDENT>elif '<STR_LIT>' in objectinfo and objectinfo['<STR_LIT>']:<EOL><INDENT>axes.text(<NUM_LIT>,<NUM_LIT>,<EOL>'<STR_LIT>' % (objectinfo['<STR_LIT>'],),<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL><DEDENT>if jkcolor:<EOL><INDENT>axes.text(<NUM_LIT>,<NUM_LIT>,<EOL>'<STR_LIT>' % (jkcolor,<EOL>objectinfo['<STR_LIT>']),<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL><DEDENT>elif '<STR_LIT>' in objectinfo and objectinfo['<STR_LIT>']:<EOL><INDENT>axes.text(<NUM_LIT>,<NUM_LIT>,<EOL>'<STR_LIT>' % (objectinfo['<STR_LIT>'],),<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL><DEDENT>if '<STR_LIT>' in objectinfo and objectinfo['<STR_LIT>']:<EOL><INDENT>axes.text(<NUM_LIT>,<NUM_LIT>,'<STR_LIT>' % objectinfo['<STR_LIT>'],<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL><DEDENT>if ('<STR_LIT>' in objectinfo and '<STR_LIT>' in objectinfo and<EOL>objectinfo['<STR_LIT>'] and objectinfo['<STR_LIT>']):<EOL><INDENT>axes.text(<NUM_LIT>,<NUM_LIT>,<EOL>r'<STR_LIT>' % (<EOL>gmag, int(teff_val)),<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL><DEDENT>if ('<STR_LIT>' in objectinfo and objectinfo['<STR_LIT>'] and<EOL>'<STR_LIT>' in objectinfo and objectinfo['<STR_LIT>']):<EOL><INDENT>pm = total_proper_motion(objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>'])<EOL>axes.text(<NUM_LIT>,<NUM_LIT>,r'<STR_LIT>' % pm,<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL>if '<STR_LIT>' in objectinfo and objectinfo['<STR_LIT>']:<EOL><INDENT>rpm = reduced_proper_motion(objectinfo['<STR_LIT>'],pm)<EOL>axes.text(<NUM_LIT>,<NUM_LIT>,'<STR_LIT>' % rpm,<EOL>ha='<STR_LIT:left>',va='<STR_LIT>',transform=axes.transAxes,<EOL>fontsize=<NUM_LIT>)<EOL><DEDENT><DEDENT><DEDENT>

Makes periodogram, objectinfo, and finder tile for `checkplot_png` and
    `twolsp_checkplot_png`.

    Parameters
    ----------

    axes : matplotlib.axes.Axes object
        The Axes object which will contain the plot being made.

    lspinfo : dict
        Dict containing results from a period-finder in `astrobase.periodbase`
        or a dict that corresponds to that format.

    objectinfo : dict
        Dict containing basic info about the object being processed.

    findercmap : matplotlib Colormap object or str
        The Colormap object to use for the finder chart image.

    finderconvolve : astropy.convolution.Kernel object or None
        If not None, the Kernel object to use for convolving the finder image.

    verbose : bool
        If True, indicates progress.

    findercachedir : str
        The directory where the FITS finder images are downloaded and cached.

    Returns
    -------

    Does not return anything, works on the input Axes object directly.


scaledplottime = stimes - npmin(stimes)<EOL>axes.plot(scaledplottime,<EOL>smags,<EOL>marker='<STR_LIT:o>',<EOL>ms=ms, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL>if not magsarefluxes:<EOL><INDENT>plot_ylim = axes.get_ylim()<EOL>axes.set_ylim((plot_ylim[<NUM_LIT:1>], plot_ylim[<NUM_LIT:0>]))<EOL><DEDENT>axes.set_xlim((npmin(scaledplottime)-<NUM_LIT:1.0>,<EOL>npmax(scaledplottime)+<NUM_LIT:1.0>))<EOL>axes.grid(color='<STR_LIT>',<EOL>alpha=<NUM_LIT>,<EOL>zorder=<NUM_LIT:0>,<EOL>linewidth=<NUM_LIT:1.0>,<EOL>linestyle='<STR_LIT::>')<EOL>plot_xlabel = '<STR_LIT>' % npmin(stimes)<EOL>if magsarefluxes:<EOL><INDENT>plot_ylabel = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>plot_ylabel = '<STR_LIT>'<EOL><DEDENT>axes.set_xlabel(plot_xlabel)<EOL>axes.set_ylabel(plot_ylabel)<EOL>axes.get_yaxis().get_major_formatter().set_useOffset(False)<EOL>axes.get_xaxis().get_major_formatter().set_useOffset(False)<EOL>

Makes the mag-series plot tile for `checkplot_png` and
    `twolsp_checkplot_png`.

    axes : matplotlib.axes.Axes object
        The Axes object where the generated plot will go.

    stimes,smags,serrs : np.array
        The mag/flux time-series arrays along with associated errors. These
        should all have been run through nan-stripping and sigma-clipping
        beforehand.

    magsarefluxes : bool
        If True, indicates the input time-series is fluxes and not mags so the
        plot y-axis direction and range can be set appropriately.

    ms : float
        The `markersize` kwarg to use when making the mag-series plot.

    Returns
    -------

    Does not return anything, works on the input Axes object directly.


plotvarepoch = None<EOL>if varepoch is None:<EOL><INDENT>plotvarepoch = npmin(stimes)<EOL><DEDENT>elif isinstance(varepoch, str) and varepoch == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>spfit = spline_fit_magseries(stimes,<EOL>smags,<EOL>serrs,<EOL>varperiod,<EOL>magsarefluxes=magsarefluxes,<EOL>sigclip=None,<EOL>verbose=verbose)<EOL>plotvarepoch = spfit['<STR_LIT>']['<STR_LIT>']<EOL>if len(plotvarepoch) != <NUM_LIT:1>:<EOL><INDENT>plotvarepoch = varepoch[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGERROR('<STR_LIT>')<EOL>sgfit = savgol_fit_magseries(stimes,<EOL>smags,<EOL>serrs,<EOL>varperiod,<EOL>sigclip=None,<EOL>magsarefluxes=magsarefluxes,<EOL>verbose=verbose)<EOL>plotvarepoch = sgfit['<STR_LIT>']['<STR_LIT>']<EOL>if len(plotvarepoch) != <NUM_LIT:1>:<EOL><INDENT>plotvarepoch = plotvarepoch[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if plotvarepoch is None:<EOL><INDENT>LOGERROR('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>plotvarepoch = npmin(stimes)<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(varepoch, list):<EOL><INDENT>try:<EOL><INDENT>if twolspmode:<EOL><INDENT>thisvarepochlist = varepoch[lspmethodind]<EOL>plotvarepoch = thisvarepochlist[periodind]<EOL><DEDENT>else:<EOL><INDENT>plotvarepoch = varepoch[periodind]<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>plotvarepoch = npmin(stimes)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>plotvarepoch = varepoch<EOL><DEDENT>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>' %<EOL>(varperiod, plotvarepoch))<EOL><DEDENT>phasedlc = phase_magseries(stimes,<EOL>smags,<EOL>varperiod,<EOL>plotvarepoch,<EOL>wrap=phasewrap,<EOL>sort=phasesort)<EOL>plotphase = phasedlc['<STR_LIT>']<EOL>plotmags = phasedlc['<STR_LIT>']<EOL>if phasebin:<EOL><INDENT>binphasedlc = phase_bin_magseries(plotphase,<EOL>plotmags,<EOL>binsize=phasebin,<EOL>minbinelems=minbinelems)<EOL>binplotphase = binphasedlc['<STR_LIT>']<EOL>binplotmags = binphasedlc['<STR_LIT>']<EOL><DEDENT>axes.plot(plotphase,<EOL>plotmags,<EOL>marker='<STR_LIT:o>',<EOL>ms=phasems, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL>if phasebin:<EOL><INDENT>axes.plot(binplotphase,<EOL>binplotmags,<EOL>marker='<STR_LIT:o>',<EOL>ms=phasebinms, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL><DEDENT>if not magsarefluxes:<EOL><INDENT>plot_ylim = axes.get_ylim()<EOL>axes.set_ylim((plot_ylim[<NUM_LIT:1>], plot_ylim[<NUM_LIT:0>]))<EOL><DEDENT>if not plotxlim:<EOL><INDENT>axes.set_xlim((npmin(plotphase)-<NUM_LIT:0.1>,<EOL>npmax(plotphase)+<NUM_LIT:0.1>))<EOL><DEDENT>else:<EOL><INDENT>axes.set_xlim((plotxlim[<NUM_LIT:0>],plotxlim[<NUM_LIT:1>]))<EOL><DEDENT>axes.grid(color='<STR_LIT>',<EOL>alpha=<NUM_LIT>,<EOL>zorder=<NUM_LIT:0>,<EOL>linewidth=<NUM_LIT:1.0>,<EOL>linestyle='<STR_LIT::>')<EOL>plot_xlabel = '<STR_LIT>'<EOL>if magsarefluxes:<EOL><INDENT>plot_ylabel = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>plot_ylabel = '<STR_LIT>'<EOL><DEDENT>axes.set_xlabel(plot_xlabel)<EOL>axes.set_ylabel(plot_ylabel)<EOL>axes.get_yaxis().get_major_formatter().set_useOffset(False)<EOL>axes.get_xaxis().get_major_formatter().set_useOffset(False)<EOL>if periodind == <NUM_LIT:0>:<EOL><INDENT>plottitle = '<STR_LIT>' % (<EOL>METHODSHORTLABELS[lspmethod],<EOL>varperiod,<EOL>plotvarepoch<EOL>)<EOL><DEDENT>elif periodind == <NUM_LIT:1> and not twolspmode:<EOL><INDENT>plottitle = '<STR_LIT>' % (<EOL>METHODSHORTLABELS[lspmethod],<EOL>varperiod,<EOL>plotvarepoch<EOL>)<EOL><DEDENT>elif periodind == <NUM_LIT:2> and not twolspmode:<EOL><INDENT>plottitle = '<STR_LIT>' % (<EOL>METHODSHORTLABELS[lspmethod],<EOL>varperiod,<EOL>plotvarepoch<EOL>)<EOL><DEDENT>elif periodind > <NUM_LIT:2> and not twolspmode:<EOL><INDENT>plottitle = '<STR_LIT>' % (<EOL>METHODSHORTLABELS[lspmethod],<EOL>periodind-<NUM_LIT:1>,<EOL>varperiod,<EOL>plotvarepoch<EOL>)<EOL><DEDENT>elif periodind > <NUM_LIT:0>:<EOL><INDENT>plottitle = '<STR_LIT>' % (<EOL>METHODSHORTLABELS[lspmethod],<EOL>periodind+<NUM_LIT:1>,<EOL>varperiod,<EOL>plotvarepoch<EOL>)<EOL><DEDENT>axes.set_title(plottitle)<EOL>if (plotxlim and isinstance(plotxlim, (list,tuple)) and<EOL>len(plotxlim) == <NUM_LIT:2> and xliminsetmode is True):<EOL><INDENT>axesylim = axes.get_ylim()<EOL>if magsarefluxes:<EOL><INDENT>axes.set_ylim(axesylim[<NUM_LIT:0>],<EOL>axesylim[<NUM_LIT:1>] + <NUM_LIT:0.5>*npabs(axesylim[<NUM_LIT:1>]-axesylim[<NUM_LIT:0>]))<EOL><DEDENT>else:<EOL><INDENT>axes.set_ylim(axesylim[<NUM_LIT:0>],<EOL>axesylim[<NUM_LIT:1>] - <NUM_LIT:0.5>*npabs(axesylim[<NUM_LIT:1>]-axesylim[<NUM_LIT:0>]))<EOL><DEDENT>inset = inset_axes(axes, width="<STR_LIT>", height="<STR_LIT>", loc=<NUM_LIT:1>)<EOL>inset.plot(plotphase,<EOL>plotmags,<EOL>marker='<STR_LIT:o>',<EOL>ms=<NUM_LIT>, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL>if phasebin:<EOL><INDENT>inset.plot(binplotphase,<EOL>binplotmags,<EOL>marker='<STR_LIT:o>',<EOL>ms=<NUM_LIT>, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL><DEDENT>if phasewrap:<EOL><INDENT>inset.set_xlim(-<NUM_LIT>,<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>inset.set_xlim(-<NUM_LIT:0.1>,<NUM_LIT>)<EOL><DEDENT>if not magsarefluxes:<EOL><INDENT>inset_ylim = inset.get_ylim()<EOL>inset.set_ylim((inset_ylim[<NUM_LIT:1>], inset_ylim[<NUM_LIT:0>]))<EOL><DEDENT>inset.text(<NUM_LIT:0.5>,<NUM_LIT:0.1>,'<STR_LIT>',<EOL>ha='<STR_LIT>',va='<STR_LIT>',transform=inset.transAxes)<EOL>inset.set_xticks([])<EOL>inset.set_yticks([])<EOL><DEDENT>

Makes the phased magseries plot tile for the `checkplot_png` and
    `twolsp_checkplot_png` functions.

    Parameters
    ----------

    axes : matplotlib.axes.Axes object
        The Axes object where the generated plot will be written.

    periodind : int
        The index of the current best period being processed in the lspinfo
        dict.

    stimes,smags,serrs : np.array
        The mag/flux time-series arrays along with associated errors. These
        should all have been run through nan-stripping and sigma-clipping
        beforehand.

    varperiod : float or None
        The period to use for this phased light curve plot tile.

    varepoch : 'min' or float or list of lists or None
        The epoch to use for this phased light curve plot tile. If this is a
        float, will use the provided value directly. If this is 'min', will
        automatically figure out the time-of-minimum of the phased light
        curve. If this is None, will use the mimimum value of `stimes` as the
        epoch of the phased light curve plot. If this is a list of lists, will
        use the provided value of `lspmethodind` to look up the current
        period-finder method and the provided value of `periodind` to look up
        the epoch associated with that method and the current period. This is
        mostly only useful when `twolspmode` is True.

    phasewrap : bool
        If this is True, the phased time-series will be wrapped around
        phase 0.0.

    phasesort : bool
        If True, will sort the phased light curve in order of increasing phase.

    phasebin: float
        The bin size to use to group together measurements closer than this
        amount in phase. This is in units of phase. If this is a float, a
        phase-binned version of the phased light curve will be overplotted on
        top of the regular phased light curve.

    minbinelems : int
        The minimum number of elements required per phase bin to include it in
        the phased LC plot.

    plotxlim : sequence of two floats or None
        The x-range (min, max) of the phased light curve plot. If None, will be
        determined automatically.

    lspmethod : str
        One of the three-letter keys corresponding to period-finder method names
        in the `astrobase.plotbase.METHODSHORTLABELS` dict. Used to set the plot
        title correctly.

    lspmethodind : int
        If `twolspmode` is set, this will be used to look up the correct epoch
        associated with the current period-finder method and period.

    xliminsetmode : bool
        If this is True, the generated phased light curve plot will use the
        values of `plotxlim` as the main plot x-axis limits (i.e. zoomed-in if
        `plotxlim` is a range smaller than the full phase range), and will show
        the full phased light curve plot as an smaller inset. Useful for
        planetary transit light curves.

    twolspmode : bool
        If this is True, will use the `lspmethodind` and `periodind` to look up
        the correct values of epoch, etc. in the provided `varepoch` list of
        lists for plotting purposes.

    magsarefluxes : bool
        If True, indicates the input time-series is fluxes and not mags so the
        plot y-axis direction and range can be set appropriately.

    verbose : bool
        If True, indicates progress.

    phasems : float
        The marker size to use for the main phased light curve plot symbols.

    phasebinms : float
        The marker size to use for the binned phased light curve plot symbols.

    Returns
    -------

    Does not return anything, works on the input Axes object directly.


if not outfile and isinstance(lspinfo,str):<EOL><INDENT>plotfpath = os.path.join(<EOL>os.path.dirname(lspinfo),<EOL>'<STR_LIT>' % (<EOL>os.path.basename(lspinfo),<EOL>)<EOL>)<EOL><DEDENT>elif outfile:<EOL><INDENT>plotfpath = outfile<EOL><DEDENT>else:<EOL><INDENT>plotfpath = '<STR_LIT>'<EOL><DEDENT>if isinstance(lspinfo,str) and os.path.exists(lspinfo):<EOL><INDENT>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>' % lspinfo)<EOL><DEDENT>if '<STR_LIT>' in lspinfo:<EOL><INDENT>with gzip.open(lspinfo,'<STR_LIT:rb>') as infd:<EOL><INDENT>lspinfo = pickle.load(infd)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>with open(lspinfo,'<STR_LIT:rb>') as infd:<EOL><INDENT>lspinfo = pickle.load(infd)<EOL><DEDENT><DEDENT><DEDENT>if ('<STR_LIT>' in lspinfo and<EOL>'<STR_LIT>' in lspinfo and<EOL>'<STR_LIT>' in lspinfo):<EOL><INDENT>bestperiod = lspinfo['<STR_LIT>']<EOL>nbestperiods = lspinfo['<STR_LIT>']<EOL>lspmethod = lspinfo['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>LOGERROR('<STR_LIT>')<EOL>return None<EOL><DEDENT>if not npisfinite(bestperiod):<EOL><INDENT>LOGWARNING('<STR_LIT>')<EOL>return None<EOL><DEDENT>fig, axes = plt.subplots(<NUM_LIT:3>,<NUM_LIT:3>)<EOL>axes = npravel(axes)<EOL>fig.set_size_inches(<NUM_LIT:30>,<NUM_LIT>)<EOL>_make_periodogram(axes[<NUM_LIT:0>],lspinfo,objectinfo,<EOL>findercmap, finderconvolve,<EOL>verbose=verbose,<EOL>findercachedir=findercachedir)<EOL>stimes, smags, serrs = sigclip_magseries(times,<EOL>mags,<EOL>errs,<EOL>magsarefluxes=magsarefluxes,<EOL>sigclip=sigclip)<EOL>if normto is not False:<EOL><INDENT>stimes, smags = normalize_magseries(stimes, smags,<EOL>normto=normto,<EOL>magsarefluxes=magsarefluxes,<EOL>mingap=normmingap)<EOL><DEDENT>if len(stimes) >= <NUM_LIT:50>:<EOL><INDENT>_make_magseries_plot(axes[<NUM_LIT:1>], stimes, smags, serrs,<EOL>magsarefluxes=magsarefluxes)<EOL>lspbestperiods = nbestperiods[::]<EOL>lspperiodone = lspbestperiods[<NUM_LIT:0>]<EOL>lspbestperiods.insert(<NUM_LIT:1>,lspperiodone*<NUM_LIT>)<EOL>lspbestperiods.insert(<NUM_LIT:1>,lspperiodone*<NUM_LIT:0.5>)<EOL>for periodind, varperiod in enumerate(lspbestperiods):<EOL><INDENT>if periodind == <NUM_LIT:0> and bestperiodhighlight:<EOL><INDENT>if MPLVERSION >= (<NUM_LIT:2>,<NUM_LIT:0>,<NUM_LIT:0>):<EOL><INDENT>axes[periodind+<NUM_LIT:2>].set_facecolor(bestperiodhighlight)<EOL><DEDENT>else:<EOL><INDENT>axes[periodind+<NUM_LIT:2>].set_axis_bgcolor(bestperiodhighlight)<EOL><DEDENT><DEDENT>_make_phased_magseries_plot(axes[periodind+<NUM_LIT:2>],<EOL>periodind,<EOL>stimes, smags, serrs,<EOL>varperiod, varepoch,<EOL>phasewrap, phasesort,<EOL>phasebin, minbinelems,<EOL>plotxlim, lspmethod,<EOL>xliminsetmode=xliminsetmode,<EOL>magsarefluxes=magsarefluxes,<EOL>verbose=verbose)<EOL><DEDENT>fig.set_tight_layout(True)<EOL>if plotfpath.endswith('<STR_LIT>'):<EOL><INDENT>fig.savefig(plotfpath,dpi=plotdpi)<EOL><DEDENT>else:<EOL><INDENT>fig.savefig(plotfpath)<EOL><DEDENT>plt.close('<STR_LIT:all>')<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>' % plotfpath)<EOL><DEDENT>return plotfpath<EOL><DEDENT>else:<EOL><INDENT>LOGWARNING('<STR_LIT>')<EOL>for periodind in range(<NUM_LIT:5>):<EOL><INDENT>axes[periodind+<NUM_LIT:2>].text(<EOL><NUM_LIT:0.5>,<NUM_LIT:0.5>,<EOL>('<STR_LIT>'),<EOL>horizontalalignment='<STR_LIT>',<EOL>verticalalignment='<STR_LIT>',<EOL>transform=axes[periodind+<NUM_LIT:2>].transAxes<EOL>)<EOL><DEDENT>fig.set_tight_layout(True)<EOL>if plotfpath.endswith('<STR_LIT>'):<EOL><INDENT>fig.savefig(plotfpath, dpi=plotdpi)<EOL><DEDENT>else:<EOL><INDENT>fig.savefig(plotfpath)<EOL><DEDENT>plt.close('<STR_LIT:all>')<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>' % plotfpath)<EOL><DEDENT>return plotfpath<EOL><DEDENT>

This makes a checkplot PNG using the output from a period-finder routine.

    A checkplot is a 3 x 3 grid of plots like so::

        [periodogram + objectinfo] [     unphased LC     ] [period 1 phased LC]
        [  period 1 phased LC /2 ] [period 1 phased LC x2] [period 2 phased LC]
        [   period 3 phased LC   ] [period 4 phased LC   ] [period 5 phased LC]

    This is used to sanity check the five best periods obtained from a
    period-finder function in `astrobase.periodbase` or from your own
    period-finder routines if their results can be turned into a dict with the
    format shown below.

    Parameters
    ----------

    lspinfo : dict or str
        If this is a dict, it must be a dict produced by an
        `astrobase.periodbase` period-finder function or a dict from your own
        period-finder function or routine that is of the form below with at
        least these keys::

            {'periods': np.array of all periods searched by the period-finder,
             'lspvals': np.array of periodogram power value for each period,
             'bestperiod': a float value that is the period with the highest
                           peak in the periodogram, i.e. the most-likely actual
                           period,
             'method': a three-letter code naming the period-finder used; must
                       be one of the keys in the
                       `astrobase.periodbase.METHODLABELS` dict,
             'nbestperiods': a list of the periods corresponding to periodogram
                             peaks (`nbestlspvals` below) to annotate on the
                             periodogram plot so they can be called out
                             visually,
             'nbestlspvals': a list of the power values associated with
                             periodogram peaks to annotate on the periodogram
                             plot so they can be called out visually; should be
                             the same length as `nbestperiods` above}

        `nbestperiods` and `nbestlspvals` must have at least 5 elements each,
        e.g. describing the five 'best' (highest power) peaks in the
        periodogram.

        If lspinfo is a str, then it must be a path to a pickle file (ending
        with the extension '.pkl' or '.pkl.gz') that contains a dict of the form
        described above.

    times,mags,errs : np.array
        The mag/flux time-series arrays to process along with associated errors.

    varepoch : 'min' or float or None or list of lists
        This sets the time of minimum light finding strategy for the checkplot::

                                                   the epoch used for all phased
            If `varepoch` is None               -> light curve plots will be
                                                   `min(times)`.

            If `varepoch='min'`                 -> automatic epoch finding for all
                                                   periods using light curve fits.

            If varepoch is a single float       -> this epoch will be used for all
                                                   phased light curve plots

            If varepoch is a list of floats        each epoch will be applied to
            with length = `len(nbestperiods)+2` -> the phased light curve for each
            from period-finder results             period specifically

        If you use a list for varepoch, it must be of length
        `len(lspinfo['nbestperiods']) + 2`, because we insert half and twice the
        period into the best periods list to make those phased LC plots.

    magsarefluxes : bool
        If True, indicates the input time-series is fluxes and not mags so the
        plot y-axis direction and range can be set appropriately.

    objectinfo : dict or None
        If provided, this is a dict containing information on the object whose
        light curve is being processed. This function will then be able to look
        up and download a finder chart for this object and write that to the
        output checkplot PNG image.The `objectinfo` dict must be of the form and
        contain at least the keys described below::

            {'objectid': the name of the object,
             'ra': the right ascension of the object in decimal degrees,
             'decl': the declination of the object in decimal degrees,
             'ndet': the number of observations of this object}

        You can also provide magnitudes and proper motions of the object using
        the following keys and the appropriate values in the `objectinfo`
        dict. These will be used to calculate colors, total and reduced proper
        motion, etc. and display these in the output checkplot PNG.

        - SDSS mag keys: 'sdssu', 'sdssg', 'sdssr', 'sdssi', 'sdssz'
        - 2MASS mag keys: 'jmag', 'hmag', 'kmag'
        - Cousins mag keys: 'bmag', 'vmag'
        - GAIA specific keys: 'gmag', 'teff'
        - proper motion keys: 'pmra', 'pmdecl'

    findercmap : str or matplotlib.cm.ColorMap object
        The Colormap object to use for the finder chart image.

    finderconvolve : astropy.convolution.Kernel object or None
        If not None, the Kernel object to use for convolving the finder image.

    findercachedir : str
        The directory where the FITS finder images are downloaded and cached.

    normto : {'globalmedian', 'zero'} or a float
        This sets the normalization target::

            'globalmedian' -> norms each mag to global median of the LC column
            'zero'         -> norms each mag to zero
            a float        -> norms each mag to this specified float value.

    normmingap : float
        This defines how much the difference between consecutive measurements is
        allowed to be to consider them as parts of different timegroups. By
        default it is set to 4.0 days.

    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.

    phasewrap : bool
        If this is True, the phased time-series will be wrapped around phase
        0.0.

    phasesort : bool
        If this is True, the phased time-series will be sorted in phase.

    phasebin : float or None
        If this is provided, indicates the bin size to use to group together
        measurements closer than this amount in phase. This is in units of
        phase. The binned phased light curve will be overplotted on top of the
        phased light curve. Useful for when one has many measurement points and
        needs to pick out a small trend in an otherwise noisy phased light
        curve.

    minbinelems : int
        The minimum number of elements in each phase bin.

    plotxlim : sequence of two floats or None
        The x-axis limits to use when making the phased light curve plot. By
        default, this is (-0.8, 0.8), which places phase 0.0 at the center of
        the plot and covers approximately two cycles in phase to make any trends
        clear.

    xliminsetmode : bool
        If this is True, the generated phased light curve plot will use the
        values of `plotxlim` as the main plot x-axis limits (i.e. zoomed-in if
        `plotxlim` is a range smaller than the full phase range), and will show
        the full phased light curve plot as an smaller inset. Useful for
        planetary transit light curves.

    bestperiodhighlight : str or None
        If not None, this is a str with a matplotlib color specification to use
        as the background color to highlight the phased light curve plot of the
        'best' period and epoch combination. If None, no highlight will be
        applied.

    outfile : str or None
        The file name of the file to save the checkplot to. If this is None,
        will write to a file called 'checkplot.png' in the current working
        directory.

    plotdpi : int
        Sets the resolution in DPI for PNG plots (default = 100).

    verbose : bool
        If False, turns off many of the informational messages. Useful for
        when an external function is driving lots of `checkplot_png` calls.

    Returns
    -------

    str
        The file path to the generated checkplot PNG file.


<EOL>if not outfile and isinstance(lspinfo1,str):<EOL><INDENT>plotfpath = os.path.join(<EOL>os.path.dirname(lspinfo1),<EOL>'<STR_LIT>' % (<EOL>os.path.basename(lspinfo1),<EOL>)<EOL>)<EOL><DEDENT>elif outfile:<EOL><INDENT>plotfpath = outfile<EOL><DEDENT>else:<EOL><INDENT>plotfpath = '<STR_LIT>'<EOL><DEDENT>if isinstance(lspinfo1,str) and os.path.exists(lspinfo1):<EOL><INDENT>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>' % lspinfo1)<EOL><DEDENT>if '<STR_LIT>' in lspinfo1:<EOL><INDENT>with gzip.open(lspinfo1,'<STR_LIT:rb>') as infd:<EOL><INDENT>lspinfo1 = pickle.load(infd)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>with open(lspinfo1,'<STR_LIT:rb>') as infd:<EOL><INDENT>lspinfo1 = pickle.load(infd)<EOL><DEDENT><DEDENT><DEDENT>if isinstance(lspinfo2,str) and os.path.exists(lspinfo2):<EOL><INDENT>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>' % lspinfo2)<EOL><DEDENT>if '<STR_LIT>' in lspinfo2:<EOL><INDENT>with gzip.open(lspinfo2,'<STR_LIT:rb>') as infd:<EOL><INDENT>lspinfo2 = pickle.load(infd)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>with open(lspinfo2,'<STR_LIT:rb>') as infd:<EOL><INDENT>lspinfo2 = pickle.load(infd)<EOL><DEDENT><DEDENT><DEDENT>if ('<STR_LIT>' in lspinfo1 and '<STR_LIT>' in lspinfo2 and<EOL>'<STR_LIT>' in lspinfo1 and '<STR_LIT>' in lspinfo2 and<EOL>'<STR_LIT>' in lspinfo1 and '<STR_LIT>' in lspinfo2):<EOL><INDENT>bestperiod1 = lspinfo1['<STR_LIT>']<EOL>nbestperiods1 = lspinfo1['<STR_LIT>']<EOL>lspmethod1 = lspinfo1['<STR_LIT>']<EOL>bestperiod2 = lspinfo2['<STR_LIT>']<EOL>nbestperiods2 = lspinfo2['<STR_LIT>']<EOL>lspmethod2 = lspinfo2['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>LOGERROR('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>return None<EOL><DEDENT>if (not npisfinite(bestperiod1)) or (not npisfinite(bestperiod2)):<EOL><INDENT>LOGWARNING('<STR_LIT>')<EOL>return None<EOL><DEDENT>fig, axes = plt.subplots(<NUM_LIT:3>,<NUM_LIT:3>)<EOL>axes = npravel(axes)<EOL>fig.set_size_inches(<NUM_LIT:30>,<NUM_LIT>)<EOL>_make_periodogram(axes[<NUM_LIT:0>], lspinfo1, objectinfo,<EOL>findercmap, finderconvolve,<EOL>verbose=verbose,<EOL>findercachedir=findercachedir)<EOL>_make_periodogram(axes[<NUM_LIT:1>], lspinfo2, None,<EOL>findercmap, finderconvolve)<EOL>stimes, smags, serrs = sigclip_magseries(times,<EOL>mags,<EOL>errs,<EOL>magsarefluxes=magsarefluxes,<EOL>sigclip=sigclip)<EOL>if normto is not False:<EOL><INDENT>stimes, smags = normalize_magseries(stimes, smags,<EOL>normto=normto,<EOL>magsarefluxes=magsarefluxes,<EOL>mingap=normmingap)<EOL><DEDENT>if len(stimes) >= <NUM_LIT:50>:<EOL><INDENT>_make_magseries_plot(axes[<NUM_LIT:2>], stimes, smags, serrs,<EOL>magsarefluxes=magsarefluxes,<EOL>ms=unphasedms)<EOL>lspbestperiods1 = nbestperiods1[::]<EOL>lspbestperiods2 = nbestperiods2[::]<EOL>for periodind, varperiod, plotaxes in zip([<NUM_LIT:0>,<NUM_LIT:1>,<NUM_LIT:2>],<EOL>lspbestperiods1[:<NUM_LIT:3>],<EOL>[axes[<NUM_LIT:3>], axes[<NUM_LIT:4>], axes[<NUM_LIT:5>]]):<EOL><INDENT>if periodind == <NUM_LIT:0> and bestperiodhighlight:<EOL><INDENT>if MPLVERSION >= (<NUM_LIT:2>,<NUM_LIT:0>,<NUM_LIT:0>):<EOL><INDENT>plotaxes.set_facecolor(bestperiodhighlight)<EOL><DEDENT>else:<EOL><INDENT>plotaxes.set_axis_bgcolor(bestperiodhighlight)<EOL><DEDENT><DEDENT>_make_phased_magseries_plot(plotaxes,<EOL>periodind,<EOL>stimes, smags, serrs,<EOL>varperiod, varepoch,<EOL>phasewrap, phasesort,<EOL>phasebin, minbinelems,<EOL>plotxlim, lspmethod1,<EOL>lspmethodind=<NUM_LIT:0>,<EOL>twolspmode=True,<EOL>magsarefluxes=magsarefluxes,<EOL>xliminsetmode=xliminsetmode,<EOL>verbose=verbose,<EOL>phasems=phasems,<EOL>phasebinms=phasebinms)<EOL><DEDENT>for periodind, varperiod, plotaxes in zip([<NUM_LIT:0>,<NUM_LIT:1>,<NUM_LIT:2>],<EOL>lspbestperiods2[:<NUM_LIT:3>],<EOL>[axes[<NUM_LIT:6>], axes[<NUM_LIT:7>], axes[<NUM_LIT:8>]]):<EOL><INDENT>if periodind == <NUM_LIT:0> and bestperiodhighlight:<EOL><INDENT>if MPLVERSION >= (<NUM_LIT:2>,<NUM_LIT:0>,<NUM_LIT:0>):<EOL><INDENT>plotaxes.set_facecolor(bestperiodhighlight)<EOL><DEDENT>else:<EOL><INDENT>plotaxes.set_axis_bgcolor(bestperiodhighlight)<EOL><DEDENT><DEDENT>_make_phased_magseries_plot(plotaxes,<EOL>periodind,<EOL>stimes, smags, serrs,<EOL>varperiod, varepoch,<EOL>phasewrap, phasesort,<EOL>phasebin, minbinelems,<EOL>plotxlim, lspmethod2,<EOL>lspmethodind=<NUM_LIT:1>,<EOL>twolspmode=True,<EOL>magsarefluxes=magsarefluxes,<EOL>xliminsetmode=xliminsetmode,<EOL>verbose=verbose,<EOL>phasems=phasems,<EOL>phasebinms=phasebinms)<EOL><DEDENT>fig.set_tight_layout(True)<EOL>if plotfpath.endswith('<STR_LIT>'):<EOL><INDENT>fig.savefig(plotfpath,dpi=plotdpi)<EOL><DEDENT>else:<EOL><INDENT>fig.savefig(plotfpath)<EOL><DEDENT>plt.close()<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>' % plotfpath)<EOL><DEDENT>return plotfpath<EOL><DEDENT>else:<EOL><INDENT>LOGWARNING('<STR_LIT>')<EOL>for periodind in range(<NUM_LIT:5>):<EOL><INDENT>axes[periodind+<NUM_LIT:2>].text(<EOL><NUM_LIT:0.5>,<NUM_LIT:0.5>,<EOL>('<STR_LIT>'),<EOL>horizontalalignment='<STR_LIT>',<EOL>verticalalignment='<STR_LIT>',<EOL>transform=axes[periodind+<NUM_LIT:2>].transAxes<EOL>)<EOL><DEDENT>fig.set_tight_layout(True)<EOL>if plotfpath.endswith('<STR_LIT>'):<EOL><INDENT>fig.savefig(plotfpath, dpi=plotdpi)<EOL><DEDENT>else:<EOL><INDENT>fig.savefig(plotfpath)<EOL><DEDENT>plt.close()<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>' % plotfpath)<EOL><DEDENT>return plotfpath<EOL><DEDENT>

This makes a checkplot using results from two independent period-finders.

    Adapted from Luke Bouma's implementation of a similar function in his
    work. This makes a special checkplot that uses two lspinfo dictionaries,
    from two independent period-finding methods. For EBs, it's probably best to
    use Stellingwerf PDM or Schwarzenberg-Czerny AoV as one of these, and the
    Box Least-squared Search method as the other one.

    The checkplot layout in this case is::

        [ pgram1 + objectinfo ] [        pgram2       ] [     unphased LC     ]
        [ pgram1 P1 phased LC ] [ pgram1 P2 phased LC ] [ pgram1 P3 phased LC ]
        [ pgram2 P1 phased LC ] [ pgram2 P2 phased LC ] [ pgram2 P3 phased LC ]

    where:

    - pgram1 is the plot for the periodogram in the lspinfo1 dict
    - pgram1 P1, P2, and P3 are the best three periods from lspinfo1
    - pgram2 is the plot for the periodogram in the lspinfo2 dict
    - pgram2 P1, P2, and P3 are the best three periods from lspinfo2

    Note that we take the output file name from lspinfo1 if lspinfo1 is a string
    filename pointing to a (gzipped) pickle containing the results dict from a
    period-finding routine similar to those in periodbase.

    Parameters
    ----------

    lspinfo1,lspinfo2 : dict or str
        If this is a dict, it must be a dict produced by an
        `astrobase.periodbase` period-finder function or a dict from your own
        period-finder function or routine that is of the form below with at
        least these keys::

            {'periods': np.array of all periods searched by the period-finder,
             'lspvals': np.array of periodogram power value for each period,
             'bestperiod': a float value that is the period with the highest
                           peak in the periodogram, i.e. the most-likely actual
                           period,
             'method': a three-letter code naming the period-finder used; must
                       be one of the keys in the
                       `astrobase.periodbase.METHODLABELS` dict,
             'nbestperiods': a list of the periods corresponding to periodogram
                             peaks (`nbestlspvals` below) to annotate on the
                             periodogram plot so they can be called out
                             visually,
             'nbestlspvals': a list of the power values associated with
                             periodogram peaks to annotate on the periodogram
                             plot so they can be called out visually; should be
                             the same length as `nbestperiods` above}

        `nbestperiods` and `nbestlspvals` must have at least 3 elements each,
        e.g. describing the three 'best' (highest power) peaks in the
        periodogram.

        If lspinfo is a str, then it must be a path to a pickle file (ending
        with the extension '.pkl' or '.pkl.gz') that contains a dict of the form
        described above.

    times,mags,errs : np.array
        The mag/flux time-series arrays to process along with associated errors.

    varepoch : 'min' or float or None or list of lists
        This sets the time of minimum light finding strategy for the checkplot::

                                                   the epoch used for all phased
            If `varepoch` is None               -> light curve plots will be
                                                   `min(times)`.

            If `varepoch='min'`                 -> automatic epoch finding for all
                                                   periods using light curve fits.

            If varepoch is a single float       -> this epoch will be used for all
                                                   phased light curve plots

            If varepoch is a list of floats        each epoch will be applied to
            with length = `len(nbestperiods)` ->   the phased light curve for each
            from period-finder results             period specifically

        If you use a list for varepoch, it must be of length
        `len(lspinfo['nbestperiods'])`.

    magsarefluxes : bool
        If True, indicates the input time-series is fluxes and not mags so the
        plot y-axis direction and range can be set appropriately/

    objectinfo : dict or None
        If provided, this is a dict containing information on the object whose
        light curve is being processed. This function will then be able to look
        up and download a finder chart for this object and write that to the
        output checkplot PNG image.The `objectinfo` dict must be of the form and
        contain at least the keys described below::

            {'objectid': the name of the object,
             'ra': the right ascension of the object in decimal degrees,
             'decl': the declination of the object in decimal degrees,
             'ndet': the number of observations of this object}

        You can also provide magnitudes and proper motions of the object using
        the following keys and the appropriate values in the `objectinfo`
        dict. These will be used to calculate colors, total and reduced proper
        motion, etc. and display these in the output checkplot PNG.

        - SDSS mag keys: 'sdssu', 'sdssg', 'sdssr', 'sdssi', 'sdssz'
        - 2MASS mag keys: 'jmag', 'hmag', 'kmag'
        - Cousins mag keys: 'bmag', 'vmag'
        - GAIA specific keys: 'gmag', 'teff'
        - proper motion keys: 'pmra', 'pmdecl'

    findercmap : str or matplotlib.cm.ColorMap object
        The Colormap object to use for the finder chart image.

    finderconvolve : astropy.convolution.Kernel object or None
        If not None, the Kernel object to use for convolving the finder image.

    findercachedir : str
        The directory where the FITS finder images are downloaded and cached.

    normto : {'globalmedian', 'zero'} or a float
        This sets the LC normalization target::

            'globalmedian' -> norms each mag to global median of the LC column
            'zero'         -> norms each mag to zero
            a float        -> norms each mag to this specified float value.

    normmingap : float
        This defines how much the difference between consecutive measurements is
        allowed to be to consider them as parts of different timegroups. By
        default it is set to 4.0 days.

    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.

    phasewrap : bool
        If this is True, the phased time-series will be wrapped around phase
        0.0.

    phasesort : bool
        If this is True, the phased time-series will be sorted in phase.

    phasebin : float or None
        If this is provided, indicates the bin size to use to group together
        measurements closer than this amount in phase. This is in units of
        phase. The binned phased light curve will be overplotted on top of the
        phased light curve. Useful for when one has many measurement points and
        needs to pick out a small trend in an otherwise noisy phased light
        curve.

    minbinelems : int
        The minimum number of elements in each phase bin.

    plotxlim : sequence of two floats or None
        The x-axis limits to use when making the phased light curve plot. By
        default, this is (-0.8, 0.8), which places phase 0.0 at the center of
        the plot and covers approximately two cycles in phase to make any trends
        clear.

    unphasedms : float
        The marker size to use for the main unphased light curve plot symbols.

    phasems : float
        The marker size to use for the main phased light curve plot symbols.

    phasebinms : float
        The marker size to use for the binned phased light curve plot symbols.

    xliminsetmode : bool
        If this is True, the generated phased light curve plot will use the
        values of `plotxlim` as the main plot x-axis limits (i.e. zoomed-in if
        `plotxlim` is a range smaller than the full phase range), and will show
        the full phased light curve plot as an smaller inset. Useful for
        planetary transit light curves.

    bestperiodhighlight : str or None
        If not None, this is a str with a matplotlib color specification to use
        as the background color to highlight the phased light curve plot of the
        'best' period and epoch combination. If None, no highlight will be
        applied.

    outfile : str or None
        The file name of the file to save the checkplot to. If this is None,
        will write to a file called 'checkplot.png' in the current working
        directory.

    plotdpi : int
        Sets the resolution in DPI for PNG plots (default = 100).

    verbose : bool
        If False, turns off many of the informational messages. Useful for
        when an external function is driving lots of `checkplot_png` calls.

    Returns
    -------

    str
        The file path to the generated checkplot PNG file.