def bls_snr(blsdict,<EOL>times,<EOL>mags,<EOL>errs,<EOL>assumeserialbls=False,<EOL>magsarefluxes=False,<EOL>sigclip=<NUM_LIT>,<EOL>npeaks=None,<EOL>perioddeltapercent=<NUM_LIT:10>,<EOL>ingressdurationfraction=<NUM_LIT:0.1>,<EOL>verbose=True):
<EOL>if (npeaks and (<NUM_LIT:0> < npeaks < len(blsdict['<STR_LIT>']))):<EOL><INDENT>nperiods = npeaks<EOL><DEDENT>else:<EOL><INDENT>if verbose:<EOL><INDENT>LOGWARNING('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>len(blsdict['<STR_LIT>']))<EOL><DEDENT>nperiods = len(blsdict['<STR_LIT>'])<EOL><DEDENT>nbestperiods = blsdict['<STR_LIT>'][:nperiods]<EOL>stimes, smags, serrs = sigclip_magseries(times,<EOL>mags,<EOL>errs,<EOL>magsarefluxes=magsarefluxes,<EOL>sigclip=sigclip)<EOL>if len(stimes) > <NUM_LIT:9> and len(smags) > <NUM_LIT:9> and len(serrs) > <NUM_LIT:9>:<EOL><INDENT>nbestsnrs = []<EOL>transitdepth, transitduration = [], []<EOL>nphasebins, transingressbin, transegressbin = [], [], []<EOL>allsubtractedmags = []<EOL>allphasedmags = []<EOL>allphases = []<EOL>allblsmodels = []<EOL>refitperiods = []<EOL>refitepochs = []<EOL>for period in nbestperiods:<EOL><INDENT>startp = period - perioddeltapercent*period/<NUM_LIT><EOL>if startp < <NUM_LIT:0>:<EOL><INDENT>startp = period<EOL><DEDENT>endp = period + perioddeltapercent*period/<NUM_LIT><EOL>if not assumeserialbls:<EOL><INDENT>prevkwargs = blsdict['<STR_LIT>'].copy()<EOL>prevkwargs['<STR_LIT>'] = verbose<EOL>prevkwargs['<STR_LIT>'] = startp<EOL>prevkwargs['<STR_LIT>'] = endp<EOL>prevkwargs['<STR_LIT>'] = None<EOL>blsres = bls_serial_pfind(stimes,<EOL>smags,<EOL>serrs,<EOL>**prevkwargs)<EOL><DEDENT>else:<EOL><INDENT>blsres = blsdict<EOL><DEDENT>thistransdepth = blsres['<STR_LIT>']['<STR_LIT>']<EOL>thistransduration = blsres['<STR_LIT>']['<STR_LIT>']<EOL>thisbestperiod = blsres['<STR_LIT>']<EOL>thistransingressbin = blsres['<STR_LIT>']['<STR_LIT>']<EOL>thistransegressbin = blsres['<STR_LIT>']['<STR_LIT>']<EOL>thisnphasebins = blsdict['<STR_LIT>']['<STR_LIT>']<EOL>stats = _get_bls_stats(stimes,<EOL>smags,<EOL>serrs,<EOL>thistransdepth,<EOL>thistransduration,<EOL>ingressdurationfraction,<EOL>nphasebins,<EOL>thistransingressbin,<EOL>thistransegressbin,<EOL>thisbestperiod,<EOL>thisnphasebins,<EOL>magsarefluxes=magsarefluxes,<EOL>verbose=verbose)<EOL>nbestsnrs.append(stats['<STR_LIT>'])<EOL>transitdepth.append(stats['<STR_LIT>'])<EOL>transitduration.append(stats['<STR_LIT>'])<EOL>transingressbin.append(stats['<STR_LIT>'])<EOL>transegressbin.append(stats['<STR_LIT>'])<EOL>nphasebins.append(stats['<STR_LIT>'])<EOL>refitperiods.append(stats['<STR_LIT>'])<EOL>refitepochs.append(stats['<STR_LIT>'])<EOL>allsubtractedmags.append(stats['<STR_LIT>'])<EOL>allphasedmags.append(stats['<STR_LIT>'])<EOL>allphases.append(stats['<STR_LIT>'])<EOL>allblsmodels.append(stats['<STR_LIT>'])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGERROR('<STR_LIT>')<EOL>nbestsnrs = None<EOL>transitdepth, transitduration = None, None<EOL>nphasebins, transingressbin, transegressbin = None, None, None<EOL>allsubtractedmags, allphases, allphasedmags = None, None, None<EOL><DEDENT>return {'<STR_LIT>':npeaks,<EOL>'<STR_LIT>':refitperiods,<EOL>'<STR_LIT>':refitepochs,<EOL>'<STR_LIT>':nbestsnrs,<EOL>'<STR_LIT>':transitdepth,<EOL>'<STR_LIT>':transitduration,<EOL>'<STR_LIT>':nphasebins,<EOL>'<STR_LIT>':transingressbin,<EOL>'<STR_LIT>':transegressbin,<EOL>'<STR_LIT>':allblsmodels,<EOL>'<STR_LIT>':allsubtractedmags,<EOL>'<STR_LIT>':allphasedmags,<EOL>'<STR_LIT>':allphases}<EOL>
Calculates the signal to noise ratio for each best peak in the BLS
    periodogram, along with transit depth, duration, and refit period and epoch.

    The following equation is used for SNR::

        SNR = (transit model depth / RMS of LC with transit model subtracted)
              * sqrt(number of points in transit)

    Parameters
    ----------

    blsdict : dict
        This is an lspinfo dict produced by either `bls_parallel_pfind` or
        `bls_serial_pfind` in this module, or by your own BLS function. If you
        provide results in a dict from an external BLS function, make sure this
        matches the form below::

            {'bestperiod': the best period value in the periodogram,
             'bestlspval': the periodogram peak associated with the best period,
             'nbestpeaks': the input value of nbestpeaks,
             'nbestlspvals': nbestpeaks-size list of best period peak values,
             'nbestperiods': nbestpeaks-size list of best periods,
             'lspvals': the full array of periodogram powers,
             'frequencies': the full array of frequencies considered,
             'periods': the full array of periods considered,
             'blsresult': list of result dicts from eebls.f wrapper functions,
             'stepsize': the actual stepsize used,
             'nfreq': the actual nfreq used,
             'nphasebins': the actual nphasebins used,
             'mintransitduration': the input mintransitduration,
             'maxtransitduration': the input maxtransitdurations,
             'method':'bls' -> the name of the period-finder method,
             'kwargs':{ dict of all of the input kwargs for record-keeping}}

    times,mags,errs : np.array
        These contain the magnitude/flux time-series and any associated errors.

    assumeserialbls : bool
        If this is True, this function will not rerun BLS around each best peak
        in the input lspinfo dict to refit the periods and epochs. This is
        usally required for `bls_parallel_pfind` so set this to False if you use
        results from that function. The parallel method breaks up the frequency
        space into chunks for speed, and the results may not exactly match those
        from a regular BLS run.

    magsarefluxes : bool
        Set to True if the input measurements in `mags` are actually fluxes and
        not magnitudes.

    npeaks : int or None
        This controls how many of the periods in `blsdict['nbestperiods']` to
        find the SNR for. If it's None, then this will calculate the SNR for all
        of them. If it's an integer between 1 and
        `len(blsdict['nbestperiods'])`, will calculate for only the specified
        number of peak periods, starting from the best period.

    perioddeltapercent : float
        The fraction of the period provided to use to search around this
        value. This is a percentage. The period range searched will then be::

            [period - (perioddeltapercent/100.0)*period,
             period + (perioddeltapercent/100.0)*period]

    ingressdurationfraction : float
        The fraction of the transit duration to use to generate an initial value
        of the transit ingress duration for the BLS model refit. This will be
        fit by this function.

    verbose : bool
        If True, will indicate progress and any problems encountered.

    Returns
    -------

    dict
        A dict of the following form is returned::

            {'npeaks: the number of periodogram peaks requested to get SNR for,
             'period': list of refit best periods for each requested peak,
             'epoch': list of refit epochs (i.e. mid-transit times),
             'snr':list of SNRs of the transit for each requested peak,
             'transitdepth':list of depths of the transits,
             'transitduration':list of durations of the transits,
             'nphasebins':the input value of nphasebins,
             'transingressbin':the phase bin containing transit ingress,
             'transegressbin':the phase bin containing transit egress,
             'allblsmodels':the full BLS models used along with its parameters,
             'allsubtractedmags':BLS models - phased light curves,
             'allphasedmags':the phase light curves,
             'allphases': the phase values}