<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)


if len(a) != len(b):<EOL><INDENT>return False<EOL><DEDENT>result = <NUM_LIT:0><EOL>if isinstance(a[<NUM_LIT:0>], int):  <EOL><INDENT>for x, y in zip(a, b):<EOL><INDENT>result |= x ^ y<EOL><DEDENT><DEDENT>else:  <EOL><INDENT>for x, y in zip(a, b):<EOL><INDENT>result |= ord(x) ^ ord(y)<EOL><DEDENT><DEDENT>return result == <NUM_LIT:0><EOL>

This compares two values in constant time.

Taken from tornado:

https://github.com/tornadoweb/tornado/blob/
d4eb8eb4eb5cc9a6677e9116ef84ded8efba8859/tornado/web.py#L3060


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.


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.


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 this `RequestHandler`.


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.


<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.


This handles initial setup of the `RequestHandler`.


<EOL>if '<STR_LIT>' not in self.currentproject:<EOL><INDENT>self.currentproject['<STR_LIT>'] = {}<EOL><DEDENT>self.write(self.currentproject)<EOL>

This handles GET requests for the current checkplot-list.json file.

Used with AJAX from frontend.


<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>objectid = self.get_argument('<STR_LIT>', None)<EOL>changes = self.get_argument('<STR_LIT>',None)<EOL>if not objectid or not changes:<EOL><INDENT>msg = ("<STR_LIT>"<EOL>"<STR_LIT>")<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>objectid = xhtml_escape(objectid)<EOL>changes = json.loads(changes)<EOL>if '<STR_LIT>' not in self.currentproject:<EOL><INDENT>self.currentproject['<STR_LIT>'] = {}<EOL><DEDENT>self.currentproject['<STR_LIT>'][objectid] = changes<EOL>with open(self.cplistfile,'<STR_LIT:w>') as outfd:<EOL><INDENT>json.dump(self.currentproject, outfd)<EOL><DEDENT>msg = ("<STR_LIT>"<EOL>"<STR_LIT>" % objectid)<EOL>LOGGER.info(msg)<EOL>resultdict = {'<STR_LIT:status>':'<STR_LIT:success>',<EOL>'<STR_LIT:message>':msg,<EOL>'<STR_LIT>':self.readonly,<EOL>'<STR_LIT:result>':{'<STR_LIT>':objectid,<EOL>'<STR_LIT>':changes}}<EOL>self.write(resultdict)<EOL>self.finish()<EOL>

This handles POST requests.

        Saves the changes made by the user on the frontend back to the current
        checkplot-list.json file.


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 a POST request.

        TODO: implement this.

        This will save the results of the previous tool run to the checkplot
        file and the JSON filelist.

        This is only called when the user explicitly clicks on the 'permanently
        update checkplot with results' button. If the server is in readonly
        mode, this has no effect.

        This will copy everything from the '.pkl-cpserver-temp' file to the
        actual checkplot pickle and then remove that file.


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


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.


return reduce(getitem, keylist, datadict)<EOL>

This gets a requested dict key by walking the dict.

    Parameters
    ----------

    datadict : dict
        The dict to get the specified key from.

    keylist : list of str
        This is a list of keys to use to walk the dict and get to the key that
        is provided as the last element in `keylist`. For example::

            keylist = ['key1','key2','key3']

        will walk `datadict` recursively to get to `datadict[key1][key2][key3]`.

    Returns
    -------

    object
        The dict value of the specified key address.


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>aparser = argparse.ArgumentParser(<EOL>epilog=PROGEPILOG,<EOL>description=PROGDESC,<EOL>formatter_class=argparse.RawDescriptionHelpFormatter,<EOL>)<EOL>aparser.add_argument(<EOL>'<STR_LIT>',<EOL>action='<STR_LIT:store>',<EOL>choices=['<STR_LIT>','<STR_LIT>'],<EOL>type=str,<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>)<EOL>aparser.add_argument(<EOL>'<STR_LIT>',<EOL>action='<STR_LIT:store>',<EOL>type=str,<EOL>help=("<STR_LIT>")<EOL>)<EOL>aparser.add_argument(<EOL>'<STR_LIT>',<EOL>action='<STR_LIT:store>',<EOL>default='<STR_LIT>',<EOL>type=str,<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>)<EOL>aparser.add_argument(<EOL>'<STR_LIT>',<EOL>action='<STR_LIT:store>',<EOL>type=str,<EOL>help=("<STR_LIT>")<EOL>)<EOL>aparser.add_argument(<EOL>'<STR_LIT>',<EOL>action='<STR_LIT>',<EOL>type=str,<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>)<EOL>aparser.add_argument(<EOL>'<STR_LIT>',<EOL>action='<STR_LIT:store>',<EOL>type=int,<EOL>default=<NUM_LIT>,<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>)<EOL>aparser.add_argument(<EOL>'<STR_LIT>',<EOL>action='<STR_LIT:store>',<EOL>type=str,<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>)<EOL>aparser.add_argument(<EOL>'<STR_LIT>',<EOL>action='<STR_LIT:store>',<EOL>type=int,<EOL>default=int(CPU_COUNT/<NUM_LIT>),<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>)<EOL>args = aparser.parse_args()<EOL>checkplotbasedir = args.cpdir<EOL>fileglob = args.search<EOL>splitout = args.splitout<EOL>outprefix = args.outprefix if args.outprefix else None<EOL>if args.sortby:<EOL><INDENT>sortkey, sortorder = args.sortby.split('<STR_LIT:|>')<EOL>if outprefix is None:<EOL><INDENT>outprefix = args.sortby<EOL><DEDENT><DEDENT>else:<EOL><INDENT>sortkey, sortorder = '<STR_LIT>', '<STR_LIT>'<EOL><DEDENT>if args.filterby:<EOL><INDENT>filterkeys, filterconditions = [], []<EOL>for filt in args.filterby:<EOL><INDENT>f = filt.split('<STR_LIT:|>')<EOL>filterkeys.append(f[<NUM_LIT:0>])<EOL>filterconditions.append(f[<NUM_LIT:1>])<EOL><DEDENT>if outprefix is None:<EOL><INDENT>outprefix = '<STR_LIT:->'.join(args.filterby)<EOL><DEDENT>else:<EOL><INDENT>outprefix = '<STR_LIT>' % ('<STR_LIT:->'.join(args.filterby), outprefix)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>filterkeys, filterconditions = None, None<EOL><DEDENT>if args.cptype == '<STR_LIT>':<EOL><INDENT>checkplotext = '<STR_LIT>'<EOL><DEDENT>elif args.cptype == '<STR_LIT>':<EOL><INDENT>checkplotext = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>"<EOL>% args.cptype)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>currdir = os.getcwd()<EOL>checkplotglob = os.path.join(checkplotbasedir,<EOL>'<STR_LIT>' % (fileglob, checkplotext))<EOL>print('<STR_LIT>' % checkplotglob)<EOL>searchresults = glob.glob(checkplotglob)<EOL>if searchresults:<EOL><INDENT>print('<STR_LIT>' %<EOL>(len(searchresults), checkplotbasedir))<EOL>sortdone = False<EOL>filterok = False<EOL>filterstatements = []<EOL>if ((args.cptype == '<STR_LIT>') and<EOL>((sortkey and sortorder) or (filterkeys and filterconditions))):<EOL><INDENT>keystoget = []<EOL>if (sortkey and sortorder):<EOL><INDENT>print('<STR_LIT>' %<EOL>(sortkey, sortorder))<EOL>sortkeys = sortkey.split('<STR_LIT:.>')<EOL>if sys.version_info[:<NUM_LIT:2>] < (<NUM_LIT:3>,<NUM_LIT:4>):<EOL><INDENT>sortkeys = [(int(x) if x.isdigit() else x)<EOL>for x in sortkeys]<EOL><DEDENT>else:<EOL><INDENT>sortkeys = [(int(x) if x.isdecimal() else x)<EOL>for x in sortkeys]<EOL><DEDENT>keystoget.append(sortkeys)<EOL><DEDENT>if (filterkeys and filterconditions):<EOL><INDENT>print('<STR_LIT>' %<EOL>(filterkeys, filterconditions))<EOL>for fdk in filterkeys:<EOL><INDENT>fdictkeys = fdk.split('<STR_LIT:.>')<EOL>fdictkeys = [(int(x) if x.isdecimal() else x)<EOL>for x in fdictkeys]<EOL>keystoget.append(fdictkeys)<EOL><DEDENT><DEDENT>print('<STR_LIT>'<EOL>% args.maxkeyworkers)<EOL>pool = mp.Pool(args.maxkeyworkers)<EOL>tasks = [(x, keystoget) for x in searchresults]<EOL>keytargets = pool.map(checkplot_infokey_worker, tasks)<EOL>pool.close()<EOL>pool.join()<EOL>if (len(keystoget) > <NUM_LIT:1> and<EOL>(sortkey and sortorder) and<EOL>(filterkeys and filterconditions)):<EOL><INDENT>sorttargets = [x[<NUM_LIT:0>] for x in keytargets]<EOL>filtertargets = [x[<NUM_LIT:1>:] for x in keytargets]<EOL><DEDENT>elif (len(keystoget) > <NUM_LIT:1> and<EOL>(not (sortkey and sortorder)) and<EOL>(filterkeys and filterconditions)):<EOL><INDENT>sorttargets = None<EOL>filtertargets = keytargets<EOL><DEDENT>elif (len(keystoget) == <NUM_LIT:1> and<EOL>(sortkey and sortorder) and<EOL>(not(filterkeys and filterconditions))):<EOL><INDENT>sorttargets = keytargets<EOL>filtertargets = None<EOL><DEDENT>elif (len(keystoget) == <NUM_LIT:1> and<EOL>(filterkeys and filterconditions) and<EOL>(not(sortkey and sortorder))):<EOL><INDENT>sorttargets = None<EOL>filtertargets = keytargets<EOL><DEDENT>searchresults = np.array(searchresults)<EOL>if sorttargets:<EOL><INDENT>sorttargets = np.ravel(np.array(sorttargets))<EOL>sortind = np.argsort(sorttargets)<EOL>if sortorder == '<STR_LIT>':<EOL><INDENT>sortind = sortind[::-<NUM_LIT:1>]<EOL><DEDENT>searchresults = searchresults[sortind]<EOL>sortdone = True<EOL><DEDENT>if filtertargets:<EOL><INDENT>finalfilterind = []<EOL>for ind, fcond in enumerate(filterconditions):<EOL><INDENT>thisftarget = np.array([x[ind] for x in filtertargets])<EOL>if (sortdone):<EOL><INDENT>thisftarget = thisftarget[sortind]<EOL><DEDENT>try:<EOL><INDENT>foperator, foperand = fcond.split('<STR_LIT:@>')<EOL>foperator = FILTEROPS[foperator]<EOL>filterstr = (<EOL>'<STR_LIT>' %<EOL>(foperator, foperand)<EOL>)<EOL>filterind = eval(filterstr)<EOL>finalfilterind.append(filterind)<EOL>filterstatements.append('<STR_LIT>' % (filterkeys[ind],<EOL>foperator,<EOL>foperand))<EOL><DEDENT>except Exception as e:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(args.filterby[ind], e))<EOL>print('<STR_LIT>')<EOL><DEDENT><DEDENT>finalfilterind = np.column_stack(finalfilterind)<EOL>finalfilterind = np.all(finalfilterind, axis=<NUM_LIT:1>)<EOL>filterresults = searchresults[finalfilterind]<EOL>if filterresults.size > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>' %<EOL>(repr(args.filterby), filterresults.size))<EOL>searchresults = filterresults<EOL>filterok = True<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>' %<EOL>(repr(args.filterby), ))<EOL>print('<STR_LIT>')<EOL><DEDENT><DEDENT>searchresults = searchresults.tolist()<EOL>if not(sortkey and sortorder):<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>searchresults = sorted(searchresults)<EOL>sortkey = '<STR_LIT:filename>'<EOL>sortorder = '<STR_LIT>'<EOL><DEDENT><DEDENT>nchunks = int(len(searchresults)/splitout) + <NUM_LIT:1><EOL>searchchunks = [searchresults[x*splitout:x*splitout+splitout] for x<EOL>in range(nchunks)]<EOL>if nchunks > <NUM_LIT:1>:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>' % (splitout, nchunks))<EOL><DEDENT>if (filterkeys and filterconditions) and not filterok:<EOL><INDENT>filterstatements = []<EOL><DEDENT>for chunkind, chunk in enumerate(searchchunks):<EOL><INDENT>outjson = os.path.abspath(<EOL>os.path.join(<EOL>currdir,<EOL>'<STR_LIT>' % (<EOL>('<STR_LIT>' % outprefix if outprefix is not None else '<STR_LIT>'),<EOL>('<STR_LIT>' % chunkind if len(searchchunks) > <NUM_LIT:1> else '<STR_LIT>'),<EOL>)<EOL>)<EOL>)<EOL>outjson = outjson.replace('<STR_LIT:|>','<STR_LIT:_>')<EOL>outjson = outjson.replace('<STR_LIT:@>','<STR_LIT:_>')<EOL>if os.path.exists(outjson):<EOL><INDENT>if sys.version_info[:<NUM_LIT:2>] < (<NUM_LIT:3>,<NUM_LIT:0>):<EOL><INDENT>answer = raw_input(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>outjson<EOL>)<EOL><DEDENT>else:<EOL><INDENT>answer = input(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>outjson<EOL>)<EOL><DEDENT>if answer and answer == '<STR_LIT:y>':<EOL><INDENT>with open(outjson,'<STR_LIT:w>') as outfd:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>' % outjson)<EOL>outdict = {<EOL>'<STR_LIT>':chunk,<EOL>'<STR_LIT>':len(chunk),<EOL>'<STR_LIT>':sortkey,<EOL>'<STR_LIT>':sortorder,<EOL>'<STR_LIT>':filterstatements<EOL>}<EOL>json.dump(outdict,outfd)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>with open(outjson,'<STR_LIT:r>') as infd:<EOL><INDENT>indict = json.load(infd)<EOL><DEDENT>indict['<STR_LIT>'] = chunk<EOL>indict['<STR_LIT>'] = len(chunk)<EOL>indict['<STR_LIT>'] = sortkey<EOL>indict['<STR_LIT>'] = sortorder<EOL>indict['<STR_LIT>'] = filterstatements<EOL>with open(outjson,'<STR_LIT:w>') as outfd:<EOL><INDENT>json.dump(indict, outfd)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>with open(outjson,'<STR_LIT:w>') as outfd:<EOL><INDENT>outdict = {'<STR_LIT>':chunk,<EOL>'<STR_LIT>':len(chunk),<EOL>'<STR_LIT>':sortkey,<EOL>'<STR_LIT>':sortorder,<EOL>'<STR_LIT>':filterstatements}<EOL>json.dump(outdict,outfd)<EOL><DEDENT><DEDENT>if os.path.exists(outjson):<EOL><INDENT>print('<STR_LIT>' % outjson)<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>print('<STR_LIT>' % checkplotbasedir)<EOL><DEDENT>

This is the main function of this script.

    The current script args are shown below ::

        Usage: checkplotlist [-h] [--search SEARCH] [--sortby SORTBY]
                             [--filterby FILTERBY] [--splitout SPLITOUT]
                             [--outprefix OUTPREFIX] [--maxkeyworkers MAXKEYWORKERS]
                             {pkl,png} cpdir

        This makes a checkplot file list for use with the checkplot-viewer.html
        (for checkplot PNGs) or the checkplotserver.py (for checkplot pickles)
        webapps.

        positional arguments:
          {pkl,png}             type of checkplot to search for: pkl -> checkplot
                                pickles, png -> checkplot PNGs
          cpdir                 directory containing the checkplots to process

        optional arguments:
          -h, --help            show this help message and exit
          --search SEARCH       file glob prefix to use when searching for checkplots,
                                default: '*checkplot*', (the extension is added
                                automatically - .png or .pkl)
          --sortby SORTBY       the sort key and order to use when sorting
          --filterby FILTERBY   the filter key and condition to use when filtering.
                                you can specify this multiple times to filter by
                                several keys at once. all filters are joined with a
                                logical AND operation in the order they're given.
          --splitout SPLITOUT   if there are more than SPLITOUT objects in the target
                                directory (default: 5000), checkplotlist will split
                                the output JSON into multiple files. this helps keep
                                the checkplotserver webapp responsive.
          --outprefix OUTPREFIX
                                a prefix string to use for the output JSON file(s).
                                use this to separate out different sort orders or
                                filter conditions, for example. if this isn't
                                provided, but --sortby or --filterby are, will use
                                those to figure out the output files' prefixes
          --maxkeyworkers MAXKEYWORKERS
                                the number of parallel workers that will be launched
                                to retrieve checkplot key values used for sorting and
                                filtering (default: 2)


<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.