def get_recovered_variables_for_magbin(simbasedir,<EOL>magbinmedian,<EOL>stetson_stdev_min=<NUM_LIT>,<EOL>inveta_stdev_min=<NUM_LIT>,<EOL>iqr_stdev_min=<NUM_LIT>,<EOL>statsonly=True):
<EOL>with open(os.path.join(simbasedir, '<STR_LIT>'),'<STR_LIT:rb>') as infd:<EOL><INDENT>siminfo = pickle.load(infd)<EOL><DEDENT>objectids = siminfo['<STR_LIT>']<EOL>varflags = siminfo['<STR_LIT>']<EOL>sdssr = siminfo['<STR_LIT>']<EOL>timecols = siminfo['<STR_LIT>']<EOL>magcols = siminfo['<STR_LIT>']<EOL>errcols = siminfo['<STR_LIT>']<EOL>fakelc_formatkey = '<STR_LIT>' % siminfo['<STR_LIT>']<EOL>lcproc.register_lcformat(<EOL>fakelc_formatkey,<EOL>'<STR_LIT>',<EOL>timecols,<EOL>magcols,<EOL>errcols,<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>magsarefluxes=siminfo['<STR_LIT>']<EOL>)<EOL>outdir = os.path.join(simbasedir, '<STR_LIT>')<EOL>if not os.path.exists(outdir):<EOL><INDENT>os.mkdir(outdir)<EOL><DEDENT>varfeaturedir = os.path.join(simbasedir, '<STR_LIT>')<EOL>varthreshinfof = os.path.join(<EOL>outdir,<EOL>'<STR_LIT>' % (magbinmedian,<EOL>stetson_stdev_min,<EOL>inveta_stdev_min)<EOL>)<EOL>varthresh = varthreshold.variability_threshold(<EOL>varfeaturedir,<EOL>varthreshinfof,<EOL>lcformat=fakelc_formatkey,<EOL>min_stetj_stdev=stetson_stdev_min,<EOL>min_inveta_stdev=inveta_stdev_min,<EOL>min_iqr_stdev=iqr_stdev_min,<EOL>verbose=False<EOL>)<EOL>magbins = varthresh['<STR_LIT>']<EOL>magbininds = np.digitize(sdssr, magbins)<EOL>binned_objectids = []<EOL>binned_actualvars = []<EOL>binned_actualnotvars = []<EOL>for mbinind, _magi in zip(np.unique(magbininds),<EOL>range(len(magbins)-<NUM_LIT:1>)):<EOL><INDENT>thisbinind = np.where(magbininds == mbinind)<EOL>thisbin_objectids = objectids[thisbinind]<EOL>thisbin_varflags = varflags[thisbinind]<EOL>thisbin_actualvars = thisbin_objectids[thisbin_varflags]<EOL>thisbin_actualnotvars = thisbin_objectids[~thisbin_varflags]<EOL>binned_objectids.append(thisbin_objectids)<EOL>binned_actualvars.append(thisbin_actualvars)<EOL>binned_actualnotvars.append(thisbin_actualnotvars)<EOL><DEDENT>recdict = {<EOL>'<STR_LIT>':simbasedir,<EOL>'<STR_LIT>':timecols,<EOL>'<STR_LIT>':magcols,<EOL>'<STR_LIT>':errcols,<EOL>'<STR_LIT>':siminfo['<STR_LIT>'],<EOL>'<STR_LIT>':stetson_stdev_min,<EOL>'<STR_LIT>':inveta_stdev_min,<EOL>'<STR_LIT>':iqr_stdev_min,<EOL>'<STR_LIT>':magbinmedian,<EOL>}<EOL>for magcol in magcols:<EOL><INDENT>magbinind = np.where(<EOL>np.array(varthresh[magcol]['<STR_LIT>']) == magbinmedian<EOL>)<EOL>magbinind = np.asscalar(magbinind[<NUM_LIT:0>])<EOL>thisbin_objectids = binned_objectids[magbinind]<EOL>thisbin_actualvars = binned_actualvars[magbinind]<EOL>thisbin_actualnotvars = binned_actualnotvars[magbinind]<EOL>stet_recoveredvars = varthresh[magcol][<EOL>'<STR_LIT>'<EOL>][magbinind]<EOL>stet_recoverednotvars = np.setdiff1d(thisbin_objectids,<EOL>stet_recoveredvars)<EOL>stet_truepositives = np.intersect1d(stet_recoveredvars,<EOL>thisbin_actualvars)<EOL>stet_falsepositives = np.intersect1d(stet_recoveredvars,<EOL>thisbin_actualnotvars)<EOL>stet_truenegatives = np.intersect1d(stet_recoverednotvars,<EOL>thisbin_actualnotvars)<EOL>stet_falsenegatives = np.intersect1d(stet_recoverednotvars,<EOL>thisbin_actualvars)<EOL>stet_recall = recall(stet_truepositives.size,<EOL>stet_falsenegatives.size)<EOL>stet_precision = precision(stet_truepositives.size,<EOL>stet_falsepositives.size)<EOL>stet_mcc = matthews_correl_coeff(stet_truepositives.size,<EOL>stet_truenegatives.size,<EOL>stet_falsepositives.size,<EOL>stet_falsenegatives.size)<EOL>inveta_recoveredvars = varthresh[magcol][<EOL>'<STR_LIT>'<EOL>][magbinind]<EOL>inveta_recoverednotvars = np.setdiff1d(thisbin_objectids,<EOL>inveta_recoveredvars)<EOL>inveta_truepositives = np.intersect1d(inveta_recoveredvars,<EOL>thisbin_actualvars)<EOL>inveta_falsepositives = np.intersect1d(inveta_recoveredvars,<EOL>thisbin_actualnotvars)<EOL>inveta_truenegatives = np.intersect1d(inveta_recoverednotvars,<EOL>thisbin_actualnotvars)<EOL>inveta_falsenegatives = np.intersect1d(inveta_recoverednotvars,<EOL>thisbin_actualvars)<EOL>inveta_recall = recall(inveta_truepositives.size,<EOL>inveta_falsenegatives.size)<EOL>inveta_precision = precision(inveta_truepositives.size,<EOL>inveta_falsepositives.size)<EOL>inveta_mcc = matthews_correl_coeff(inveta_truepositives.size,<EOL>inveta_truenegatives.size,<EOL>inveta_falsepositives.size,<EOL>inveta_falsenegatives.size)<EOL>iqr_recoveredvars = varthresh[magcol][<EOL>'<STR_LIT>'<EOL>][magbinind]<EOL>iqr_recoverednotvars = np.setdiff1d(thisbin_objectids,<EOL>iqr_recoveredvars)<EOL>iqr_truepositives = np.intersect1d(iqr_recoveredvars,<EOL>thisbin_actualvars)<EOL>iqr_falsepositives = np.intersect1d(iqr_recoveredvars,<EOL>thisbin_actualnotvars)<EOL>iqr_truenegatives = np.intersect1d(iqr_recoverednotvars,<EOL>thisbin_actualnotvars)<EOL>iqr_falsenegatives = np.intersect1d(iqr_recoverednotvars,<EOL>thisbin_actualvars)<EOL>iqr_recall = recall(iqr_truepositives.size,<EOL>iqr_falsenegatives.size)<EOL>iqr_precision = precision(iqr_truepositives.size,<EOL>iqr_falsepositives.size)<EOL>iqr_mcc = matthews_correl_coeff(iqr_truepositives.size,<EOL>iqr_truenegatives.size,<EOL>iqr_falsepositives.size,<EOL>iqr_falsenegatives.size)<EOL>stet_missed_inveta_found = np.setdiff1d(inveta_truepositives,<EOL>stet_truepositives)<EOL>stet_missed_iqr_found = np.setdiff1d(iqr_truepositives,<EOL>stet_truepositives)<EOL>inveta_missed_stet_found = np.setdiff1d(stet_truepositives,<EOL>inveta_truepositives)<EOL>inveta_missed_iqr_found = np.setdiff1d(iqr_truepositives,<EOL>inveta_truepositives)<EOL>iqr_missed_stet_found = np.setdiff1d(stet_truepositives,<EOL>iqr_truepositives)<EOL>iqr_missed_inveta_found = np.setdiff1d(inveta_truepositives,<EOL>iqr_truepositives)<EOL>if not statsonly:<EOL><INDENT>recdict[magcol] = {<EOL>'<STR_LIT>':stet_recoveredvars,<EOL>'<STR_LIT>':stet_truepositives,<EOL>'<STR_LIT>':stet_falsepositives,<EOL>'<STR_LIT>':stet_truenegatives,<EOL>'<STR_LIT>':stet_falsenegatives,<EOL>'<STR_LIT>':stet_precision,<EOL>'<STR_LIT>':stet_recall,<EOL>'<STR_LIT>':stet_mcc,<EOL>'<STR_LIT>':inveta_recoveredvars,<EOL>'<STR_LIT>':inveta_truepositives,<EOL>'<STR_LIT>':inveta_falsepositives,<EOL>'<STR_LIT>':inveta_truenegatives,<EOL>'<STR_LIT>':inveta_falsenegatives,<EOL>'<STR_LIT>':inveta_precision,<EOL>'<STR_LIT>':inveta_recall,<EOL>'<STR_LIT>':inveta_mcc,<EOL>'<STR_LIT>':iqr_recoveredvars,<EOL>'<STR_LIT>':iqr_truepositives,<EOL>'<STR_LIT>':iqr_falsepositives,<EOL>'<STR_LIT>':iqr_truenegatives,<EOL>'<STR_LIT>':iqr_falsenegatives,<EOL>'<STR_LIT>':iqr_precision,<EOL>'<STR_LIT>':iqr_recall,<EOL>'<STR_LIT>':iqr_mcc,<EOL>'<STR_LIT>':stet_missed_inveta_found,<EOL>'<STR_LIT>':stet_missed_iqr_found,<EOL>'<STR_LIT>':inveta_missed_stet_found,<EOL>'<STR_LIT>':inveta_missed_iqr_found,<EOL>'<STR_LIT>':iqr_missed_stet_found,<EOL>'<STR_LIT>':iqr_missed_inveta_found,<EOL>'<STR_LIT>':thisbin_actualvars,<EOL>'<STR_LIT>':thisbin_actualnotvars,<EOL>'<STR_LIT>':thisbin_objectids,<EOL>'<STR_LIT>':magbinind,<EOL>}<EOL><DEDENT>else:<EOL><INDENT>recdict[magcol] = {<EOL>'<STR_LIT>':stet_recoveredvars.size,<EOL>'<STR_LIT>':stet_truepositives.size,<EOL>'<STR_LIT>':stet_falsepositives.size,<EOL>'<STR_LIT>':stet_truenegatives.size,<EOL>'<STR_LIT>':stet_falsenegatives.size,<EOL>'<STR_LIT>':stet_precision,<EOL>'<STR_LIT>':stet_recall,<EOL>'<STR_LIT>':stet_mcc,<EOL>'<STR_LIT>':inveta_recoveredvars.size,<EOL>'<STR_LIT>':inveta_truepositives.size,<EOL>'<STR_LIT>':inveta_falsepositives.size,<EOL>'<STR_LIT>':inveta_truenegatives.size,<EOL>'<STR_LIT>':inveta_falsenegatives.size,<EOL>'<STR_LIT>':inveta_precision,<EOL>'<STR_LIT>':inveta_recall,<EOL>'<STR_LIT>':inveta_mcc,<EOL>'<STR_LIT>':iqr_recoveredvars.size,<EOL>'<STR_LIT>':iqr_truepositives.size,<EOL>'<STR_LIT>':iqr_falsepositives.size,<EOL>'<STR_LIT>':iqr_truenegatives.size,<EOL>'<STR_LIT>':iqr_falsenegatives.size,<EOL>'<STR_LIT>':iqr_precision,<EOL>'<STR_LIT>':iqr_recall,<EOL>'<STR_LIT>':iqr_mcc,<EOL>'<STR_LIT>':stet_missed_inveta_found.size,<EOL>'<STR_LIT>':stet_missed_iqr_found.size,<EOL>'<STR_LIT>':inveta_missed_stet_found.size,<EOL>'<STR_LIT>':inveta_missed_iqr_found.size,<EOL>'<STR_LIT>':iqr_missed_stet_found.size,<EOL>'<STR_LIT>':iqr_missed_inveta_found.size,<EOL>'<STR_LIT>':thisbin_actualvars.size,<EOL>'<STR_LIT>':thisbin_actualnotvars.size,<EOL>'<STR_LIT>':thisbin_objectids.size,<EOL>'<STR_LIT>':magbinind,<EOL>}<EOL><DEDENT><DEDENT>return recdict<EOL>
This runs variability selection for the given magbinmedian.

    To generate a full recovery matrix over all magnitude bins, run this
    function for each magbin over the specified stetson_stdev_min and
    inveta_stdev_min grid.

    Parameters
    ----------

    simbasedir : str
        The input directory of fake LCs.

    magbinmedian : float
        The magbin to run the variable recovery for. This is an item from the
        dict from `simbasedir/fakelcs-info.pkl: `fakelcinfo['magrms'][magcol]`
        list for each magcol and designates which magbin to get the recovery
        stats for.

    stetson_stdev_min : float
        The minimum sigma above the trend in the Stetson J variability index
        distribution for this magbin to use to consider objects as variable.

    inveta_stdev_min : float
        The minimum sigma above the trend in the 1/eta variability index
        distribution for this magbin to use to consider objects as variable.

    iqr_stdev_min : float
        The minimum sigma above the trend in the IQR variability index
        distribution for this magbin to use to consider objects as variable.

    statsonly : bool
        If this is True, only the final stats will be returned. If False, the
        full arrays used to generate the stats will also be returned.

    Returns
    -------

    dict
        The returned dict contains statistics for this magbin and if requested,
        the full arrays used to calculate the statistics.