signature:
def plot_periodicvar_recovery_results ( precvar_results , aliases_count_as_recovered = None , magbins = None , periodbins = None , amplitudebins = None , ndetbins = None , minbinsize = 1 , plotfile_ext = 'png' , ) :
    '''This plots the results of periodic var recovery .
 This function makes plots for periodicvar recovered fraction as a function
 of :
 - magbin
 - periodbin
 - amplitude of variability
 - ndet
 with plot lines broken down by :
 - magcol
 - periodfinder
 - vartype
 - recovery status
 The kwargs ` magbins ` , ` periodbins ` , ` amplitudebins ` , and ` ndetbins ` can be
 used to set the bin lists as needed . The kwarg ` minbinsize ` controls how
 many elements per bin are required to accept a bin in processing its
 recovery characteristics for mags , periods , amplitudes , and ndets .
 Parameters
 precvar _ results : dict or str
 This is either a dict returned by parallel _ periodicvar _ recovery or the
 pickle created by that function .
 aliases _ count _ as _ recovered : list of str or ' all '
 This is used to set which kinds of aliases this function considers as
 ' recovered ' objects . Normally , we require that recovered objects have a
 recovery status of ' actual ' to indicate the actual period was
 recovered . To change this default behavior , aliases _ count _ as _ recovered
 can be set to a list of alias status strings that should be considered
 as ' recovered ' objects as well . Choose from the following alias types : :
 ' twice ' recovered _ p = 2.0 * actual _ p
 ' half ' recovered _ p = 0.5 * actual _ p
 ' ratio _ over _ 1plus ' recovered _ p = actual _ p / ( 1.0 + actual _ p )
 ' ratio _ over _ 1minus ' recovered _ p = actual _ p / ( 1.0 - actual _ p )
 ' ratio _ over _ 1plus _ twice ' recovered _ p = actual _ p / ( 1.0 + 2.0 * actual _ p )
 ' ratio _ over _ 1minus _ twice ' recovered _ p = actual _ p / ( 1.0-2.0 * actual _ p )
 ' ratio _ over _ 1plus _ thrice ' recovered _ p = actual _ p / ( 1.0 + 3.0 * actual _ p )
 ' ratio _ over _ 1minus _ thrice ' recovered _ p = actual _ p / ( 1.0-3.0 * actual _ p )
 ' ratio _ over _ minus1 ' recovered _ p = actual _ p / ( actual _ p - 1.0)
 ' ratio _ over _ twice _ minus1 ' recovered _ p = actual _ p / ( 2.0 * actual _ p - 1.0)
 or set ` aliases _ count _ as _ recovered = ' all ' ` to include all of the above in
 the ' recovered ' periodic var list .
 magbins : np . array
 The magnitude bins to plot the recovery rate results over . If None , the
 default mag bins will be used : ` np . arange ( 8.0,16.25,0.25 ) ` .
 periodbins : np . array
 The period bins to plot the recovery rate results over . If None , the
 default period bins will be used : ` np . arange ( 0.0,500.0,0.5 ) ` .
 amplitudebins : np . array
 The variability amplitude bins to plot the recovery rate results
 over . If None , the default amplitude bins will be used :
 ` np . arange ( 0.0,2.0,0.05 ) ` .
 ndetbins : np . array
 The ndet bins to plot the recovery rate results over . If None , the
 default ndet bins will be used : ` np . arange ( 0.0,60000.0,1000.0 ) ` .
 minbinsize : int
 The minimum number of objects per bin required to plot a bin and its
 recovery fraction on the plot .
 plotfile _ ext : { ' png ' , ' pdf ' }
 Sets the plot output files ' extension .
 Returns
 dict
 A dict containing recovery fraction statistics and the paths to each of
 the plots made .'''

implementation:
# get the result pickle / dict
if isinstance ( precvar_results , str ) and os . path . exists ( precvar_results ) :
    with open ( precvar_results , 'rb' ) as infd :
        precvar = pickle . load ( infd )
elif isinstance ( precvar_results , dict ) :
    precvar = precvar_results
else :
    LOGERROR ( 'could not understand the input ' 'periodic var recovery dict/pickle' )
    return None
# get the simbasedir and open the fakelc - info . pkl . we ' ll need the magbins
# definition from here .
simbasedir = precvar [ 'simbasedir' ]
lcinfof = os . path . join ( simbasedir , 'fakelcs-info.pkl' )
if not os . path . exists ( lcinfof ) :
    LOGERROR ( 'fakelcs-info.pkl does not exist in %s, can\'t continue' % simbasedir )
    return None
with open ( lcinfof , 'rb' ) as infd :
    lcinfo = pickle . load ( infd )
# get the magcols , vartypes , sdssr , isvariable flags
magcols = lcinfo [ 'magcols' ]
objectid = lcinfo [ 'objectid' ]
ndet = lcinfo [ 'ndet' ]
sdssr = lcinfo [ 'sdssr' ]
# get the actual periodic vars
actual_periodicvars = precvar [ 'actual_periodicvars' ]
# generate lists of objects binned by magbins and periodbins
LOGINFO ( 'getting sdssr and ndet for actual periodic vars...' )
# get the sdssr and ndet for all periodic vars
periodicvar_sdssr = [ ]
periodicvar_ndet = [ ]
periodicvar_objectids = [ ]
for pobj in actual_periodicvars :
    pobjind = objectid == pobj
    periodicvar_objectids . append ( pobj )
    periodicvar_sdssr . append ( sdssr [ pobjind ] )
    periodicvar_ndet . append ( ndet [ pobjind ] )
periodicvar_sdssr = np . array ( periodicvar_sdssr )
periodicvar_objectids = np . array ( periodicvar_objectids )
periodicvar_ndet = np . array ( periodicvar_ndet )
LOGINFO ( 'getting periods, vartypes, ' 'amplitudes, ndet for actual periodic vars...' )
# get the periods , vartypes , amplitudes for the actual periodic vars
periodicvar_periods = [ np . asscalar ( precvar [ 'details' ] [ x ] [ 'actual_varperiod' ] ) for x in periodicvar_objectids ]
periodicvar_amplitudes = [ np . asscalar ( precvar [ 'details' ] [ x ] [ 'actual_varamplitude' ] ) for x in periodicvar_objectids ]
periodicvar_vartypes = [ precvar [ 'details' ] [ x ] [ 'actual_vartype' ] for x in periodicvar_objectids ]
# do the binning
# bin by mag
LOGINFO ( 'binning actual periodic vars by magnitude...' )
magbinned_sdssr = [ ]
magbinned_periodicvars = [ ]
if not magbins :
    magbins = PERIODREC_DEFAULT_MAGBINS
magbininds = np . digitize ( np . ravel ( periodicvar_sdssr ) , magbins )
for mbinind , magi in zip ( np . unique ( magbininds ) , range ( len ( magbins ) - 1 ) ) :
    thisbin_periodicvars = periodicvar_objectids [ magbininds == mbinind ]
    if ( thisbin_periodicvars . size > ( minbinsize - 1 ) ) :
        magbinned_sdssr . append ( ( magbins [ magi ] + magbins [ magi + 1 ] ) / 2.0 )
        magbinned_periodicvars . append ( thisbin_periodicvars )
# bin by period
LOGINFO ( 'binning actual periodic vars by period...' )
periodbinned_periods = [ ]
periodbinned_periodicvars = [ ]
if not periodbins :
    periodbins = PERIODREC_DEFAULT_PERIODBINS
periodbininds = np . digitize ( np . ravel ( periodicvar_periods ) , periodbins )
for pbinind , peri in zip ( np . unique ( periodbininds ) , range ( len ( periodbins ) - 1 ) ) :
    thisbin_periodicvars = periodicvar_objectids [ periodbininds == pbinind ]
    if ( thisbin_periodicvars . size > ( minbinsize - 1 ) ) :
        periodbinned_periods . append ( ( periodbins [ peri ] + periodbins [ peri + 1 ] ) / 2.0 )
        periodbinned_periodicvars . append ( thisbin_periodicvars )
# bin by amplitude of variability
LOGINFO ( 'binning actual periodic vars by variability amplitude...' )
amplitudebinned_amplitudes = [ ]
amplitudebinned_periodicvars = [ ]
if not amplitudebins :
    amplitudebins = PERIODREC_DEFAULT_AMPBINS
amplitudebininds = np . digitize ( np . ravel ( np . abs ( periodicvar_amplitudes ) ) , amplitudebins )
for abinind , ampi in zip ( np . unique ( amplitudebininds ) , range ( len ( amplitudebins ) - 1 ) ) :
    thisbin_periodicvars = periodicvar_objectids [ amplitudebininds == abinind ]
    if ( thisbin_periodicvars . size > ( minbinsize - 1 ) ) :
        amplitudebinned_amplitudes . append ( ( amplitudebins [ ampi ] + amplitudebins [ ampi + 1 ] ) / 2.0 )
        amplitudebinned_periodicvars . append ( thisbin_periodicvars )
# bin by ndet
LOGINFO ( 'binning actual periodic vars by ndet...' )
ndetbinned_ndets = [ ]
ndetbinned_periodicvars = [ ]
if not ndetbins :
    ndetbins = PERIODREC_DEFAULT_NDETBINS
ndetbininds = np . digitize ( np . ravel ( periodicvar_ndet ) , ndetbins )
for nbinind , ndeti in zip ( np . unique ( ndetbininds ) , range ( len ( ndetbins ) - 1 ) ) :
    thisbin_periodicvars = periodicvar_objectids [ ndetbininds == nbinind ]
    if ( thisbin_periodicvars . size > ( minbinsize - 1 ) ) :
        ndetbinned_ndets . append ( ( ndetbins [ ndeti ] + ndetbins [ ndeti + 1 ] ) / 2.0 )
        ndetbinned_periodicvars . append ( thisbin_periodicvars )
# now figure out what ' recovered ' means using the provided
# aliases _ count _ as _ recovered kwarg
recovered_status = [ 'actual' ]
if isinstance ( aliases_count_as_recovered , list ) :
    for atype in aliases_count_as_recovered :
        if atype in ALIAS_TYPES :
            recovered_status . append ( atype )
        else :
            LOGWARNING ( 'unknown alias type: %s, skipping' % atype )
elif aliases_count_as_recovered and aliases_count_as_recovered == 'all' :
    for atype in ALIAS_TYPES [ 1 : ] :
        recovered_status . append ( atype )
# find all the matching objects for these recovered statuses
recovered_periodicvars = np . array ( [ precvar [ 'details' ] [ x ] [ 'objectid' ] for x in precvar [ 'details' ] if ( precvar [ 'details' ] [ x ] is not None and precvar [ 'details' ] [ x ] [ 'best_recovered_status' ] in recovered_status ) ] , dtype = np . unicode_ )
LOGINFO ( 'recovered %s/%s periodic variables (frac: %.3f) with ' 'period recovery status: %s' % ( recovered_periodicvars . size , actual_periodicvars . size , float ( recovered_periodicvars . size / actual_periodicvars . size ) , ', ' . join ( recovered_status ) ) )
# get the objects recovered per bin and overall recovery fractions per bin
magbinned_recovered_objects = [ np . intersect1d ( x , recovered_periodicvars ) for x in magbinned_periodicvars ]
magbinned_recfrac = np . array ( [ float ( x . size / y . size ) for x , y in zip ( magbinned_recovered_objects , magbinned_periodicvars ) ] )
periodbinned_recovered_objects = [ np . intersect1d ( x , recovered_periodicvars ) for x in periodbinned_periodicvars ]
periodbinned_recfrac = np . array ( [ float ( x . size / y . size ) for x , y in zip ( periodbinned_recovered_objects , periodbinned_periodicvars ) ] )
amplitudebinned_recovered_objects = [ np . intersect1d ( x , recovered_periodicvars ) for x in amplitudebinned_periodicvars ]
amplitudebinned_recfrac = np . array ( [ float ( x . size / y . size ) for x , y in zip ( amplitudebinned_recovered_objects , amplitudebinned_periodicvars ) ] )
ndetbinned_recovered_objects = [ np . intersect1d ( x , recovered_periodicvars ) for x in ndetbinned_periodicvars ]
ndetbinned_recfrac = np . array ( [ float ( x . size / y . size ) for x , y in zip ( ndetbinned_recovered_objects , ndetbinned_periodicvars ) ] )
# convert the bin medians to arrays
magbinned_sdssr = np . array ( magbinned_sdssr )
periodbinned_periods = np . array ( periodbinned_periods )
amplitudebinned_amplitudes = np . array ( amplitudebinned_amplitudes )
ndetbinned_ndets = np . array ( ndetbinned_ndets )
# this is the initial output dict
outdict = { 'simbasedir' : simbasedir , 'precvar_results' : precvar , 'magcols' : magcols , 'objectids' : objectid , 'ndet' : ndet , 'sdssr' : sdssr , 'actual_periodicvars' : actual_periodicvars , 'recovered_periodicvars' : recovered_periodicvars , 'recovery_definition' : recovered_status , # mag binned actual periodicvars
# note that only bins with nobjects > minbinsize are included
'magbins' : magbins , 'magbinned_mags' : magbinned_sdssr , 'magbinned_periodicvars' : magbinned_periodicvars , 'magbinned_recoveredvars' : magbinned_recovered_objects , 'magbinned_recfrac' : magbinned_recfrac , # period binned actual periodicvars
# note that only bins with nobjects > minbinsize are included
'periodbins' : periodbins , 'periodbinned_periods' : periodbinned_periods , 'periodbinned_periodicvars' : periodbinned_periodicvars , 'periodbinned_recoveredvars' : periodbinned_recovered_objects , 'periodbinned_recfrac' : periodbinned_recfrac , # amplitude binned actual periodicvars
# note that only bins with nobjects > minbinsize are included
'amplitudebins' : amplitudebins , 'amplitudebinned_amplitudes' : amplitudebinned_amplitudes , 'amplitudebinned_periodicvars' : amplitudebinned_periodicvars , 'amplitudebinned_recoveredvars' : amplitudebinned_recovered_objects , 'amplitudebinned_recfrac' : amplitudebinned_recfrac , # ndet binned actual periodicvars
# note that only bins with nobjects > minbinsize are included
'ndetbins' : ndetbins , 'ndetbinned_ndets' : ndetbinned_ndets , 'ndetbinned_periodicvars' : ndetbinned_periodicvars , 'ndetbinned_recoveredvars' : ndetbinned_recovered_objects , 'ndetbinned_recfrac' : ndetbinned_recfrac , }
# figure out which pfmethods were used
all_pfmethods = np . unique ( np . concatenate ( [ np . unique ( precvar [ 'details' ] [ x ] [ 'recovery_pfmethods' ] ) for x in precvar [ 'details' ] ] ) )
# figure out all vartypes
all_vartypes = np . unique ( [ ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] ) for x in precvar [ 'details' ] if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] is not None ) ] )
# figure out all alias types
all_aliastypes = recovered_status
# add these to the outdict
outdict [ 'aliastypes' ] = all_aliastypes
outdict [ 'pfmethods' ] = all_pfmethods
outdict [ 'vartypes' ] = all_vartypes
# these are recfracs per - magcol , - vartype , - periodfinder , - aliastype
# binned appropriately by mags , periods , amplitudes , and ndet
# all of these have the shape as the magcols , aliastypes , pfmethods , and
# vartypes lists above .
magbinned_per_magcol_recfracs = [ ]
magbinned_per_vartype_recfracs = [ ]
magbinned_per_pfmethod_recfracs = [ ]
magbinned_per_aliastype_recfracs = [ ]
periodbinned_per_magcol_recfracs = [ ]
periodbinned_per_vartype_recfracs = [ ]
periodbinned_per_pfmethod_recfracs = [ ]
periodbinned_per_aliastype_recfracs = [ ]
amplitudebinned_per_magcol_recfracs = [ ]
amplitudebinned_per_vartype_recfracs = [ ]
amplitudebinned_per_pfmethod_recfracs = [ ]
amplitudebinned_per_aliastype_recfracs = [ ]
ndetbinned_per_magcol_recfracs = [ ]
ndetbinned_per_vartype_recfracs = [ ]
ndetbinned_per_pfmethod_recfracs = [ ]
ndetbinned_per_aliastype_recfracs = [ ]
# finally , we do stuff for the plots !
recplotdir = os . path . join ( simbasedir , 'periodic-variable-recovery-plots' )
if not os . path . exists ( recplotdir ) :
    os . mkdir ( recplotdir )
# 1 . recovery - rate by magbin
# 1a . plot of overall recovery rate per magbin
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
plt . plot ( magbinned_sdssr , magbinned_recfrac , marker = '.' , ms = 0.0 )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'overall recovery fraction by periodic var magnitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-magnitudes-overall.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 1b . plot of recovery rate per magbin per magcol
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
for magcol in magcols :
    thismagcol_recfracs = [ ]
    for magbin_pv , magbin_rv in zip ( magbinned_periodicvars , magbinned_recovered_objects ) :
        thisbin_thismagcol_recvars = [ x for x in magbin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_magcol' ] == magcol ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thismagcol_recvars ) . size / magbin_pv . size )
        thismagcol_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( magbinned_sdssr , np . array ( thismagcol_recfracs ) , marker = '.' , label = 'magcol: %s' % magcol , ms = 0.0 )
    # add this to the outdict array
    magbinned_per_magcol_recfracs . append ( np . array ( thismagcol_recfracs ) )
# finish up the plot
plt . plot ( magbinned_sdssr , magbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per magcol recovery fraction by periodic var magnitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-magnitudes-magcols.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 1c . plot of recovery rate per magbin per periodfinder
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out which pfmethods were used
all_pfmethods = np . unique ( np . concatenate ( [ np . unique ( precvar [ 'details' ] [ x ] [ 'recovery_pfmethods' ] ) for x in precvar [ 'details' ] ] ) )
for pfm in all_pfmethods :
    thispf_recfracs = [ ]
    for magbin_pv , magbin_rv in zip ( magbinned_periodicvars , magbinned_recovered_objects ) :
        thisbin_thispf_recvars = [ x for x in magbin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_pfmethod' ] == pfm ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thispf_recvars ) . size / magbin_pv . size )
        thispf_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( magbinned_sdssr , np . array ( thispf_recfracs ) , marker = '.' , label = '%s' % pfm . upper ( ) , ms = 0.0 )
    # add this to the outdict array
    magbinned_per_pfmethod_recfracs . append ( np . array ( thispf_recfracs ) )
# finish up the plot
plt . plot ( magbinned_sdssr , magbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per period-finder recovery fraction by periodic var magnitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-magnitudes-pfmethod.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 1d . plot of recovery rate per magbin per variable type
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out all vartypes
all_vartypes = np . unique ( [ ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] ) for x in precvar [ 'details' ] if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] is not None ) ] )
for vt in all_vartypes :
    thisvt_recfracs = [ ]
    for magbin_pv , magbin_rv in zip ( magbinned_periodicvars , magbinned_recovered_objects ) :
        thisbin_thisvt_recvars = [ x for x in magbin_rv if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] == vt ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thisvt_recvars ) . size / magbin_pv . size )
        thisvt_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( magbinned_sdssr , np . array ( thisvt_recfracs ) , marker = '.' , label = '%s' % vt , ms = 0.0 )
    # add this to the outdict array
    magbinned_per_vartype_recfracs . append ( np . array ( thisvt_recfracs ) )
# finish up the plot
plt . plot ( magbinned_sdssr , magbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per vartype recovery fraction by periodic var magnitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-magnitudes-vartype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 1e . plot of recovery rate per magbin per alias type
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out all alias types
all_aliastypes = recovered_status
for at in all_aliastypes :
    thisat_recfracs = [ ]
    for magbin_pv , magbin_rv in zip ( magbinned_periodicvars , magbinned_recovered_objects ) :
        thisbin_thisat_recvars = [ x for x in magbin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_status' ] [ 0 ] == at ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thisat_recvars ) . size / magbin_pv . size )
        thisat_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( magbinned_sdssr , np . array ( thisat_recfracs ) , marker = '.' , label = '%s' % at , ms = 0.0 )
    # add this to the outdict array
    magbinned_per_aliastype_recfracs . append ( np . array ( thisat_recfracs ) )
# finish up the plot
plt . plot ( magbinned_sdssr , magbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per alias-type recovery fraction by periodic var magnitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-magnitudes-aliastype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 2 . recovery - rate by periodbin
# 2a . plot of overall recovery rate per periodbin
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
plt . plot ( periodbinned_periods , periodbinned_recfrac , marker = '.' , ms = 0.0 )
plt . xlabel ( 'periodic variable period [days]' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'overall recovery fraction by periodic var periods' )
plt . ylim ( ( 0 , 1 ) )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-periods-overall.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 2b . plot of recovery rate per periodbin per magcol
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
for magcol in magcols :
    thismagcol_recfracs = [ ]
    for periodbin_pv , periodbin_rv in zip ( periodbinned_periodicvars , periodbinned_recovered_objects ) :
        thisbin_thismagcol_recvars = [ x for x in periodbin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_magcol' ] == magcol ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thismagcol_recvars ) . size / periodbin_pv . size )
        thismagcol_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( periodbinned_periods , np . array ( thismagcol_recfracs ) , marker = '.' , label = 'magcol: %s' % magcol , ms = 0.0 )
    # add this to the outdict array
    periodbinned_per_magcol_recfracs . append ( np . array ( thismagcol_recfracs ) )
# finish up the plot
plt . plot ( periodbinned_periods , periodbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per magcol recovery fraction by periodic var periods' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-periods-magcols.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 2c . plot of recovery rate per periodbin per periodfinder
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out which pfmethods were used
all_pfmethods = np . unique ( np . concatenate ( [ np . unique ( precvar [ 'details' ] [ x ] [ 'recovery_pfmethods' ] ) for x in precvar [ 'details' ] ] ) )
for pfm in all_pfmethods :
    thispf_recfracs = [ ]
    for periodbin_pv , periodbin_rv in zip ( periodbinned_periodicvars , periodbinned_recovered_objects ) :
        thisbin_thispf_recvars = [ x for x in periodbin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_pfmethod' ] == pfm ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thispf_recvars ) . size / periodbin_pv . size )
        thispf_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( periodbinned_periods , np . array ( thispf_recfracs ) , marker = '.' , label = '%s' % pfm . upper ( ) , ms = 0.0 )
    # add this to the outdict array
    periodbinned_per_pfmethod_recfracs . append ( np . array ( thispf_recfracs ) )
# finish up the plot
plt . plot ( periodbinned_periods , periodbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per period-finder recovery fraction by periodic var periods' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-periods-pfmethod.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 2d . plot of recovery rate per periodbin per variable type
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out all vartypes
all_vartypes = np . unique ( [ ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] ) for x in precvar [ 'details' ] if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] is not None ) ] )
for vt in all_vartypes :
    thisvt_recfracs = [ ]
    for periodbin_pv , periodbin_rv in zip ( periodbinned_periodicvars , periodbinned_recovered_objects ) :
        thisbin_thisvt_recvars = [ x for x in periodbin_rv if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] == vt ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thisvt_recvars ) . size / periodbin_pv . size )
        thisvt_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( periodbinned_periods , np . array ( thisvt_recfracs ) , marker = '.' , label = '%s' % vt , ms = 0.0 )
    # add this to the outdict array
    periodbinned_per_vartype_recfracs . append ( np . array ( thisvt_recfracs ) )
# finish up the plot
plt . plot ( periodbinned_periods , periodbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per vartype recovery fraction by periodic var magnitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-periods-vartype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 2e . plot of recovery rate per periodbin per alias type
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out all vartypes
all_aliastypes = recovered_status
for at in all_aliastypes :
    thisat_recfracs = [ ]
    for periodbin_pv , periodbin_rv in zip ( periodbinned_periodicvars , periodbinned_recovered_objects ) :
        thisbin_thisat_recvars = [ x for x in periodbin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_status' ] [ 0 ] == at ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thisat_recvars ) . size / periodbin_pv . size )
        thisat_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( periodbinned_periods , np . array ( thisat_recfracs ) , marker = '.' , label = '%s' % at , ms = 0.0 )
    # add this to the outdict array
    periodbinned_per_aliastype_recfracs . append ( np . array ( thisat_recfracs ) )
# finish up the plot
plt . plot ( periodbinned_periods , periodbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per alias-type recovery fraction by periodic var magnitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-periods-aliastype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 3 . recovery - rate by amplitude bin
# 3a . plot of overall recovery rate per amplitude bin
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
plt . plot ( amplitudebinned_amplitudes , amplitudebinned_recfrac , marker = '.' , ms = 0.0 )
plt . xlabel ( 'periodic variable amplitude [mag]' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'overall recovery fraction by periodic var amplitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-amplitudes-overall.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 3b . plot of recovery rate per amplitude bin per magcol
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
for magcol in magcols :
    thismagcol_recfracs = [ ]
    for amplitudebin_pv , amplitudebin_rv in zip ( amplitudebinned_periodicvars , amplitudebinned_recovered_objects ) :
        thisbin_thismagcol_recvars = [ x for x in amplitudebin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_magcol' ] == magcol ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thismagcol_recvars ) . size / amplitudebin_pv . size )
        thismagcol_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( amplitudebinned_amplitudes , np . array ( thismagcol_recfracs ) , marker = '.' , label = 'magcol: %s' % magcol , ms = 0.0 )
    # add this to the outdict array
    amplitudebinned_per_magcol_recfracs . append ( np . array ( thismagcol_recfracs ) )
# finish up the plot
plt . plot ( amplitudebinned_amplitudes , amplitudebinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per magcol recovery fraction by periodic var amplitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-amplitudes-magcols.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 3c . plot of recovery rate per amplitude bin per periodfinder
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out which pfmethods were used
all_pfmethods = np . unique ( np . concatenate ( [ np . unique ( precvar [ 'details' ] [ x ] [ 'recovery_pfmethods' ] ) for x in precvar [ 'details' ] ] ) )
for pfm in all_pfmethods :
    thispf_recfracs = [ ]
    for amplitudebin_pv , amplitudebin_rv in zip ( amplitudebinned_periodicvars , amplitudebinned_recovered_objects ) :
        thisbin_thispf_recvars = [ x for x in amplitudebin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_pfmethod' ] == pfm ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thispf_recvars ) . size / amplitudebin_pv . size )
        thispf_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( amplitudebinned_amplitudes , np . array ( thispf_recfracs ) , marker = '.' , label = '%s' % pfm . upper ( ) , ms = 0.0 )
    # add this to the outdict array
    amplitudebinned_per_pfmethod_recfracs . append ( np . array ( thispf_recfracs ) )
# finish up the plot
plt . plot ( amplitudebinned_amplitudes , amplitudebinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per period-finder recovery fraction by periodic var amplitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-amplitudes-pfmethod.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 3d . plot of recovery rate per amplitude bin per variable type
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out all vartypes
all_vartypes = np . unique ( [ ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] ) for x in precvar [ 'details' ] if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] is not None ) ] )
for vt in all_vartypes :
    thisvt_recfracs = [ ]
    for amplitudebin_pv , amplitudebin_rv in zip ( amplitudebinned_periodicvars , amplitudebinned_recovered_objects ) :
        thisbin_thisvt_recvars = [ x for x in amplitudebin_rv if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] == vt ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thisvt_recvars ) . size / amplitudebin_pv . size )
        thisvt_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( amplitudebinned_amplitudes , np . array ( thisvt_recfracs ) , marker = '.' , label = '%s' % vt , ms = 0.0 )
    # add this to the outdict array
    amplitudebinned_per_vartype_recfracs . append ( np . array ( thisvt_recfracs ) )
# finish up the plot
plt . plot ( amplitudebinned_amplitudes , amplitudebinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per vartype recovery fraction by periodic var amplitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-amplitudes-vartype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 3e . plot of recovery rate per amplitude bin per alias type
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out all vartypes
all_aliastypes = recovered_status
for at in all_aliastypes :
    thisat_recfracs = [ ]
    for amplitudebin_pv , amplitudebin_rv in zip ( amplitudebinned_periodicvars , amplitudebinned_recovered_objects ) :
        thisbin_thisat_recvars = [ x for x in amplitudebin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_status' ] [ 0 ] == at ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thisat_recvars ) . size / amplitudebin_pv . size )
        thisat_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( amplitudebinned_amplitudes , np . array ( thisat_recfracs ) , marker = '.' , label = '%s' % at , ms = 0.0 )
    # add this to the outdict array
    amplitudebinned_per_aliastype_recfracs . append ( np . array ( thisat_recfracs ) )
# finish up the plot
plt . plot ( amplitudebinned_amplitudes , amplitudebinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per alias-type recovery fraction by periodic var amplitudes' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-amplitudes-aliastype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 4 . recovery - rate by ndet bin
# 4a . plot of overall recovery rate per ndet bin
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
plt . plot ( ndetbinned_ndets , ndetbinned_recfrac , marker = '.' , ms = 0.0 )
plt . xlabel ( 'periodic variable light curve points' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'overall recovery fraction by periodic var ndet' )
plt . ylim ( ( 0 , 1 ) )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-ndet-overall.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 4b . plot of recovery rate per ndet bin per magcol
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
for magcol in magcols :
    thismagcol_recfracs = [ ]
    for ndetbin_pv , ndetbin_rv in zip ( ndetbinned_periodicvars , ndetbinned_recovered_objects ) :
        thisbin_thismagcol_recvars = [ x for x in ndetbin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_magcol' ] == magcol ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thismagcol_recvars ) . size / ndetbin_pv . size )
        thismagcol_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( ndetbinned_ndets , np . array ( thismagcol_recfracs ) , marker = '.' , label = 'magcol: %s' % magcol , ms = 0.0 )
    # add this to the outdict array
    ndetbinned_per_magcol_recfracs . append ( np . array ( thismagcol_recfracs ) )
# finish up the plot
plt . plot ( ndetbinned_ndets , ndetbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per magcol recovery fraction by periodic var ndets' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-ndet-magcols.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 4c . plot of recovery rate per ndet bin per periodfinder
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out which pfmethods were used
all_pfmethods = np . unique ( np . concatenate ( [ np . unique ( precvar [ 'details' ] [ x ] [ 'recovery_pfmethods' ] ) for x in precvar [ 'details' ] ] ) )
for pfm in all_pfmethods :
    thispf_recfracs = [ ]
    for ndetbin_pv , ndetbin_rv in zip ( ndetbinned_periodicvars , ndetbinned_recovered_objects ) :
        thisbin_thispf_recvars = [ x for x in ndetbin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_pfmethod' ] == pfm ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thispf_recvars ) . size / ndetbin_pv . size )
        thispf_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( ndetbinned_ndets , np . array ( thispf_recfracs ) , marker = '.' , label = '%s' % pfm . upper ( ) , ms = 0.0 )
    # add this to the outdict array
    ndetbinned_per_pfmethod_recfracs . append ( np . array ( thispf_recfracs ) )
# finish up the plot
plt . plot ( ndetbinned_ndets , ndetbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per period-finder recovery fraction by periodic var ndets' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-ndet-pfmethod.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 4d . plot of recovery rate per ndet bin per variable type
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out all vartypes
all_vartypes = np . unique ( [ ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] ) for x in precvar [ 'details' ] if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] in PERIODIC_VARTYPES ) ] )
for vt in all_vartypes :
    thisvt_recfracs = [ ]
    for ndetbin_pv , ndetbin_rv in zip ( ndetbinned_periodicvars , ndetbinned_recovered_objects ) :
        thisbin_thisvt_recvars = [ x for x in ndetbin_rv if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] == vt ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thisvt_recvars ) . size / ndetbin_pv . size )
        thisvt_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( ndetbinned_ndets , np . array ( thisvt_recfracs ) , marker = '.' , label = '%s' % vt , ms = 0.0 )
    # add this to the outdict array
    ndetbinned_per_vartype_recfracs . append ( np . array ( thisvt_recfracs ) )
# finish up the plot
plt . plot ( ndetbinned_ndets , ndetbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per vartype recovery fraction by periodic var ndets' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-ndet-vartype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 4e . plot of recovery rate per ndet bin per alias type
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
# figure out all vartypes
all_aliastypes = recovered_status
for at in all_aliastypes :
    thisat_recfracs = [ ]
    for ndetbin_pv , ndetbin_rv in zip ( ndetbinned_periodicvars , ndetbinned_recovered_objects ) :
        thisbin_thisat_recvars = [ x for x in ndetbin_rv if ( precvar [ 'details' ] [ x ] [ 'best_recovered_status' ] [ 0 ] == at ) ]
        thisbin_thismagcol_recfrac = ( np . array ( thisbin_thisat_recvars ) . size / ndetbin_pv . size )
        thisat_recfracs . append ( thisbin_thismagcol_recfrac )
    # now that we have per magcol recfracs , plot them
    plt . plot ( ndetbinned_ndets , np . array ( thisat_recfracs ) , marker = '.' , label = '%s' % at , ms = 0.0 )
    # add this to the outdict array
    ndetbinned_per_aliastype_recfracs . append ( np . array ( thisat_recfracs ) )
# finish up the plot
plt . plot ( ndetbinned_ndets , ndetbinned_recfrac , marker = '.' , ms = 0.0 , label = 'overall' , color = 'k' )
plt . xlabel ( r'SDSS $r$ magnitude' )
plt . ylabel ( 'recovered fraction of periodic variables' )
plt . title ( 'per alias-type recovery fraction by periodic var ndets' )
plt . ylim ( ( 0 , 1 ) )
plt . legend ( markerscale = 10.0 )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-binned-ndet-aliastype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# update the lists in the outdict
outdict [ 'magbinned_per_magcol_recfracs' ] = ( magbinned_per_magcol_recfracs )
outdict [ 'magbinned_per_pfmethod_recfracs' ] = ( magbinned_per_pfmethod_recfracs )
outdict [ 'magbinned_per_vartype_recfracs' ] = ( magbinned_per_vartype_recfracs )
outdict [ 'magbinned_per_aliastype_recfracs' ] = ( magbinned_per_aliastype_recfracs )
outdict [ 'periodbinned_per_magcol_recfracs' ] = ( periodbinned_per_magcol_recfracs )
outdict [ 'periodbinned_per_pfmethod_recfracs' ] = ( periodbinned_per_pfmethod_recfracs )
outdict [ 'periodbinned_per_vartype_recfracs' ] = ( periodbinned_per_vartype_recfracs )
outdict [ 'periodbinned_per_aliastype_recfracs' ] = ( periodbinned_per_aliastype_recfracs )
outdict [ 'amplitudebinned_per_magcol_recfracs' ] = ( amplitudebinned_per_magcol_recfracs )
outdict [ 'amplitudebinned_per_pfmethod_recfracs' ] = ( amplitudebinned_per_pfmethod_recfracs )
outdict [ 'amplitudebinned_per_vartype_recfracs' ] = ( amplitudebinned_per_vartype_recfracs )
outdict [ 'amplitudebinned_per_aliastype_recfracs' ] = ( amplitudebinned_per_aliastype_recfracs )
outdict [ 'ndetbinned_per_magcol_recfracs' ] = ( ndetbinned_per_magcol_recfracs )
outdict [ 'ndetbinned_per_pfmethod_recfracs' ] = ( ndetbinned_per_pfmethod_recfracs )
outdict [ 'ndetbinned_per_vartype_recfracs' ] = ( ndetbinned_per_vartype_recfracs )
outdict [ 'ndetbinned_per_aliastype_recfracs' ] = ( ndetbinned_per_aliastype_recfracs )
# get the overall recovered vars per pfmethod
overall_recvars_per_pfmethod = [ ]
for pfm in all_pfmethods :
    thispfm_recvars = np . array ( [ x for x in precvar [ 'details' ] if ( ( x in recovered_periodicvars ) and ( precvar [ 'details' ] [ x ] [ 'best_recovered_pfmethod' ] == pfm ) ) ] )
    overall_recvars_per_pfmethod . append ( thispfm_recvars )
# get the overall recovered vars per vartype
overall_recvars_per_vartype = [ ]
for vt in all_vartypes :
    thisvt_recvars = np . array ( [ x for x in precvar [ 'details' ] if ( ( x in recovered_periodicvars ) and ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] == vt ) ) ] )
    overall_recvars_per_vartype . append ( thisvt_recvars )
# get the overall recovered vars per magcol
overall_recvars_per_magcol = [ ]
for mc in magcols :
    thismc_recvars = np . array ( [ x for x in precvar [ 'details' ] if ( ( x in recovered_periodicvars ) and ( precvar [ 'details' ] [ x ] [ 'best_recovered_magcol' ] == mc ) ) ] )
    overall_recvars_per_magcol . append ( thismc_recvars )
# get the overall recovered vars per aliastype
overall_recvars_per_aliastype = [ ]
for at in all_aliastypes :
    thisat_recvars = np . array ( [ x for x in precvar [ 'details' ] if ( ( x in recovered_periodicvars ) and ( precvar [ 'details' ] [ x ] [ 'best_recovered_status' ] == at ) ) ] )
    overall_recvars_per_aliastype . append ( thisat_recvars )
# update the outdict with these
outdict [ 'overall_recfrac_per_pfmethod' ] = np . array ( [ x . size / actual_periodicvars . size for x in overall_recvars_per_pfmethod ] )
outdict [ 'overall_recfrac_per_vartype' ] = np . array ( [ x . size / actual_periodicvars . size for x in overall_recvars_per_vartype ] )
outdict [ 'overall_recfrac_per_magcol' ] = np . array ( [ x . size / actual_periodicvars . size for x in overall_recvars_per_magcol ] )
outdict [ 'overall_recfrac_per_aliastype' ] = np . array ( [ x . size / actual_periodicvars . size for x in overall_recvars_per_aliastype ] )
# 5 . bar plot of overall recovery rate per pfmethod
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
xt = np . arange ( len ( all_pfmethods ) )
xl = all_pfmethods
plt . barh ( xt , outdict [ 'overall_recfrac_per_pfmethod' ] , 0.50 )
plt . yticks ( xt , xl )
plt . xlabel ( 'period-finding method' )
plt . ylabel ( 'overall recovery rate' )
plt . title ( 'overall recovery rate per period-finding method' )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-overall-pfmethod.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 6 . bar plot of overall recovery rate per magcol
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
xt = np . arange ( len ( magcols ) )
xl = magcols
plt . barh ( xt , outdict [ 'overall_recfrac_per_magcol' ] , 0.50 )
plt . yticks ( xt , xl )
plt . xlabel ( 'light curve magnitude column' )
plt . ylabel ( 'overall recovery rate' )
plt . title ( 'overall recovery rate per light curve magcol' )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-overall-magcol.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 7 . bar plot of overall recovery rate per aliastype
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
xt = np . arange ( len ( all_aliastypes ) )
xl = all_aliastypes
plt . barh ( xt , outdict [ 'overall_recfrac_per_aliastype' ] , 0.50 )
plt . yticks ( xt , xl )
plt . xlabel ( 'period recovery status' )
plt . ylabel ( 'overall recovery rate' )
plt . title ( 'overall recovery rate per period recovery status' )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-overall-aliastype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 8 . bar plot of overall recovery rate per vartype
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
xt = np . arange ( len ( all_vartypes ) )
xl = all_vartypes
plt . barh ( xt , outdict [ 'overall_recfrac_per_vartype' ] , 0.50 )
plt . yticks ( xt , xl )
plt . xlabel ( 'periodic variable type' )
plt . ylabel ( 'overall recovery rate' )
plt . title ( 'overall recovery rate per periodic variable type' )
plt . savefig ( os . path . join ( recplotdir , 'recfrac-overall-vartype.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 9 . overall recovered period periodogram for objects that aren ' t actual
# periodic variables . this effectively should give us the window function of
# the observations
notvariable_recovered_periods = np . concatenate ( [ precvar [ 'details' ] [ x ] [ 'recovery_periods' ] for x in precvar [ 'details' ] if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] is None ) ] )
notvariable_recovered_lspvals = np . concatenate ( [ precvar [ 'details' ] [ x ] [ 'recovery_lspvals' ] for x in precvar [ 'details' ] if ( precvar [ 'details' ] [ x ] [ 'actual_vartype' ] is None ) ] )
sortind = np . argsort ( notvariable_recovered_periods )
notvariable_recovered_periods = notvariable_recovered_periods [ sortind ]
notvariable_recovered_lspvals = notvariable_recovered_lspvals [ sortind ]
outdict [ 'notvariable_recovered_periods' ] = notvariable_recovered_periods
outdict [ 'notvariable_recovered_lspvals' ] = notvariable_recovered_lspvals
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
plt . plot ( notvariable_recovered_periods , notvariable_recovered_lspvals , ms = 1.0 , linestyle = 'none' , marker = '.' )
plt . xscale ( 'log' )
plt . xlabel ( 'recovered periods [days]' )
plt . ylabel ( 'recovered normalized periodogram power' )
plt . title ( 'periodogram for actual not-variable objects' )
plt . savefig ( os . path . join ( recplotdir , 'recovered-periodogram-nonvariables.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# 10 . overall recovered period histogram for objects marked
# not - variable . this gives us the most common periods
fig = plt . figure ( figsize = ( 6.4 * 1.5 , 4.8 * 1.5 ) )
plt . hist ( notvariable_recovered_periods , bins = np . arange ( 0.02 , 300.0 , 1.0e-3 ) , histtype = 'step' )
plt . xscale ( 'log' )
plt . xlabel ( 'recovered periods [days]' )
plt . ylabel ( 'number of times periods recovered' )
plt . title ( 'recovered period histogram for non-variable objects' )
plt . savefig ( os . path . join ( recplotdir , 'recovered-period-hist-nonvariables.%s' % plotfile_ext ) , dpi = 100 , bbox_inches = 'tight' )
plt . close ( 'all' )
# at the end , write the outdict to a pickle and return it
outfile = os . path . join ( simbasedir , 'periodicvar-recovery-plotresults.pkl' )
with open ( outfile , 'wb' ) as outfd :
    pickle . dump ( outdict , outfd , pickle . HIGHEST_PROTOCOL )
return outdict


signature:
def mast_query ( service , params , data = None , apiversion = 'v0' , forcefetch = False , cachedir = '~/.astrobase/mast-cache' , verbose = True , timeout = 10.0 , refresh = 5.0 , maxtimeout = 90.0 , maxtries = 3 , raiseonfail = False , jitter = 5.0 ) :
    '''This queries the STScI MAST service for catalog data .
 All results are downloaded as JSON files that are written to ` cachedir ` .
 Parameters
 service : str
 This is the name of the service to use . See
 https : / / mast . stsci . edu / api / v0 / _ services . html for a list of all available
 services .
 params : dict
 This is a dict containing the input params to the service as described
 on its details page linked in the ` service description page on MAST
 < https : / / mast . stsci . edu / api / v0 / _ services . html > ` _ .
 data : dict or None
 This contains optional data to upload to the service .
 apiversion : str
 The API version of the MAST service to use . This sets the URL that this
 function will call , using ` apiversion ` as key into the ` MAST _ URLS ` dict
 above .
 forcefetch : bool
 If this is True , the query will be retried even if cached results for
 it exist .
 cachedir : str
 This points to the directory where results will be downloaded .
 verbose : bool
 If True , will indicate progress and warn of any issues .
 timeout : float
 This sets the amount of time in seconds to wait for the service to
 respond to our initial request .
 refresh : float
 This sets the amount of time in seconds to wait before checking if the
 result file is available . If the results file isn ' t available after
 ` refresh ` seconds have elapsed , the function will wait for ` refresh `
 seconds continuously , until ` maxtimeout ` is reached or the results file
 becomes available .
 maxtimeout : float
 The maximum amount of time in seconds to wait for a result to become
 available after submitting our query request .
 maxtries : int
 The maximum number of tries ( across all mirrors tried ) to make to either
 submit the request or download the results , before giving up .
 raiseonfail : bool
 If this is True , the function will raise an Exception if something goes
 wrong , instead of returning None .
 jitter : float
 This is used to control the scale of the random wait in seconds before
 starting the query . Useful in parallelized situations .
 Returns
 dict
 This returns a dict of the following form : :
 { ' params ' : dict of the input params used for the query ,
 ' provenance ' : ' cache ' or ' new download ' ,
 ' result ' : path to the file on disk with the downloaded data table }'''

implementation:
# this matches :
# https : / / mast . stsci . edu / api / v0 / class _ mashup _ 1_1 _ mashup _ request . html
inputparams = { 'format' : 'json' , 'params' : params , 'service' : service , 'timeout' : timeout , }
if data is not None :
    inputparams [ 'data' ] = data
# see if the cachedir exists
if '~' in cachedir :
    cachedir = os . path . expanduser ( cachedir )
if not os . path . exists ( cachedir ) :
    os . makedirs ( cachedir )
# generate the cachefname and look for it
xcachekey = '-' . join ( [ repr ( inputparams [ x ] ) for x in sorted ( inputparams . keys ( ) ) ] )
cachekey = hashlib . sha256 ( xcachekey . encode ( ) ) . hexdigest ( )
cachefname = os . path . join ( cachedir , '%s.json' % ( cachekey , ) )
provenance = 'cache'
# # RUN A NEW QUERY # #
# otherwise , we check the cache if it ' s done already , or run it again if not
if forcefetch or ( not os . path . exists ( cachefname ) ) :
    time . sleep ( random . randint ( 1 , jitter ) )
    provenance = 'new download'
    waitdone = False
    timeelapsed = 0.0
    ntries = 1
    url = MAST_URLS [ apiversion ] [ 'url' ]
    formdata = { 'request' : json . dumps ( inputparams ) }
    while ( not waitdone ) or ( ntries < maxtries ) :
        if timeelapsed > maxtimeout :
            retdict = None
            break
        try :
            resp = requests . post ( url , data = formdata , # we ' ll let the service time us out first
            # if that fails , we ' ll timeout ourselves
            timeout = timeout + 1.0 )
            resp . raise_for_status ( )
            respjson = resp . json ( )
            if respjson [ 'status' ] == 'COMPLETE' :
                data = respjson [ 'data' ]
                nrows = len ( data )
                if nrows > 0 :
                    with open ( cachefname , 'w' ) as outfd :
                        json . dump ( respjson , outfd )
                    retdict = { 'params' : inputparams , 'provenance' : provenance , 'cachefname' : cachefname }
                    waitdone = True
                    if verbose :
                        LOGINFO ( 'query successful. nmatches: %s' % nrows )
                    break
                else :
                    LOGERROR ( 'no matching objects found for inputparams: %r' % inputparams )
                    retdict = None
                    waitdone = True
                    break
            # if we ' re still executing after the initial timeout is done
            elif respjson [ 'status' ] == 'EXECUTING' :
                if verbose :
                    LOGINFO ( 'query is still executing, ' 'waiting %s seconds to retry...' % refresh )
                waitdone = False
                time . sleep ( refresh )
                timeelapsed = timeelapsed + refresh
                retdict = None
            else :
                LOGERROR ( 'Query failed! Message from service: %s' % respjson [ 'msg' ] )
                retdict = None
                waitdone = True
                break
        except requests . exceptions . Timeout as e :
            if verbose :
                LOGWARNING ( 'MAST query try timed out, ' 'site is probably down. ' 'Waiting for %s seconds to try again...' % refresh )
            waitdone = False
            time . sleep ( refresh )
            timeelapsed = timeelapsed + refresh
            retdict = None
        except KeyboardInterrupt as e :
            LOGERROR ( 'MAST request wait aborted for ' '%s' % repr ( inputparams ) )
            return None
        except Exception as e :
            LOGEXCEPTION ( 'MAST query failed!' )
            if raiseonfail :
                raise
            return None
        # increment number of tries at the bottom of the loop
        ntries = ntries + 1
    # done with waiting for completion
    if retdict is None :
        LOGERROR ( 'Timed out, errored out, or reached maximum number ' 'of tries with no response. Query was: %r' % inputparams )
        return None
    else :
        return retdict
# otherwise , get the file from the cache
else :
    if verbose :
        LOGINFO ( 'getting cached MAST query result for ' 'request: %s' % ( repr ( inputparams ) ) )
    retdict = { 'params' : inputparams , 'provenance' : provenance , 'cachefname' : cachefname }
    return retdict


signature:
def tic_conesearch ( ra , decl , radius_arcmin = 5.0 , apiversion = 'v0' , forcefetch = False , cachedir = '~/.astrobase/mast-cache' , verbose = True , timeout = 10.0 , refresh = 5.0 , maxtimeout = 90.0 , maxtries = 3 , jitter = 5.0 , raiseonfail = False ) :
    '''This runs a TESS Input Catalog cone search on MAST .
 If you use this , please cite the TIC paper ( Stassun et al 2018;
 http : / / adsabs . harvard . edu / abs / 2018AJ . . . . 156 . . 102S ) . Also see the " living "
 TESS input catalog docs :
 https : / / docs . google . com / document / d / 1zdiKMs4Ld4cXZ2DW4lMX - fuxAF6hPHTjqjIwGqnfjqI
 Also see : https : / / mast . stsci . edu / api / v0 / _ t _ i _ cfields . html for the fields
 returned by the service and present in the result JSON file .
 Parameters
 ra , decl : float
 The center coordinates of the cone - search in decimal degrees .
 radius _ arcmin : float
 The cone - search radius in arcminutes .
 apiversion : str
 The API version of the MAST service to use . This sets the URL that this
 function will call , using ` apiversion ` as key into the ` MAST _ URLS ` dict
 above .
 forcefetch : bool
 If this is True , the query will be retried even if cached results for
 it exist .
 cachedir : str
 This points to the directory where results will be downloaded .
 verbose : bool
 If True , will indicate progress and warn of any issues .
 timeout : float
 This sets the amount of time in seconds to wait for the service to
 respond to our initial request .
 refresh : float
 This sets the amount of time in seconds to wait before checking if the
 result file is available . If the results file isn ' t available after
 ` refresh ` seconds have elapsed , the function will wait for ` refresh `
 seconds continuously , until ` maxtimeout ` is reached or the results file
 becomes available .
 maxtimeout : float
 The maximum amount of time in seconds to wait for a result to become
 available after submitting our query request .
 maxtries : int
 The maximum number of tries ( across all mirrors tried ) to make to either
 submit the request or download the results , before giving up .
 jitter : float
 This is used to control the scale of the random wait in seconds before
 starting the query . Useful in parallelized situations .
 raiseonfail : bool
 If this is True , the function will raise an Exception if something goes
 wrong , instead of returning None .
 Returns
 dict
 This returns a dict of the following form : :
 { ' params ' : dict of the input params used for the query ,
 ' provenance ' : ' cache ' or ' new download ' ,
 ' result ' : path to the file on disk with the downloaded data table }'''

implementation:
params = { 'ra' : ra , 'dec' : decl , 'radius' : radius_arcmin / 60.0 }
service = 'Mast.Catalogs.Tic.Cone'
return mast_query ( service , params , jitter = jitter , apiversion = apiversion , forcefetch = forcefetch , cachedir = cachedir , verbose = verbose , timeout = timeout , refresh = refresh , maxtimeout = maxtimeout , maxtries = maxtries , raiseonfail = raiseonfail )


signature:
def tic_xmatch ( ra , decl , radius_arcsec = 5.0 , apiversion = 'v0' , forcefetch = False , cachedir = '~/.astrobase/mast-cache' , verbose = True , timeout = 90.0 , refresh = 5.0 , maxtimeout = 180.0 , maxtries = 3 , jitter = 5.0 , raiseonfail = False ) :
    '''This does a cross - match with TIC .
 Parameters
 ra , decl : np . arrays or lists of floats
 The coordinates that will be cross - matched against the TIC .
 radius _ arcsec : float
 The cross - match radius in arcseconds .
 apiversion : str
 The API version of the MAST service to use . This sets the URL that this
 function will call , using ` apiversion ` as key into the ` MAST _ URLS ` dict
 above .
 forcefetch : bool
 If this is True , the query will be retried even if cached results for
 it exist .
 cachedir : str
 This points to the directory where results will be downloaded .
 verbose : bool
 If True , will indicate progress and warn of any issues .
 timeout : float
 This sets the amount of time in seconds to wait for the service to
 respond to our initial request .
 refresh : float
 This sets the amount of time in seconds to wait before checking if the
 result file is available . If the results file isn ' t available after
 ` refresh ` seconds have elapsed , the function will wait for ` refresh `
 seconds continuously , until ` maxtimeout ` is reached or the results file
 becomes available .
 maxtimeout : float
 The maximum amount of time in seconds to wait for a result to become
 available after submitting our query request .
 maxtries : int
 The maximum number of tries ( across all mirrors tried ) to make to either
 submit the request or download the results , before giving up .
 jitter : float
 This is used to control the scale of the random wait in seconds before
 starting the query . Useful in parallelized situations .
 raiseonfail : bool
 If this is True , the function will raise an Exception if something goes
 wrong , instead of returning None .
 Returns
 dict
 This returns a dict of the following form : :
 { ' params ' : dict of the input params used for the query ,
 ' provenance ' : ' cache ' or ' new download ' ,
 ' result ' : path to the file on disk with the downloaded data table }'''

implementation:
service = 'Mast.Tic.Crossmatch'
xmatch_input = { 'fields' : [ { 'name' : 'ra' , 'type' : 'float' } , { 'name' : 'dec' , 'type' : 'float' } ] }
xmatch_input [ 'data' ] = [ { 'ra' : x , 'dec' : y } for ( x , y ) in zip ( ra , decl ) ]
params = { 'raColumn' : 'ra' , 'decColumn' : 'dec' , 'radius' : radius_arcsec / 3600.0 }
return mast_query ( service , params , data = xmatch_input , jitter = jitter , apiversion = apiversion , forcefetch = forcefetch , cachedir = cachedir , verbose = verbose , timeout = timeout , refresh = refresh , maxtimeout = maxtimeout , maxtries = maxtries , raiseonfail = raiseonfail )


signature:
def tic_objectsearch ( objectid , idcol_to_use = "ID" , apiversion = 'v0' , forcefetch = False , cachedir = '~/.astrobase/mast-cache' , verbose = True , timeout = 90.0 , refresh = 5.0 , maxtimeout = 180.0 , maxtries = 3 , jitter = 5.0 , raiseonfail = False ) :
    '''This runs a TIC search for a specified TIC ID .
 Parameters
 objectid : str
 The object ID to look up information for .
 idcol _ to _ use : str
 This is the name of the object ID column to use when looking up the
 provided ` objectid ` . This is one of { ' ID ' , ' HIP ' , ' TYC ' , ' UCAC ' ,
 ' TWOMASS ' , ' ALLWISE ' , ' SDSS ' , ' GAIA ' , ' APASS ' , ' KIC ' } .
 apiversion : str
 The API version of the MAST service to use . This sets the URL that this
 function will call , using ` apiversion ` as key into the ` MAST _ URLS ` dict
 above .
 forcefetch : bool
 If this is True , the query will be retried even if cached results for
 it exist .
 cachedir : str
 This points to the directory where results will be downloaded .
 verbose : bool
 If True , will indicate progress and warn of any issues .
 timeout : float
 This sets the amount of time in seconds to wait for the service to
 respond to our initial request .
 refresh : float
 This sets the amount of time in seconds to wait before checking if the
 result file is available . If the results file isn ' t available after
 ` refresh ` seconds have elapsed , the function will wait for ` refresh `
 seconds continuously , until ` maxtimeout ` is reached or the results file
 becomes available .
 maxtimeout : float
 The maximum amount of time in seconds to wait for a result to become
 available after submitting our query request .
 maxtries : int
 The maximum number of tries ( across all mirrors tried ) to make to either
 submit the request or download the results , before giving up .
 jitter : float
 This is used to control the scale of the random wait in seconds before
 starting the query . Useful in parallelized situations .
 raiseonfail : bool
 If this is True , the function will raise an Exception if something goes
 wrong , instead of returning None .
 Returns
 dict
 This returns a dict of the following form : :
 { ' params ' : dict of the input params used for the query ,
 ' provenance ' : ' cache ' or ' new download ' ,
 ' result ' : path to the file on disk with the downloaded data table }'''

implementation:
params = { 'columns' : '*' , 'filters' : [ { "paramName" : idcol_to_use , "values" : [ str ( objectid ) ] } ] }
service = 'Mast.Catalogs.Filtered.Tic'
return mast_query ( service , params , jitter = jitter , apiversion = apiversion , forcefetch = forcefetch , cachedir = cachedir , verbose = verbose , timeout = timeout , refresh = refresh , maxtimeout = maxtimeout , maxtries = maxtries , raiseonfail = raiseonfail )


signature:
def send_email ( sender , subject , content , email_recipient_list , email_address_list , email_user = None , email_pass = None , email_server = None ) :
    '''This sends an email to addresses , informing them about events .
 The email account settings are retrieved from the settings file as described
 above .
 Parameters
 sender : str
 The name of the sender to use in the email header .
 subject : str
 Subject of the email .
 content : str
 Content of the email .
 email _ recipient list : list of str
 This is a list of email recipient names of the form :
 ` [ ' Example Person 1 ' , ' Example Person 1 ' , . . . ] `
 email _ recipient list : list of str
 This is a list of email recipient addresses of the form :
 ` [ ' example1 @ example . com ' , ' example2 @ example . org ' , . . . ] `
 email _ user : str
 The username of the email server account that will send the emails . If
 this is None , the value of EMAIL _ USER from the
 ~ / . astrobase / . emailsettings file will be used . If that is None as well ,
 this function won ' t work .
 email _ pass : str
 The password of the email server account that will send the emails . If
 this is None , the value of EMAIL _ PASS from the
 ~ / . astrobase / . emailsettings file will be used . If that is None as well ,
 this function won ' t work .
 email _ server : str
 The address of the email server that will send the emails . If this is
 None , the value of EMAIL _ USER from the ~ / . astrobase / . emailsettings file
 will be used . If that is None as well , this function won ' t work .
 Returns
 bool
 True if email sending succeeded . False if email sending failed .'''

implementation:
if not email_user :
    email_user = EMAIL_USER
if not email_pass :
    email_pass = EMAIL_PASSWORD
if not email_server :
    email_server = EMAIL_SERVER
if not email_server and email_user and email_pass :
    raise ValueError ( "no email server address and " "credentials available, can't continue" )
msg_text = EMAIL_TEMPLATE . format ( sender = sender , hostname = socket . gethostname ( ) , activity_time = '%sZ' % datetime . utcnow ( ) . isoformat ( ) , activity_report = content )
email_sender = '%s <%s>' % ( sender , EMAIL_USER )
# put together the recipient and email lists
email_recipients = [ ( '%s <%s>' % ( x , y ) ) for ( x , y ) in zip ( email_recipient_list , email_address_list ) ]
# put together the rest of the message
email_msg = MIMEText ( msg_text )
email_msg [ 'From' ] = email_sender
email_msg [ 'To' ] = ', ' . join ( email_recipients )
email_msg [ 'Message-Id' ] = make_msgid ( )
email_msg [ 'Subject' ] = '[%s on %s] %s' % ( sender , socket . gethostname ( ) , subject )
email_msg [ 'Date' ] = formatdate ( time . time ( ) )
# start the email process
try :
    server = smtplib . SMTP ( EMAIL_SERVER , 587 )
    server_ehlo_response = server . ehlo ( )
    if server . has_extn ( 'STARTTLS' ) :
        try :
            tls_start_response = server . starttls ( )
            tls_ehlo_response = server . ehlo ( )
            login_response = server . login ( EMAIL_USER , EMAIL_PASSWORD )
            send_response = ( server . sendmail ( email_sender , email_address_list , email_msg . as_string ( ) ) )
        except Exception as e :
            print ( 'script email sending failed with error: %s' % e )
            send_response = None
        if send_response is not None :
            print ( 'script email sent successfully' )
            quit_response = server . quit ( )
            return True
        else :
            quit_response = server . quit ( )
            return False
    else :
        print ( 'email server does not support STARTTLS,' ' bailing out...' )
        quit_response = server . quit ( )
        return False
except Exception as e :
    print ( 'sending email failed with error: %s' % e )
    returnval = False
quit_response = server . quit ( )
return returnval


signature:
def fourier_sinusoidal_func ( fourierparams , times , mags , errs ) :
    '''This generates a sinusoidal light curve using a Fourier cosine series .
 Parameters
 fourierparams : list
 This MUST be a list of the following form like so : :
 [ period ,
 epoch ,
 [ amplitude _ 1 , amplitude _ 2 , amplitude _ 3 , . . . , amplitude _ X ] ,
 [ phase _ 1 , phase _ 2 , phase _ 3 , . . . , phase _ X ] ]
 where X is the Fourier order .
 times , mags , errs : np . array
 The input time - series of measurements and associated errors for which
 the model will be generated . The times will be used to generate model
 mags , and the input ` times ` , ` mags ` , and ` errs ` will be resorted by
 model phase and returned .
 Returns
 ( modelmags , phase , ptimes , pmags , perrs ) : tuple
 Returns the model mags and phase values . Also returns the input ` times ` ,
 ` mags ` , and ` errs ` sorted by the model ' s phase .'''

implementation:
period , epoch , famps , fphases = fourierparams
# figure out the order from the length of the Fourier param list
forder = len ( famps )
# phase the times with this period
iphase = ( times - epoch ) / period
iphase = iphase - np . floor ( iphase )
phasesortind = np . argsort ( iphase )
phase = iphase [ phasesortind ]
ptimes = times [ phasesortind ]
pmags = mags [ phasesortind ]
perrs = errs [ phasesortind ]
# calculate all the individual terms of the series
fseries = [ famps [ x ] * np . cos ( 2.0 * np . pi * x * phase + fphases [ x ] ) for x in range ( forder ) ]
# this is the zeroth order coefficient - a constant equal to median mag
modelmags = np . median ( mags )
# sum the series
for fo in fseries :
    modelmags += fo
return modelmags , phase , ptimes , pmags , perrs


signature:
def fourier_sinusoidal_residual ( fourierparams , times , mags , errs ) :
    '''This returns the residual between the model mags and the actual mags .
 Parameters
 fourierparams : list
 This MUST be a list of the following form like so : :
 [ period ,
 epoch ,
 [ amplitude _ 1 , amplitude _ 2 , amplitude _ 3 , . . . , amplitude _ X ] ,
 [ phase _ 1 , phase _ 2 , phase _ 3 , . . . , phase _ X ] ]
 where X is the Fourier order .
 times , mags , errs : np . array
 The input time - series of measurements and associated errors for which
 the model will be generated . The times will be used to generate model
 mags , and the input ` times ` , ` mags ` , and ` errs ` will be resorted by
 model phase and returned .
 Returns
 np . array
 The residuals between the input ` mags ` and generated ` modelmags ` ,
 weighted by the measurement errors in ` errs ` .'''

implementation:
modelmags , phase , ptimes , pmags , perrs = ( fourier_sinusoidal_func ( fourierparams , times , mags , errs ) )
# this is now a weighted residual taking into account the measurement err
return ( pmags - modelmags ) / perrs


signature:
def _make_periodogram ( axes , lspinfo , objectinfo , findercmap , finderconvolve , verbose = True , findercachedir = '~/.astrobase/stamp-cache' ) :
    '''Makes periodogram , objectinfo , and finder tile for ` checkplot _ png ` and
 ` twolsp _ checkplot _ png ` .
 Parameters
 axes : matplotlib . axes . Axes object
 The Axes object which will contain the plot being made .
 lspinfo : dict
 Dict containing results from a period - finder in ` astrobase . periodbase `
 or a dict that corresponds to that format .
 objectinfo : dict
 Dict containing basic info about the object being processed .
 findercmap : matplotlib Colormap object or str
 The Colormap object to use for the finder chart image .
 finderconvolve : astropy . convolution . Kernel object or None
 If not None , the Kernel object to use for convolving the finder image .
 verbose : bool
 If True , indicates progress .
 findercachedir : str
 The directory where the FITS finder images are downloaded and cached .
 Returns
 Does not return anything , works on the input Axes object directly .'''

implementation:
# get the appropriate plot ylabel
pgramylabel = PLOTYLABELS [ lspinfo [ 'method' ] ]
# get the periods and lspvals from lspinfo
periods = lspinfo [ 'periods' ]
lspvals = lspinfo [ 'lspvals' ]
bestperiod = lspinfo [ 'bestperiod' ]
nbestperiods = lspinfo [ 'nbestperiods' ]
nbestlspvals = lspinfo [ 'nbestlspvals' ]
# make the LSP plot on the first subplot
axes . plot ( periods , lspvals )
axes . set_xscale ( 'log' , basex = 10 )
axes . set_xlabel ( 'Period [days]' )
axes . set_ylabel ( pgramylabel )
plottitle = '%s - %.6f d' % ( METHODLABELS [ lspinfo [ 'method' ] ] , bestperiod )
axes . set_title ( plottitle )
# show the best five peaks on the plot
for bestperiod , bestpeak in zip ( nbestperiods , nbestlspvals ) :
    axes . annotate ( '%.6f' % bestperiod , xy = ( bestperiod , bestpeak ) , xycoords = 'data' , xytext = ( 0.0 , 25.0 ) , textcoords = 'offset points' , arrowprops = dict ( arrowstyle = "->" ) , fontsize = '14.0' )
# make a grid
axes . grid ( color = '#a9a9a9' , alpha = 0.9 , zorder = 0 , linewidth = 1.0 , linestyle = ':' )
# if objectinfo is present , get things from it
if ( objectinfo and isinstance ( objectinfo , dict ) and ( 'objectid' in objectinfo or 'hatid' in objectinfo ) and 'ra' in objectinfo and 'decl' in objectinfo and objectinfo [ 'ra' ] and objectinfo [ 'decl' ] ) :
    if 'objectid' not in objectinfo :
        objectid = objectinfo [ 'hatid' ]
    else :
        objectid = objectinfo [ 'objectid' ]
    if verbose :
        LOGINFO ( 'adding in object information and ' 'finder chart for %s at RA: %.3f, DEC: %.3f' % ( objectid , objectinfo [ 'ra' ] , objectinfo [ 'decl' ] ) )
    # calculate colors
    if ( 'bmag' in objectinfo and 'vmag' in objectinfo and 'jmag' in objectinfo and 'kmag' in objectinfo and 'sdssi' in objectinfo and objectinfo [ 'bmag' ] and objectinfo [ 'vmag' ] and objectinfo [ 'jmag' ] and objectinfo [ 'kmag' ] and objectinfo [ 'sdssi' ] ) :
        bvcolor = objectinfo [ 'bmag' ] - objectinfo [ 'vmag' ]
        jkcolor = objectinfo [ 'jmag' ] - objectinfo [ 'kmag' ]
        ijcolor = objectinfo [ 'sdssi' ] - objectinfo [ 'jmag' ]
    else :
        bvcolor = None
        jkcolor = None
        ijcolor = None
    if ( 'teff' in objectinfo and 'gmag' in objectinfo and objectinfo [ 'teff' ] and objectinfo [ 'gmag' ] ) : # Gaia data input
        teff_val = objectinfo [ 'teff' ]
        gmag = objectinfo [ 'gmag' ]
    # bump the ylim of the LSP plot so that the overplotted finder and
    # objectinfo can fit in this axes plot
    lspylim = axes . get_ylim ( )
    axes . set_ylim ( lspylim [ 0 ] , lspylim [ 1 ] + 0.75 * ( lspylim [ 1 ] - lspylim [ 0 ] ) )
    # get the stamp
    try :
        dss , dssheader = skyview_stamp ( objectinfo [ 'ra' ] , objectinfo [ 'decl' ] , convolvewith = finderconvolve , flip = False , cachedir = findercachedir , verbose = verbose )
        stamp = dss
        # inset plot it on the current axes
        inset = inset_axes ( axes , width = "40%" , height = "40%" , loc = 1 )
        inset . imshow ( stamp , cmap = findercmap , origin = 'lower' )
        inset . set_xticks ( [ ] )
        inset . set_yticks ( [ ] )
        inset . set_frame_on ( False )
        # grid lines pointing to the center of the frame
        inset . axvline ( x = 150 , ymin = 0.375 , ymax = 0.45 , linewidth = 2.0 , color = 'b' )
        inset . axhline ( y = 150 , xmin = 0.375 , xmax = 0.45 , linewidth = 2.0 , color = 'b' )
    except OSError as e :
        LOGERROR ( 'downloaded FITS appears to be corrupt, retrying...' )
        dss , dssheader = skyview_stamp ( objectinfo [ 'ra' ] , objectinfo [ 'decl' ] , convolvewith = finderconvolve , flip = False , forcefetch = True , cachedir = findercachedir , verbose = verbose )
        stamp = dss
        # inset plot it on the current axes
        inset = inset_axes ( axes , width = "40%" , height = "40%" , loc = 1 )
        inset . imshow ( stamp , cmap = findercmap , origin = 'lower' )
        inset . set_xticks ( [ ] )
        inset . set_yticks ( [ ] )
        inset . set_frame_on ( False )
        # grid lines pointing to the center of the frame
        inset . axvline ( x = 150 , ymin = 0.375 , ymax = 0.45 , linewidth = 2.0 , color = 'b' )
        inset . axhline ( y = 150 , xmin = 0.375 , xmax = 0.45 , linewidth = 2.0 , color = 'b' )
    except Exception as e :
        LOGEXCEPTION ( 'could not fetch a DSS stamp for this ' 'object %s using coords (%.3f,%.3f)' % ( objectid , objectinfo [ 'ra' ] , objectinfo [ 'decl' ] ) )
    # annotate with objectinfo
    axes . text ( 0.05 , 0.95 , '%s' % objectid , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    axes . text ( 0.05 , 0.91 , 'RA = %.3f, DEC = %.3f' % ( objectinfo [ 'ra' ] , objectinfo [ 'decl' ] ) , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    if bvcolor :
        axes . text ( 0.05 , 0.87 , '$B - V$ = %.3f, $V$ = %.3f' % ( bvcolor , objectinfo [ 'vmag' ] ) , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    elif 'vmag' in objectinfo and objectinfo [ 'vmag' ] :
        axes . text ( 0.05 , 0.87 , '$V$ = %.3f' % ( objectinfo [ 'vmag' ] , ) , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    if ijcolor :
        axes . text ( 0.05 , 0.83 , '$i - J$ = %.3f, $J$ = %.3f' % ( ijcolor , objectinfo [ 'jmag' ] ) , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    elif 'jmag' in objectinfo and objectinfo [ 'jmag' ] :
        axes . text ( 0.05 , 0.83 , '$J$ = %.3f' % ( objectinfo [ 'jmag' ] , ) , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    if jkcolor :
        axes . text ( 0.05 , 0.79 , '$J - K$ = %.3f, $K$ = %.3f' % ( jkcolor , objectinfo [ 'kmag' ] ) , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    elif 'kmag' in objectinfo and objectinfo [ 'kmag' ] :
        axes . text ( 0.05 , 0.79 , '$K$ = %.3f' % ( objectinfo [ 'kmag' ] , ) , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    if 'sdssr' in objectinfo and objectinfo [ 'sdssr' ] :
        axes . text ( 0.05 , 0.75 , 'SDSS $r$ = %.3f' % objectinfo [ 'sdssr' ] , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    if ( 'teff' in objectinfo and 'gmag' in objectinfo and objectinfo [ 'teff' ] and objectinfo [ 'gmag' ] ) : # gaia data available
        axes . text ( 0.05 , 0.87 , r'$G$ = %.1f, $T_\mathrm{eff}$ = %d' % ( gmag , int ( teff_val ) ) , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
    # add in proper motion stuff if available in objectinfo
    if ( 'pmra' in objectinfo and objectinfo [ 'pmra' ] and 'pmdecl' in objectinfo and objectinfo [ 'pmdecl' ] ) :
        pm = total_proper_motion ( objectinfo [ 'pmra' ] , objectinfo [ 'pmdecl' ] , objectinfo [ 'decl' ] )
        axes . text ( 0.05 , 0.67 , r'$\mu$ = %.2f mas yr$^{-1}$' % pm , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )
        if 'jmag' in objectinfo and objectinfo [ 'jmag' ] :
            rpm = reduced_proper_motion ( objectinfo [ 'jmag' ] , pm )
            axes . text ( 0.05 , 0.63 , '$H_J$ = %.2f' % rpm , ha = 'left' , va = 'center' , transform = axes . transAxes , fontsize = 18.0 )


signature:
def _make_magseries_plot ( axes , stimes , smags , serrs , magsarefluxes = False , ms = 2.0 ) :
    '''Makes the mag - series plot tile for ` checkplot _ png ` and
 ` twolsp _ checkplot _ png ` .
 axes : matplotlib . axes . Axes object
 The Axes object where the generated plot will go .
 stimes , smags , serrs : np . array
 The mag / flux time - series arrays along with associated errors . These
 should all have been run through nan - stripping and sigma - clipping
 beforehand .
 magsarefluxes : bool
 If True , indicates the input time - series is fluxes and not mags so the
 plot y - axis direction and range can be set appropriately .
 ms : float
 The ` markersize ` kwarg to use when making the mag - series plot .
 Returns
 Does not return anything , works on the input Axes object directly .'''

implementation:
scaledplottime = stimes - npmin ( stimes )
axes . plot ( scaledplottime , smags , marker = 'o' , ms = ms , ls = 'None' , mew = 0 , color = 'green' , rasterized = True )
# flip y axis for mags
if not magsarefluxes :
    plot_ylim = axes . get_ylim ( )
    axes . set_ylim ( ( plot_ylim [ 1 ] , plot_ylim [ 0 ] ) )
# set the x axis limit
axes . set_xlim ( ( npmin ( scaledplottime ) - 1.0 , npmax ( scaledplottime ) + 1.0 ) )
# make a grid
axes . grid ( color = '#a9a9a9' , alpha = 0.9 , zorder = 0 , linewidth = 1.0 , linestyle = ':' )
# make the x and y axis labels
plot_xlabel = 'JD - %.3f' % npmin ( stimes )
if magsarefluxes :
    plot_ylabel = 'flux'
else :
    plot_ylabel = 'magnitude'
axes . set_xlabel ( plot_xlabel )
axes . set_ylabel ( plot_ylabel )
# fix the yaxis ticks ( turns off offset and uses the full
# value of the yaxis tick )
axes . get_yaxis ( ) . get_major_formatter ( ) . set_useOffset ( False )
axes . get_xaxis ( ) . get_major_formatter ( ) . set_useOffset ( False )


signature:
def _make_phased_magseries_plot ( axes , periodind , stimes , smags , serrs , varperiod , varepoch , phasewrap , phasesort , phasebin , minbinelems , plotxlim , lspmethod , lspmethodind = 0 , xliminsetmode = False , twolspmode = False , magsarefluxes = False , verbose = True , phasems = 2.0 , phasebinms = 4.0 ) :
    '''Makes the phased magseries plot tile for the ` checkplot _ png ` and
 ` twolsp _ checkplot _ png ` functions .
 Parameters
 axes : matplotlib . axes . Axes object
 The Axes object where the generated plot will be written .
 periodind : int
 The index of the current best period being processed in the lspinfo
 dict .
 stimes , smags , serrs : np . array
 The mag / flux time - series arrays along with associated errors . These
 should all have been run through nan - stripping and sigma - clipping
 beforehand .
 varperiod : float or None
 The period to use for this phased light curve plot tile .
 varepoch : ' min ' or float or list of lists or None
 The epoch to use for this phased light curve plot tile . If this is a
 float , will use the provided value directly . If this is ' min ' , will
 automatically figure out the time - of - minimum of the phased light
 curve . If this is None , will use the mimimum value of ` stimes ` as the
 epoch of the phased light curve plot . If this is a list of lists , will
 use the provided value of ` lspmethodind ` to look up the current
 period - finder method and the provided value of ` periodind ` to look up
 the epoch associated with that method and the current period . This is
 mostly only useful when ` twolspmode ` is True .
 phasewrap : bool
 If this is True , the phased time - series will be wrapped around
 phase 0.0.
 phasesort : bool
 If True , will sort the phased light curve in order of increasing phase .
 phasebin : float
 The bin size to use to group together measurements closer than this
 amount in phase . This is in units of phase . If this is a float , a
 phase - binned version of the phased light curve will be overplotted on
 top of the regular phased light curve .
 minbinelems : int
 The minimum number of elements required per phase bin to include it in
 the phased LC plot .
 plotxlim : sequence of two floats or None
 The x - range ( min , max ) of the phased light curve plot . If None , will be
 determined automatically .
 lspmethod : str
 One of the three - letter keys corresponding to period - finder method names
 in the ` astrobase . plotbase . METHODSHORTLABELS ` dict . Used to set the plot
 title correctly .
 lspmethodind : int
 If ` twolspmode ` is set , this will be used to look up the correct epoch
 associated with the current period - finder method and period .
 xliminsetmode : bool
 If this is True , the generated phased light curve plot will use the
 values of ` plotxlim ` as the main plot x - axis limits ( i . e . zoomed - in if
 ` plotxlim ` is a range smaller than the full phase range ) , and will show
 the full phased light curve plot as an smaller inset . Useful for
 planetary transit light curves .
 twolspmode : bool
 If this is True , will use the ` lspmethodind ` and ` periodind ` to look up
 the correct values of epoch , etc . in the provided ` varepoch ` list of
 lists for plotting purposes .
 magsarefluxes : bool
 If True , indicates the input time - series is fluxes and not mags so the
 plot y - axis direction and range can be set appropriately .
 verbose : bool
 If True , indicates progress .
 phasems : float
 The marker size to use for the main phased light curve plot symbols .
 phasebinms : float
 The marker size to use for the binned phased light curve plot symbols .
 Returns
 Does not return anything , works on the input Axes object directly .'''

implementation:
plotvarepoch = None
# figure out the epoch , if it ' s None , use the min of the time
if varepoch is None :
    plotvarepoch = npmin ( stimes )
# if the varepoch is ' min ' , then fit a spline to the light curve
# phased using the min of the time , find the fit mag minimum and use
# the time for that as the varepoch
elif isinstance ( varepoch , str ) and varepoch == 'min' :
    try :
        spfit = spline_fit_magseries ( stimes , smags , serrs , varperiod , magsarefluxes = magsarefluxes , sigclip = None , verbose = verbose )
        plotvarepoch = spfit [ 'fitinfo' ] [ 'fitepoch' ]
        if len ( plotvarepoch ) != 1 :
            plotvarepoch = varepoch [ 0 ]
    except Exception as e :
        LOGERROR ( 'spline fit failed, trying SavGol fit' )
        sgfit = savgol_fit_magseries ( stimes , smags , serrs , varperiod , sigclip = None , magsarefluxes = magsarefluxes , verbose = verbose )
        plotvarepoch = sgfit [ 'fitinfo' ] [ 'fitepoch' ]
        if len ( plotvarepoch ) != 1 :
            plotvarepoch = plotvarepoch [ 0 ]
    finally :
        if plotvarepoch is None :
            LOGERROR ( 'could not find a min epoch time, ' 'using min(times) as the epoch for ' 'the phase-folded LC' )
            plotvarepoch = npmin ( stimes )
elif isinstance ( varepoch , list ) :
    try :
        if twolspmode :
            thisvarepochlist = varepoch [ lspmethodind ]
            plotvarepoch = thisvarepochlist [ periodind ]
        else :
            plotvarepoch = varepoch [ periodind ]
    except Exception as e :
        LOGEXCEPTION ( "varepoch provided in list form either doesn't match " "the length of nbestperiods from the period-finder " "result, or something else went wrong. using min(times) " "as the epoch instead" )
        plotvarepoch = npmin ( stimes )
# the final case is to use the provided varepoch directly
else :
    plotvarepoch = varepoch
if verbose :
    LOGINFO ( 'plotting phased LC with period %.6f, epoch %.5f' % ( varperiod , plotvarepoch ) )
# phase the magseries
phasedlc = phase_magseries ( stimes , smags , varperiod , plotvarepoch , wrap = phasewrap , sort = phasesort )
plotphase = phasedlc [ 'phase' ]
plotmags = phasedlc [ 'mags' ]
# if we ' re supposed to bin the phases , do so
if phasebin :
    binphasedlc = phase_bin_magseries ( plotphase , plotmags , binsize = phasebin , minbinelems = minbinelems )
    binplotphase = binphasedlc [ 'binnedphases' ]
    binplotmags = binphasedlc [ 'binnedmags' ]
# finally , make the phased LC plot
axes . plot ( plotphase , plotmags , marker = 'o' , ms = phasems , ls = 'None' , mew = 0 , color = 'gray' , rasterized = True )
# overlay the binned phased LC plot if we ' re making one
if phasebin :
    axes . plot ( binplotphase , binplotmags , marker = 'o' , ms = phasebinms , ls = 'None' , mew = 0 , color = '#1c1e57' , rasterized = True )
# flip y axis for mags
if not magsarefluxes :
    plot_ylim = axes . get_ylim ( )
    axes . set_ylim ( ( plot_ylim [ 1 ] , plot_ylim [ 0 ] ) )
# set the x axis limit
if not plotxlim :
    axes . set_xlim ( ( npmin ( plotphase ) - 0.1 , npmax ( plotphase ) + 0.1 ) )
else :
    axes . set_xlim ( ( plotxlim [ 0 ] , plotxlim [ 1 ] ) )
# make a grid
axes . grid ( color = '#a9a9a9' , alpha = 0.9 , zorder = 0 , linewidth = 1.0 , linestyle = ':' )
# make the x and y axis labels
plot_xlabel = 'phase'
if magsarefluxes :
    plot_ylabel = 'flux'
else :
    plot_ylabel = 'magnitude'
axes . set_xlabel ( plot_xlabel )
axes . set_ylabel ( plot_ylabel )
# fix the yaxis ticks ( turns off offset and uses the full
# value of the yaxis tick )
axes . get_yaxis ( ) . get_major_formatter ( ) . set_useOffset ( False )
axes . get_xaxis ( ) . get_major_formatter ( ) . set_useOffset ( False )
# make the plot title
if periodind == 0 :
    plottitle = '%s best period: %.6f d - epoch: %.5f' % ( METHODSHORTLABELS [ lspmethod ] , varperiod , plotvarepoch )
elif periodind == 1 and not twolspmode :
    plottitle = '%s best period x 0.5: %.6f d - epoch: %.5f' % ( METHODSHORTLABELS [ lspmethod ] , varperiod , plotvarepoch )
elif periodind == 2 and not twolspmode :
    plottitle = '%s best period x 2: %.6f d - epoch: %.5f' % ( METHODSHORTLABELS [ lspmethod ] , varperiod , plotvarepoch )
elif periodind > 2 and not twolspmode :
    plottitle = '%s peak %s: %.6f d - epoch: %.5f' % ( METHODSHORTLABELS [ lspmethod ] , periodind - 1 , varperiod , plotvarepoch )
elif periodind > 0 :
    plottitle = '%s peak %s: %.6f d - epoch: %.5f' % ( METHODSHORTLABELS [ lspmethod ] , periodind + 1 , varperiod , plotvarepoch )
axes . set_title ( plottitle )
# if we ' re making an inset plot showing the full range
if ( plotxlim and isinstance ( plotxlim , ( list , tuple ) ) and len ( plotxlim ) == 2 and xliminsetmode is True ) : # bump the ylim of the plot so that the inset can fit in this axes plot
    axesylim = axes . get_ylim ( )
    if magsarefluxes :
        axes . set_ylim ( axesylim [ 0 ] , axesylim [ 1 ] + 0.5 * npabs ( axesylim [ 1 ] - axesylim [ 0 ] ) )
    else :
        axes . set_ylim ( axesylim [ 0 ] , axesylim [ 1 ] - 0.5 * npabs ( axesylim [ 1 ] - axesylim [ 0 ] ) )
    # put the inset axes in
    inset = inset_axes ( axes , width = "40%" , height = "40%" , loc = 1 )
    # make the scatter plot for the phased LC plot
    inset . plot ( plotphase , plotmags , marker = 'o' , ms = 2.0 , ls = 'None' , mew = 0 , color = 'gray' , rasterized = True )
    # overlay the binned phased LC plot if we ' re making one
    if phasebin :
        inset . plot ( binplotphase , binplotmags , marker = 'o' , ms = 4.0 , ls = 'None' , mew = 0 , color = '#1c1e57' , rasterized = True )
    # show the full phase coverage
    # show the full phase coverage
    if phasewrap :
        inset . set_xlim ( - 0.2 , 0.8 )
    else :
        inset . set_xlim ( - 0.1 , 1.1 )
    # flip y axis for mags
    if not magsarefluxes :
        inset_ylim = inset . get_ylim ( )
        inset . set_ylim ( ( inset_ylim [ 1 ] , inset_ylim [ 0 ] ) )
    # set the plot title
    inset . text ( 0.5 , 0.1 , 'full phased light curve' , ha = 'center' , va = 'center' , transform = inset . transAxes )
    # don ' t show axes labels or ticks
    inset . set_xticks ( [ ] )
    inset . set_yticks ( [ ] )