def _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=False,<EOL>verbose=False):
try:<EOL><INDENT>me_epochbin = int((thistransegressbin +<EOL>thistransingressbin)/<NUM_LIT>)<EOL>me_phases = (<EOL>(stimes - stimes.min())/thisbestperiod -<EOL>npfloor((stimes - stimes.min())/thisbestperiod)<EOL>)<EOL>me_phases_sortind = npargsort(me_phases)<EOL>me_sorted_phases = me_phases[me_phases_sortind]<EOL>me_sorted_times = stimes[me_phases_sortind]<EOL>me_bins = nplinspace(<NUM_LIT:0.0>, <NUM_LIT:1.0>, thisnphasebins)<EOL>me_bininds = npdigitize(me_sorted_phases, me_bins)<EOL>me_centertransit_ind = me_bininds == me_epochbin<EOL>me_centertransit_phase = (<EOL>npmedian(me_sorted_phases[me_centertransit_ind])<EOL>)<EOL>me_centertransit_timeloc = npwhere(<EOL>npabs(me_sorted_phases - me_centertransit_phase) ==<EOL>npmin(npabs(me_sorted_phases - me_centertransit_phase))<EOL>)<EOL>me_centertransit_time = me_sorted_times[<EOL>me_centertransit_timeloc<EOL>]<EOL>if me_centertransit_time.size > <NUM_LIT:1>:<EOL><INDENT>LOGWARNING('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(thisbestperiod, repr(me_centertransit_time)))<EOL><DEDENT>thisminepoch = me_centertransit_time[<NUM_LIT:0>]<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL>savfit = savgol_fit_magseries(stimes, smags, serrs,<EOL>thisbestperiod,<EOL>magsarefluxes=magsarefluxes,<EOL>verbose=verbose,<EOL>sigclip=None)<EOL>thisminepoch = savfit['<STR_LIT>']['<STR_LIT>']<EOL><DEDENT>if isinstance(thisminepoch, npndarray):<EOL><INDENT>if verbose:<EOL><INDENT>LOGWARNING('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>% repr(thisminepoch))<EOL><DEDENT>thisminepoch = thisminepoch[<NUM_LIT:0>]<EOL><DEDENT>transitparams = [<EOL>thisbestperiod,<EOL>thisminepoch,<EOL>thistransdepth,<EOL>thistransduration,<EOL>ingressdurationfraction*thistransduration<EOL>]<EOL>modelfit = traptransit_fit_magseries(<EOL>stimes,<EOL>smags,<EOL>serrs,<EOL>transitparams,<EOL>sigclip=None,<EOL>magsarefluxes=magsarefluxes,<EOL>verbose=verbose<EOL>)<EOL>if modelfit and modelfit['<STR_LIT>']['<STR_LIT>'] is not None:<EOL><INDENT>fitparams = modelfit['<STR_LIT>']['<STR_LIT>']<EOL>fiterrs = modelfit['<STR_LIT>']['<STR_LIT>']<EOL>modelmags, actualmags, modelphase = (<EOL>modelfit['<STR_LIT>']['<STR_LIT>'],<EOL>modelfit['<STR_LIT>']['<STR_LIT>'],<EOL>modelfit['<STR_LIT>']['<STR_LIT>']<EOL>)<EOL>subtractedmags = actualmags - modelmags<EOL>subtractedrms = npstd(subtractedmags)<EOL>fit_period, fit_epoch, fit_depth, fit_duration, fit_ingress_dur = (<EOL>fitparams<EOL>)<EOL>npts_in_transit = modelfit['<STR_LIT>']['<STR_LIT>']<EOL>transit_snr = (<EOL>npsqrt(npts_in_transit) * npabs(fit_depth/subtractedrms)<EOL>)<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(fit_period, fit_epoch))<EOL>LOGINFO('<STR_LIT>' % npts_in_transit)<EOL>LOGINFO('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(fit_depth,<EOL>fit_duration,<EOL>transit_snr))<EOL><DEDENT>return {'<STR_LIT>':fit_period,<EOL>'<STR_LIT>':fit_epoch,<EOL>'<STR_LIT>':transit_snr,<EOL>'<STR_LIT>':fit_depth,<EOL>'<STR_LIT>':fit_duration,<EOL>'<STR_LIT>':nphasebins,<EOL>'<STR_LIT>':thistransingressbin,<EOL>'<STR_LIT>':thistransegressbin,<EOL>'<STR_LIT>':npts_in_transit,<EOL>'<STR_LIT>':modelmags,<EOL>'<STR_LIT>':subtractedmags,<EOL>'<STR_LIT>':actualmags,<EOL>'<STR_LIT>':modelphase,<EOL>'<STR_LIT>':fitparams,<EOL>'<STR_LIT>':fiterrs,<EOL>'<STR_LIT>':modelfit}<EOL><DEDENT>else:<EOL><INDENT>phased_magseries = phase_magseries_with_errs(stimes,<EOL>smags,<EOL>serrs,<EOL>thisbestperiod,<EOL>thisminepoch,<EOL>wrap=False,<EOL>sort=True)<EOL>tphase = phased_magseries['<STR_LIT>']<EOL>tmags = phased_magseries['<STR_LIT>']<EOL>transitphase = thistransduration/<NUM_LIT><EOL>transitindices = ((tphase < transitphase) |<EOL>(tphase > (<NUM_LIT:1.0> - transitphase)))<EOL>blsmodel = npfull_like(tmags, npmedian(tmags))<EOL>if magsarefluxes:<EOL><INDENT>blsmodel[transitindices] = (<EOL>blsmodel[transitindices] - thistransdepth<EOL>)<EOL><DEDENT>else:<EOL><INDENT>blsmodel[transitindices] = (<EOL>blsmodel[transitindices] - thistransdepth<EOL>)<EOL><DEDENT>subtractedmags = tmags - blsmodel<EOL>subtractedrms = npstd(subtractedmags)<EOL>npts_in_transit = len(tmags[transitindices])<EOL>thissnr = (<EOL>npsqrt(npts_in_transit) * npabs(thistransdepth/subtractedrms)<EOL>)<EOL>if verbose:<EOL><INDENT>LOGINFO('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(thisbestperiod, thisminepoch))<EOL>LOGINFO('<STR_LIT>' % (<NUM_LIT:1.0> -<EOL>transitphase,<EOL><NUM_LIT:1.0>))<EOL>LOGINFO('<STR_LIT>' % (<NUM_LIT:0.0>,<EOL>transitphase))<EOL>LOGINFO('<STR_LIT>' % tmags[transitindices].size)<EOL>LOGINFO('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(thistransdepth,<EOL>thistransduration,<EOL>thissnr))<EOL><DEDENT>return {'<STR_LIT>':thisbestperiod,<EOL>'<STR_LIT>':thisminepoch,<EOL>'<STR_LIT>':thissnr,<EOL>'<STR_LIT>':thistransdepth,<EOL>'<STR_LIT>':thistransduration,<EOL>'<STR_LIT>':nphasebins,<EOL>'<STR_LIT>':thistransingressbin,<EOL>'<STR_LIT>':thistransegressbin,<EOL>'<STR_LIT>':blsmodel,<EOL>'<STR_LIT>':subtractedmags,<EOL>'<STR_LIT>':tmags,<EOL>'<STR_LIT>':tphase}<EOL><DEDENT>
Actually calculates the stats.