<EOL>if fast_mode is True:<EOL><INDENT>skyview_lookup = False<EOL>skyview_timeout = <NUM_LIT><EOL>skyview_retry_failed = False<EOL>dust_timeout = <NUM_LIT><EOL>gaia_submit_timeout = <NUM_LIT><EOL>gaia_max_timeout = <NUM_LIT><EOL>gaia_submit_tries = <NUM_LIT:2><EOL>complete_query_later = False<EOL>search_simbad = False<EOL><DEDENT>elif isinstance(fast_mode, (int, float)) and fast_mode > <NUM_LIT:0.0>:<EOL><INDENT>skyview_lookup = True<EOL>skyview_timeout = fast_mode<EOL>skyview_retry_failed = False<EOL>dust_timeout = fast_mode<EOL>gaia_submit_timeout = <NUM_LIT>*fast_mode<EOL>gaia_max_timeout = fast_mode<EOL>gaia_submit_tries = <NUM_LIT:2><EOL>complete_query_later = False<EOL>search_simbad = False<EOL><DEDENT>else:<EOL><INDENT>skyview_lookup = True<EOL>skyview_timeout = <NUM_LIT><EOL>skyview_retry_failed = True<EOL>dust_timeout = <NUM_LIT><EOL>search_simbad = True<EOL><DEDENT>if (isinstance(objectinfo, dict) and<EOL>('<STR_LIT>' in objectinfo or '<STR_LIT>' in objectinfo) and<EOL>'<STR_LIT>' in objectinfo and '<STR_LIT>' in objectinfo and<EOL>objectinfo['<STR_LIT>'] and objectinfo['<STR_LIT>']):<EOL><INDENT>if '<STR_LIT>' not in objectinfo:<EOL><INDENT>objectid = objectinfo['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>objectid = objectinfo['<STR_LIT>']<EOL><DEDENT>if verbose and skyview_lookup:<EOL><INDENT>LOGINFO('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(objectid, objectinfo['<STR_LIT>'], objectinfo['<STR_LIT>']))<EOL><DEDENT>elif verbose and not skyview_lookup:<EOL><INDENT>LOGINFO('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(objectid, objectinfo['<STR_LIT>'], objectinfo['<STR_LIT>']))<EOL><DEDENT>try:<EOL><INDENT>if skyview_lookup:<EOL><INDENT>try:<EOL><INDENT>finder, finderheader = skyview_stamp(<EOL>objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>'],<EOL>convolvewith=finderconvolve,<EOL>verbose=verbose,<EOL>flip=False,<EOL>cachedir=findercachedir,<EOL>timeout=skyview_timeout,<EOL>retry_failed=skyview_retry_failed,<EOL>)<EOL><DEDENT>except OSError as e:<EOL><INDENT>if not fast_mode:<EOL><INDENT>LOGERROR(<EOL>'<STR_LIT>'<EOL>)<EOL>finder, finderheader = skyview_stamp(<EOL>objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>'],<EOL>convolvewith=finderconvolve,<EOL>verbose=verbose,<EOL>flip=False,<EOL>cachedir=findercachedir,<EOL>forcefetch=True,<EOL>timeout=skyview_timeout,<EOL>retry_failed=False  <EOL>)<EOL><DEDENT><DEDENT>finderfig = plt.figure(figsize=(<NUM_LIT:3>,<NUM_LIT:3>),dpi=plotdpi)<EOL>finderwcs = WCS(finderheader)<EOL>ax = finderfig.add_subplot(<NUM_LIT>, frameon=False)<EOL>ax.imshow(finder, cmap=findercmap, origin='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>finder, finderheader, finderfig, finderwcs = (<EOL>None, None, None, None<EOL>)<EOL><DEDENT>if (lclistpkl is not None and<EOL>nbrradiusarcsec is not None and<EOL>nbrradiusarcsec > <NUM_LIT:0.0>):<EOL><INDENT>if isinstance(lclistpkl, str) and os.path.exists(lclistpkl):<EOL><INDENT>if lclistpkl.endswith('<STR_LIT>'):<EOL><INDENT>infd = gzip.open(lclistpkl,'<STR_LIT:rb>')<EOL><DEDENT>else:<EOL><INDENT>infd = open(lclistpkl,'<STR_LIT:rb>')<EOL><DEDENT>lclist = pickle.load(infd)<EOL>infd.close()<EOL><DEDENT>elif isinstance(lclistpkl, dict):<EOL><INDENT>lclist = lclistpkl<EOL><DEDENT>else:<EOL><INDENT>LOGERROR('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>lclist = dict()<EOL><DEDENT>if '<STR_LIT>' not in lclist:<EOL><INDENT>LOGERROR('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>% (objectid, lclistpkl))<EOL>neighbors = None<EOL>kdt = None<EOL><DEDENT>else:<EOL><INDENT>kdt = lclist['<STR_LIT>']<EOL>obj_cosdecl = np.cos(np.radians(objectinfo['<STR_LIT>']))<EOL>obj_sindecl = np.sin(np.radians(objectinfo['<STR_LIT>']))<EOL>obj_cosra = np.cos(np.radians(objectinfo['<STR_LIT>']))<EOL>obj_sinra = np.sin(np.radians(objectinfo['<STR_LIT>']))<EOL>obj_xyz = np.column_stack((obj_cosra*obj_cosdecl,<EOL>obj_sinra*obj_cosdecl,<EOL>obj_sindecl))<EOL>match_xyzdist = (<EOL><NUM_LIT> * np.sin(np.radians(nbrradiusarcsec/<NUM_LIT>)/<NUM_LIT>)<EOL>)<EOL>matchdists, matchinds = kdt.query(<EOL>obj_xyz,<EOL>k=maxnumneighbors+<NUM_LIT:1>,  <EOL>distance_upper_bound=match_xyzdist<EOL>)<EOL>mdsorted = np.argsort(matchdists[<NUM_LIT:0>])<EOL>matchdists = matchdists[<NUM_LIT:0>][mdsorted]<EOL>matchinds = matchinds[<NUM_LIT:0>][mdsorted]<EOL>neighbors = []<EOL>nbrind = <NUM_LIT:0><EOL>for md, mi in zip(matchdists, matchinds):<EOL><INDENT>if np.isfinite(md) and md > <NUM_LIT:0.0>:<EOL><INDENT>if skyview_lookup:<EOL><INDENT>pixcoords = finderwcs.all_world2pix(<EOL>np.array([[lclist['<STR_LIT>']['<STR_LIT>'][mi],<EOL>lclist['<STR_LIT>']['<STR_LIT>'][mi]]]),<EOL><NUM_LIT:0><EOL>)<EOL>thisnbr = {<EOL>'<STR_LIT>':(<EOL>lclist['<STR_LIT>']['<STR_LIT>'][mi]<EOL>),<EOL>'<STR_LIT>':lclist['<STR_LIT>']['<STR_LIT>'][mi],<EOL>'<STR_LIT>':lclist['<STR_LIT>']['<STR_LIT>'][mi],<EOL>'<STR_LIT>':pixcoords[<NUM_LIT:0>,<NUM_LIT:0>],<EOL>'<STR_LIT>':<NUM_LIT> - pixcoords[<NUM_LIT:0>,<NUM_LIT:1>],<EOL>'<STR_LIT>':_xyzdist_to_distarcsec(md),<EOL>'<STR_LIT>': lclist['<STR_LIT>']['<STR_LIT>'][mi]<EOL>}<EOL>neighbors.append(thisnbr)<EOL>nbrind = nbrind+<NUM_LIT:1><EOL>annotatex = pixcoords[<NUM_LIT:0>,<NUM_LIT:0>]<EOL>annotatey = pixcoords[<NUM_LIT:0>,<NUM_LIT:1>]<EOL>if ((<NUM_LIT> - annotatex) > <NUM_LIT>):<EOL><INDENT>offx = annotatex + <NUM_LIT><EOL>xha = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>offx = annotatex - <NUM_LIT><EOL>xha = '<STR_LIT>'<EOL><DEDENT>if ((<NUM_LIT> - annotatey) > <NUM_LIT>):<EOL><INDENT>offy = annotatey - <NUM_LIT><EOL>yha = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>offy = annotatey + <NUM_LIT><EOL>yha = '<STR_LIT>'<EOL><DEDENT>ax.annotate('<STR_LIT>' % nbrind,<EOL>(annotatex, annotatey),<EOL>xytext=(offx, offy),<EOL>arrowprops={'<STR_LIT>':'<STR_LIT>',<EOL>'<STR_LIT>':'<STR_LIT>',<EOL>'<STR_LIT:width>':<NUM_LIT:1.0>,<EOL>'<STR_LIT>':<NUM_LIT:1.0>,<EOL>'<STR_LIT>':<NUM_LIT:0.1>,<EOL>'<STR_LIT>':<NUM_LIT:0.0>},<EOL>color='<STR_LIT>',<EOL>horizontalalignment=xha,<EOL>verticalalignment=yha)<EOL><DEDENT>else:<EOL><INDENT>thisnbr = {<EOL>'<STR_LIT>':(<EOL>lclist['<STR_LIT>']['<STR_LIT>'][mi]<EOL>),<EOL>'<STR_LIT>':lclist['<STR_LIT>']['<STR_LIT>'][mi],<EOL>'<STR_LIT>':lclist['<STR_LIT>']['<STR_LIT>'][mi],<EOL>'<STR_LIT>':<NUM_LIT:0.0>,<EOL>'<STR_LIT>':<NUM_LIT:0.0>,<EOL>'<STR_LIT>':_xyzdist_to_distarcsec(md),<EOL>'<STR_LIT>': lclist['<STR_LIT>']['<STR_LIT>'][mi]<EOL>}<EOL>neighbors.append(thisnbr)<EOL>nbrind = nbrind+<NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>neighbors = None<EOL>kdt = None<EOL><DEDENT>if skyview_lookup:<EOL><INDENT>ax.set_xticks([])<EOL>ax.set_yticks([])<EOL>object_pixcoords = finderwcs.all_world2pix(<EOL>[[objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>']]],<EOL><NUM_LIT:0><EOL>)<EOL>ax.axvline(<EOL>x=object_pixcoords[<NUM_LIT:0>,<NUM_LIT:0>],<EOL>ymin=<NUM_LIT>,<EOL>ymax=<NUM_LIT>,<EOL>linewidth=<NUM_LIT:1>,<EOL>color='<STR_LIT:b>'<EOL>)<EOL>ax.axhline(<EOL>y=object_pixcoords[<NUM_LIT:0>,<NUM_LIT:1>],<EOL>xmin=<NUM_LIT>,<EOL>xmax=<NUM_LIT>,<EOL>linewidth=<NUM_LIT:1>,<EOL>color='<STR_LIT:b>'<EOL>)<EOL>ax.set_frame_on(False)<EOL>finderpng = StrIO()<EOL>finderfig.savefig(finderpng,<EOL>bbox_inches='<STR_LIT>',<EOL>pad_inches=<NUM_LIT:0.0>, format='<STR_LIT>')<EOL>plt.close()<EOL>finderpng.seek(<NUM_LIT:0>)<EOL>finderb64 = base64.b64encode(finderpng.read())<EOL>finderpng.close()<EOL><DEDENT>else:<EOL><INDENT>finderb64 = None<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(objectid, objectinfo['<STR_LIT>'], objectinfo['<STR_LIT>']))<EOL>finderb64 = None<EOL>neighbors = None<EOL>kdt = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>finderb64 = None<EOL>neighbors = None<EOL>kdt = None<EOL><DEDENT>if isinstance(objectinfo, dict):<EOL><INDENT>if '<STR_LIT>' not in objectinfo and '<STR_LIT>' in objectinfo:<EOL><INDENT>objectid = objectinfo['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = objectid<EOL><DEDENT>elif '<STR_LIT>' in objectinfo:<EOL><INDENT>objectid = objectinfo['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>objectid = os.urandom(<NUM_LIT:12>).hex()[:<NUM_LIT:7>]<EOL>objectinfo['<STR_LIT>'] = objectid<EOL>LOGWARNING('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>nbrfeat = neighbor_gaia_features(<EOL>objectinfo,<EOL>kdt,<EOL>nbrradiusarcsec,<EOL>verbose=False,<EOL>gaia_submit_timeout=gaia_submit_timeout,<EOL>gaia_submit_tries=gaia_submit_tries,<EOL>gaia_max_timeout=gaia_max_timeout,<EOL>gaia_mirror=gaia_mirror,<EOL>complete_query_later=complete_query_later,<EOL>search_simbad=search_simbad<EOL>)<EOL>objectinfo.update(nbrfeat)<EOL>if ( ('<STR_LIT>' not in objectinfo) or<EOL>( ('<STR_LIT>' in objectinfo) and<EOL>( (objectinfo['<STR_LIT>'] is None) or<EOL>(not np.isfinite(objectinfo['<STR_LIT>'])) ) ) ):<EOL><INDENT>if '<STR_LIT>' in nbrfeat['<STR_LIT>']:<EOL><INDENT>objectinfo['<STR_LIT>'] = nbrfeat['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = nbrfeat['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = '<STR_LIT>'<EOL>if verbose:<EOL><INDENT>LOGWARNING('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>objectinfo['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if ( ('<STR_LIT>' not in objectinfo) or<EOL>( ('<STR_LIT>' in objectinfo) and<EOL>( (objectinfo['<STR_LIT>'] is None) or<EOL>(not np.isfinite(objectinfo['<STR_LIT>'])) ) ) ):<EOL><INDENT>if '<STR_LIT>' in nbrfeat['<STR_LIT>']:<EOL><INDENT>objectinfo['<STR_LIT>'] = nbrfeat['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = nbrfeat['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = '<STR_LIT>'<EOL>if verbose:<EOL><INDENT>LOGWARNING('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>objectinfo['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if '<STR_LIT>' in objectinfo['<STR_LIT>']:<EOL><INDENT>objectinfo['<STR_LIT>'] = objectinfo['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = objectinfo['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = objectinfo['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = objectinfo['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = (<EOL>objectinfo['<STR_LIT>'][<NUM_LIT:0>]<EOL>)<EOL>objectinfo['<STR_LIT>'] = objectinfo['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = objectinfo['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = objectinfo['<STR_LIT>'][<NUM_LIT:0>]<EOL>objectinfo['<STR_LIT>'] = objectinfo['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>objectinfo['<STR_LIT>'] = None<EOL>objectinfo['<STR_LIT>'] = np.nan<EOL>objectinfo['<STR_LIT>'] = np.nan<EOL>objectinfo['<STR_LIT>'] = np.nan<EOL>objectinfo['<STR_LIT>'] = np.nan<EOL>objectinfo['<STR_LIT>'] = np.nan<EOL>objectinfo['<STR_LIT>'] = np.nan<EOL>objectinfo['<STR_LIT>'] = np.nan<EOL>objectinfo['<STR_LIT>'] = np.nan<EOL><DEDENT>if ('<STR_LIT>' in objectinfo and<EOL>objectinfo['<STR_LIT>'] is not None and<EOL>np.isfinite(objectinfo['<STR_LIT>']) and<EOL>'<STR_LIT>' in objectinfo and<EOL>objectinfo['<STR_LIT>'] is not None and<EOL>np.isfinite(objectinfo['<STR_LIT>'])):<EOL><INDENT>try:<EOL><INDENT>ticres = tic_conesearch(objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>'],<EOL>radius_arcmin=<NUM_LIT>/<NUM_LIT>,<EOL>verbose=verbose,<EOL>timeout=gaia_max_timeout,<EOL>maxtries=gaia_submit_tries)<EOL>if ticres is not None:<EOL><INDENT>with open(ticres['<STR_LIT>'],'<STR_LIT:r>') as infd:<EOL><INDENT>ticinfo = json.load(infd)<EOL><DEDENT>if ('<STR_LIT:data>' in ticinfo and<EOL>len(ticinfo['<STR_LIT:data>']) > <NUM_LIT:0> and<EOL>isinstance(ticinfo['<STR_LIT:data>'][<NUM_LIT:0>], dict)):<EOL><INDENT>objectinfo['<STR_LIT>'] = str(ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>'])<EOL>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT:version>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT:d>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>if (objectinfo['<STR_LIT>'] is not None and<EOL>np.isfinite(objectinfo['<STR_LIT>']) and<EOL>objectinfo['<STR_LIT>'] is not None and<EOL>np.isfinite(objectinfo['<STR_LIT>'])):<EOL><INDENT>objectinfo['<STR_LIT>'] = (<EOL>magnitudes.absolute_gaia_magnitude(<EOL>objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>']<EOL>)<EOL>)<EOL><DEDENT><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL>objectinfo['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT>if ('<STR_LIT>' not in objectinfo or<EOL>('<STR_LIT>' in objectinfo and<EOL>(objectinfo['<STR_LIT>'] is None or<EOL>not np.isfinite(objectinfo['<STR_LIT>'])))):<EOL><INDENT>objectinfo['<STR_LIT>'] = ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>objectinfo['<STR_LIT>'] = (<EOL>ticinfo['<STR_LIT:data>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>LOGERROR('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>']))<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>'],<EOL>objectinfo['<STR_LIT>']))<EOL><DEDENT><DEDENT>coordfeat = coord_features(objectinfo)<EOL>colorfeat = color_features(objectinfo,<EOL>deredden=deredden_object,<EOL>custom_bandpasses=custom_bandpasses,<EOL>dust_timeout=dust_timeout)<EOL>colorclass = color_classification(colorfeat, coordfeat)<EOL>objectinfo.update(colorfeat)<EOL>objectinfo.update(coordfeat)<EOL>objectinfo.update(colorclass)<EOL>checkplotdict = {'<STR_LIT>':objectid,<EOL>'<STR_LIT>':neighbors,<EOL>'<STR_LIT>':objectinfo,<EOL>'<STR_LIT>':finderb64,<EOL>'<STR_LIT>':sigclip,<EOL>'<STR_LIT>':normto,<EOL>'<STR_LIT>':normmingap}<EOL>checkplotdict['<STR_LIT>']['<STR_LIT>'] = None<EOL><DEDENT>else:<EOL><INDENT>checkplotdict = {'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':[],<EOL>'<STR_LIT>':[],<EOL>'<STR_LIT>':[],<EOL>'<STR_LIT>':[],<EOL>'<STR_LIT>':[],<EOL>'<STR_LIT>':[],<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None<EOL>},<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':sigclip,<EOL>'<STR_LIT>':normto,<EOL>'<STR_LIT>':normmingap}<EOL><DEDENT>if isinstance(varinfo, dict):<EOL><INDENT>checkplotdict['<STR_LIT>'] = varinfo<EOL><DEDENT>else:<EOL><INDENT>checkplotdict['<STR_LIT>'] = {<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>'<STR_LIT>':None,<EOL>}<EOL><DEDENT>return checkplotdict<EOL>

This returns the finder chart and object information as a dict.

    Parameters
    ----------

    objectinfo : dict or None
        If provided, this is a dict containing information on the object whose
        light curve is being processed. This function will then be able to look
        up and download a finder chart for this object and write that to the
        output checkplotdict. External services such as GAIA, SIMBAD, TIC@MAST,
        etc. will also be used to look up this object by its coordinates, and
        will add in information available from those services.

        The `objectinfo` dict must be of the form and contain at least the keys
        described below::

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

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

            'pmra' -> the proper motion in mas/yr in right ascension,
            'pmdecl' -> the proper motion in mas/yr in declination,
            'umag'  -> U mag		 -> colors: U-B, U-V, U-g
            'bmag'  -> B mag		 -> colors: U-B, B-V
            'vmag'  -> V mag		 -> colors: U-V, B-V, V-R, V-I, V-K
            'rmag'  -> R mag		 -> colors: V-R, R-I
            'imag'  -> I mag		 -> colors: g-I, V-I, R-I, B-I
            'jmag'  -> 2MASS J mag	 -> colors: J-H, J-K, g-J, i-J
            'hmag'  -> 2MASS H mag	 -> colors: J-H, H-K
            'kmag'  -> 2MASS Ks mag	 -> colors: g-Ks, H-Ks, J-Ks, V-Ks
            'sdssu' -> SDSS u mag	 -> colors: u-g, u-V
            'sdssg' -> SDSS g mag	 -> colors: g-r, g-i, g-K, u-g, U-g, g-J
            'sdssr' -> SDSS r mag	 -> colors: r-i, g-r
            'sdssi' -> SDSS i mag	 -> colors: r-i, i-z, g-i, i-J, i-W1
            'sdssz' -> SDSS z mag	 -> colors: i-z, z-W2, g-z
            'ujmag' -> UKIRT J mag	 -> colors: J-H, H-K, J-K, g-J, i-J
            'uhmag' -> UKIRT H mag	 -> colors: J-H, H-K
            'ukmag' -> UKIRT K mag	 -> colors: g-K, H-K, J-K, V-K
            'irac1' -> Spitzer IRAC1 mag -> colors: i-I1, I1-I2
            'irac2' -> Spitzer IRAC2 mag -> colors: I1-I2, I2-I3
            'irac3' -> Spitzer IRAC3 mag -> colors: I2-I3
            'irac4' -> Spitzer IRAC4 mag -> colors: I3-I4
            'wise1' -> WISE W1 mag	 -> colors: i-W1, W1-W2
            'wise2' -> WISE W2 mag	 -> colors: W1-W2, W2-W3
            'wise3' -> WISE W3 mag	 -> colors: W2-W3
            'wise4' -> WISE W4 mag	 -> colors: W3-W4

        If you have magnitude measurements in other bands, use the
        `custom_bandpasses` kwarg to pass these in.

        If this is None, no object information will be incorporated into the
        checkplot (kind of making it effectively useless for anything other than
        glancing at the phased light curves at various 'best' periods from the
        period-finder results).

    varinfo : dict or None
        If this is None, a blank dict of the form below will be added to the
        checkplotdict::

            {'objectisvar': None -> variability flag (None indicates unset),
             'vartags': CSV str containing variability type tags from review,
             'varisperiodic': None -> periodic variability flag (None -> unset),
             'varperiod': the period associated with the periodic variability,
             'varepoch': the epoch associated with the periodic variability}

        If you provide a dict matching this format in this kwarg, this will be
        passed unchanged to the output checkplotdict produced.

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

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

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

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

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

    normto : {'globalmedian', 'zero'} or a float
        This is specified as below::

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

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

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

    custom_bandpasses : dict
        This is a dict used to provide custom bandpass definitions for any
        magnitude measurements in the objectinfo dict that are not automatically
        recognized by :py:func:`astrobase.varclass.starfeatures.color_features`.

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

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

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

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

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

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

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

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

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

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

    fast_mode : bool or float
        This runs the external catalog operations in a "fast" mode, with short
        timeouts and not trying to hit external catalogs that take a long time
        to respond.

        If this is set to True, the default settings for the external requests
        will then become::

            skyview_lookup = False
            skyview_timeout = 10.0
            skyview_retry_failed = False
            dust_timeout = 10.0
            gaia_submit_timeout = 7.0
            gaia_max_timeout = 10.0
            gaia_submit_tries = 2
            complete_query_later = False
            search_simbad = False

        If this is a float, will run in "fast" mode with the provided timeout
        value in seconds and the following settings::

            skyview_lookup = True
            skyview_timeout = fast_mode
            skyview_retry_failed = False
            dust_timeout = fast_mode
            gaia_submit_timeout = 0.66*fast_mode
            gaia_max_timeout = fast_mode
            gaia_submit_tries = 2
            complete_query_later = False
            search_simbad = False

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

    Returns
    -------

    dict
        A checkplotdict is returned containing the objectinfo and varinfo dicts,
        ready to use with the functions below to add in light curve plots,
        phased LC plots, xmatch info, etc.


<EOL>pgramylabel = PLOTYLABELS[lspinfo['<STR_LIT>']]<EOL>periods = lspinfo['<STR_LIT>']<EOL>lspvals = lspinfo['<STR_LIT>']<EOL>bestperiod = lspinfo['<STR_LIT>']<EOL>nbestperiods = lspinfo['<STR_LIT>']<EOL>nbestlspvals = lspinfo['<STR_LIT>']<EOL>pgramfig = plt.figure(figsize=(<NUM_LIT>,<NUM_LIT>),dpi=plotdpi)<EOL>plt.plot(periods,lspvals)<EOL>plt.xscale('<STR_LIT>',basex=<NUM_LIT:10>)<EOL>plt.xlabel('<STR_LIT>')<EOL>plt.ylabel(pgramylabel)<EOL>plottitle = '<STR_LIT>' % (METHODLABELS[lspinfo['<STR_LIT>']],<EOL>bestperiod)<EOL>plt.title(plottitle)<EOL>for xbestperiod, xbestpeak in zip(nbestperiods,<EOL>nbestlspvals):<EOL><INDENT>plt.annotate('<STR_LIT>' % xbestperiod,<EOL>xy=(xbestperiod, xbestpeak), xycoords='<STR_LIT:data>',<EOL>xytext=(<NUM_LIT:0.0>,<NUM_LIT>), textcoords='<STR_LIT>',<EOL>arrowprops=dict(arrowstyle="<STR_LIT>"),fontsize='<STR_LIT>')<EOL><DEDENT>plt.grid(color='<STR_LIT>',<EOL>alpha=<NUM_LIT>,<EOL>zorder=<NUM_LIT:0>,<EOL>linewidth=<NUM_LIT:1.0>,<EOL>linestyle='<STR_LIT::>')<EOL>pgrampng = StrIO()<EOL>pgramfig.savefig(pgrampng,<EOL>pad_inches=<NUM_LIT:0.0>, format='<STR_LIT>')<EOL>plt.close()<EOL>pgrampng.seek(<NUM_LIT:0>)<EOL>pgramb64 = base64.b64encode(pgrampng.read())<EOL>pgrampng.close()<EOL>if not override_pfmethod:<EOL><INDENT>checkplotdict = {<EOL>lspinfo['<STR_LIT>']:{<EOL>'<STR_LIT>':periods,<EOL>'<STR_LIT>':lspvals,<EOL>'<STR_LIT>':bestperiod,<EOL>'<STR_LIT>':nbestperiods,<EOL>'<STR_LIT>':nbestlspvals,<EOL>'<STR_LIT>':pgramb64,<EOL>}<EOL>}<EOL><DEDENT>else:<EOL><INDENT>checkplotdict = {<EOL>override_pfmethod:{<EOL>'<STR_LIT>':periods,<EOL>'<STR_LIT>':lspvals,<EOL>'<STR_LIT>':bestperiod,<EOL>'<STR_LIT>':nbestperiods,<EOL>'<STR_LIT>':nbestlspvals,<EOL>'<STR_LIT>':pgramb64,<EOL>}<EOL>}<EOL><DEDENT>return checkplotdict<EOL>

This returns the periodogram plot PNG as base64, plus info as a dict.

    Parameters
    ----------

    lspinfo : dict
        This is an lspinfo dict containing results from a period-finding
        function. If it's from an astrobase period-finding function in
        periodbase, this will already be in the correct format. To use external
        period-finder results with this function, the `lspinfo` dict must be of
        the following form, with at least the keys listed below::

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

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

    plotdpi : int
        The resolution in DPI of the output periodogram plot to make.

    override_pfmethod : str or None
        This is used to set a custom label for this periodogram
        method. Normally, this is taken from the 'method' key in the input
        `lspinfo` dict, but if you want to override the output method name,
        provide this as a string here. This can be useful if you have multiple
        results you want to incorporate into a checkplotdict from a single
        period-finder (e.g. if you ran BLS over several period ranges
        separately).

    Returns
    -------

    dict
        Returns a dict that contains the following items::

            {methodname: {'periods':the period array from lspinfo,
                          'lspval': the periodogram power array from lspinfo,
                          'bestperiod': the best period from lspinfo,
                          'nbestperiods': the 'nbestperiods' list from lspinfo,
                          'nbestlspvals': the 'nbestlspvals' list from lspinfo,
                          'periodogram': base64 encoded string representation of
                                         the periodogram plot}}

        The dict is returned in this format so it can be directly incorporated
        under the period-finder's label `methodname` in a checkplotdict, using
        Python's dict `update()` method.


def _pkl_magseries_plot(stimes, smags, serrs,<EOL>plotdpi=<NUM_LIT:100>,<EOL>magsarefluxes=False):

scaledplottime = stimes - npmin(stimes)<EOL>magseriesfig = plt.figure(figsize=(<NUM_LIT>,<NUM_LIT>),dpi=plotdpi)<EOL>plt.plot(scaledplottime,<EOL>smags,<EOL>marker='<STR_LIT:o>',<EOL>ms=<NUM_LIT>, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL>if not magsarefluxes:<EOL><INDENT>plot_ylim = plt.ylim()<EOL>plt.ylim((plot_ylim[<NUM_LIT:1>], plot_ylim[<NUM_LIT:0>]))<EOL><DEDENT>plt.xlim((npmin(scaledplottime)-<NUM_LIT>,<EOL>npmax(scaledplottime)+<NUM_LIT>))<EOL>plt.grid(color='<STR_LIT>',<EOL>alpha=<NUM_LIT>,<EOL>zorder=<NUM_LIT:0>,<EOL>linewidth=<NUM_LIT:1.0>,<EOL>linestyle='<STR_LIT::>')<EOL>plot_xlabel = '<STR_LIT>' % npmin(stimes)<EOL>if magsarefluxes:<EOL><INDENT>plot_ylabel = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>plot_ylabel = '<STR_LIT>'<EOL><DEDENT>plt.xlabel(plot_xlabel)<EOL>plt.ylabel(plot_ylabel)<EOL>plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)<EOL>plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)<EOL>magseriespng = StrIO()<EOL>magseriesfig.savefig(magseriespng,<EOL>pad_inches=<NUM_LIT>, format='<STR_LIT>')<EOL>plt.close()<EOL>magseriespng.seek(<NUM_LIT:0>)<EOL>magseriesb64 = base64.b64encode(magseriespng.read())<EOL>magseriespng.close()<EOL>checkplotdict = {<EOL>'<STR_LIT>':{<EOL>'<STR_LIT>':magseriesb64,<EOL>'<STR_LIT>':stimes,<EOL>'<STR_LIT>':smags,<EOL>'<STR_LIT>':serrs<EOL>}<EOL>}<EOL>return checkplotdict<EOL>

This returns the magseries plot PNG as base64, plus arrays as dict.

    Parameters
    ----------

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

    plotdpi : int
        The resolution of the plot to make in DPI.

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

    Returns
    -------

    dict
        A dict of the following form is returned::

            {'magseries': {'plot': base64 encoded str representation of the
                                   magnitude/flux time-series plot,
                           'times': the `stimes` array,
                           'mags': the `smags` array,
                           'errs': the 'serrs' array}}

        The dict is returned in this format so it can be directly incorporated
        in a checkplotdict, using Python's dict `update()` method.


<EOL>phasedseriesfig = plt.figure(figsize=(<NUM_LIT>,<NUM_LIT>),dpi=plotdpi)<EOL>plotvarepoch = None<EOL>if varepoch is None:<EOL><INDENT>plotvarepoch = npmin(stimes)<EOL><DEDENT>elif isinstance(varepoch,str) and varepoch == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>spfit = spline_fit_magseries(stimes,<EOL>smags,<EOL>serrs,<EOL>varperiod,<EOL>magsarefluxes=magsarefluxes,<EOL>sigclip=None,<EOL>verbose=verbose)<EOL>plotvarepoch = spfit['<STR_LIT>']['<STR_LIT>']<EOL>if len(plotvarepoch) != <NUM_LIT:1>:<EOL><INDENT>plotvarepoch = plotvarepoch[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>LOGERROR('<STR_LIT>')<EOL>sgfit = savgol_fit_magseries(stimes,<EOL>smags,<EOL>serrs,<EOL>varperiod,<EOL>sigclip=None,<EOL>magsarefluxes=magsarefluxes,<EOL>verbose=verbose)<EOL>plotvarepoch = sgfit['<STR_LIT>']['<STR_LIT>']<EOL>if len(plotvarepoch) != <NUM_LIT:1>:<EOL><INDENT>plotvarepoch = plotvarepoch[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if plotvarepoch is None:<EOL><INDENT>LOGERROR('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>plotvarepoch = npmin(stimes)<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(varepoch, list):<EOL><INDENT>try:<EOL><INDENT>thisvarepochlist = varepoch[lspmethodind]<EOL>plotvarepoch = thisvarepochlist[periodind]<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>plotvarepoch = npmin(stimes)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>plotvarepoch = varepoch<EOL><DEDENT>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>' %<EOL>(lspmethod, periodind, varperiod, plotvarepoch))<EOL><DEDENT>if periodind == <NUM_LIT:0>:<EOL><INDENT>plottitle = '<STR_LIT>' % (<EOL>(METHODSHORTLABELS[lspmethod] if lspmethod in METHODSHORTLABELS<EOL>else lspmethod),<EOL>varperiod,<EOL>plotvarepoch<EOL>)<EOL><DEDENT>elif periodind > <NUM_LIT:0>:<EOL><INDENT>plottitle = '<STR_LIT>' % (<EOL>(METHODSHORTLABELS[lspmethod] if lspmethod in METHODSHORTLABELS<EOL>else lspmethod),<EOL>periodind+<NUM_LIT:1>,<EOL>varperiod,<EOL>plotvarepoch<EOL>)<EOL><DEDENT>elif periodind == -<NUM_LIT:1>:<EOL><INDENT>plottitle = '<STR_LIT>' % (<EOL>lspmethod,<EOL>varperiod,<EOL>plotvarepoch<EOL>)<EOL><DEDENT>phasedlc = phase_magseries(stimes,<EOL>smags,<EOL>varperiod,<EOL>plotvarepoch,<EOL>wrap=phasewrap,<EOL>sort=phasesort)<EOL>plotphase = phasedlc['<STR_LIT>']<EOL>plotmags = phasedlc['<STR_LIT>']<EOL>if phasebin:<EOL><INDENT>binphasedlc = phase_bin_magseries(plotphase,<EOL>plotmags,<EOL>binsize=phasebin,<EOL>minbinelems=minbinelems)<EOL>binplotphase = binphasedlc['<STR_LIT>']<EOL>binplotmags = binphasedlc['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>binplotphase = None<EOL>binplotmags = None<EOL><DEDENT>plt.plot(plotphase,<EOL>plotmags,<EOL>marker='<STR_LIT:o>',<EOL>ms=<NUM_LIT>, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL>if phasebin:<EOL><INDENT>plt.plot(binplotphase,<EOL>binplotmags,<EOL>marker='<STR_LIT:o>',<EOL>ms=<NUM_LIT>, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL><DEDENT>if overplotfit and isinstance(overplotfit, dict):<EOL><INDENT>fitmethod = overplotfit['<STR_LIT>']<EOL>fitredchisq = overplotfit['<STR_LIT>']<EOL>plotfitmags = overplotfit['<STR_LIT>']['<STR_LIT>']<EOL>plotfittimes = overplotfit['<STR_LIT>']['<STR_LIT>']<EOL>fitphasedlc = phase_magseries(plotfittimes,<EOL>plotfitmags,<EOL>varperiod,<EOL>plotvarepoch,<EOL>wrap=phasewrap,<EOL>sort=phasesort)<EOL>plotfitphase = fitphasedlc['<STR_LIT>']<EOL>plotfitmags = fitphasedlc['<STR_LIT>']<EOL>plotfitlabel = (r'<STR_LIT>' %<EOL>(fitmethod, fitredchisq))<EOL>plt.plot(plotfitphase, plotfitmags,'<STR_LIT>',<EOL>linewidth=<NUM_LIT:3>, rasterized=True,label=plotfitlabel)<EOL>plt.legend(loc='<STR_LIT>', frameon=False)<EOL><DEDENT>if not magsarefluxes:<EOL><INDENT>plot_ylim = plt.ylim()<EOL>plt.ylim((plot_ylim[<NUM_LIT:1>], plot_ylim[<NUM_LIT:0>]))<EOL><DEDENT>if not plotxlim:<EOL><INDENT>plt.xlim((npmin(plotphase)-<NUM_LIT:0.1>,<EOL>npmax(plotphase)+<NUM_LIT:0.1>))<EOL><DEDENT>else:<EOL><INDENT>plt.xlim((plotxlim[<NUM_LIT:0>],plotxlim[<NUM_LIT:1>]))<EOL><DEDENT>ax = plt.gca()<EOL>if isinstance(xgridlines, (list, tuple)):<EOL><INDENT>ax.set_xticks(xgridlines, minor=False)<EOL><DEDENT>plt.grid(color='<STR_LIT>',<EOL>alpha=<NUM_LIT>,<EOL>zorder=<NUM_LIT:0>,<EOL>linewidth=<NUM_LIT:1.0>,<EOL>linestyle='<STR_LIT::>')<EOL>plot_xlabel = '<STR_LIT>'<EOL>if magsarefluxes:<EOL><INDENT>plot_ylabel = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>plot_ylabel = '<STR_LIT>'<EOL><DEDENT>plt.xlabel(plot_xlabel)<EOL>plt.ylabel(plot_ylabel)<EOL>plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)<EOL>plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)<EOL>plt.title(plottitle)<EOL>if (periodind == <NUM_LIT:0> or periodind == -<NUM_LIT:1>) and bestperiodhighlight:<EOL><INDENT>if MPLVERSION >= (<NUM_LIT:2>,<NUM_LIT:0>,<NUM_LIT:0>):<EOL><INDENT>plt.gca().set_facecolor(bestperiodhighlight)<EOL><DEDENT>else:<EOL><INDENT>plt.gca().set_axis_bgcolor(bestperiodhighlight)<EOL><DEDENT><DEDENT>if (plotxlim and isinstance(plotxlim, (list, tuple)) and<EOL>len(plotxlim) == <NUM_LIT:2> and xliminsetmode is True):<EOL><INDENT>axesylim = plt.gca().get_ylim()<EOL>if magsarefluxes:<EOL><INDENT>plt.gca().set_ylim(<EOL>axesylim[<NUM_LIT:0>],<EOL>axesylim[<NUM_LIT:1>] + <NUM_LIT:0.5>*npabs(axesylim[<NUM_LIT:1>]-axesylim[<NUM_LIT:0>])<EOL>)<EOL><DEDENT>else:<EOL><INDENT>plt.gca().set_ylim(<EOL>axesylim[<NUM_LIT:0>],<EOL>axesylim[<NUM_LIT:1>] - <NUM_LIT:0.5>*npabs(axesylim[<NUM_LIT:1>]-axesylim[<NUM_LIT:0>])<EOL>)<EOL><DEDENT>inset = inset_axes(plt.gca(), width="<STR_LIT>", height="<STR_LIT>", loc=<NUM_LIT:1>)<EOL>inset.plot(plotphase,<EOL>plotmags,<EOL>marker='<STR_LIT:o>',<EOL>ms=<NUM_LIT>, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL>if phasebin:<EOL><INDENT>inset.plot(binplotphase,<EOL>binplotmags,<EOL>marker='<STR_LIT:o>',<EOL>ms=<NUM_LIT>, ls='<STR_LIT:None>',mew=<NUM_LIT:0>,<EOL>color='<STR_LIT>',<EOL>rasterized=True)<EOL><DEDENT>if phasewrap:<EOL><INDENT>inset.set_xlim(-<NUM_LIT>,<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>inset.set_xlim(-<NUM_LIT:0.1>,<NUM_LIT>)<EOL><DEDENT>if not magsarefluxes:<EOL><INDENT>inset_ylim = inset.get_ylim()<EOL>inset.set_ylim((inset_ylim[<NUM_LIT:1>], inset_ylim[<NUM_LIT:0>]))<EOL><DEDENT>inset.text(<NUM_LIT:0.5>,<NUM_LIT>,'<STR_LIT>',<EOL>ha='<STR_LIT>',va='<STR_LIT>',transform=inset.transAxes)<EOL>inset.set_xticks([])<EOL>inset.set_yticks([])<EOL><DEDENT>phasedseriespng = StrIO()<EOL>phasedseriesfig.savefig(phasedseriespng,<EOL>pad_inches=<NUM_LIT:0.0>, format='<STR_LIT>')<EOL>plt.close()<EOL>phasedseriespng.seek(<NUM_LIT:0>)<EOL>phasedseriesb64 = base64.b64encode(phasedseriespng.read())<EOL>phasedseriespng.close()<EOL>retdict = {<EOL>'<STR_LIT>':phasedseriesb64,<EOL>'<STR_LIT>':varperiod,<EOL>'<STR_LIT>':plotvarepoch,<EOL>'<STR_LIT>':plotphase,<EOL>'<STR_LIT>':plotmags,<EOL>'<STR_LIT>':binplotphase,<EOL>'<STR_LIT>':binplotmags,<EOL>'<STR_LIT>':phasewrap,<EOL>'<STR_LIT>':phasesort,<EOL>'<STR_LIT>':phasebin,<EOL>'<STR_LIT>':minbinelems,<EOL>'<STR_LIT>':plotxlim,<EOL>'<STR_LIT>':overplotfit,<EOL>}<EOL>if directreturn or checkplotdict is None:<EOL><INDENT>return retdict<EOL><DEDENT>else:<EOL><INDENT>if override_pfmethod:<EOL><INDENT>checkplotdict[override_pfmethod][periodind] = retdict<EOL><DEDENT>else:<EOL><INDENT>checkplotdict[lspmethod][periodind] = retdict<EOL><DEDENT>return checkplotdict<EOL><DEDENT>

This returns the phased magseries plot PNG as base64 plus info as a dict.

    Parameters
    ----------

    checkplotdict : dict
        This is an existing checkplotdict to update. If it's None or
        `directreturn` = True, then the generated dict result for this magseries
        plot will be returned directly.

    lspmethod : str
        lspmethod is a string indicating the type of period-finding algorithm
        that produced the period. If this is not in
        `astrobase.plotbase.METHODSHORTLABELS`, it will be used verbatim. In
        most cases, this will come directly from the lspinfo dict produced by a
        period-finder function.

    periodind : int
        This is the index of the current periodogram period being operated
        on::

            If == 0 -> best period and `bestperiodhighlight` is applied if not
                       None
            If > 0   -> some other peak of the periodogram
            If == -1 -> special mode w/ no periodogram labels and enabled
                        highlight

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

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

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

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

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

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

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

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

    plotdpi : int
        The resolution of the output plot PNGs in dots per inch.

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

    xgridlines : list of floats or None
        If this is provided, must be a list of floats corresponding to the phase
        values where to draw vertical dashed lines as a means of highlighting
        these.

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

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

    directreturn : bool
        If this set to True, will return only the dict corresponding to the
        phased LC plot for the input `periodind` and `lspmethod` and not return
        this result embedded in a checkplotdict.

    overplotfit : dict
        If this is provided, it must be a dict of the form returned by one of
        the astrobase.lcfit.fit_XXXXX_magseries functions. This can be used to
        overplot a light curve model fit on top of the phased light curve plot
        returned by this function. The `overplotfit` dict has the following
        form, including at least the keys listed here::

            {'fittype':str: name of fit method,
            'fitchisq':float: the chi-squared value of the fit,
            'fitredchisq':float: the reduced chi-squared value of the fit,
            'fitinfo':{'fitmags':array: model mags or fluxes from fit function},
            'magseries':{'times':array: times where the fitmags are evaluated}}

        `fitmags` and `times` should all be of the same size. The input
        `overplotfit` dict is copied over to the checkplotdict for each specific
        phased LC plot to save all of this information for use later.

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

    override_pfmethod : str or None
        This is used to set a custom label for the periodogram method. Normally,
        this is taken from the 'method' key in the input `lspinfo` dict, but if
        you want to override the output method name, provide this as a string
        here. This can be useful if you have multiple results you want to
        incorporate into a checkplotdict from a single period-finder (e.g. if
        you ran BLS over several period ranges separately).

    Returns
    -------

    dict
        Returns a dict of the following form::

            {lspmethod: {'plot': the phased LC plot as base64 str,
                         'period': the period used for this phased LC,
                         'epoch': the epoch used for this phased LC,
                         'phase': phase value array,
                         'phasedmags': mags/fluxes sorted in phase order,
                         'binphase': array of binned phase values,
                         'binphasedmags': mags/fluxes sorted in binphase order,
                         'phasewrap': value of the input `phasewrap` kwarg,
                         'phasesort': value of the input `phasesort` kwarg,
                         'phasebin': value of the input `phasebin` kwarg,
                         'minbinelems': value of the input `minbinelems` kwarg,
                         'plotxlim': value of the input `plotxlim` kwarg,
                         'lcfit': the provided `overplotfit` dict}}

        The dict is in this form because we can use Python dicts' `update()`
        method to update an existing checkplotdict. If `returndirect` is True,
        only the inner dict is returned.


This makes new GCE worker nodes.

    Use preemptible instances and startup/shutdown scripts to emulate AWS spot
    fleet behavior and run stuff at cheaper prices.

    TODO: finish this


This deletes GCE worker nodes.

TODO: finish this


if not client:<EOL><INDENT>if (service_account_json is not None and<EOL>os.path.exists(service_account_json)):<EOL><INDENT>client = storage.Client.from_service_account_json(<EOL>service_account_json<EOL>)<EOL><DEDENT>else:<EOL><INDENT>client = storage.Client()<EOL><DEDENT><DEDENT>try:<EOL><INDENT>bucket = client.get_bucket(bucketname)<EOL>blob = bucket.get_blob(filename)<EOL>blob.download_to_filename(local_file)<EOL>return local_file<EOL><DEDENT>except Exception as e:<EOL><INDENT>for alt_extension in altexts:<EOL><INDENT>split_ext = os.path.splitext(filename)<EOL>check_file = split_ext[<NUM_LIT:0>] + alt_extension<EOL>try:<EOL><INDENT>bucket = client.get_bucket(bucket)<EOL>blob = bucket.get_blob(check_file)<EOL>blob.download_to_filename(<EOL>local_file.replace(split_ext[-<NUM_LIT:1>],<EOL>alt_extension)<EOL>)<EOL>return local_file.replace(split_ext[-<NUM_LIT:1>],<EOL>alt_extension)<EOL><DEDENT>except Exception as e:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>' % (bucket, filename))<EOL>if raiseonfail:<EOL><INDENT>raise<EOL><DEDENT>return None<EOL><DEDENT>

This gets a single file from a Google Cloud Storage bucket.

    Parameters
    ----------

    bucketname : str
        The name of the GCS bucket to download the file from.

    filename : str
        The full name of the file to download, including all prefixes.

    local_file : str
        Path to where the downloaded file will be stored.

    altexts : None or list of str
        If not None, this is a list of alternate extensions to try for the file
        other than the one provided in `filename`. For example, to get anything
        that's an .sqlite where .sqlite.gz is expected, use altexts=[''] to
        strip the .gz.

    client : google.cloud.storage.Client instance
        The instance of the Client to use to perform the download operation. If
        this is None, a new Client will be used. If this is None and
        `service_account_json` points to a downloaded JSON file with GCS
        credentials, a new Client with the provided credentials will be used. If
        this is not None, the existing Client instance will be used.

    service_account_json : str
        Path to a downloaded GCS credentials JSON file.

    raiseonfail : bool
        If True, will re-raise whatever Exception caused the operation to fail
        and break out immediately.

    Returns
    -------

    str
        Path to the downloaded filename or None if the download was
        unsuccessful.


bucket_item = url.replace('<STR_LIT>','<STR_LIT>')<EOL>bucket_item = bucket_item.split('<STR_LIT:/>')<EOL>bucket = bucket_item[<NUM_LIT:0>]<EOL>filekey = '<STR_LIT:/>'.join(bucket_item[<NUM_LIT:1>:])<EOL>return gcs_get_file(bucket,<EOL>filekey,<EOL>bucket_item[-<NUM_LIT:1>],<EOL>altexts=altexts,<EOL>client=client,<EOL>service_account_json=service_account_json,<EOL>raiseonfail=raiseonfail)<EOL>

This gets a single file from a Google Cloud Storage bucket.

    This uses the gs:// URL instead of a bucket name and key.

    Parameters
    ----------

    url : str
        GCS URL to download. This should begin with 'gs://'.

    altexts : None or list of str
        If not None, this is a list of alternate extensions to try for the file
        other than the one provided in `filename`. For example, to get anything
        that's an .sqlite where .sqlite.gz is expected, use altexts=[''] to
        strip the .gz.

    client : google.cloud.storage.Client instance
        The instance of the Client to use to perform the download operation. If
        this is None, a new Client will be used. If this is None and
        `service_account_json` points to a downloaded JSON file with GCS
        credentials, a new Client with the provided credentials will be used. If
        this is not None, the existing Client instance will be used.

    service_account_json : str
        Path to a downloaded GCS credentials JSON file.

    raiseonfail : bool
        If True, will re-raise whatever Exception caused the operation to fail
        and break out immediately.

    Returns
    -------

    str
        Path to the downloaded filename or None if the download was
        unsuccessful.


if not client:<EOL><INDENT>if (service_account_json is not None and<EOL>os.path.exists(service_account_json)):<EOL><INDENT>client = storage.Client.from_service_account_json(<EOL>service_account_json<EOL>)<EOL><DEDENT>else:<EOL><INDENT>client = storage.Client()<EOL><DEDENT><DEDENT>try:<EOL><INDENT>bucket = client.get_bucket(bucketname)<EOL>remote_blob = bucket.blob(local_file)<EOL>remote_blob.upload_from_filename(local_file)<EOL>return '<STR_LIT>' % (bucketname, local_file.lstrip('<STR_LIT:/>'))<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>' % (local_file,<EOL>bucket))<EOL>if raiseonfail:<EOL><INDENT>raise<EOL><DEDENT>return None<EOL><DEDENT>

This puts a single file into a Google Cloud Storage bucket.

    Parameters
    ----------

    local_file : str
        Path to the file to upload to GCS.

    bucket : str
        The GCS bucket to upload the file to.

    service_account_json : str
        Path to a downloaded GCS credentials JSON file.

    client : google.cloud.storage.Client instance
        The instance of the Client to use to perform the download operation. If
        this is None, a new Client will be used. If this is None and
        `service_account_json` points to a downloaded JSON file with GCS
        credentials, a new Client with the provided credentials will be used. If
        this is not None, the existing Client instance will be used.

    raiseonfail : bool
        If True, will re-raise whatever Exception caused the operation to fail
        and break out immediately.

    Returns
    -------

    str or None
        If the file upload is successful, returns the gs:// URL of the uploaded
        file. If it failed, will return None.


This creates a Google Pub/Sub topic.

TODO: finish this


This deletes a Google Pub/Sub topic.

TODO: finish this


This synchronously pulls a single message from a pubsub topic.

TODO: finish this


This publishes a JSON message to a topic.

TODO: finish this


return (<EOL><NUM_LIT> * (min_radius_hint**(<NUM_LIT>/<NUM_LIT>)) * (period**(-<NUM_LIT>/<NUM_LIT>)),<EOL><NUM_LIT> * (max_radius_hint**(<NUM_LIT>/<NUM_LIT>)) * (period**(-<NUM_LIT>/<NUM_LIT>))<EOL>)<EOL>

This figures out the minimum and max transit duration (q) given a period
    and min/max stellar radius hints.

    One can get stellar radii from various places:

    - GAIA distances and luminosities
    - the TESS input catalog
    - isochrone fits

    The equation used is::

        q ~ 0.076 x R**(2/3) x P**(-2/3)

        P = period in days
        R = stellar radius in solar radii

    Parameters
    ----------

    period : float
        The orbital period of the transiting planet.

    min_radius_hint,max_radius_hint : float
        The minimum and maximum radii of the star the planet is orbiting around.

    Returns
    -------

    (min_transit_duration, max_transit_duration) : tuple
        The returned tuple contains the minimum and maximum transit durations
        allowed for the orbital geometry of this planetary system. These can be
        used with the BLS period-search functions in
        :py:mod:`astrobase.periodbase.kbls` or
        :py:mod:`astrobase.periodbase.abls` to refine the period-search to only
        physically possible transit durations.


if magsarefluxes:<EOL><INDENT>if not np.isclose(np.nanmedian(modelmags), <NUM_LIT:1>, atol=atol_normalization):<EOL><INDENT>raise AssertionError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise NotImplementedError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>if not transitdepth:<EOL><INDENT>transitdepth = np.abs(np.max(modelmags) - np.min(modelmags))<EOL><DEDENT>if not len(mags) == len(modelmags):<EOL><INDENT>from scipy.interpolate import interp1d<EOL>fn = interp1d(modeltimes, modelmags, kind='<STR_LIT>', bounds_error=True,<EOL>fill_value=np.nan)<EOL>modelmags = fn(times)<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>')<EOL><DEDENT><DEDENT>subtractedmags = mags - modelmags<EOL>if isinstance(indsforrms, np.ndarray):<EOL><INDENT>subtractedrms = np.std(subtractedmags[indsforrms])<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>subtractedrms = np.std(subtractedmags)<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>')<EOL><DEDENT><DEDENT>def _get_npoints_in_transit(modelmags):<EOL><INDENT>if np.nanmedian(modelmags) == <NUM_LIT:1>:<EOL><INDENT>return len(modelmags[(modelmags != <NUM_LIT:1>)])<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError<EOL><DEDENT><DEDENT>if not npoints_in_transit:<EOL><INDENT>npoints_in_transit = _get_npoints_in_transit(modelmags)<EOL><DEDENT>snr = np.sqrt(npoints_in_transit) * transitdepth/subtractedrms<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>'.format(npoints_in_transit) +<EOL>'<STR_LIT>'.format(transitdepth) +<EOL>'<STR_LIT>'.format(subtractedrms) +<EOL>'<STR_LIT>'.format(snr))<EOL><DEDENT>return snr, transitdepth, subtractedrms<EOL>

Calculate the total SNR of a transit assuming gaussian uncertainties.

    `modelmags` gets interpolated onto the cadence of `mags`. The noise is
    calculated as the 1-sigma std deviation of the residual (see below).

    Following Carter et al. 2009::

        Q = sqrt( Γ T ) * δ / σ

    for Q the total SNR of the transit in the r->0 limit, where::

        r = Rp/Rstar,
        T = transit duration,
        δ = transit depth,
        σ = RMS of the lightcurve in transit.
        Γ = sampling rate

    Thus Γ * T is roughly the number of points obtained during transit.
    (This doesn't correctly account for the SNR during ingress/egress, but this
    is a second-order correction).

    Note this is the same total SNR as described by e.g., Kovacs et al. 2002,
    their Equation 11.

    NOTE: this only works with fluxes at the moment.

    Parameters
    ----------

    times,mags : np.array
        The input flux time-series to process.

    modeltimes,modelmags : np.array
        A transiting planet model, either from BLS, a trapezoid model, or a
        Mandel-Agol model.

    atol_normalization : float
        The absolute tolerance to which the median of the passed model fluxes
        must be equal to 1.

    indsforrms : np.array
        A array of bools of `len(mags)` used to select points for the RMS
        measurement. If not passed, the RMS of the entire passed timeseries is
        used as an approximation. Genearlly, it's best to use out of transit
        points, so the RMS measurement is not model-dependent.

    magsarefluxes : bool
        Currently forced to be True because this function only works with
        fluxes.

    verbose : bool
        If True, indicates progress and warns about problems.

    transitdepth : float or None
        If the transit depth is known, pass it in here. Otherwise, it is
        calculated assuming OOT flux is 1.

    npoints_in_transits : int or None
        If the number of points in transit is known, pass it in here. Otherwise,
        the function will guess at this value.

    Returns
    -------

    (snr, transit_depth, noise) : tuple
        The returned tuple contains the calculated SNR, transit depth, and noise
        of the residual lightcurve calculated using the relation described
        above.


t_ingress = t_ingress_min*u.minute<EOL>t_duration = t_duration_hr*u.hour<EOL>theta = t_ingress/t_duration<EOL>sigma_tc = (<NUM_LIT:1>/snr * t_duration * np.sqrt(theta/<NUM_LIT:2>))<EOL>LOGINFO('<STR_LIT>'.format(t_ingress))<EOL>LOGINFO('<STR_LIT>'.format(t_duration))<EOL>LOGINFO('<STR_LIT>'.format(snr) +<EOL>'<STR_LIT>'.format(<EOL>sigma_tc.to(u.minute), sigma_tc.to(u.hour), sigma_tc.to(u.day)))<EOL>return sigma_tc.to(u.day).value<EOL>

Using Carter et al. 2009's estimate, calculate the theoretical optimal
    precision on mid-transit time measurement possible given a transit of a
    particular SNR.

    The relation used is::

        sigma_tc = Q^{-1} * T * sqrt(θ/2)

        Q = SNR of the transit.
        T = transit duration, which is 2.14 hours from discovery paper.
        θ = τ/T = ratio of ingress to total duration
                ~= (few minutes [guess]) / 2.14 hours

    Parameters
    ----------

    snr : float
        The measured signal-to-noise of the transit, e,g. from
        :py:func:`astrobase.periodbase.kbls.bls_stats_singleperiod` or from
        running the `.compute_stats()` method on an Astropy BoxLeastSquares
        object.

    t_ingress_min : float
        The ingress duration in minutes. This is t_I to t_II in Winn (2010)
        nomenclature.

    t_duration_hr : float
        The transit duration in hours. This is t_I to t_IV in Winn (2010)
        nomenclature.

    Returns
    -------

    float
        Returns the precision achievable for transit-center time as calculated
        from the relation above. This is in days.


if trapd:<EOL><INDENT>period = trapd['<STR_LIT>']['<STR_LIT>'][<NUM_LIT:0>]<EOL>t0 = trapd['<STR_LIT>']['<STR_LIT>']<EOL>transitduration_phase = trapd['<STR_LIT>']['<STR_LIT>'][<NUM_LIT:3>]<EOL>tdur = period * transitduration_phase<EOL><DEDENT>else:<EOL><INDENT>period = blsd['<STR_LIT>']<EOL>t0 = blsd['<STR_LIT>']<EOL>tdur = (<EOL>period *<EOL>(blsd['<STR_LIT>']-blsd['<STR_LIT>'])/blsd['<STR_LIT>']<EOL>)<EOL>if not blsd['<STR_LIT>'] > blsd['<STR_LIT>']:<EOL><INDENT>raise NotImplementedError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT><DEDENT>tmids = [t0 + ix*period for ix in range(-nperiodint,nperiodint)]<EOL>sel = (tmids > np.nanmin(time)) & (tmids < np.nanmax(time))<EOL>tmids_obsd = np.array(tmids)[sel]<EOL>t_Is = tmids_obsd - tdur/<NUM_LIT:2><EOL>t_IVs = tmids_obsd + tdur/<NUM_LIT:2><EOL>t_starts = t_Is - extra_maskfrac * tdur<EOL>t_ends = t_IVs + extra_maskfrac * tdur<EOL>return tmids_obsd, t_starts, t_ends<EOL>

Given a BLS period, epoch, and transit ingress/egress points (usually
    from :py:func:`astrobase.periodbase.kbls.bls_stats_singleperiod`), return
    the times within transit durations + `extra_maskfrac` of each transit.

    Optionally, can use the (more accurate) trapezoidal fit period and epoch, if
    it's passed.  Useful for inspecting individual transits, and masking them
    out if desired.

    Parameters
    ----------

    blsd : dict
        This is the dict returned by
        :py:func:`astrobase.periodbase.kbls.bls_stats_singleperiod`.

    time : np.array
        The times from the time-series of transit observations used to calculate
        the initial period.

    extra_maskfrac : float
        This is the separation from in-transit points you desire, in units of
        the transit duration. `extra_maskfrac = 0` if you just want points
        inside transit (see below).

    trapd : dict
        This is a dict returned by
        :py:func:`astrobase.lcfit.transits.traptransit_fit_magseries` containing
        the trapezoid transit model.

    nperiodint : int
        This indicates how many periods backwards/forwards to try and identify
        transits from the epochs reported in `blsd` or `trapd`.

    Returns
    -------

    (tmids_obsd, t_starts, t_ends) : tuple of np.array
        The returned items are::

            tmids_obsd (np.ndarray): best guess of transit midtimes in
            lightcurve. Has length number of transits in lightcurve.

            t_starts (np.ndarray): t_Is - extra_maskfrac*tdur, for t_Is transit
            first contact point.

            t_ends (np.ndarray): t_Is + extra_maskfrac*tdur, for t_Is transit
            first contact point.


<EOL>endp = <NUM_LIT>*(np.nanmax(time) - np.nanmin(time))/<NUM_LIT:2><EOL>blsdict = kbls.bls_parallel_pfind(time, flux, err_flux,<EOL>magsarefluxes=magsarefluxes, startp=<NUM_LIT:0.1>,<EOL>endp=endp, maxtransitduration=<NUM_LIT>,<EOL>nworkers=nworkers, sigclip=sigclip)<EOL>blsd = kbls.bls_stats_singleperiod(time, flux, err_flux,<EOL>blsdict['<STR_LIT>'],<EOL>magsarefluxes=True, sigclip=sigclip,<EOL>perioddeltapercent=<NUM_LIT:5>)<EOL>if blsfit_savpath:<EOL><INDENT>make_fit_plot(blsd['<STR_LIT>'], blsd['<STR_LIT>'], None,<EOL>blsd['<STR_LIT>'], blsd['<STR_LIT>'], blsd['<STR_LIT>'],<EOL>blsd['<STR_LIT>'], blsfit_savpath,<EOL>magsarefluxes=magsarefluxes)<EOL><DEDENT>ingduration_guess = blsd['<STR_LIT>'] * <NUM_LIT>  <EOL>transitparams = [<EOL>blsd['<STR_LIT>'], blsd['<STR_LIT>'], blsd['<STR_LIT>'],<EOL>blsd['<STR_LIT>'], ingduration_guess<EOL>]<EOL>if trapfit_savpath:<EOL><INDENT>trapd = traptransit_fit_magseries(time, flux, err_flux,<EOL>transitparams,<EOL>magsarefluxes=magsarefluxes,<EOL>sigclip=sigclip,<EOL>plotfit=trapfit_savpath)<EOL><DEDENT>tmids, t_starts, t_ends = get_transit_times(blsd,<EOL>time,<EOL>extra_maskfrac,<EOL>trapd=trapd)<EOL>return tmids, t_starts, t_ends<EOL>

Gets the transit start, middle, and end times for transits in a given
    time-series of observations.

    Parameters
    ----------

    time,flux,err_flux : np.array
        The input flux time-series measurements and their associated measurement
        errors

    blsfit_savpath : str or None
        If provided as a str, indicates the path of the fit plot to make for a
        simple BLS model fit to the transit using the obtained period and epoch.

    trapfit_savpath : str or None
        If provided as a str, indicates the path of the fit plot to make for a
        trapezoidal transit model fit to the transit using the obtained period
        and epoch.

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

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

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

    magsarefluxes : bool
        This is by default True for this function, since it works on fluxes only
        at the moment.

    nworkers : int
        The number of parallel BLS period-finder workers to use.

    extra_maskfrac : float
        This is the separation (N) from in-transit points you desire, in units
        of the transit duration. `extra_maskfrac = 0` if you just want points
        inside transit, otherwise::

            t_starts = t_Is - N*tdur, t_ends = t_IVs + N*tdur

        Thus setting N=0.03 masks slightly more than the guessed transit
        duration.

    Returns
    -------

    (tmids_obsd, t_starts, t_ends) : tuple
        The returned items are::

            tmids_obsd (np.ndarray): best guess of transit midtimes in
            lightcurve. Has length number of transits in lightcurve.

            t_starts (np.ndarray): t_Is - extra_maskfrac*tdur, for t_Is transit
            first contact point.

            t_ends (np.ndarray): t_Is + extra_maskfrac*tdur, for t_Is transit
            first contact point.


tmids_obsd, t_starts, t_ends = (<EOL>given_lc_get_transit_tmids_tstarts_tends(<EOL>time, flux, err_flux, blsfit_savpath=blsfit_savpath,<EOL>trapfit_savpath=trapfit_savpath, magsarefluxes=magsarefluxes,<EOL>nworkers=nworkers, sigclip=sigclip, extra_maskfrac=extra_maskfrac<EOL>)<EOL>)<EOL>in_transit = np.zeros_like(time).astype(bool)<EOL>for t_start, t_end in zip(t_starts, t_ends):<EOL><INDENT>this_transit = ( (time > t_start) & (time < t_end) )<EOL>in_transit |= this_transit<EOL><DEDENT>out_of_transit = ~in_transit<EOL>if in_out_transit_savpath:<EOL><INDENT>_in_out_transit_plot(time, flux, in_transit, out_of_transit,<EOL>in_out_transit_savpath)<EOL><DEDENT>return time[out_of_transit], flux[out_of_transit], err_flux[out_of_transit]<EOL>

This gets the out-of-transit light curve points.

    Relevant during iterative masking of transits for multiple planet system
    search.

    Parameters
    ----------

    time,flux,err_flux : np.array
        The input flux time-series measurements and their associated measurement
        errors

    blsfit_savpath : str or None
        If provided as a str, indicates the path of the fit plot to make for a
        simple BLS model fit to the transit using the obtained period and epoch.

    trapfit_savpath : str or None
        If provided as a str, indicates the path of the fit plot to make for a
        trapezoidal transit model fit to the transit using the obtained period
        and epoch.

    in_out_transit_savpath : str or None
        If provided as a str, indicates the path of the plot file that will be
        made for a plot showing the in-transit points and out-of-transit points
        tagged separately.

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

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

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

    magsarefluxes : bool
        This is by default True for this function, since it works on fluxes only
        at the moment.

    nworkers : int
        The number of parallel BLS period-finder workers to use.

    extra_maskfrac : float
        This is the separation (N) from in-transit points you desire, in units
        of the transit duration. `extra_maskfrac = 0` if you just want points
        inside transit, otherwise::

            t_starts = t_Is - N*tdur, t_ends = t_IVs + N*tdur

        Thus setting N=0.03 masks slightly more than the guessed transit
        duration.

    Returns
    -------

    (times_oot, fluxes_oot, errs_oot) : tuple of np.array
        The `times`, `flux`, `err_flux` values from the input at the time values
        out-of-transit are returned.


return median_filter(mags, size=windowsize, mode='<STR_LIT>')<EOL>

This smooths the magseries with a median filter that reflects the array
    at the boundary.

    See https://docs.scipy.org/doc/scipy/reference/tutorial/ndimage.html for
    details.

    Parameters
    ----------

    mags : np.array
        The input mags/flux time-series to smooth.

    windowsize : int
        This is a odd integer containing the smoothing window size.

    Returns
    -------

    np.array
        The smoothed mag/flux time-series array.


return medfilt(mags, windowsize)<EOL>

This smooths the magseries with a simple median filter.

    This function pads with zeros near the boundary, see:

    https://stackoverflow.com/questions/24585706/scipy-medfilt-wrong-result

    Typically this is bad.

    Parameters
    ----------

    mags : np.array
        The input mags/flux time-series to smooth.

    windowsize : int
        This is a odd integer containing the smoothing window size.

    Returns
    -------

    np.array
        The smoothed mag/flux time-series array.


def smooth_magseries_gaussfilt(mags, windowsize, windowfwhm=<NUM_LIT:7>):

convkernel = Gaussian1DKernel(windowfwhm, x_size=windowsize)<EOL>smoothed = convolve(mags, convkernel, boundary='<STR_LIT>')<EOL>return smoothed<EOL>

This smooths the magseries with a Gaussian kernel.

    Parameters
    ----------

    mags : np.array
        The input mags/flux time-series to smooth.

    windowsize : int
        This is a odd integer containing the smoothing window size.

    windowfwhm : int
        This is an odd integer containing the FWHM of the applied Gaussian
        window function.

    Returns
    -------

    np.array
        The smoothed mag/flux time-series array.


def smooth_magseries_savgol(mags, windowsize, polyorder=<NUM_LIT:2>):

smoothed = savgol_filter(mags, windowsize, polyorder)<EOL>return smoothed<EOL>

This smooths the magseries with a Savitsky-Golay filter.

    Parameters
    ----------

    mags : np.array
        The input mags/flux time-series to smooth.

    windowsize : int
        This is a odd integer containing the smoothing window size.

    polyorder : int
        This is an integer containing the polynomial degree order to use when
        generating the Savitsky-Golay filter.

    Returns
    -------

    np.array
        The smoothed mag/flux time-series array.


def _old_epd_diffmags(coeff, fsv, fdv, fkv, xcc, ycc, bgv, bge, mag):

return -(coeff[<NUM_LIT:0>]*fsv**<NUM_LIT> +<EOL>coeff[<NUM_LIT:1>]*fsv +<EOL>coeff[<NUM_LIT:2>]*fdv**<NUM_LIT> +<EOL>coeff[<NUM_LIT:3>]*fdv +<EOL>coeff[<NUM_LIT:4>]*fkv**<NUM_LIT> +<EOL>coeff[<NUM_LIT:5>]*fkv +<EOL>coeff[<NUM_LIT:6>] +<EOL>coeff[<NUM_LIT:7>]*fsv*fdv +<EOL>coeff[<NUM_LIT:8>]*fsv*fkv +<EOL>coeff[<NUM_LIT:9>]*fdv*fkv +<EOL>coeff[<NUM_LIT:10>]*np.sin(<NUM_LIT:2>*np.pi*xcc) +<EOL>coeff[<NUM_LIT:11>]*np.cos(<NUM_LIT:2>*np.pi*xcc) +<EOL>coeff[<NUM_LIT:12>]*np.sin(<NUM_LIT:2>*np.pi*ycc) +<EOL>coeff[<NUM_LIT>]*np.cos(<NUM_LIT:2>*np.pi*ycc) +<EOL>coeff[<NUM_LIT>]*np.sin(<NUM_LIT:4>*np.pi*xcc) +<EOL>coeff[<NUM_LIT:15>]*np.cos(<NUM_LIT:4>*np.pi*xcc) +<EOL>coeff[<NUM_LIT:16>]*np.sin(<NUM_LIT:4>*np.pi*ycc) +<EOL>coeff[<NUM_LIT>]*np.cos(<NUM_LIT:4>*np.pi*ycc) +<EOL>coeff[<NUM_LIT>]*bgv +<EOL>coeff[<NUM_LIT>]*bge -<EOL>mag)<EOL>

This calculates the difference in mags after EPD coefficients are
calculated.

final EPD mags = median(magseries) + epd_diffmags()


def _old_epd_magseries(times, mags, errs,<EOL>fsv, fdv, fkv, xcc, ycc, bgv, bge,<EOL>epdsmooth_windowsize=<NUM_LIT>,<EOL>epdsmooth_sigclip=<NUM_LIT>,<EOL>epdsmooth_func=smooth_magseries_signal_medfilt,<EOL>epdsmooth_extraparams=None):

<EOL>finiteind = np.isfinite(mags)<EOL>mags_median = np.median(mags[finiteind])<EOL>mags_stdev = np.nanstd(mags)<EOL>if epdsmooth_sigclip:<EOL><INDENT>excludeind = abs(mags - mags_median) < epdsmooth_sigclip*mags_stdev<EOL>finalind = finiteind & excludeind<EOL><DEDENT>else:<EOL><INDENT>finalind = finiteind<EOL><DEDENT>final_mags = mags[finalind]<EOL>final_len = len(final_mags)<EOL>if isinstance(epdsmooth_extraparams, dict):<EOL><INDENT>smoothedmags = epdsmooth_func(final_mags,<EOL>epdsmooth_windowsize,<EOL>**epdsmooth_extraparams)<EOL><DEDENT>else:<EOL><INDENT>smoothedmags = epdsmooth_func(final_mags, epdsmooth_windowsize)<EOL><DEDENT>epdmatrix = np.c_[fsv[finalind]**<NUM_LIT>,<EOL>fsv[finalind],<EOL>fdv[finalind]**<NUM_LIT>,<EOL>fdv[finalind],<EOL>fkv[finalind]**<NUM_LIT>,<EOL>fkv[finalind],<EOL>np.ones(final_len),<EOL>fsv[finalind]*fdv[finalind],<EOL>fsv[finalind]*fkv[finalind],<EOL>fdv[finalind]*fkv[finalind],<EOL>np.sin(<NUM_LIT:2>*np.pi*xcc[finalind]),<EOL>np.cos(<NUM_LIT:2>*np.pi*xcc[finalind]),<EOL>np.sin(<NUM_LIT:2>*np.pi*ycc[finalind]),<EOL>np.cos(<NUM_LIT:2>*np.pi*ycc[finalind]),<EOL>np.sin(<NUM_LIT:4>*np.pi*xcc[finalind]),<EOL>np.cos(<NUM_LIT:4>*np.pi*xcc[finalind]),<EOL>np.sin(<NUM_LIT:4>*np.pi*ycc[finalind]),<EOL>np.cos(<NUM_LIT:4>*np.pi*ycc[finalind]),<EOL>bgv[finalind],<EOL>bge[finalind]]<EOL>try:<EOL><INDENT>coeffs, residuals, rank, singulars = lstsq(epdmatrix, smoothedmags,<EOL>rcond=None)<EOL>if DEBUG:<EOL><INDENT>print('<STR_LIT>' % (coeffs, residuals))<EOL><DEDENT>retdict = {'<STR_LIT>':times,<EOL>'<STR_LIT>':(mags_median +<EOL>_old_epd_diffmags(coeffs, fsv, fdv,<EOL>fkv, xcc, ycc, bgv, bge, mags)),<EOL>'<STR_LIT>':errs,<EOL>'<STR_LIT>':coeffs,<EOL>'<STR_LIT>':residuals}<EOL>return retdict<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>')<EOL>retdict = {'<STR_LIT>':times,<EOL>'<STR_LIT>':np.full_like(mags, np.nan),<EOL>'<STR_LIT>':errs,<EOL>'<STR_LIT>':coeffs,<EOL>'<STR_LIT>':residuals}<EOL>return retdict<EOL><DEDENT>

Detrends a magnitude series given in mag using accompanying values of S in
fsv, D in fdv, K in fkv, x coords in xcc, y coords in ycc, background in
bgv, and background error in bge. smooth is used to set a smoothing
parameter for the fit function. Does EPD voodoo.


def _epd_function(coeffs, fsv, fdv, fkv, xcc, ycc, bgv, bge, iha, izd):

return (coeffs[<NUM_LIT:0>]*fsv*fsv +<EOL>coeffs[<NUM_LIT:1>]*fsv +<EOL>coeffs[<NUM_LIT:2>]*fdv*fdv +<EOL>coeffs[<NUM_LIT:3>]*fdv +<EOL>coeffs[<NUM_LIT:4>]*fkv*fkv +<EOL>coeffs[<NUM_LIT:5>]*fkv +<EOL>coeffs[<NUM_LIT:6>] +<EOL>coeffs[<NUM_LIT:7>]*fsv*fdv +<EOL>coeffs[<NUM_LIT:8>]*fsv*fkv +<EOL>coeffs[<NUM_LIT:9>]*fdv*fkv +<EOL>coeffs[<NUM_LIT:10>]*np.sin(<NUM_LIT:2>*pi_value*xcc) +<EOL>coeffs[<NUM_LIT:11>]*np.cos(<NUM_LIT:2>*pi_value*xcc) +<EOL>coeffs[<NUM_LIT:12>]*np.sin(<NUM_LIT:2>*pi_value*ycc) +<EOL>coeffs[<NUM_LIT>]*np.cos(<NUM_LIT:2>*pi_value*ycc) +<EOL>coeffs[<NUM_LIT>]*np.sin(<NUM_LIT:4>*pi_value*xcc) +<EOL>coeffs[<NUM_LIT:15>]*np.cos(<NUM_LIT:4>*pi_value*xcc) +<EOL>coeffs[<NUM_LIT:16>]*np.sin(<NUM_LIT:4>*pi_value*ycc) +<EOL>coeffs[<NUM_LIT>]*np.cos(<NUM_LIT:4>*pi_value*ycc) +<EOL>coeffs[<NUM_LIT>]*bgv +<EOL>coeffs[<NUM_LIT>]*bge +<EOL>coeffs[<NUM_LIT:20>]*iha +<EOL>coeffs[<NUM_LIT>]*izd)<EOL>

This is the EPD function to fit using a smoothed mag-series.


def _epd_residual(coeffs, mags, fsv, fdv, fkv, xcc, ycc, bgv, bge, iha, izd):

f = _epd_function(coeffs, fsv, fdv, fkv, xcc, ycc, bgv, bge, iha, izd)<EOL>residual = mags - f<EOL>return residual<EOL>

This is the residual function to minimize using scipy.optimize.leastsq.


def _epd_residual2(coeffs,<EOL>times, mags, errs,<EOL>fsv, fdv, fkv, xcc, ycc, bgv, bge, iha, izd):

This is the residual function to minimize using
    scipy.optimize.least_squares.

    This variant is for :py:func:`.epd_magseries_extparams`.


def epd_magseries(times, mags, errs,<EOL>fsv, fdv, fkv, xcc, ycc, bgv, bge, iha, izd,<EOL>magsarefluxes=False,<EOL>epdsmooth_sigclip=<NUM_LIT>,<EOL>epdsmooth_windowsize=<NUM_LIT>,<EOL>epdsmooth_func=smooth_magseries_savgol,<EOL>epdsmooth_extraparams=None):

finind = np.isfinite(times) & np.isfinite(mags) & np.isfinite(errs)<EOL>ftimes, fmags, ferrs = times[::][finind], mags[::][finind], errs[::][finind]<EOL>ffsv, ffdv, ffkv, fxcc, fycc, fbgv, fbge, fiha, fizd = (<EOL>fsv[::][finind],<EOL>fdv[::][finind],<EOL>fkv[::][finind],<EOL>xcc[::][finind],<EOL>ycc[::][finind],<EOL>bgv[::][finind],<EOL>bge[::][finind],<EOL>iha[::][finind],<EOL>izd[::][finind],<EOL>)<EOL>stimes, smags, serrs, separams = sigclip_magseries_with_extparams(<EOL>times, mags, errs,<EOL>[fsv, fdv, fkv, xcc, ycc, bgv, bge, iha, izd],<EOL>sigclip=epdsmooth_sigclip,<EOL>magsarefluxes=magsarefluxes<EOL>)<EOL>sfsv, sfdv, sfkv, sxcc, sycc, sbgv, sbge, siha, sizd = separams<EOL>if isinstance(epdsmooth_extraparams, dict):<EOL><INDENT>smoothedmags = epdsmooth_func(smags,<EOL>epdsmooth_windowsize,<EOL>**epdsmooth_extraparams)<EOL><DEDENT>else:<EOL><INDENT>smoothedmags = epdsmooth_func(smags, epdsmooth_windowsize)<EOL><DEDENT>initcoeffs = np.zeros(<NUM_LIT>)<EOL>leastsqfit = leastsq(_epd_residual,<EOL>initcoeffs,<EOL>args=(smoothedmags,<EOL>sfsv, sfdv, sfkv, sxcc,<EOL>sycc, sbgv, sbge, siha, sizd),<EOL>full_output=True)<EOL>if leastsqfit[-<NUM_LIT:1>] in (<NUM_LIT:1>,<NUM_LIT:2>,<NUM_LIT:3>,<NUM_LIT:4>):<EOL><INDENT>fitcoeffs = leastsqfit[<NUM_LIT:0>]<EOL>epdfit = _epd_function(fitcoeffs,<EOL>ffsv, ffdv, ffkv, fxcc, fycc,<EOL>fbgv, fbge, fiha, fizd)<EOL>epdmags = npmedian(fmags) + fmags - epdfit<EOL>retdict = {'<STR_LIT>':ftimes,<EOL>'<STR_LIT>':epdmags,<EOL>'<STR_LIT>':ferrs,<EOL>'<STR_LIT>':fitcoeffs,<EOL>'<STR_LIT>':leastsqfit,<EOL>'<STR_LIT>':epdfit,<EOL>'<STR_LIT>':npmedian(epdmags),<EOL>'<STR_LIT>':npmedian(npabs(epdmags - npmedian(epdmags)))}<EOL>return retdict<EOL><DEDENT>else:<EOL><INDENT>LOGERROR('<STR_LIT>')<EOL>return None<EOL><DEDENT>

Detrends a magnitude series using External Parameter Decorrelation.

    Requires a set of external parameters similar to those present in HAT light
    curves. At the moment, the HAT light-curve-specific external parameters are:

    - S: the 'fsv' column in light curves,
    - D: the 'fdv' column in light curves,
    - K: the 'fkv' column in light curves,
    - x coords: the 'xcc' column in light curves,
    - y coords: the 'ycc' column in light curves,
    - background value: the 'bgv' column in light curves,
    - background error: the 'bge' column in light curves,
    - hour angle: the 'iha' column in light curves,
    - zenith distance: the 'izd' column in light curves

    S, D, and K are defined as follows:

    - S -> measure of PSF sharpness (~1/sigma^2 sosmaller S = wider PSF)
    - D -> measure of PSF ellipticity in xy direction
    - K -> measure of PSF ellipticity in cross direction

    S, D, K are related to the PSF's variance and covariance, see eqn 30-33 in
    A. Pal's thesis: https://arxiv.org/abs/0906.3486

    NOTE: The errs are completely ignored and returned unchanged (except for
    sigclip and finite filtering).

    Parameters
    ----------

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

    fsv : np.array
        Array containing the external parameter `S` of the same length as times.

    fdv : np.array
        Array containing the external parameter `D` of the same length as times.

    fkv : np.array
        Array containing the external parameter `K` of the same length as times.

    xcc : np.array
        Array containing the external parameter `x-coords` of the same length as
        times.

    ycc : np.array
        Array containing the external parameter `y-coords` of the same length as
        times.

    bgv : np.array
        Array containing the external parameter `background value` of the same
        length as times.

    bge : np.array
        Array containing the external parameter `background error` of the same
        length as times.

    iha : np.array
        Array containing the external parameter `hour angle` of the same length
        as times.

    izd : np.array
        Array containing the external parameter `zenith distance` of the same
        length as times.

    magsarefluxes : bool
        Set this to True if `mags` actually contains fluxes.

    epdsmooth_sigclip : float or int or sequence of two floats/ints or None
        This specifies how to sigma-clip the input LC before fitting the EPD
        function to it.

        If a single float or int, a symmetric sigma-clip will be performed using
        the number provided as the sigma-multiplier to cut out from the input
        time-series.

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

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

    epdsmooth_windowsize : int
        This is the number of LC points to smooth over to generate a smoothed
        light curve that will be used to fit the EPD function.

    epdsmooth_func : Python function
        This sets the smoothing filter function to use. A Savitsky-Golay filter
        is used to smooth the light curve by default. The functions that can be
        used with this kwarg are listed in `varbase.trends`. If you want to use
        your own function, it MUST have the following signature::

                def smoothfunc(mags_array, window_size, **extraparams)

        and return a numpy array of the same size as `mags_array` with the
        smoothed time-series. Any extra params can be provided using the
        `extraparams` dict.

    epdsmooth_extraparams : dict
        This is a dict of any extra filter params to supply to the smoothing
        function.

    Returns
    -------

    dict
        Returns a dict of the following form::

            {'times':the input times after non-finite elems removed,
             'mags':the EPD detrended mag values (the EPD mags),
             'errs':the errs after non-finite elems removed,
             'fitcoeffs':EPD fit coefficient values,
             'fitinfo':the full tuple returned by scipy.leastsq,
             'fitmags':the EPD fit function evaluated at times,
             'mags_median': this is median of the EPD mags,
             'mags_mad': this is the MAD of EPD mags}