try:<EOL><INDENT>(lcfile, lcformat, lcformatdir,<EOL>tcol, mcol, ecol,<EOL>timebase, interpolate_type, sigclip) = task<EOL>try:<EOL><INDENT>formatinfo = get_lcformat(lcformat,<EOL>use_lcformat_dir=lcformatdir)<EOL>if formatinfo:<EOL><INDENT>(dfileglob, readerfunc,<EOL>dtimecols, dmagcols, derrcols,<EOL>magsarefluxes, normfunc) = formatinfo<EOL><DEDENT>else:<EOL><INDENT>LOGERROR("<STR_LIT>")<EOL>return None<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION("<STR_LIT>")<EOL>return None<EOL><DEDENT>lcdict = readerfunc(lcfile)<EOL>if ( (isinstance(lcdict, (list, tuple))) and<EOL>(isinstance(lcdict[<NUM_LIT:0>], dict)) ):<EOL><INDENT>lcdict = lcdict[<NUM_LIT:0>]<EOL><DEDENT>outdict = {}<EOL>if '<STR_LIT:.>' in tcol:<EOL><INDENT>tcolget = tcol.split('<STR_LIT:.>')<EOL><DEDENT>else:<EOL><INDENT>tcolget = [tcol]<EOL><DEDENT>times = _dict_get(lcdict, tcolget)<EOL>if '<STR_LIT:.>' in mcol:<EOL><INDENT>mcolget = mcol.split('<STR_LIT:.>')<EOL><DEDENT>else:<EOL><INDENT>mcolget = [mcol]<EOL><DEDENT>mags = _dict_get(lcdict, mcolget)<EOL>if '<STR_LIT:.>' in ecol:<EOL><INDENT>ecolget = ecol.split('<STR_LIT:.>')<EOL><DEDENT>else:<EOL><INDENT>ecolget = [ecol]<EOL><DEDENT>errs = _dict_get(lcdict, ecolget)<EOL>if normfunc is None:<EOL><INDENT>ntimes, nmags = normalize_magseries(<EOL>times, mags,<EOL>magsarefluxes=magsarefluxes<EOL>)<EOL><DEDENT>times, mags, errs = ntimes, nmags, errs<EOL>stimes, smags, serrs = sigclip_magseries(times,<EOL>mags,<EOL>errs,<EOL>sigclip=sigclip)<EOL>mags_interpolator = spi.interp1d(stimes, smags,<EOL>kind=interpolate_type,<EOL>fill_value='<STR_LIT>')<EOL>errs_interpolator = spi.interp1d(stimes, serrs,<EOL>kind=interpolate_type,<EOL>fill_value='<STR_LIT>')<EOL>interpolated_mags = mags_interpolator(timebase)<EOL>interpolated_errs = errs_interpolator(timebase)<EOL>magmedian = np.median(interpolated_mags)<EOL>renormed_mags = interpolated_mags - magmedian<EOL>outdict = {'<STR_LIT>':renormed_mags,<EOL>'<STR_LIT>':interpolated_errs,<EOL>'<STR_LIT>':interpolated_mags}<EOL>return outdict<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>' % repr(task))<EOL>return None<EOL><DEDENT>

This is a parallel worker that reforms light curves for TFA.

task[0] = lcfile
task[1] = lcformat
task[2] = lcformatdir
task[3] = timecol
task[4] = magcol
task[5] = errcol
task[6] = timebase
task[7] = interpolate_type
task[8] = sigclip


def add_cpinfo_to_lclist(<EOL>checkplots,  <EOL>initial_lc_catalog,<EOL>magcol,  <EOL>outfile,<EOL>checkplotglob='<STR_LIT>',<EOL>infokeys=CPINFO_DEFAULTKEYS,<EOL>nworkers=NCPUS<EOL>):

<EOL>if not isinstance(checkplots, list) and os.path.exists(checkplots):<EOL><INDENT>checkplots = sorted(glob.glob(os.path.join(checkplots, checkplotglob)))<EOL><DEDENT>tasklist = [(cpf, infokeys) for cpf in checkplots]<EOL>with ProcessPoolExecutor(max_workers=nworkers) as executor:<EOL><INDENT>resultfutures = executor.map(_cpinfo_key_worker, tasklist)<EOL><DEDENT>results = [x for x in resultfutures]<EOL>executor.shutdown()<EOL>with open(initial_lc_catalog,'<STR_LIT:rb>') as infd:<EOL><INDENT>lc_catalog = pickle.load(infd)<EOL><DEDENT>catalog_objectids = np.array(lc_catalog['<STR_LIT>']['<STR_LIT>'])<EOL>checkplot_objectids = np.array([x[<NUM_LIT:0>] for x in results])<EOL>extrainfokeys = []<EOL>actualkeys = []<EOL>for keyspec in infokeys:<EOL><INDENT>key, dtype, firstlevel, overwrite_append, nonesub, nansub = keyspec<EOL>if firstlevel:<EOL><INDENT>eik = key<EOL><DEDENT>else:<EOL><INDENT>eik = '<STR_LIT>' % (magcol, key)<EOL><DEDENT>extrainfokeys.append(eik)<EOL>eactual = eik.split('<STR_LIT:.>')<EOL>if not eactual[-<NUM_LIT:1>].isdigit():<EOL><INDENT>if not firstlevel:<EOL><INDENT>eactual = '<STR_LIT:.>'.join([eactual[<NUM_LIT:0>], eactual[-<NUM_LIT:1>]])<EOL><DEDENT>else:<EOL><INDENT>eactual = eactual[-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>elastkey = eactual[-<NUM_LIT:2>]<EOL>if elastkey.endswith('<STR_LIT>'):<EOL><INDENT>elastkey = elastkey[:-<NUM_LIT:2>]<EOL><DEDENT>elif elastkey.endswith('<STR_LIT:s>'):<EOL><INDENT>elastkey = elastkey[:-<NUM_LIT:1>]<EOL><DEDENT>if not firstlevel:<EOL><INDENT>eactual = '<STR_LIT:.>'.join([eactual[<NUM_LIT:0>], elastkey])<EOL><DEDENT>else:<EOL><INDENT>eactual = elastkey<EOL><DEDENT><DEDENT>actualkeys.append(eactual)<EOL>if eactual not in lc_catalog['<STR_LIT>']:<EOL><INDENT>lc_catalog['<STR_LIT>'].append(eactual)<EOL><DEDENT>lc_catalog['<STR_LIT>'][eactual] = []<EOL><DEDENT>for catobj in tqdm(catalog_objectids):<EOL><INDENT>cp_objind = np.where(checkplot_objectids == catobj)<EOL>if len(cp_objind[<NUM_LIT:0>]) > <NUM_LIT:0>:<EOL><INDENT>thiscpinfo = results[cp_objind[<NUM_LIT:0>][<NUM_LIT:0>]]<EOL>thiscpinfo = thiscpinfo[<NUM_LIT:1>:]<EOL>for ekind, ek in enumerate(actualkeys):<EOL><INDENT>lc_catalog['<STR_LIT>'][ek].append(<EOL>thiscpinfo[ekind]<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for ekind, ek in enumerate(actualkeys):<EOL><INDENT>thiskeyspec = infokeys[ekind]<EOL>nonesub = thiskeyspec[-<NUM_LIT:2>]<EOL>lc_catalog['<STR_LIT>'][ek].append(<EOL>nonesub<EOL>)<EOL><DEDENT><DEDENT><DEDENT>for ek in actualkeys:<EOL><INDENT>lc_catalog['<STR_LIT>'][ek] = np.array(<EOL>lc_catalog['<STR_LIT>'][ek]<EOL>)<EOL><DEDENT>if '<STR_LIT>' in lc_catalog:<EOL><INDENT>if magcol not in lc_catalog['<STR_LIT>']:<EOL><INDENT>lc_catalog['<STR_LIT>'].append(magcol)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>lc_catalog['<STR_LIT>'] = [magcol]<EOL><DEDENT>with open(outfile, '<STR_LIT:wb>') as outfd:<EOL><INDENT>pickle.dump(lc_catalog, outfd, protocol=pickle.HIGHEST_PROTOCOL)<EOL><DEDENT>return outfile<EOL>

This adds checkplot info to the initial light curve catalogs generated by
    `make_lclist`.

    This is used to incorporate all the extra info checkplots can have for
    objects back into columns in the light curve catalog produced by
    `make_lclist`. Objects are matched between the checkplots and the light
    curve catalog using their `objectid`. This then allows one to search this
    'augmented' light curve catalog by these extra columns. The 'augmented'
    light curve catalog also forms the basis for search interface provided by
    the LCC-Server.

    The default list of keys that will be extracted from a checkplot and added
    as columns in the initial light curve catalog is listed above in the
    `CPINFO_DEFAULTKEYS` list.

    Parameters
    ----------

    checkplots : str or list
        If this is a str, is interpreted as a directory which will be searched
        for checkplot pickle files using `checkplotglob`. If this is a list, it
        will be interpreted as a list of checkplot pickle files to process.

    initial_lc_catalog : str
        This is the path to the light curve catalog pickle made by
        `make_lclist`.

    magcol : str
        This is used to indicate the light curve magnitude column to extract
        magnitude column specific information. For example, Stetson variability
        indices can be generated using magnitude measurements in separate
        photometric apertures, which appear in separate `magcols` in the
        checkplot. To associate each such feature of the object with its
        specific `magcol`, pass that `magcol` in here. This `magcol` will then
        be added as a prefix to the resulting column in the 'augmented' LC
        catalog, e.g. Stetson J will appear as `magcol1_stetsonj` and
        `magcol2_stetsonj` for two separate magcols.

    outfile : str
        This is the file name of the output 'augmented' light curve catalog
        pickle file that will be written.

    infokeys : list of tuples

        This is a list of keys to extract from the checkplot and some info on
        how this extraction is to be done. Each key entry is a six-element
        tuple of the following form:

        - key name in the checkplot
        - numpy dtype of the value of this key
        - False if key is associated with a magcol or True otherwise
        - False if subsequent updates to the same column name will append to
          existing key values in the output augmented light curve catalog or
          True if these will overwrite the existing key value
        - character to use to substitute a None value of the key in the
          checkplot in the output light curve catalog column
        - character to use to substitute a nan value of the key in the
          checkplot in the output light curve catalog column

        See the `CPFINFO_DEFAULTKEYS` list above for examples.

    nworkers : int
        The number of parallel workers to launch to extract checkplot
        information.

    Returns
    -------

    str
        Returns the path to the generated 'augmented' light curve catalog pickle
        file.


cpfile, keyspeclist = task<EOL>keystoget = [x[<NUM_LIT:0>] for x in keyspeclist]<EOL>nonesubs = [x[-<NUM_LIT:2>] for x in keyspeclist]<EOL>nansubs = [x[-<NUM_LIT:1>] for x in keyspeclist]<EOL>for i, k in enumerate(keystoget):<EOL><INDENT>thisk = k.split('<STR_LIT:.>')<EOL>if sys.version_info[:<NUM_LIT:2>] < (<NUM_LIT:3>,<NUM_LIT:4>):<EOL><INDENT>thisk = [(int(x) if x.isdigit() else x) for x in thisk]<EOL><DEDENT>else:<EOL><INDENT>thisk = [(int(x) if x.isdecimal() else x) for x in thisk]<EOL><DEDENT>keystoget[i] = thisk<EOL><DEDENT>keystoget.insert(<NUM_LIT:0>,['<STR_LIT>'])<EOL>nonesubs.insert(<NUM_LIT:0>, '<STR_LIT>')<EOL>nansubs.insert(<NUM_LIT:0>,'<STR_LIT>')<EOL>vals = checkplot_infokey_worker((cpfile, keystoget))<EOL>for val, nonesub, nansub, valind in zip(vals, nonesubs,<EOL>nansubs, range(len(vals))):<EOL><INDENT>if val is None:<EOL><INDENT>outval = nonesub<EOL><DEDENT>elif isinstance(val, float) and not np.isfinite(val):<EOL><INDENT>outval = nansub<EOL><DEDENT>elif isinstance(val, (list, tuple)):<EOL><INDENT>outval = '<STR_LIT:U+002CU+0020>'.join(val)<EOL><DEDENT>else:<EOL><INDENT>outval = val<EOL><DEDENT>vals[valind] = outval<EOL><DEDENT>return vals<EOL>

This wraps `checkplotlist.checkplot_infokey_worker`.

    This is used to get the correct dtype for each element in retrieved results.

    Parameters
    ----------

    task : tuple
        task[0] = cpfile
        task[1] = keyspeclist (infokeys kwarg from `add_cpinfo_to_lclist`)

    Returns
    -------

    dict
        All of the requested keys from the checkplot are returned along with
        their values in a dict.


<EOL>tornado.options.parse_command_line()<EOL>DEBUG = True if options.debugmode == <NUM_LIT:1> else False<EOL>LOGGER = logging.getLogger('<STR_LIT>')<EOL>if DEBUG:<EOL><INDENT>LOGGER.setLevel(logging.DEBUG)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.setLevel(logging.INFO)<EOL><DEDENT>MAXPROCS = options.maxprocs<EOL>ASSETPATH = options.assetpath<EOL>BASEURL = options.baseurl<EOL>EXECUTOR = ProcessPoolExecutor(MAXPROCS)<EOL>if options.standalone:<EOL><INDENT>if ( (not options.sharedsecret) or<EOL>(options.sharedsecret and<EOL>not os.path.exists(options.sharedsecret)) ):<EOL><INDENT>LOGGER.error('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>elif options.sharedsecret and os.path.exists(options.sharedsecret):<EOL><INDENT>fileperm = oct(os.stat(options.sharedsecret)[stat.ST_MODE])<EOL>if fileperm == '<STR_LIT>' or fileperm == '<STR_LIT>':<EOL><INDENT>with open(options.sharedsecret,'<STR_LIT:r>') as infd:<EOL><INDENT>SHAREDSECRET = infd.read().strip('<STR_LIT:\n>')<EOL>standalonespec = (<EOL>r'<STR_LIT>',<EOL>cphandlers.StandaloneHandler,<EOL>{'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':SHAREDSECRET}<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>options.sharedsecret)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>HANDLERS = [standalonespec]<EOL><DEDENT>else:<EOL><INDENT>if not BASEURL.endswith('<STR_LIT:/>'):<EOL><INDENT>BASEURL = BASEURL + '<STR_LIT:/>'<EOL><DEDENT>READONLY = options.readonly<EOL>if READONLY:<EOL><INDENT>LOGGER.warning('<STR_LIT>')<EOL><DEDENT>CURRENTDIR = os.getcwd()<EOL>cplistfile = options.checkplotlist<EOL>if cplistfile and os.path.exists(cplistfile):<EOL><INDENT>with open(cplistfile,'<STR_LIT:r>') as infd:<EOL><INDENT>CHECKPLOTLIST = json.load(infd)<EOL><DEDENT>LOGGER.info('<STR_LIT>' % cplistfile)<EOL><DEDENT>elif cplistfile and not os.path.exists(cplistfile):<EOL><INDENT>helpmsg = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" %<EOL>(cplistfile, os.path.join(modpath,'<STR_LIT>'))<EOL>)<EOL>LOGGER.error(helpmsg)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.warning('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % CURRENTDIR)<EOL>if os.path.exists(<EOL>os.path.join(CURRENTDIR,'<STR_LIT>')<EOL>):<EOL><INDENT>cplistfile = os.path.join(CURRENTDIR,'<STR_LIT>')<EOL>with open(cplistfile,'<STR_LIT:r>') as infd:<EOL><INDENT>CHECKPLOTLIST = json.load(infd)<EOL><DEDENT>LOGGER.info('<STR_LIT>' % cplistfile)<EOL><DEDENT>elif os.path.exists(os.path.join(CURRENTDIR,<EOL>'<STR_LIT>')):<EOL><INDENT>cplistfile = os.path.join(CURRENTDIR,<EOL>'<STR_LIT>')<EOL>with open(cplistfile,'<STR_LIT:r>') as infd:<EOL><INDENT>CHECKPLOTLIST = json.load(infd)<EOL><DEDENT>LOGGER.info('<STR_LIT>' % cplistfile)<EOL><DEDENT>else:<EOL><INDENT>helpmsg = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>LOGGER.error(helpmsg)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>HANDLERS = [<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>cphandlers.IndexHandler,<EOL>{'<STR_LIT>':CURRENTDIR,<EOL>'<STR_LIT>':ASSETPATH,<EOL>'<STR_LIT>':CHECKPLOTLIST,<EOL>'<STR_LIT>':cplistfile,<EOL>'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':READONLY,<EOL>'<STR_LIT>':BASEURL}),<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>cphandlers.CheckplotHandler,<EOL>{'<STR_LIT>':CURRENTDIR,<EOL>'<STR_LIT>':ASSETPATH,<EOL>'<STR_LIT>':CHECKPLOTLIST,<EOL>'<STR_LIT>':cplistfile,<EOL>'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':READONLY}),<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>cphandlers.CheckplotListHandler,<EOL>{'<STR_LIT>':CURRENTDIR,<EOL>'<STR_LIT>':ASSETPATH,<EOL>'<STR_LIT>':CHECKPLOTLIST,<EOL>'<STR_LIT>':cplistfile,<EOL>'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':READONLY}),<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>cphandlers.LCToolHandler,<EOL>{'<STR_LIT>':CURRENTDIR,<EOL>'<STR_LIT>':ASSETPATH,<EOL>'<STR_LIT>':CHECKPLOTLIST,<EOL>'<STR_LIT>':cplistfile,<EOL>'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':READONLY}),<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>tornado.web.StaticFileHandler, {'<STR_LIT:path>': CURRENTDIR})<EOL>]<EOL><DEDENT>app = tornado.web.Application(<EOL>handlers=HANDLERS,<EOL>static_path=ASSETPATH,<EOL>template_path=ASSETPATH,<EOL>static_url_prefix='<STR_LIT>'.format(baseurl=BASEURL),<EOL>compress_response=True,<EOL>debug=DEBUG,<EOL>)<EOL>http_server = tornado.httpserver.HTTPServer(app, xheaders=True)<EOL>portok = False<EOL>serverport = options.port<EOL>maxtrys = <NUM_LIT:5><EOL>thistry = <NUM_LIT:0><EOL>while not portok and thistry < maxtrys:<EOL><INDENT>try:<EOL><INDENT>http_server.listen(serverport, options.serve)<EOL>portok = True<EOL><DEDENT>except socket.error as e:<EOL><INDENT>LOGGER.warning('<STR_LIT>' %<EOL>(options.serve, serverport, serverport + <NUM_LIT:1>))<EOL>serverport = serverport + <NUM_LIT:1><EOL><DEDENT><DEDENT>if not portok:<EOL><INDENT>LOGGER.error('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>LOGGER.info('<STR_LIT>' %<EOL>(options.serve, serverport, BASEURL))<EOL>signal.signal(signal.SIGINT,_recv_sigint)<EOL>signal.signal(signal.SIGTERM,_recv_sigint)<EOL>try:<EOL><INDENT>tornado.ioloop.IOLoop.instance().start()<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>LOGGER.info('<STR_LIT>')<EOL>tornado.ioloop.IOLoop.instance().stop()<EOL><DEDENT>EXECUTOR.shutdown()<EOL>time.sleep(<NUM_LIT:3>)<EOL>

This launches the server. The current script args are shown below::

  Usage: checkplotserver [OPTIONS]

  Options:

    --help                           show this help information

  checkplotserver.py options:

    --assetpath                      Sets the asset (server images, css, js, DB)
                                     path for checkplotserver.
                                     (default <astrobase install dir>
                                      /astrobase/cpserver/cps-assets)
    --baseurl                        Set the base URL of the checkplotserver.
                                     This is useful when you're running
                                     checkplotserver on a remote machine and are
                                     reverse-proxying more than one instances of
                                     it so you can access them using HTTP from
                                     outside on different base URLs like
                                     /cpserver1/, /cpserver2/, etc. If this is
                                     set, all URLs will take the form
                                     [baseurl]/..., instead of /... (default /)
    --checkplotlist                  The path to the checkplot-filelist.json file
                                     listing checkplots to load and serve. If
                                     this is not provided, checkplotserver will
                                     look for a checkplot-pickle-flist.json in
                                     the directory that it was started in
    --debugmode                      start up in debug mode if set to 1. (default
                                     0)
    --maxprocs                       Number of background processes to use for
                                     saving/loading checkplot files and running
                                     light curves tools (default 2)
    --port                           Run on the given port. (default 5225)
    --readonly                       Run the server in readonly mode. This is
                                     useful for a public-facing instance of
                                     checkplotserver where you just want to allow
                                     collaborators to review objects but not edit
                                     them. (default False)
    --serve                          Bind to given address and serve content.
                                     (default 127.0.0.1)
    --sharedsecret                   a file containing a cryptographically secure
                                     string that is used to authenticate requests
                                     that come into the special standalone mode.
    --standalone                     This starts the server in standalone mode.
                                     (default 0)

  tornado/log.py options:

    --log-file-max-size              max size of log files before rollover
                                     (default 100000000)
    --log-file-num-backups           number of log files to keep (default 10)
    --log-file-prefix=PATH           Path prefix for log files. Note that if you
                                     are running multiple tornado processes,
                                     log_file_prefix must be different for each
                                     of them (e.g. include the port number)
    --log-rotate-interval            The interval value of timed rotating
                                     (default 1)
    --log-rotate-mode                The mode of rotating files(time or size)
                                     (default size)
    --log-rotate-when                specify the type of TimedRotatingFileHandler
                                     interval other options:('S', 'M', 'H', 'D',
                                     'W0'-'W6') (default midnight)
    --log-to-stderr                  Send log output to stderr (colorized if
                                     possible). By default use stderr if
                                     --log_file_prefix is not set and no other
                                     logging is configured.
    --logging=debug|info|warning|error|none
                                     Set the Python log level. If 'none', tornado
                                     won't touch the logging configuration.
                                     (default info)


def initialize(self, currentdir, assetpath, cplist,<EOL>cplistfile, executor, readonly):

self.currentdir = currentdir<EOL>self.assetpath = assetpath<EOL>self.currentproject = cplist<EOL>self.cplistfile = cplistfile<EOL>self.executor = executor<EOL>self.readonly = readonly<EOL>

This handles initial setup of the `RequestHandler`.


self.executor = executor<EOL>self.secret = secret<EOL>


if isinstance(obj, np.ndarray):<EOL><INDENT>return obj.tolist()<EOL><DEDENT>elif isinstance(obj, bytes):<EOL><INDENT>return obj.decode()<EOL><DEDENT>elif isinstance(obj, complex):<EOL><INDENT>return (obj.real, obj.imag)<EOL><DEDENT>elif (isinstance(obj, (float, np.float64, np.float_)) and<EOL>not np.isfinite(obj)):<EOL><INDENT>return None<EOL><DEDENT>elif isinstance(obj, (np.int8, np.int16, np.int32, np.int64)):<EOL><INDENT>return int(obj)<EOL><DEDENT>else:<EOL><INDENT>return json.JSONEncoder.default(self, obj)<EOL><DEDENT>

Overrides the default serializer for `JSONEncoder`.

        This can serialize the following objects in addition to what
        `JSONEncoder` can already do.

        - `np.array`
        - `bytes`
        - `complex`
        - `np.float64` and other `np.dtype` objects

        Parameters
        ----------

        obj : object
            A Python object to serialize to JSON.

        Returns
        -------

        str
            A JSON encoded representation of the input object.


<EOL>if self.readonly:<EOL><INDENT>msg = "<STR_LIT>"<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>try:<EOL><INDENT>self.cpfile = base64.b64decode(url_unescape(cpfile)).decode()<EOL>cpcontents = self.get_argument('<STR_LIT>', default=None)<EOL>savetopng = self.get_argument('<STR_LIT>', default=None)<EOL>if not self.cpfile or not cpcontents:<EOL><INDENT>msg = "<STR_LIT>"<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>cpcontents = json.loads(cpcontents)<EOL>updated = {'<STR_LIT>': cpcontents['<STR_LIT>'],<EOL>'<STR_LIT>':cpcontents['<STR_LIT>'],<EOL>'<STR_LIT>':cpcontents['<STR_LIT>'],<EOL>'<STR_LIT>':cpcontents['<STR_LIT>']}<EOL>cpfpath = os.path.join(<EOL>os.path.abspath(os.path.dirname(self.cplistfile)),<EOL>self.cpfile<EOL>)<EOL>LOGGER.info('<STR_LIT>' % cpfpath)<EOL>if not os.path.exists(cpfpath):<EOL><INDENT>msg = "<STR_LIT>" % cpfpath<EOL>LOGGER.error(msg)<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>updated = yield self.executor.submit(checkplot_pickle_update,<EOL>cpfpath, updated)<EOL>if updated:<EOL><INDENT>LOGGER.info('<STR_LIT>' % updated)<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:success>',<EOL>'<STR_LIT:message>':'<STR_LIT>',<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':{'<STR_LIT>':updated,<EOL>'<STR_LIT>':utime.time(),<EOL>'<STR_LIT>':cpcontents,<EOL>'<STR_LIT>': None}}<EOL>if savetopng:<EOL><INDENT>cpfpng = os.path.abspath(cpfpath.replace('<STR_LIT>','<STR_LIT>'))<EOL>cpfpng = StrIO()<EOL>pngdone = yield self.executor.submit(<EOL>checkplot_pickle_to_png,<EOL>cpfpath, cpfpng<EOL>)<EOL>if pngdone is not None:<EOL><INDENT>pngdone.seek(<NUM_LIT:0>)<EOL>pngbin = pngdone.read()<EOL>pngb64 = base64.b64encode(pngbin)<EOL>pngdone.close()<EOL>del pngbin<EOL>resultdict['<STR_LIT:result>']['<STR_LIT>'] = pngb64<EOL><DEDENT>else:<EOL><INDENT>resultdict['<STR_LIT:result>']['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT><DEDENT>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>' %<EOL>(self.cpfile, cpcontents))<EOL>msg = "<STR_LIT>"<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGGER.exception('<STR_LIT>' %<EOL>(self.cpfile, cpcontents))<EOL>msg = "<STR_LIT>"<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>

This handles POST requests.

        Also an AJAX endpoint. Updates the persistent checkplot dict using the
        changes from the UI, and then saves it back to disk. This could
        definitely be faster by just loading the checkplot into a server-wide
        shared dict or something.


def initialize(self, currentdir, assetpath, cplist,<EOL>cplistfile, executor, readonly, baseurl):

self.currentdir = currentdir<EOL>self.assetpath = assetpath<EOL>self.currentproject = cplist<EOL>self.cplistfile = cplistfile<EOL>self.executor = executor<EOL>self.readonly = readonly<EOL>self.baseurl = baseurl<EOL>


<EOL>project_checkplots = self.currentproject['<STR_LIT>']<EOL>project_checkplotbasenames = [os.path.basename(x)<EOL>for x in project_checkplots]<EOL>project_checkplotindices = range(len(project_checkplots))<EOL>project_cpsortkey = self.currentproject['<STR_LIT>']<EOL>if self.currentproject['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>project_cpsortorder = '<STR_LIT>'<EOL><DEDENT>elif self.currentproject['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>project_cpsortorder = '<STR_LIT>'<EOL><DEDENT>project_cpfilterstatements = self.currentproject['<STR_LIT>']<EOL>self.render('<STR_LIT>',<EOL>project_checkplots=project_checkplots,<EOL>project_cpsortorder=project_cpsortorder,<EOL>project_cpsortkey=project_cpsortkey,<EOL>project_cpfilterstatements=project_cpfilterstatements,<EOL>project_checkplotbasenames=project_checkplotbasenames,<EOL>project_checkplotindices=project_checkplotindices,<EOL>project_checkplotfile=self.cplistfile,<EOL>readonly=self.readonly,<EOL>baseurl=self.baseurl)<EOL>

This handles GET requests to the index page.

        TODO: provide the correct baseurl from the checkplotserver options dict,
        so the frontend JS can just read that off immediately.


if cpfile:<EOL><INDENT>self.cpfile = (<EOL>xhtml_escape(base64.b64decode(url_unescape(cpfile)))<EOL>)<EOL>if self.cpfile in self.currentproject['<STR_LIT>']:<EOL><INDENT>cpfpath = os.path.join(<EOL>os.path.abspath(os.path.dirname(self.cplistfile)),<EOL>self.cpfile<EOL>)<EOL>if not os.path.exists(cpfpath):<EOL><INDENT>msg = "<STR_LIT>" % cpfpath<EOL>LOGGER.error(msg)<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>forcereload = self.get_argument('<STR_LIT>',False)<EOL>if forcereload and xhtml_escape(forcereload):<EOL><INDENT>forcereload = True if forcereload == '<STR_LIT:true>' else False<EOL><DEDENT>cpobjectid = self.get_argument('<STR_LIT>',None)<EOL>lctool = self.get_argument('<STR_LIT>', None)<EOL>resultdict = {'<STR_LIT:status>':None,<EOL>'<STR_LIT:message>':None,<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>if lctool:<EOL><INDENT>lctool = xhtml_escape(lctool)<EOL>lctoolargs = []<EOL>lctoolkwargs = {}<EOL>if lctool in CPTOOLMAP:<EOL><INDENT>try:<EOL><INDENT>for xkwarg, xkwargtype, xkwargdef in zip(<EOL>CPTOOLMAP[lctool]['<STR_LIT>'],<EOL>CPTOOLMAP[lctool]['<STR_LIT>'],<EOL>CPTOOLMAP[lctool]['<STR_LIT>']<EOL>):<EOL><INDENT>if xkwargtype is list:<EOL><INDENT>wbkwarg = self.get_arguments(xkwarg)<EOL>if len(wbkwarg) > <NUM_LIT:0>:<EOL><INDENT>wbkwarg = [url_unescape(xhtml_escape(x))<EOL>for x in wbkwarg]<EOL><DEDENT>else:<EOL><INDENT>wbkwarg = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>wbkwarg = self.get_argument(xkwarg, None)<EOL>if wbkwarg is not None:<EOL><INDENT>wbkwarg = url_unescape(<EOL>xhtml_escape(wbkwarg)<EOL>)<EOL><DEDENT><DEDENT>LOGGER.info('<STR_LIT>' %<EOL>(xkwarg, repr(wbkwarg)))<EOL>if wbkwarg is None:<EOL><INDENT>wbkwarg = xkwargdef<EOL><DEDENT>else:<EOL><INDENT>if xkwargtype is list:<EOL><INDENT>wbkwarg = [float(x) for x in wbkwarg]<EOL><DEDENT>elif xkwargtype is bool:<EOL><INDENT>if wbkwarg == '<STR_LIT:false>':<EOL><INDENT>wbkwarg = False<EOL><DEDENT>elif wbkwarg == '<STR_LIT:true>':<EOL><INDENT>wbkwarg = True<EOL><DEDENT>else:<EOL><INDENT>wbkwarg = xkwargdef<EOL><DEDENT><DEDENT>else:<EOL><INDENT>wbkwarg = xkwargtype(wbkwarg)<EOL><DEDENT><DEDENT>if xkwarg.endswith('<STR_LIT>'):<EOL><INDENT>xkwarg = xkwarg.rstrip('<STR_LIT>')<EOL><DEDENT>lctoolkwargs.update({xkwarg:wbkwarg})<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGGER.exception('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, xkwarg))<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT:error>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, xkwarg)<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {'<STR_LIT>':cpobjectid}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>' % lctool)<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT:error>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>' % lctool<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {'<STR_LIT>':cpobjectid}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>')<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT:error>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>'<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {'<STR_LIT>':cpobjectid}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>LOGGER.info('<STR_LIT>' % cpfpath)<EOL>cpdict = yield self.executor.submit(<EOL>_read_checkplot_picklefile, cpfpath<EOL>)<EOL>tempfpath = cpfpath + '<STR_LIT>'<EOL>if os.path.exists(tempfpath):<EOL><INDENT>tempcpdict = yield self.executor.submit(<EOL>_read_checkplot_picklefile, tempfpath<EOL>)<EOL><DEDENT>else:<EOL><INDENT>tempcpdict = {<EOL>'<STR_LIT>':cpdict['<STR_LIT>'],<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':cpdict['<STR_LIT>']['<STR_LIT>'],<EOL>'<STR_LIT>':cpdict['<STR_LIT>']['<STR_LIT>'],<EOL>'<STR_LIT>':cpdict['<STR_LIT>']['<STR_LIT>'],<EOL>}<EOL>}<EOL><DEDENT>if not forcereload:<EOL><INDENT>cptimes, cpmags, cperrs = (<EOL>tempcpdict['<STR_LIT>']['<STR_LIT>'],<EOL>tempcpdict['<STR_LIT>']['<STR_LIT>'],<EOL>tempcpdict['<STR_LIT>']['<STR_LIT>'],<EOL>)<EOL>LOGGER.info('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>cptimes, cpmags, cperrs = (cpdict['<STR_LIT>']['<STR_LIT>'],<EOL>cpdict['<STR_LIT>']['<STR_LIT>'],<EOL>cpdict['<STR_LIT>']['<STR_LIT>'])<EOL>LOGGER.info('<STR_LIT>')<EOL><DEDENT>for xarg, xargtype in zip(CPTOOLMAP[lctool]['<STR_LIT:args>'],<EOL>CPTOOLMAP[lctool]['<STR_LIT>']):<EOL><INDENT>if xarg is None:<EOL><INDENT>lctoolargs.append(None)<EOL><DEDENT>elif xarg == '<STR_LIT>':<EOL><INDENT>lctoolargs.append(cptimes)<EOL><DEDENT>elif xarg == '<STR_LIT>':<EOL><INDENT>lctoolargs.append(cpmags)<EOL><DEDENT>elif xarg == '<STR_LIT>':<EOL><INDENT>lctoolargs.append(cperrs)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>if xargtype is list:<EOL><INDENT>wbarg = self.get_arguments(xarg)<EOL><DEDENT>else:<EOL><INDENT>wbarg = url_unescape(<EOL>xhtml_escape(<EOL>self.get_argument(xarg, None)<EOL>)<EOL>)<EOL><DEDENT>if xargtype is list:<EOL><INDENT>wbarg = [float(x) for x in wbarg]<EOL><DEDENT>elif xargtype is float and xarg == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>wbarg = xargtype(wbarg)<EOL><DEDENT>except Exception as e:<EOL><INDENT>wbarg = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>wbarg = xargtype(wbarg)<EOL><DEDENT>lctoolargs.append(wbarg)<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGGER.exception('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, xarg))<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT:error>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, xarg)<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {'<STR_LIT>':cpobjectid}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT><DEDENT><DEDENT>LOGGER.info(lctool)<EOL>LOGGER.info(lctoolargs)<EOL>LOGGER.info(lctoolkwargs)<EOL>resloc = CPTOOLMAP[lctool]['<STR_LIT>']<EOL>objectid = cpdict['<STR_LIT>']<EOL>if lctool in ('<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'):<EOL><INDENT>lspmethod = resloc[<NUM_LIT:0>]<EOL>if (lspmethod in tempcpdict and<EOL>isinstance(tempcpdict[lspmethod], dict) and<EOL>(not forcereload)):<EOL><INDENT>bestperiod = (<EOL>tempcpdict[lspmethod]['<STR_LIT>']<EOL>)<EOL>nbestperiods = (<EOL>tempcpdict[lspmethod]['<STR_LIT>']<EOL>)<EOL>nbestlspvals = (<EOL>tempcpdict[lspmethod]['<STR_LIT>']<EOL>)<EOL>periodogram = (<EOL>tempcpdict[lspmethod]['<STR_LIT>']<EOL>)<EOL>phasedlc0plot = (<EOL>tempcpdict[lspmethod][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>phasedlc0period = float(<EOL>tempcpdict[lspmethod][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>phasedlc0epoch = float(<EOL>tempcpdict[lspmethod][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, tempfpath)<EOL>)<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>lspmethod:{<EOL>'<STR_LIT>':nbestperiods,<EOL>'<STR_LIT>':periodogram,<EOL>'<STR_LIT>':bestperiod,<EOL>'<STR_LIT>':nbestlspvals,<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':phasedlc0plot,<EOL>'<STR_LIT>':phasedlc0period,<EOL>'<STR_LIT>':phasedlc0epoch,<EOL>}<EOL>}<EOL>}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>else:<EOL><INDENT>if lctoolkwargs['<STR_LIT>'] is not None:<EOL><INDENT>wtimes, wmags, werrs = lcmath.sigclip_magseries(<EOL>lctoolargs[<NUM_LIT:0>],<EOL>lctoolargs[<NUM_LIT:1>],<EOL>lctoolargs[<NUM_LIT:2>],<EOL>sigclip=lctoolkwargs['<STR_LIT>'],<EOL>magsarefluxes=lctoolkwargs['<STR_LIT>']<EOL>)<EOL>lctoolargs[<NUM_LIT:0>] = wtimes<EOL>lctoolargs[<NUM_LIT:1>] = wmags<EOL>lctoolargs[<NUM_LIT:2>] = werrs<EOL><DEDENT>if lctoolkwargs['<STR_LIT>']:<EOL><INDENT>wtimes, wmags, werrs = (lctoolargs[<NUM_LIT:0>],<EOL>lctoolargs[<NUM_LIT:1>],<EOL>lctoolargs[<NUM_LIT:2>])<EOL>filtermasks = [<EOL>np.full_like(wtimes, False, dtype=np.bool_)<EOL>]<EOL>filterstr = lctoolkwargs['<STR_LIT>']<EOL>filters = filterstr.split('<STR_LIT:U+002C>')<EOL>filters = [<EOL>x.strip().lstrip('<STR_LIT:(>').rstrip('<STR_LIT:)>').strip()<EOL>for x in filters<EOL>]<EOL>for filt in filters:<EOL><INDENT>try:<EOL><INDENT>thisfilt = filt.split('<STR_LIT::>')<EOL>if len(thisfilt) == <NUM_LIT:2>:<EOL><INDENT>filt_lo = float(thisfilt[<NUM_LIT:0>])<EOL>filt_hi = float(thisfilt[<NUM_LIT:1>])<EOL>filtermasks.append(<EOL>((wtimes -<EOL>cptimes.min()) < filt_hi) &<EOL>((wtimes -<EOL>cptimes.min()) > filt_lo)<EOL>)<EOL><DEDENT>elif (len(thisfilt) == <NUM_LIT:3> and<EOL>thisfilt[<NUM_LIT:0>].strip() == '<STR_LIT>'):<EOL><INDENT>filt_lo = float(thisfilt[<NUM_LIT:1>])<EOL>filt_hi = float(thisfilt[<NUM_LIT:2>])<EOL>filtermasks.append(np.logical_not(<EOL>(((wtimes -<EOL>cptimes.min()) < filt_hi) &<EOL>((wtimes -<EOL>cptimes.min()) > filt_lo))<EOL>))<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if len(filtermasks) > <NUM_LIT:0>:<EOL><INDENT>filterind = np.column_stack(filtermasks)<EOL>filterind = np.any(filterind, axis=<NUM_LIT:1>)<EOL>lctoolargs[<NUM_LIT:0>] = wtimes[filterind]<EOL>lctoolargs[<NUM_LIT:1>] = wmags[filterind]<EOL>lctoolargs[<NUM_LIT:2>] = werrs[filterind]<EOL><DEDENT><DEDENT>if lctoolkwargs['<STR_LIT>']:<EOL><INDENT>wtimes, wmags, werrs = (lctoolargs[<NUM_LIT:0>],<EOL>lctoolargs[<NUM_LIT:1>],<EOL>lctoolargs[<NUM_LIT:2>])<EOL>filtermasks = [<EOL>np.full_like(wtimes, False, dtype=np.bool_)<EOL>]<EOL>filterstr = lctoolkwargs['<STR_LIT>']<EOL>filters = filterstr.split('<STR_LIT:U+002C>')<EOL>filters = [<EOL>x.strip().strip()<EOL>for x in filters<EOL>]<EOL>for filt in filters:<EOL><INDENT>try:<EOL><INDENT>thisfilt = filt.split('<STR_LIT::>')<EOL>if len(thisfilt) == <NUM_LIT:2>:<EOL><INDENT>filt_lo = float(thisfilt[<NUM_LIT:0>])<EOL>filt_hi = float(thisfilt[<NUM_LIT:1>])<EOL>filtermasks.append(<EOL>(wmags < filt_hi) &<EOL>(wmags > filt_lo)<EOL>)<EOL><DEDENT>elif (len(thisfilt) == <NUM_LIT:3> and<EOL>thisfilt[<NUM_LIT:0>].strip() == '<STR_LIT>'):<EOL><INDENT>filt_lo = float(thisfilt[<NUM_LIT:1>])<EOL>filt_hi = float(thisfilt[<NUM_LIT:2>])<EOL>filtermasks.append(np.logical_not(<EOL>((wmags < filt_hi) &<EOL>(wmags > filt_lo))<EOL>))<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if len(filtermasks) > <NUM_LIT:0>:<EOL><INDENT>filterind = np.column_stack(filtermasks)<EOL>filterind = np.any(filterind, axis=<NUM_LIT:1>)<EOL>lctoolargs[<NUM_LIT:0>] = wtimes[filterind]<EOL>lctoolargs[<NUM_LIT:1>] = wmags[filterind]<EOL>lctoolargs[<NUM_LIT:2>] = werrs[filterind]<EOL><DEDENT><DEDENT>del lctoolkwargs['<STR_LIT>']<EOL>del lctoolkwargs['<STR_LIT>']<EOL>lctoolfunction = CPTOOLMAP[lctool]['<STR_LIT>']<EOL>funcresults = yield self.executor.submit(<EOL>lctoolfunction,<EOL>*lctoolargs,<EOL>**lctoolkwargs<EOL>)<EOL>nbestperiods = funcresults['<STR_LIT>']<EOL>nbestlspvals = funcresults['<STR_LIT>']<EOL>bestperiod = funcresults['<STR_LIT>']<EOL>pgramres = yield self.executor.submit(<EOL>_pkl_periodogram,<EOL>funcresults,<EOL>)<EOL>phasedlcargs0 = (None,<EOL>lspmethod,<EOL>-<NUM_LIT:1>,<EOL>lctoolargs[<NUM_LIT:0>],<EOL>lctoolargs[<NUM_LIT:1>],<EOL>lctoolargs[<NUM_LIT:2>],<EOL>nbestperiods[<NUM_LIT:0>],<EOL>'<STR_LIT>')<EOL>if len(nbestperiods) > <NUM_LIT:1>:<EOL><INDENT>phasedlcargs1 = (None,<EOL>lspmethod,<EOL>-<NUM_LIT:1>,<EOL>lctoolargs[<NUM_LIT:0>],<EOL>lctoolargs[<NUM_LIT:1>],<EOL>lctoolargs[<NUM_LIT:2>],<EOL>nbestperiods[<NUM_LIT:1>],<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>phasedlcargs1 = None<EOL><DEDENT>if len(nbestperiods) > <NUM_LIT:2>:<EOL><INDENT>phasedlcargs2 = (None,<EOL>lspmethod,<EOL>-<NUM_LIT:1>,<EOL>lctoolargs[<NUM_LIT:0>],<EOL>lctoolargs[<NUM_LIT:1>],<EOL>lctoolargs[<NUM_LIT:2>],<EOL>nbestperiods[<NUM_LIT:2>],<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>phasedlcargs2 = None<EOL><DEDENT>phasedlckwargs = {<EOL>'<STR_LIT>':False,<EOL>'<STR_LIT>':lctoolkwargs['<STR_LIT>'],<EOL>'<STR_LIT>':'<STR_LIT>',<EOL>}<EOL>phasedlc0 = yield self.executor.submit(<EOL>_pkl_phased_magseries_plot,<EOL>*phasedlcargs0,<EOL>**phasedlckwargs<EOL>)<EOL>if phasedlcargs1 is not None:<EOL><INDENT>phasedlc1 = yield self.executor.submit(<EOL>_pkl_phased_magseries_plot,<EOL>*phasedlcargs1,<EOL>**phasedlckwargs<EOL>)<EOL><DEDENT>else:<EOL><INDENT>phasedlc1 = None<EOL><DEDENT>if phasedlcargs2 is not None:<EOL><INDENT>phasedlc2 = yield self.executor.submit(<EOL>_pkl_phased_magseries_plot,<EOL>*phasedlcargs2,<EOL>**phasedlckwargs<EOL>)<EOL><DEDENT>else:<EOL><INDENT>phasedlc2 = None<EOL><DEDENT>if not self.readonly:<EOL><INDENT>tempcpdict[lspmethod] = {<EOL>'<STR_LIT>':funcresults['<STR_LIT>'],<EOL>'<STR_LIT>':funcresults['<STR_LIT>'],<EOL>'<STR_LIT>':funcresults['<STR_LIT>'],<EOL>'<STR_LIT>':funcresults['<STR_LIT>'],<EOL>'<STR_LIT>':funcresults['<STR_LIT>'],<EOL>'<STR_LIT>':(<EOL>pgramres[lspmethod]['<STR_LIT>']<EOL>),<EOL><NUM_LIT:0>:phasedlc0,<EOL>}<EOL>if phasedlc1 is not None:<EOL><INDENT>tempcpdict[lspmethod][<NUM_LIT:1>] = phasedlc1<EOL><DEDENT>if phasedlc2 is not None:<EOL><INDENT>tempcpdict[lspmethod][<NUM_LIT:2>] = phasedlc2<EOL><DEDENT>savekwargs = {<EOL>'<STR_LIT>':tempfpath,<EOL>'<STR_LIT>':pickle.HIGHEST_PROTOCOL<EOL>}<EOL>savedcpf = yield self.executor.submit(<EOL>_write_checkplot_picklefile,<EOL>tempcpdict,<EOL>**savekwargs<EOL>)<EOL>LOGGER.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, savedcpf)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>periodogram = pgramres[lspmethod]['<STR_LIT>']<EOL>phasedlc0plot = phasedlc0['<STR_LIT>']<EOL>phasedlc0period = float(phasedlc0['<STR_LIT>'])<EOL>phasedlc0epoch = float(phasedlc0['<STR_LIT>'])<EOL>if phasedlc1 is not None:<EOL><INDENT>phasedlc1plot = phasedlc1['<STR_LIT>']<EOL>phasedlc1period = float(phasedlc1['<STR_LIT>'])<EOL>phasedlc1epoch = float(phasedlc1['<STR_LIT>'])<EOL><DEDENT>if phasedlc2 is not None:<EOL><INDENT>phasedlc2plot = phasedlc2['<STR_LIT>']<EOL>phasedlc2period = float(phasedlc2['<STR_LIT>'])<EOL>phasedlc2epoch = float(phasedlc2['<STR_LIT>'])<EOL><DEDENT>resultdict['<STR_LIT:status>'] = '<STR_LIT:success>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>lspmethod:{<EOL>'<STR_LIT>':nbestperiods,<EOL>'<STR_LIT>':nbestlspvals,<EOL>'<STR_LIT>':periodogram,<EOL>'<STR_LIT>':bestperiod,<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':phasedlc0plot,<EOL>'<STR_LIT>':phasedlc0period,<EOL>'<STR_LIT>':phasedlc0epoch,<EOL>},<EOL>}<EOL>}<EOL>if phasedlc1 is not None:<EOL><INDENT>resultdict['<STR_LIT:result>'][lspmethod]['<STR_LIT>'] = {<EOL>'<STR_LIT>':phasedlc1plot,<EOL>'<STR_LIT>':phasedlc1period,<EOL>'<STR_LIT>':phasedlc1epoch,<EOL>}<EOL><DEDENT>if phasedlc2 is not None:<EOL><INDENT>resultdict['<STR_LIT:result>'][lspmethod]['<STR_LIT>'] = {<EOL>'<STR_LIT>':phasedlc2plot,<EOL>'<STR_LIT>':phasedlc2period,<EOL>'<STR_LIT>':phasedlc2epoch,<EOL>}<EOL><DEDENT>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT><DEDENT>elif lctool == '<STR_LIT>':<EOL><INDENT>lspmethod = lctoolargs[<NUM_LIT:1>]<EOL>periodind = lctoolargs[<NUM_LIT:2>]<EOL>if (not forcereload and lspmethod in tempcpdict and<EOL>isinstance(tempcpdict[lspmethod], dict) and<EOL>periodind in tempcpdict[lspmethod] and<EOL>isinstance(tempcpdict[lspmethod][periodind], dict)):<EOL><INDENT>phasedlc = tempcpdict[lspmethod][periodind]<EOL>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, tempfpath)<EOL>)<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>retkey = '<STR_LIT>' % periodind<EOL>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>lspmethod:{<EOL>retkey:phasedlc<EOL>}<EOL>}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>else:<EOL><INDENT>lctoolkwargs['<STR_LIT>'] = '<STR_LIT>'<EOL>lctoolargs[<NUM_LIT:2>] = -<NUM_LIT:1><EOL>if lctoolkwargs['<STR_LIT>'] is not None:<EOL><INDENT>stimes, smags, serrs = lcmath.sigclip_magseries(<EOL>lctoolargs[<NUM_LIT:3>],<EOL>lctoolargs[<NUM_LIT:4>],<EOL>lctoolargs[<NUM_LIT:5>],<EOL>sigclip=lctoolkwargs['<STR_LIT>'],<EOL>magsarefluxes=lctoolkwargs['<STR_LIT>']<EOL>)<EOL><DEDENT>else:<EOL><INDENT>stimes, smags, serrs = (lctoolargs[<NUM_LIT:3>],<EOL>lctoolargs[<NUM_LIT:4>],<EOL>lctoolargs[<NUM_LIT:5>])<EOL><DEDENT>if lctoolkwargs['<STR_LIT>']:<EOL><INDENT>wtimes, wmags, werrs = stimes, smags, serrs<EOL>filtermasks = [<EOL>np.full_like(wtimes, False, dtype=np.bool_)<EOL>]<EOL>filterstr = lctoolkwargs['<STR_LIT>']<EOL>filters = filterstr.split('<STR_LIT:U+002C>')<EOL>filters = [<EOL>x.strip().lstrip('<STR_LIT:(>').rstrip('<STR_LIT:)>').strip()<EOL>for x in filters<EOL>]<EOL>for filt in filters:<EOL><INDENT>try:<EOL><INDENT>thisfilt = filt.split('<STR_LIT::>')<EOL>if len(thisfilt) == <NUM_LIT:2>:<EOL><INDENT>filt_lo = float(thisfilt[<NUM_LIT:0>])<EOL>filt_hi = float(thisfilt[<NUM_LIT:1>])<EOL>filtermasks.append(<EOL>((wtimes -<EOL>cptimes.min()) < filt_hi) &<EOL>((wtimes -<EOL>cptimes.min()) > filt_lo)<EOL>)<EOL><DEDENT>elif (len(thisfilt) == <NUM_LIT:3> and<EOL>thisfilt[<NUM_LIT:0>].strip() == '<STR_LIT>'):<EOL><INDENT>filt_lo = float(thisfilt[<NUM_LIT:1>])<EOL>filt_hi = float(thisfilt[<NUM_LIT:2>])<EOL>filtermasks.append(np.logical_not(<EOL>(((wtimes -<EOL>cptimes.min()) < filt_hi) &<EOL>((wtimes -<EOL>cptimes.min()) > filt_lo))<EOL>))<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if len(filtermasks) > <NUM_LIT:0>:<EOL><INDENT>filterind = np.column_stack(filtermasks)<EOL>filterind = np.any(filterind, axis=<NUM_LIT:1>)<EOL>stimes = wtimes[filterind]<EOL>smags = wmags[filterind]<EOL>serrs = werrs[filterind]<EOL><DEDENT><DEDENT>if lctoolkwargs['<STR_LIT>']:<EOL><INDENT>wtimes, wmags, werrs = stimes, smags, serrs<EOL>filtermasks = [<EOL>np.full_like(wtimes, False, dtype=np.bool_)<EOL>]<EOL>filterstr = lctoolkwargs['<STR_LIT>']<EOL>filters = filterstr.split('<STR_LIT:U+002C>')<EOL>filters = [<EOL>x.strip().strip()<EOL>for x in filters<EOL>]<EOL>for filt in filters:<EOL><INDENT>try:<EOL><INDENT>thisfilt = filt.split('<STR_LIT::>')<EOL>if len(thisfilt) == <NUM_LIT:2>:<EOL><INDENT>filt_lo = float(thisfilt[<NUM_LIT:0>])<EOL>filt_hi = float(thisfilt[<NUM_LIT:1>])<EOL>filtermasks.append(<EOL>(wmags < filt_hi) &<EOL>(wmags > filt_lo)<EOL>)<EOL><DEDENT>elif (len(thisfilt) == <NUM_LIT:3> and<EOL>thisfilt[<NUM_LIT:0>].strip() == '<STR_LIT>'):<EOL><INDENT>filt_lo = float(thisfilt[<NUM_LIT:1>])<EOL>filt_hi = float(thisfilt[<NUM_LIT:2>])<EOL>filtermasks.append(np.logical_not(<EOL>((wmags < filt_hi) &<EOL>(wmags > filt_lo))<EOL>))<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if len(filtermasks) > <NUM_LIT:0>:<EOL><INDENT>filterind = np.column_stack(filtermasks)<EOL>filterind = np.any(filterind, axis=<NUM_LIT:1>)<EOL>stimes = wtimes[filterind]<EOL>smags = wmags[filterind]<EOL>serrs = werrs[filterind]<EOL><DEDENT><DEDENT>del lctoolkwargs['<STR_LIT>']<EOL>del lctoolkwargs['<STR_LIT>']<EOL>if lctoolargs[-<NUM_LIT:1>] is None:<EOL><INDENT>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL>try:<EOL><INDENT>spfit = lcfit.spline_fit_magseries(<EOL>stimes,         <EOL>smags,          <EOL>serrs,          <EOL>lctoolargs[<NUM_LIT:6>],  <EOL>magsarefluxes=lctoolkwargs['<STR_LIT>'],<EOL>sigclip=None,<EOL>verbose=True<EOL>)<EOL>lctoolargs[-<NUM_LIT:1>] = spfit['<STR_LIT>']['<STR_LIT>']<EOL>if len(spfit['<STR_LIT>']['<STR_LIT>']) != <NUM_LIT:1>:<EOL><INDENT>lctoolargs[-<NUM_LIT:1>] = (<EOL>spfit['<STR_LIT>']['<STR_LIT>'][<NUM_LIT:0>]<EOL>)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGGER.exception(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL>lctoolargs[-<NUM_LIT:1>] = np.min(stimes)<EOL><DEDENT><DEDENT>lctoolargs[<NUM_LIT:3>] = stimes<EOL>lctoolargs[<NUM_LIT:4>] = smags<EOL>lctoolargs[<NUM_LIT:5>] = serrs<EOL>del lctoolkwargs['<STR_LIT>']<EOL>lctoolfunction = CPTOOLMAP[lctool]['<STR_LIT>']<EOL>funcresults = yield self.executor.submit(<EOL>lctoolfunction,<EOL>*lctoolargs,<EOL>**lctoolkwargs<EOL>)<EOL>if not self.readonly:<EOL><INDENT>if (lspmethod in tempcpdict and<EOL>isinstance(tempcpdict[lspmethod], dict)):<EOL><INDENT>if periodind in tempcpdict[lspmethod]:<EOL><INDENT>tempcpdict[lspmethod][periodind] = (<EOL>funcresults<EOL>)<EOL><DEDENT>else:<EOL><INDENT>tempcpdict[lspmethod].update(<EOL>{periodind: funcresults}<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tempcpdict[lspmethod] = {periodind: funcresults}<EOL><DEDENT>savekwargs = {<EOL>'<STR_LIT>':tempfpath,<EOL>'<STR_LIT>':pickle.HIGHEST_PROTOCOL<EOL>}<EOL>savedcpf = yield self.executor.submit(<EOL>_write_checkplot_picklefile,<EOL>tempcpdict,<EOL>**savekwargs<EOL>)<EOL>LOGGER.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, savedcpf)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>resultdict['<STR_LIT:status>'] = '<STR_LIT:success>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>retkey = '<STR_LIT>' % periodind<EOL>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>lspmethod:{<EOL>retkey:funcresults<EOL>}<EOL>}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT><DEDENT>elif lctool == '<STR_LIT>':<EOL><INDENT>if (not forcereload and<EOL>'<STR_LIT>' in tempcpdict and<EOL>isinstance(tempcpdict['<STR_LIT>'], dict) and<EOL>'<STR_LIT>' in tempcpdict['<STR_LIT>'] and<EOL>isinstance(tempcpdict['<STR_LIT>']['<STR_LIT>'], dict)):<EOL><INDENT>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, tempfpath)<EOL>)<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': (<EOL>tempcpdict['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>}<EOL>}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>else:<EOL><INDENT>lctoolfunction = CPTOOLMAP[lctool]['<STR_LIT>']<EOL>funcresults = yield self.executor.submit(<EOL>lctoolfunction,<EOL>*lctoolargs,<EOL>**lctoolkwargs<EOL>)<EOL>if not self.readonly:<EOL><INDENT>if ('<STR_LIT>' in tempcpdict and<EOL>isinstance(tempcpdict['<STR_LIT>'], dict)):<EOL><INDENT>if '<STR_LIT>' in tempcpdict['<STR_LIT>']:<EOL><INDENT>tempcpdict['<STR_LIT>']['<STR_LIT>'] = (<EOL>funcresults<EOL>)<EOL><DEDENT>else:<EOL><INDENT>tempcpdict['<STR_LIT>'].update(<EOL>{'<STR_LIT>': funcresults}<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tempcpdict['<STR_LIT>'] = {'<STR_LIT>':<EOL>funcresults}<EOL><DEDENT>savekwargs = {<EOL>'<STR_LIT>':tempfpath,<EOL>'<STR_LIT>':pickle.HIGHEST_PROTOCOL<EOL>}<EOL>savedcpf = yield self.executor.submit(<EOL>_write_checkplot_picklefile,<EOL>tempcpdict,<EOL>**savekwargs<EOL>)<EOL>LOGGER.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, savedcpf)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>resultdict['<STR_LIT:status>'] = '<STR_LIT:success>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':funcresults<EOL>}<EOL>}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT><DEDENT>elif lctool in ('<STR_LIT>','<STR_LIT>'):<EOL><INDENT>key1, key2 = resloc<EOL>if (not forcereload and<EOL>key1 in tempcpdict and<EOL>isinstance(tempcpdict[key1], dict) and<EOL>key2 in tempcpdict[key1] and<EOL>isinstance(tempcpdict[key1][key2], dict)):<EOL><INDENT>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, tempfpath)<EOL>)<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>key1: {<EOL>key2: (<EOL>tempcpdict[key1][key2]<EOL>)<EOL>}<EOL>}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>else:<EOL><INDENT>lctoolfunction = CPTOOLMAP[lctool]['<STR_LIT>']<EOL>lctoolkwargs['<STR_LIT>'] = StrIO()<EOL>funcresults = yield self.executor.submit(<EOL>lctoolfunction,<EOL>*lctoolargs,<EOL>**lctoolkwargs<EOL>)<EOL>fitfd = funcresults['<STR_LIT>']<EOL>fitfd.seek(<NUM_LIT:0>)<EOL>fitbin = fitfd.read()<EOL>fitb64 = base64.b64encode(fitbin)<EOL>fitfd.close()<EOL>funcresults['<STR_LIT>'] = fitb64<EOL>if not self.readonly:<EOL><INDENT>if (key1 in tempcpdict and<EOL>isinstance(tempcpdict[key1], dict)):<EOL><INDENT>if key2 in tempcpdict[key1]:<EOL><INDENT>tempcpdict[key1][key2] = (<EOL>funcresults<EOL>)<EOL><DEDENT>else:<EOL><INDENT>tempcpdict[key1].update(<EOL>{key2: funcresults}<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tempcpdict[key1] = {key2: funcresults}<EOL><DEDENT>savekwargs = {<EOL>'<STR_LIT>':tempfpath,<EOL>'<STR_LIT>':pickle.HIGHEST_PROTOCOL<EOL>}<EOL>savedcpf = yield self.executor.submit(<EOL>_write_checkplot_picklefile,<EOL>tempcpdict,<EOL>**savekwargs<EOL>)<EOL>LOGGER.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, savedcpf)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>fitreturndict = {'<STR_LIT>':fitb64}<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT:success>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>key1:{<EOL>key2:fitreturndict<EOL>}<EOL>}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT><DEDENT>elif lctool in ('<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'):<EOL><INDENT>key1, key2 = resloc<EOL>if (not forcereload and<EOL>key1 in tempcpdict and<EOL>isinstance(tempcpdict[key1], dict) and<EOL>key2 in tempcpdict[key1] and<EOL>isinstance(tempcpdict[key1][key2], dict)):<EOL><INDENT>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, tempfpath)<EOL>)<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>phasedfitlc = tempcpdict[key1][key2]<EOL>fitresults = {<EOL>'<STR_LIT>':phasedfitlc['<STR_LIT>']['<STR_LIT>'],<EOL>'<STR_LIT>':phasedfitlc['<STR_LIT>']['<STR_LIT>'],<EOL>'<STR_LIT>':phasedfitlc['<STR_LIT>']['<STR_LIT>'],<EOL>'<STR_LIT>':phasedfitlc['<STR_LIT>'],<EOL>'<STR_LIT>':phasedfitlc['<STR_LIT>'],<EOL>'<STR_LIT>':phasedfitlc['<STR_LIT>'],<EOL>}<EOL>if ('<STR_LIT>' in phasedfitlc['<STR_LIT>']['<STR_LIT>'] and<EOL>phasedfitlc['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>is not None):<EOL><INDENT>fitresults['<STR_LIT>'] = (<EOL>phasedfitlc['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>key1: {<EOL>key2: (<EOL>fitresults<EOL>)<EOL>}<EOL>}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>else:<EOL><INDENT>lctoolfunction = CPTOOLMAP[lctool]['<STR_LIT>']<EOL>funcresults = yield self.executor.submit(<EOL>lctoolfunction,<EOL>*lctoolargs,<EOL>**lctoolkwargs<EOL>)<EOL>phasedlcargs = (None,<EOL>'<STR_LIT>',<EOL>-<NUM_LIT:1>,<EOL>cptimes,<EOL>cpmags,<EOL>cperrs,<EOL>lctoolargs[<NUM_LIT:3>],  <EOL>'<STR_LIT>')<EOL>phasedlckwargs = {<EOL>'<STR_LIT>':False,<EOL>'<STR_LIT>':lctoolkwargs['<STR_LIT>'],<EOL>'<STR_LIT>':'<STR_LIT>',<EOL>'<STR_LIT>':funcresults<EOL>}<EOL>phasedlc = yield self.executor.submit(<EOL>_pkl_phased_magseries_plot,<EOL>*phasedlcargs,<EOL>**phasedlckwargs<EOL>)<EOL>if not self.readonly:<EOL><INDENT>if (key1 in tempcpdict and<EOL>isinstance(tempcpdict[key1], dict)):<EOL><INDENT>if key2 in tempcpdict[key1]:<EOL><INDENT>tempcpdict[key1][key2] = (<EOL>phasedlc<EOL>)<EOL><DEDENT>else:<EOL><INDENT>tempcpdict[key1].update(<EOL>{key2: phasedlc}<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tempcpdict[key1] = {key2: phasedlc}<EOL><DEDENT>savekwargs = {<EOL>'<STR_LIT>':tempfpath,<EOL>'<STR_LIT>':pickle.HIGHEST_PROTOCOL<EOL>}<EOL>savedcpf = yield self.executor.submit(<EOL>_write_checkplot_picklefile,<EOL>tempcpdict,<EOL>**savekwargs<EOL>)<EOL>LOGGER.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(lctool, savedcpf)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>fitresults = {<EOL>'<STR_LIT>':phasedlc['<STR_LIT>']['<STR_LIT>'],<EOL>'<STR_LIT>':phasedlc['<STR_LIT>']['<STR_LIT>'],<EOL>'<STR_LIT>':phasedlc['<STR_LIT>']['<STR_LIT>'],<EOL>'<STR_LIT>':phasedlc['<STR_LIT>'],<EOL>'<STR_LIT>':phasedlc['<STR_LIT>'],<EOL>'<STR_LIT>':phasedlc['<STR_LIT>'],<EOL>}<EOL>if ('<STR_LIT>' in funcresults['<STR_LIT>'] and<EOL>funcresults['<STR_LIT>']['<STR_LIT>'] is not None):<EOL><INDENT>fitresults['<STR_LIT>'] = (<EOL>funcresults['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL><DEDENT>resultdict['<STR_LIT:status>'] = '<STR_LIT:success>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>' %<EOL>lctool<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {<EOL>'<STR_LIT>':objectid,<EOL>key1:{<EOL>key2:fitresults<EOL>}<EOL>}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT><DEDENT>elif lctool == '<STR_LIT>':<EOL><INDENT>fitmethod, periodind = lctoolargs<EOL><DEDENT>elif lctool == '<STR_LIT>':<EOL><INDENT>if os.path.exists(tempfpath):<EOL><INDENT>os.remove(tempfpath)<EOL>LOGGER.warning('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(tempfpath, cpfpath))<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT:success>'<EOL><DEDENT>else:<EOL><INDENT>resultdict['<STR_LIT:status>'] = '<STR_LIT:error>'<EOL>LOGGER.warning('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(tempfpath, cpfpath))<EOL><DEDENT>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>'<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {'<STR_LIT>':cpobjectid}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>elif lctool == '<STR_LIT>':<EOL><INDENT>target = self.get_argument('<STR_LIT>',None)<EOL>if target is not None:<EOL><INDENT>target = xhtml_escape(target)<EOL>if (target not in CPTOOLMAP or<EOL>target == '<STR_LIT>' or<EOL>target == '<STR_LIT>' or<EOL>target == '<STR_LIT>' or<EOL>target == '<STR_LIT>'):<EOL><INDENT>LOGGER.error("<STR_LIT>" % target)<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT:error>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>"<STR_LIT>" % target<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {'<STR_LIT>':cpobjectid}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>targetloc = CPTOOLMAP[target]['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>' % lctool)<EOL>resultdict['<STR_LIT:status>'] = '<STR_LIT:error>'<EOL>resultdict['<STR_LIT:message>'] = (<EOL>'<STR_LIT>' % lctool<EOL>)<EOL>resultdict['<STR_LIT:result>'] = {'<STR_LIT>':cpobjectid}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>' % self.cpfile)<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':"<STR_LIT>",<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':'<STR_LIT>',<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>

This handles a GET request to run a specified LC tool.

        Parameters
        ----------

        cpfile : str
            This is the checkplot file to run the tool on.

        Returns
        -------

        str
            Returns a JSON response.

        Notes
        -----

        The URI structure is::

            /tools/<cpfile>?[args]

        where args are::

            ?lctool=<lctool>&argkey1=argval1&argkey2=argval2&...

            &forcereload=true <- if this is present, then reload values from
            original checkplot.

            &objectid=<objectid>

        `lctool` is one of the strings below

        Period search functions::

            psearch-gls: run Lomb-Scargle with given params
            psearch-bls: run BLS with given params
            psearch-pdm: run phase dispersion minimization with given params
            psearch-aov: run analysis-of-variance with given params
            psearch-mav: run analysis-of-variance (multi-harm) with given params
            psearch-acf: run ACF period search with given params
            psearch-win: run spectral window function search with given params

        Arguments recognized by all period-search functions are::

            startp=XX
            endp=XX
            magsarefluxes=True|False
            autofreq=True|False
            stepsize=XX

        Variability characterization functions::

            var-varfeatures: gets the variability features from the checkplot or
                             recalculates if they're not present

            var-prewhiten: pre-whitens the light curve with a sinusoidal signal

            var-masksig: masks a given phase location with given width from the
                         light curve

        Light curve manipulation functions ::

            phasedlc-newplot: make phased LC with new provided period/epoch
            lcfit-fourier: fit a Fourier function to the phased LC
            lcfit-spline: fit a spline function to the phased LC
            lcfit-legendre: fit a Legendre polynomial to the phased LC
            lcfit-savgol: fit a Savitsky-Golay polynomial to the phased LC

        FIXME: figure out how to cache the results of these functions
        temporarily and save them back to the checkplot after we click on save
        in the frontend.

        TODO: look for a checkplot-blah-blah.pkl-cps-processing file in the same
        place as the usual pickle file. if this exists and is newer than the pkl
        file, load it instead. Or have a checkplotdict['cpservertemp'] item.


This handles initial setup of this `RequestHandler`.


provided_key = self.get_argument('<STR_LIT:key>',default=None)<EOL>if not provided_key:<EOL><INDENT>LOGGER.error('<STR_LIT>')<EOL>retdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':('<STR_LIT>'<EOL>'<STR_LIT>'),<EOL>'<STR_LIT:result>':None,<EOL>'<STR_LIT>':True}<EOL>self.set_status(<NUM_LIT>)<EOL>self.write(retdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>else:<EOL><INDENT>provided_key = xhtml_escape(provided_key)<EOL>if not _time_independent_equals(provided_key,<EOL>self.secret):<EOL><INDENT>LOGGER.error('<STR_LIT>')<EOL>retdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':('<STR_LIT>'<EOL>'<STR_LIT>'),<EOL>'<STR_LIT:result>':None,<EOL>'<STR_LIT>':True}<EOL>self.set_status(<NUM_LIT>)<EOL>self.write(retdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT><DEDENT>LOGGER.info('<STR_LIT>')<EOL>checkplotfname = self.get_argument('<STR_LIT>', default=None)<EOL>if checkplotfname:<EOL><INDENT>try:<EOL><INDENT>cpfpath = xhtml_escape(<EOL>base64.b64decode(url_unescape(checkplotfname))<EOL>)<EOL><DEDENT>except Exception as e:<EOL><INDENT>msg = '<STR_LIT>'<EOL>LOGGER.error(msg)<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT:result>':None,<EOL>'<STR_LIT>':True}<EOL>self.set_status(<NUM_LIT>)<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>LOGGER.info('<STR_LIT>' % cpfpath)<EOL>if not os.path.exists(cpfpath):<EOL><INDENT>msg = "<STR_LIT>" % cpfpath<EOL>LOGGER.error(msg)<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT:result>':None,<EOL>'<STR_LIT>':True}<EOL>self.set_status(<NUM_LIT>)<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>cpdict = yield self.executor.submit(<EOL>_read_checkplot_picklefile, cpfpath<EOL>)<EOL>LOGGER.info('<STR_LIT>' % cpfpath)<EOL>objectid = cpdict['<STR_LIT>']<EOL>objectinfo = cpdict['<STR_LIT>']<EOL>varinfo = cpdict['<STR_LIT>']<EOL>if '<STR_LIT>' in cpdict:<EOL><INDENT>pfmethods = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>pfmethods = []<EOL>for pfm in PFMETHODS:<EOL><INDENT>if pfm in cpdict:<EOL><INDENT>pfmethods.append(pfm)<EOL><DEDENT><DEDENT><DEDENT>neighbors = []<EOL>if ('<STR_LIT>' in cpdict and<EOL>cpdict['<STR_LIT>'] is not None and<EOL>len(cpdict['<STR_LIT>'])) > <NUM_LIT:0>:<EOL><INDENT>nbrlist = cpdict['<STR_LIT>']<EOL>for nbr in nbrlist:<EOL><INDENT>if '<STR_LIT>' in nbr:<EOL><INDENT>nbrmagdiffs = nbr['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>nbrmagdiffs = None<EOL><DEDENT>if '<STR_LIT>' in nbr:<EOL><INDENT>nbrcolordiffs = nbr['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>nbrcolordiffs = None<EOL><DEDENT>thisnbrdict = {<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbrmagdiffs,<EOL>'<STR_LIT>':nbrcolordiffs<EOL>}<EOL>}<EOL>try:<EOL><INDENT>nbr_magseries = nbr['<STR_LIT>']['<STR_LIT>']<EOL>thisnbrdict['<STR_LIT>'] = nbr_magseries<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGGER.error(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (nbr['<STR_LIT>'],<EOL>cpdict['<STR_LIT>'])<EOL>)<EOL><DEDENT>try:<EOL><INDENT>for pfm in pfmethods:<EOL><INDENT>if pfm in nbr:<EOL><INDENT>thisnbrdict[pfm] = {<EOL>'<STR_LIT>':nbr[pfm][<NUM_LIT:0>]['<STR_LIT>'],<EOL>'<STR_LIT>':nbr[pfm][<NUM_LIT:0>]['<STR_LIT>'],<EOL>'<STR_LIT>':nbr[pfm][<NUM_LIT:0>]['<STR_LIT>']<EOL>}<EOL><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGGER.error(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (nbr['<STR_LIT>'],<EOL>cpdict['<STR_LIT>'])<EOL>)<EOL><DEDENT>neighbors.append(thisnbrdict)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>objectcomments = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>objectcomments = None<EOL><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>objectxmatch = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>objectxmatch = None<EOL><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>colormagdiagram = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>colormagdiagram = None<EOL><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>finderchart = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>finderchart = None<EOL><DEDENT>if ('<STR_LIT>' in cpdict and<EOL>isinstance(cpdict['<STR_LIT>'], dict) and<EOL>'<STR_LIT>' in cpdict['<STR_LIT>']):<EOL><INDENT>magseries = cpdict['<STR_LIT>']['<STR_LIT>']<EOL>time0 = cpdict['<STR_LIT>']['<STR_LIT>'].min()<EOL>magseries_ndet = cpdict['<STR_LIT>']['<STR_LIT>'].size<EOL><DEDENT>else:<EOL><INDENT>magseries = None<EOL>time0 = <NUM_LIT:0.0><EOL>magseries_ndet = <NUM_LIT:0><EOL>LOGGER.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if '<STR_LIT:status>' in cpdict:<EOL><INDENT>cpstatus = cpdict['<STR_LIT:status>']<EOL><DEDENT>else:<EOL><INDENT>cpstatus = '<STR_LIT>'<EOL><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>uifilters = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>uifilters = {'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None}<EOL><DEDENT>resultdict = {<EOL>'<STR_LIT:status>':'<STR_LIT>',<EOL>'<STR_LIT:message>':'<STR_LIT>' % os.path.basename(cpfpath),<EOL>'<STR_LIT>':True,<EOL>'<STR_LIT:result>':{<EOL>'<STR_LIT>':'<STR_LIT>' % time0,<EOL>'<STR_LIT>':objectid,<EOL>'<STR_LIT>':objectinfo,<EOL>'<STR_LIT>':colormagdiagram,<EOL>'<STR_LIT>':objectcomments,<EOL>'<STR_LIT>':varinfo,<EOL>'<STR_LIT>':uifilters,<EOL>'<STR_LIT>':neighbors,<EOL>'<STR_LIT>':objectxmatch,<EOL>'<STR_LIT>':finderchart,<EOL>'<STR_LIT>':magseries,<EOL>'<STR_LIT>':magseries_ndet,<EOL>'<STR_LIT>':cpstatus,<EOL>'<STR_LIT>':pfmethods<EOL>}<EOL>}<EOL>for key in pfmethods:<EOL><INDENT>periodogram = cpdict[key]['<STR_LIT>']<EOL>if <NUM_LIT:0> in cpdict[key] and isinstance(cpdict[key][<NUM_LIT:0>], dict):<EOL><INDENT>phasedlc0plot = cpdict[key][<NUM_LIT:0>]['<STR_LIT>']<EOL>phasedlc0period = float(cpdict[key][<NUM_LIT:0>]['<STR_LIT>'])<EOL>phasedlc0epoch = float(cpdict[key][<NUM_LIT:0>]['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>phasedlc0plot = None<EOL>phasedlc0period = None<EOL>phasedlc0epoch = None<EOL><DEDENT>if (<NUM_LIT:0> in cpdict[key] and<EOL>isinstance(cpdict[key][<NUM_LIT:0>], dict) and<EOL>'<STR_LIT>' in cpdict[key][<NUM_LIT:0>] and<EOL>isinstance(cpdict[key][<NUM_LIT:0>]['<STR_LIT>'], dict)):<EOL><INDENT>phasedlc0fit = {<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:0>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:0>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:0>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:0>][<EOL>'<STR_LIT>'<EOL>]['<STR_LIT>']['<STR_LIT>'] if<EOL>'<STR_LIT>' in<EOL>cpdict[key][<NUM_LIT:0>]['<STR_LIT>']['<STR_LIT>'] else None<EOL>)<EOL>}<EOL><DEDENT>else:<EOL><INDENT>phasedlc0fit = None<EOL><DEDENT>if <NUM_LIT:1> in cpdict[key] and isinstance(cpdict[key][<NUM_LIT:1>], dict):<EOL><INDENT>phasedlc1plot = cpdict[key][<NUM_LIT:1>]['<STR_LIT>']<EOL>phasedlc1period = float(cpdict[key][<NUM_LIT:1>]['<STR_LIT>'])<EOL>phasedlc1epoch = float(cpdict[key][<NUM_LIT:1>]['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>phasedlc1plot = None<EOL>phasedlc1period = None<EOL>phasedlc1epoch = None<EOL><DEDENT>if (<NUM_LIT:1> in cpdict[key] and<EOL>isinstance(cpdict[key][<NUM_LIT:1>], dict) and<EOL>'<STR_LIT>' in cpdict[key][<NUM_LIT:1>] and<EOL>isinstance(cpdict[key][<NUM_LIT:1>]['<STR_LIT>'], dict)):<EOL><INDENT>phasedlc1fit = {<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:1>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:1>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:1>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:1>][<EOL>'<STR_LIT>'<EOL>]['<STR_LIT>']['<STR_LIT>'] if<EOL>'<STR_LIT>' in<EOL>cpdict[key][<NUM_LIT:1>]['<STR_LIT>']['<STR_LIT>'] else None<EOL>)<EOL>}<EOL><DEDENT>else:<EOL><INDENT>phasedlc1fit = None<EOL><DEDENT>if <NUM_LIT:2> in cpdict[key] and isinstance(cpdict[key][<NUM_LIT:2>], dict):<EOL><INDENT>phasedlc2plot = cpdict[key][<NUM_LIT:2>]['<STR_LIT>']<EOL>phasedlc2period = float(cpdict[key][<NUM_LIT:2>]['<STR_LIT>'])<EOL>phasedlc2epoch = float(cpdict[key][<NUM_LIT:2>]['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>phasedlc2plot = None<EOL>phasedlc2period = None<EOL>phasedlc2epoch = None<EOL><DEDENT>if (<NUM_LIT:2> in cpdict[key] and<EOL>isinstance(cpdict[key][<NUM_LIT:2>], dict) and<EOL>'<STR_LIT>' in cpdict[key][<NUM_LIT:2>] and<EOL>isinstance(cpdict[key][<NUM_LIT:2>]['<STR_LIT>'], dict)):<EOL><INDENT>phasedlc2fit = {<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:2>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:2>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:2>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:2>][<EOL>'<STR_LIT>'<EOL>]['<STR_LIT>']['<STR_LIT>'] if<EOL>'<STR_LIT>' in<EOL>cpdict[key][<NUM_LIT:2>]['<STR_LIT>']['<STR_LIT>'] else None<EOL>)<EOL>}<EOL><DEDENT>else:<EOL><INDENT>phasedlc2fit = None<EOL><DEDENT>resultdict['<STR_LIT:result>'][key] = {<EOL>'<STR_LIT>':cpdict[key]['<STR_LIT>'],<EOL>'<STR_LIT>':periodogram,<EOL>'<STR_LIT>':cpdict[key]['<STR_LIT>'],<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':phasedlc0plot,<EOL>'<STR_LIT>':phasedlc0period,<EOL>'<STR_LIT>':phasedlc0epoch,<EOL>'<STR_LIT>':phasedlc0fit,<EOL>},<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':phasedlc1plot,<EOL>'<STR_LIT>':phasedlc1period,<EOL>'<STR_LIT>':phasedlc1epoch,<EOL>'<STR_LIT>':phasedlc1fit,<EOL>},<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':phasedlc2plot,<EOL>'<STR_LIT>':phasedlc2period,<EOL>'<STR_LIT>':phasedlc2epoch,<EOL>'<STR_LIT>':phasedlc2fit,<EOL>},<EOL>}<EOL><DEDENT>self.set_header('<STR_LIT:Content-Type>','<STR_LIT>')<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>')<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':"<STR_LIT>",<EOL>'<STR_LIT>':True,<EOL>'<STR_LIT:result>':None}<EOL>self.status(<NUM_LIT>)<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>

This handles GET requests.

        Returns the requested checkplot pickle's information as JSON.

        Requires a pre-shared secret `key` argument for the operation to
        complete successfully. This is obtained from a command-line argument.


if checkplotfname:<EOL><INDENT>self.checkplotfname = xhtml_escape(<EOL>base64.b64decode(url_unescape(checkplotfname))<EOL>)<EOL>if self.checkplotfname in self.currentproject['<STR_LIT>']:<EOL><INDENT>cpfpath = os.path.join(<EOL>os.path.abspath(os.path.dirname(self.cplistfile)),<EOL>self.checkplotfname<EOL>)<EOL>LOGGER.info('<STR_LIT>' % cpfpath)<EOL>if not os.path.exists(cpfpath):<EOL><INDENT>msg = "<STR_LIT>" % cpfpath<EOL>LOGGER.error(msg)<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>raise tornado.web.Finish()<EOL><DEDENT>cpdict = yield self.executor.submit(<EOL>_read_checkplot_picklefile, cpfpath<EOL>)<EOL>LOGGER.info('<STR_LIT>' % cpfpath)<EOL>objectid = cpdict['<STR_LIT>']<EOL>objectinfo = cpdict['<STR_LIT>']<EOL>varinfo = cpdict['<STR_LIT>']<EOL>if '<STR_LIT>' in cpdict:<EOL><INDENT>pfmethods = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>pfmethods = []<EOL>for pfm in PFMETHODS:<EOL><INDENT>if pfm in cpdict:<EOL><INDENT>pfmethods.append(pfm)<EOL><DEDENT><DEDENT><DEDENT>neighbors = []<EOL>if ('<STR_LIT>' in cpdict and<EOL>cpdict['<STR_LIT>'] is not None and<EOL>len(cpdict['<STR_LIT>'])) > <NUM_LIT:0>:<EOL><INDENT>nbrlist = cpdict['<STR_LIT>']<EOL>for nbr in nbrlist:<EOL><INDENT>if '<STR_LIT>' in nbr:<EOL><INDENT>nbrmagdiffs = nbr['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>nbrmagdiffs = None<EOL><DEDENT>if '<STR_LIT>' in nbr:<EOL><INDENT>nbrcolordiffs = nbr['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>nbrcolordiffs = None<EOL><DEDENT>thisnbrdict = {<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbr['<STR_LIT>'],<EOL>'<STR_LIT>':nbrmagdiffs,<EOL>'<STR_LIT>':nbrcolordiffs<EOL>}<EOL>}<EOL>try:<EOL><INDENT>nbr_magseries = nbr['<STR_LIT>']['<STR_LIT>']<EOL>thisnbrdict['<STR_LIT>'] = nbr_magseries<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGGER.error(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (nbr['<STR_LIT>'],<EOL>cpdict['<STR_LIT>'])<EOL>)<EOL><DEDENT>try:<EOL><INDENT>for pfm in pfmethods:<EOL><INDENT>if pfm in nbr:<EOL><INDENT>thisnbrdict[pfm] = {<EOL>'<STR_LIT>':nbr[pfm][<NUM_LIT:0>]['<STR_LIT>'],<EOL>'<STR_LIT>':nbr[pfm][<NUM_LIT:0>]['<STR_LIT>'],<EOL>'<STR_LIT>':nbr[pfm][<NUM_LIT:0>]['<STR_LIT>']<EOL>}<EOL><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGGER.error(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (nbr['<STR_LIT>'],<EOL>cpdict['<STR_LIT>'])<EOL>)<EOL><DEDENT>neighbors.append(thisnbrdict)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>objectcomments = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>objectcomments = None<EOL><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>objectxmatch = cpdict['<STR_LIT>']<EOL>for xmcat in objectxmatch:<EOL><INDENT>if isinstance(objectxmatch[xmcat]['<STR_LIT:info>'], dict):<EOL><INDENT>xminfo = objectxmatch[xmcat]['<STR_LIT:info>']<EOL>for xmek in xminfo:<EOL><INDENT>if (isinstance(xminfo[xmek], float) and<EOL>(not np.isfinite(xminfo[xmek]))):<EOL><INDENT>xminfo[xmek] = None<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>objectxmatch = None<EOL><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>colormagdiagram = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>colormagdiagram = None<EOL><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>finderchart = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>finderchart = None<EOL><DEDENT>if ('<STR_LIT>' in cpdict and<EOL>isinstance(cpdict['<STR_LIT>'], dict) and<EOL>'<STR_LIT>' in cpdict['<STR_LIT>']):<EOL><INDENT>magseries = cpdict['<STR_LIT>']['<STR_LIT>']<EOL>time0 = cpdict['<STR_LIT>']['<STR_LIT>'].min()<EOL>magseries_ndet = cpdict['<STR_LIT>']['<STR_LIT>'].size<EOL><DEDENT>else:<EOL><INDENT>magseries = None<EOL>time0 = <NUM_LIT:0.0><EOL>magseries_ndet = <NUM_LIT:0><EOL>LOGGER.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if '<STR_LIT:status>' in cpdict:<EOL><INDENT>cpstatus = cpdict['<STR_LIT:status>']<EOL><DEDENT>else:<EOL><INDENT>cpstatus = '<STR_LIT>'<EOL><DEDENT>if '<STR_LIT>' in cpdict:<EOL><INDENT>uifilters = cpdict['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>uifilters = {'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None}<EOL><DEDENT>resultdict = {<EOL>'<STR_LIT:status>':'<STR_LIT>',<EOL>'<STR_LIT:message>':'<STR_LIT>' % self.checkplotfname,<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':{<EOL>'<STR_LIT>':'<STR_LIT>' % time0,<EOL>'<STR_LIT>':objectid,<EOL>'<STR_LIT>':objectinfo,<EOL>'<STR_LIT>':colormagdiagram,<EOL>'<STR_LIT>':objectcomments,<EOL>'<STR_LIT>':varinfo,<EOL>'<STR_LIT>':uifilters,<EOL>'<STR_LIT>':neighbors,<EOL>'<STR_LIT>':objectxmatch,<EOL>'<STR_LIT>':finderchart,<EOL>'<STR_LIT>':magseries,<EOL>'<STR_LIT>':magseries_ndet,<EOL>'<STR_LIT>':cpstatus,<EOL>'<STR_LIT>':pfmethods<EOL>}<EOL>}<EOL>for key in resultdict['<STR_LIT:result>']['<STR_LIT>']:<EOL><INDENT>if (isinstance(resultdict['<STR_LIT:result>']['<STR_LIT>'][key],<EOL>(float, np.float64, np.float_)) and<EOL>(not np.isfinite(resultdict['<STR_LIT:result>'][<EOL>'<STR_LIT>'<EOL>][key]))):<EOL><INDENT>resultdict['<STR_LIT:result>']['<STR_LIT>'][key] = None<EOL><DEDENT>elif (isinstance(resultdict['<STR_LIT:result>']['<STR_LIT>'][key],<EOL>ndarray)):<EOL><INDENT>thisval = resultdict['<STR_LIT:result>']['<STR_LIT>'][key]<EOL>thisval = thisval.tolist()<EOL>for i, v in enumerate(thisval):<EOL><INDENT>if (isinstance(v,(float, np.float64, np.float_)) and<EOL>(not(np.isfinite(v)))):<EOL><INDENT>thisval[i] = None<EOL><DEDENT><DEDENT>resultdict['<STR_LIT:result>']['<STR_LIT>'][key] = thisval<EOL><DEDENT><DEDENT>for key in resultdict['<STR_LIT:result>']['<STR_LIT>']:<EOL><INDENT>if (isinstance(<EOL>resultdict['<STR_LIT:result>']['<STR_LIT>'][key],<EOL>(float, np.float64, np.float_)) and<EOL>(not np.isfinite(<EOL>resultdict['<STR_LIT:result>']['<STR_LIT>'][key]<EOL>))):<EOL><INDENT>resultdict['<STR_LIT:result>']['<STR_LIT>'][key] = None<EOL><DEDENT>elif (isinstance(<EOL>resultdict['<STR_LIT:result>']['<STR_LIT>'][key],<EOL>ndarray)):<EOL><INDENT>thisval = (<EOL>resultdict['<STR_LIT:result>']['<STR_LIT>'][key]<EOL>)<EOL>thisval = thisval.tolist()<EOL>for i, v in enumerate(thisval):<EOL><INDENT>if (isinstance(v,(float, np.float64, np.float_)) and<EOL>(not(np.isfinite(v)))):<EOL><INDENT>thisval[i] = None<EOL><DEDENT><DEDENT>resultdict['<STR_LIT:result>']['<STR_LIT>'][key] = (<EOL>thisval<EOL>)<EOL><DEDENT><DEDENT>if ('<STR_LIT>' in resultdict['<STR_LIT:result>']['<STR_LIT>'] and<EOL>isinstance(resultdict['<STR_LIT:result>']['<STR_LIT>']['<STR_LIT>'],<EOL>dict)):<EOL><INDENT>for key in resultdict['<STR_LIT:result>']['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>if (isinstance(<EOL>resultdict[<EOL>'<STR_LIT:result>'<EOL>]['<STR_LIT>']['<STR_LIT>'][key],<EOL>(float, np.float64, np.float_)) and<EOL>(not np.isfinite(<EOL>resultdict[<EOL>'<STR_LIT:result>'<EOL>]['<STR_LIT>']['<STR_LIT>'][key]))):<EOL><INDENT>resultdict[<EOL>'<STR_LIT:result>'<EOL>]['<STR_LIT>']['<STR_LIT>'][key] = None<EOL><DEDENT>elif (isinstance(<EOL>resultdict[<EOL>'<STR_LIT:result>'<EOL>]['<STR_LIT>']['<STR_LIT>'][key],<EOL>ndarray)):<EOL><INDENT>thisval = (<EOL>resultdict['<STR_LIT:result>']['<STR_LIT>']['<STR_LIT>'][key]<EOL>)<EOL>thisval = thisval.tolist()<EOL>for i, v in enumerate(thisval):<EOL><INDENT>if (isinstance(v,(float,<EOL>np.float64,<EOL>np.float_)) and<EOL>(not(np.isfinite(v)))):<EOL><INDENT>thisval[i] = None<EOL><DEDENT><DEDENT>resultdict['<STR_LIT:result>']['<STR_LIT>']['<STR_LIT>'][key] = (<EOL>thisval<EOL>)<EOL><DEDENT><DEDENT><DEDENT>for key in pfmethods:<EOL><INDENT>periodogram = cpdict[key]['<STR_LIT>']<EOL>if <NUM_LIT:0> in cpdict[key] and isinstance(cpdict[key][<NUM_LIT:0>], dict):<EOL><INDENT>phasedlc0plot = cpdict[key][<NUM_LIT:0>]['<STR_LIT>']<EOL>phasedlc0period = float(cpdict[key][<NUM_LIT:0>]['<STR_LIT>'])<EOL>phasedlc0epoch = float(cpdict[key][<NUM_LIT:0>]['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>phasedlc0plot = None<EOL>phasedlc0period = None<EOL>phasedlc0epoch = None<EOL><DEDENT>if (<NUM_LIT:0> in cpdict[key] and<EOL>isinstance(cpdict[key][<NUM_LIT:0>], dict) and<EOL>'<STR_LIT>' in cpdict[key][<NUM_LIT:0>] and<EOL>isinstance(cpdict[key][<NUM_LIT:0>]['<STR_LIT>'], dict)):<EOL><INDENT>phasedlc0fit = {<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:0>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:0>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:0>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:0>][<EOL>'<STR_LIT>'<EOL>]['<STR_LIT>']['<STR_LIT>'] if<EOL>'<STR_LIT>' in<EOL>cpdict[key][<NUM_LIT:0>]['<STR_LIT>']['<STR_LIT>'] else None<EOL>)<EOL>}<EOL><DEDENT>else:<EOL><INDENT>phasedlc0fit = None<EOL><DEDENT>if <NUM_LIT:1> in cpdict[key] and isinstance(cpdict[key][<NUM_LIT:1>], dict):<EOL><INDENT>phasedlc1plot = cpdict[key][<NUM_LIT:1>]['<STR_LIT>']<EOL>phasedlc1period = float(cpdict[key][<NUM_LIT:1>]['<STR_LIT>'])<EOL>phasedlc1epoch = float(cpdict[key][<NUM_LIT:1>]['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>phasedlc1plot = None<EOL>phasedlc1period = None<EOL>phasedlc1epoch = None<EOL><DEDENT>if (<NUM_LIT:1> in cpdict[key] and<EOL>isinstance(cpdict[key][<NUM_LIT:1>], dict) and<EOL>'<STR_LIT>' in cpdict[key][<NUM_LIT:1>] and<EOL>isinstance(cpdict[key][<NUM_LIT:1>]['<STR_LIT>'], dict)):<EOL><INDENT>phasedlc1fit = {<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:1>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:1>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:1>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:1>][<EOL>'<STR_LIT>'<EOL>]['<STR_LIT>']['<STR_LIT>'] if<EOL>'<STR_LIT>' in<EOL>cpdict[key][<NUM_LIT:1>]['<STR_LIT>']['<STR_LIT>'] else None<EOL>)<EOL>}<EOL><DEDENT>else:<EOL><INDENT>phasedlc1fit = None<EOL><DEDENT>if <NUM_LIT:2> in cpdict[key] and isinstance(cpdict[key][<NUM_LIT:2>], dict):<EOL><INDENT>phasedlc2plot = cpdict[key][<NUM_LIT:2>]['<STR_LIT>']<EOL>phasedlc2period = float(cpdict[key][<NUM_LIT:2>]['<STR_LIT>'])<EOL>phasedlc2epoch = float(cpdict[key][<NUM_LIT:2>]['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>phasedlc2plot = None<EOL>phasedlc2period = None<EOL>phasedlc2epoch = None<EOL><DEDENT>if (<NUM_LIT:2> in cpdict[key] and<EOL>isinstance(cpdict[key][<NUM_LIT:2>], dict) and<EOL>'<STR_LIT>' in cpdict[key][<NUM_LIT:2>] and<EOL>isinstance(cpdict[key][<NUM_LIT:2>]['<STR_LIT>'], dict)):<EOL><INDENT>phasedlc2fit = {<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:2>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:2>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:2>]['<STR_LIT>']['<STR_LIT>']<EOL>),<EOL>'<STR_LIT>':(<EOL>cpdict[key][<NUM_LIT:2>][<EOL>'<STR_LIT>'<EOL>]['<STR_LIT>']['<STR_LIT>'] if<EOL>'<STR_LIT>' in<EOL>cpdict[key][<NUM_LIT:2>]['<STR_LIT>']['<STR_LIT>'] else None<EOL>)<EOL>}<EOL><DEDENT>else:<EOL><INDENT>phasedlc2fit = None<EOL><DEDENT>resultdict['<STR_LIT:result>'][key] = {<EOL>'<STR_LIT>':cpdict[key]['<STR_LIT>'],<EOL>'<STR_LIT>':periodogram,<EOL>'<STR_LIT>':cpdict[key]['<STR_LIT>'],<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':phasedlc0plot,<EOL>'<STR_LIT>':phasedlc0period,<EOL>'<STR_LIT>':phasedlc0epoch,<EOL>'<STR_LIT>':phasedlc0fit,<EOL>},<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':phasedlc1plot,<EOL>'<STR_LIT>':phasedlc1period,<EOL>'<STR_LIT>':phasedlc1epoch,<EOL>'<STR_LIT>':phasedlc1fit,<EOL>},<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':phasedlc2plot,<EOL>'<STR_LIT>':phasedlc2period,<EOL>'<STR_LIT>':phasedlc2epoch,<EOL>'<STR_LIT>':phasedlc2fit,<EOL>},<EOL>}<EOL><DEDENT>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>' % self.checkplotfname)<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':"<STR_LIT>",<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL>self.finish()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>resultdict = {'<STR_LIT:status>':'<STR_LIT:error>',<EOL>'<STR_LIT:message>':'<STR_LIT>',<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':None}<EOL>self.write(resultdict)<EOL><DEDENT>

This handles GET requests to serve a specific checkplot pickle.

        This is an AJAX endpoint; returns JSON that gets converted by the
        frontend into things to render.


cpf, keys = task<EOL>cpd = _read_checkplot_picklefile(cpf)<EOL>resultkeys = []<EOL>for k in keys:<EOL><INDENT>try:<EOL><INDENT>resultkeys.append(_dict_get(cpd, k))<EOL><DEDENT>except Exception as e:<EOL><INDENT>resultkeys.append(np.nan)<EOL><DEDENT><DEDENT>return resultkeys<EOL>

This gets the required keys from the requested file.

    Parameters
    ----------

    task : tuple
        Task is a two element tuple::

        - task[0] is the dict to work on

        - task[1] is a list of lists of str indicating all the key address to
          extract items from the dict for

    Returns
    -------

    list
        This is a list of all of the items at the requested key addresses.


<EOL>pklist = glob.glob(os.path.join(featuresdir, pklglob))<EOL>if maxobjects:<EOL><INDENT>pklist = pklist[:maxobjects]<EOL><DEDENT>if TQDM:<EOL><INDENT>listiterator = tqdm(pklist)<EOL><DEDENT>else:<EOL><INDENT>listiterator = pklist<EOL><DEDENT>feature_dict = {'<STR_LIT>':[],'<STR_LIT>':magcol, '<STR_LIT>':[]}<EOL>LOGINFO('<STR_LIT>' % magcol)<EOL>for pkl in listiterator:<EOL><INDENT>with open(pkl,'<STR_LIT:rb>') as infd:<EOL><INDENT>varf = pickle.load(infd)<EOL><DEDENT>objectid = varf['<STR_LIT>']<EOL>if objectid not in feature_dict['<STR_LIT>']:<EOL><INDENT>feature_dict['<STR_LIT>'].append(objectid)<EOL><DEDENT>thisfeatures = varf[magcol]<EOL>if featurestouse and len(featurestouse) > <NUM_LIT:0>:<EOL><INDENT>featurestoget = featurestouse<EOL><DEDENT>else:<EOL><INDENT>featurestoget = NONPERIODIC_FEATURES_TO_COLLECT<EOL><DEDENT>for feature in featurestoget:<EOL><INDENT>if ((feature not in feature_dict['<STR_LIT>']) and<EOL>(feature in thisfeatures)):<EOL><INDENT>feature_dict['<STR_LIT>'].append(feature)<EOL>feature_dict[feature] = []<EOL><DEDENT>if feature in thisfeatures:<EOL><INDENT>feature_dict[feature].append(<EOL>thisfeatures[feature]<EOL>)<EOL><DEDENT><DEDENT><DEDENT>for feat in feature_dict['<STR_LIT>']:<EOL><INDENT>feature_dict[feat] = np.array(feature_dict[feat])<EOL><DEDENT>feature_dict['<STR_LIT>'] = np.array(feature_dict['<STR_LIT>'])<EOL>feature_array = np.column_stack([feature_dict[feat] for feat in<EOL>feature_dict['<STR_LIT>']])<EOL>feature_dict['<STR_LIT>'] = feature_array<EOL>if isinstance(labeldict, dict):<EOL><INDENT>labelarray = np.zeros(feature_dict['<STR_LIT>'].size, dtype=np.int64)<EOL>for ind, objectid in enumerate(feature_dict['<STR_LIT>']):<EOL><INDENT>if objectid in labeldict:<EOL><INDENT>if labeltype == '<STR_LIT>':<EOL><INDENT>if labeldict[objectid]:<EOL><INDENT>labelarray[ind] = <NUM_LIT:1><EOL><DEDENT><DEDENT>elif labeltype == '<STR_LIT>':<EOL><INDENT>labelarray[ind] = labeldict[objectid]<EOL><DEDENT><DEDENT><DEDENT>feature_dict['<STR_LIT>'] = labelarray<EOL><DEDENT>feature_dict['<STR_LIT>'] = {'<STR_LIT>':pklglob,<EOL>'<STR_LIT>':featurestouse,<EOL>'<STR_LIT>':maxobjects,<EOL>'<STR_LIT>':labeltype}<EOL>with open(outfile,'<STR_LIT:wb>') as outfd:<EOL><INDENT>pickle.dump(feature_dict, outfd, pickle.HIGHEST_PROTOCOL)<EOL><DEDENT>return feature_dict<EOL>

This collects variability features into arrays for use with the classifer.

    Parameters
    ----------

    featuresdir : str
        This is the directory where all the varfeatures pickles are. Use
        `pklglob` to specify the glob to search for. The `varfeatures` pickles
        contain objectids, a light curve magcol, and features as dict
        key-vals. The :py:mod:`astrobase.lcproc.lcvfeatures` module can be used
        to produce these.

    magcol : str
        This is the key in each varfeatures pickle corresponding to the magcol
        of the light curve the variability features were extracted from.

    outfile : str
        This is the filename of the output pickle that will be written
        containing a dict of all the features extracted into np.arrays.

    pklglob : str
        This is the UNIX file glob to use to search for varfeatures pickle files
        in `featuresdir`.

    featurestouse : list of str
        Each varfeatures pickle can contain any combination of non-periodic,
        stellar, and periodic features; these must have the same names as
        elements in the list of strings provided in `featurestouse`.  This tries
        to get all the features listed in NONPERIODIC_FEATURES_TO_COLLECT by
        default. If `featurestouse` is provided as a list, gets only the
        features listed in this kwarg instead.

    maxobjects : int or None
        The controls how many pickles from the featuresdir to process. If None,
        will process all varfeatures pickles.

    labeldict : dict or None
        If this is provided, it must be a dict with the following key:val list::

            '<objectid>':<label value>

        for each objectid collected from the varfeatures pickles. This will turn
        the collected information into a training set for classifiers.

        Example: to carry out non-periodic variable feature collection of fake
        LCS prepared by :py:mod:`astrobase.fakelcs.generation`, use the value
        of the 'isvariable' dict elem from the `fakelcs-info.pkl` here, like
        so::

            labeldict={x:y for x,y in zip(fakelcinfo['objectid'],
                                          fakelcinfo['isvariable'])}

    labeltype : {'binary', 'classes'}
        This is either 'binary' or 'classes' for binary/multi-class
        classification respectively.

    Returns
    -------

    dict
        This returns a dict with all of the features collected into np.arrays,
        ready to use as input to a scikit-learn classifier.


if isinstance(classifier,str) and os.path.exists(classifier):<EOL><INDENT>with open(classifier,'<STR_LIT:rb>') as infd:<EOL><INDENT>clfdict = pickle.load(infd)<EOL><DEDENT><DEDENT>elif isinstance(classifier, dict):<EOL><INDENT>clfdict = classifier<EOL><DEDENT>else:<EOL><INDENT>LOGERROR("<STR_LIT>")<EOL>return None<EOL><DEDENT>if '<STR_LIT>' not in clfdict:<EOL><INDENT>LOGERROR("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % varfeaturesdir)<EOL>return None<EOL><DEDENT>featurestouse = clfdict['<STR_LIT>']<EOL>pklglob = clfdict['<STR_LIT>']['<STR_LIT>']<EOL>magcol = clfdict['<STR_LIT>']<EOL>featfile = os.path.join(<EOL>os.path.dirname(outpickle),<EOL>'<STR_LIT>'<EOL>)<EOL>features = collect_nonperiodic_features(<EOL>varfeaturesdir,<EOL>magcol,<EOL>featfile,<EOL>pklglob=pklglob,<EOL>featurestouse=featurestouse,<EOL>maxobjects=maxobjects<EOL>)<EOL>bestclf = clfdict['<STR_LIT>']<EOL>predicted_labels = bestclf.predict(features['<STR_LIT>'])<EOL>predicted_label_probs = bestclf.predict_proba(<EOL>features['<STR_LIT>']<EOL>)<EOL>outdict = {<EOL>'<STR_LIT>':features,<EOL>'<STR_LIT>':featfile,<EOL>'<STR_LIT>':clfdict,<EOL>'<STR_LIT>':predicted_labels,<EOL>'<STR_LIT>':predicted_label_probs,<EOL>}<EOL>with open(outpickle,'<STR_LIT:wb>') as outfd:<EOL><INDENT>pickle.dump(outdict, outfd, pickle.HIGHEST_PROTOCOL)<EOL><DEDENT>return outdict<EOL>

This applys an RF classifier trained using `train_rf_classifier`
    to varfeatures pickles in `varfeaturesdir`.

    Parameters
    ----------

    classifier : dict or str
        This is the output dict or pickle created by `get_rf_classifier`. This
        will contain a `features_name` key that will be used to collect the same
        features used to train the classifier from the varfeatures pickles in
        varfeaturesdir.

    varfeaturesdir : str
        The directory containing the varfeatures pickles for objects that will
        be classified by the trained `classifier`.

    outpickle : str
        This is a filename for the pickle that will be written containing the
        result dict from this function.

    maxobjects : int
        This sets the number of objects to process in `varfeaturesdir`.

    Returns
    -------

    dict
        The classification results after running the trained `classifier` as
        returned as a dict. This contains predicted labels and their prediction
        probabilities.


if isinstance(classifier,str) and os.path.exists(classifier):<EOL><INDENT>with open(classifier,'<STR_LIT:rb>') as infd:<EOL><INDENT>clfdict = pickle.load(infd)<EOL><DEDENT><DEDENT>elif isinstance(classifier, dict):<EOL><INDENT>clfdict = classifier<EOL><DEDENT>else:<EOL><INDENT>LOGERROR("<STR_LIT>")<EOL>return None<EOL><DEDENT>confmatrix = clfdict['<STR_LIT>']<EOL>overall_feature_importances = clfdict[<EOL>'<STR_LIT>'<EOL>].feature_importances_<EOL>feature_importances_per_tree = np.array([<EOL>tree.feature_importances_<EOL>for tree in clfdict['<STR_LIT>'].estimators_<EOL>])<EOL>stdev_feature_importances = np.std(feature_importances_per_tree,axis=<NUM_LIT:0>)<EOL>feature_names = np.array(clfdict['<STR_LIT>'])<EOL>plt.figure(figsize=(<NUM_LIT>*<NUM_LIT>,<NUM_LIT>))<EOL>plt.subplot(<NUM_LIT>)<EOL>classes = np.array(classlabels)<EOL>plt.imshow(confmatrix, interpolation='<STR_LIT>', cmap=plt.cm.Blues)<EOL>tick_marks = np.arange(len(classes))<EOL>plt.xticks(tick_marks, classes)<EOL>plt.yticks(tick_marks, classes)<EOL>plt.title('<STR_LIT>')<EOL>plt.ylabel('<STR_LIT>')<EOL>plt.xlabel('<STR_LIT>')<EOL>thresh = confmatrix.max() / <NUM_LIT><EOL>for i, j in itertools.product(range(confmatrix.shape[<NUM_LIT:0>]),<EOL>range(confmatrix.shape[<NUM_LIT:1>])):<EOL><INDENT>plt.text(j, i, confmatrix[i, j],<EOL>horizontalalignment="<STR_LIT>",<EOL>color="<STR_LIT>" if confmatrix[i, j] > thresh else "<STR_LIT>")<EOL><DEDENT>plt.subplot(<NUM_LIT>)<EOL>features = np.array(feature_names)<EOL>sorted_ind = np.argsort(overall_feature_importances)[::-<NUM_LIT:1>]<EOL>features = features[sorted_ind]<EOL>feature_names = feature_names[sorted_ind]<EOL>overall_feature_importances = overall_feature_importances[sorted_ind]<EOL>stdev_feature_importances = stdev_feature_importances[sorted_ind]<EOL>plt.bar(np.arange(<NUM_LIT:0>,features.size),<EOL>overall_feature_importances,<EOL>yerr=stdev_feature_importances,<EOL>width=<NUM_LIT>,<EOL>color='<STR_LIT>')<EOL>plt.xticks(np.arange(<NUM_LIT:0>,features.size),<EOL>features,<EOL>rotation=<NUM_LIT>)<EOL>plt.yticks([<NUM_LIT:0.0>,<NUM_LIT:0.1>,<NUM_LIT>,<NUM_LIT>,<NUM_LIT>,<NUM_LIT:0.5>,<NUM_LIT>,<NUM_LIT>,<NUM_LIT>,<NUM_LIT>,<NUM_LIT:1.0>])<EOL>plt.xlim(-<NUM_LIT>, features.size - <NUM_LIT:1.0> + <NUM_LIT>)<EOL>plt.ylim(<NUM_LIT:0.0>,<NUM_LIT>)<EOL>plt.ylabel('<STR_LIT>')<EOL>plt.title('<STR_LIT>')<EOL>plt.subplots_adjust(wspace=<NUM_LIT:0.1>)<EOL>plt.savefig(outfile,<EOL>bbox_inches='<STR_LIT>',<EOL>dpi=<NUM_LIT:100>)<EOL>plt.close('<STR_LIT:all>')<EOL>return outfile<EOL>

This plots the training results from the classifier run on the training
    set.

    - plots the confusion matrix

    - plots the feature importances

    - FIXME: plot the learning curves too, see:
      http://scikit-learn.org/stable/modules/learning_curve.html

    Parameters
    ----------

    classifier : dict or str
        This is the output dict or pickle created by `get_rf_classifier`
        containing the trained classifier.

    classlabels : list of str
        This contains all of the class labels for the current classification
        problem.

    outfile : str
        This is the filename where the plots will be written.

    Returns
    -------

    str
        The path to the generated plot file.


<EOL>if np.isfinite(ri_color) and np.isfinite(iz_color):<EOL><INDENT>obj_sti = <NUM_LIT>*ri_color + <NUM_LIT>*(iz_color + <NUM_LIT>)<EOL>obj_sts = -<NUM_LIT>*ri_color + <NUM_LIT>*(iz_color + <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>obj_sti = np.nan<EOL>obj_sts = np.nan<EOL><DEDENT>if (np.isfinite(obj_sti) and np.isfinite(obj_sts) and<EOL>(obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT>if ((obj_sti > <NUM_LIT>) and (obj_sti < <NUM_LIT>)):<EOL><INDENT>m_class = '<STR_LIT>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>m_class = None<EOL><DEDENT>return m_class, obj_sti, obj_sts<EOL>

This calculates the M-dwarf subtype given SDSS `r-i` and `i-z` colors.

    Parameters
    ----------

    ri_color : float
        The SDSS `r-i` color of the object.

    iz_color : float
        The SDSS `i-z` color of the object.

    Returns
    -------

    (subtype, index1, index2) : tuple
        `subtype`: if the star appears to be an M dwarf, will return an int
        between 0 and 9 indicating its subtype, e.g. will return 4 for an M4
        dwarf. If the object isn't an M dwarf, will return None

        `index1`, `index2`: the M-dwarf color locus value and spread of this
        object calculated from the `r-i` and `i-z` colors.