def dmag_errors(t,band,sigma=3,mode='mag',mags=np.arange(13,24,0.1)): """Given an exposure time, give dmag error bars at a range of magnitudes.""" cnts = gt.mag2counts(mags,band) ymin = (cnts*t/t)-sigma*np.sqrt(cnts*t)/t ymax = (cnts*t/t)+sigma*np.sqrt(cnts*t)/t if mode=='mag': ymin=mags-gt.counts2mag(ymin,band) ymax=mags-gt.counts2mag(ymax,band) return mags,ymin,ymax
def getcurve(band, ra0, dec0, radius, annulus=None, stepsz=None, lcurve={}, trange=None, tranges=None, verbose=0, coadd=False, minexp=1., maxgap=1., maskdepth=20, maskradius=1.5, photonfile=None, detsize=1.1): skyrange = [np.array(annulus).max().tolist() if annulus else radius, np.array(annulus).max().tolist() if annulus else radius,] if verbose: mc.print_inline("Getting exposure ranges.") if tranges is None: tranges = dbt.fGetTimeRanges(band, [ra0, dec0], trange=trange, maxgap=maxgap, minexp=minexp, verbose=verbose, detsize=detsize) elif not np.array(tranges).shape: print "No exposure time at this location: [{ra},{dec}]".format( ra=ra0,dec=dec0) # FIXME: Everything goes to hell if no exposure time is available... # TODO: Add an ability to specify or exclude specific time ranges if verbose: mc.print_inline("Moving to photon level operations.") # FIXME: This error handling is hideous. try: lcurve = quickmag(band, ra0, dec0, tranges, radius, annulus=annulus, stepsz=stepsz, verbose=verbose, coadd=coadd, maskdepth=maskdepth, maskradius=maskradius,photonfile=photonfile) lcurve['cps'] = lcurve['sources']/lcurve['exptime'] lcurve['cps_bgsub'] = (lcurve['sources']- lcurve['bg']['simple'])/lcurve['exptime'] lcurve['cps_bgsub_cheese'] = (lcurve['sources']- lcurve['bg']['cheese'])/lcurve['exptime'] lcurve['mag'] = gxt.counts2mag(lcurve['cps'],band) lcurve['mag_bgsub'] = gxt.counts2mag(lcurve['cps_bgsub'],band) lcurve['mag_bgsub_cheese'] = gxt.counts2mag( lcurve['cps_bgsub_cheese'],band) lcurve['flux'] = gxt.counts2flux(lcurve['cps'],band) lcurve['flux_bgsub'] = gxt.counts2flux(lcurve['cps_bgsub'],band) lcurve['flux_bgsub_cheese'] = gxt.counts2flux( lcurve['cps_bgsub_cheese'],band) lcurve['detrad'] = mc.distance(lcurve['detxs'],lcurve['detys'],400,400) except ValueError: lcurve['cps']=[] lcurve['cps_bgsub']=[] lcurve['cps_bgsub_cheese']=[] lcurve['mag']=[] lcurve['mag_bgsub']=[] lcurve['mag_bgsub_cheese']=[] lcurve['flux']=[] lcurve['flux_bgsub']=[] lcurve['flux_bgsub_cheese']=[] lcurve['detrad']=[] if verbose: mc.print_inline("Done.") mc.print_inline("") return lcurve
def data_errors(catmag,t,band,sigma=3,mode='mag'): if mode!='cps' and mode!='mag': print 'mode must be set to "cps" or "mag"' exit(0) cnt = gt.mag2counts(catmag,band) ymin = (cnt*t/t)-sigma*np.sqrt(cnt*t)/t ymax = (cnt*t/t)+sigma*np.sqrt(cnt*t)/t if mode=='mag': # y = gt.counts2mag(cnt*t/t,band) ymin = gt.counts2mag(ymin,band) ymax = gt.counts2mag(ymax,band) return ymin, ymax
def model_errors(catmag,band,sigma=3,mode='mag',trange=[1,1600]): """Give upper and lower expected bounds as a function of the nominal magnitude of a source. Super userful for identifying outliers. sigma = how many sigma out to set the bounds mode = ['cps','mag'] - units in which to report bounds """ if mode!='cps' and mode!='mag': print 'mode must be set to "cps" or "mag"' exit(0) x = np.arange(trange[0],trange[1]) cnt = gt.mag2counts(catmag,band) ymin = (cnt*x/x)-sigma*np.sqrt(cnt*x)/x ymax = (cnt*x/x)+sigma*np.sqrt(cnt*x)/x if mode=='mag': # y = gt.counts2mag(cnt*x/x,band) ymin = gt.counts2mag(ymin,band) ymax = gt.counts2mag(ymax,band) return ymin, ymax
data[band] = pd.read_csv('{base}{band}.csv'.format( base=base,band=band)) print '{band} sources: {cnt}'.format( band=band,cnt=data[band]['objid'].shape[0]) """dMag vs. Mag""" for band in bands: dmag = {'gphot_cheese':(lambda band: data[band]['aper4']-data[band]['mag_bgsub_cheese']), 'gphot_nomask':(lambda band: data[band]['aper4']-data[band]['mag_bgsub']), 'gphot_sigma':(lambda band: data[band]['aper4']-data[band]['mag_bgsub_sigmaclip']), 'mcat':lambda band: data[band]['aper4']- gt.counts2mag(gt.mag2counts(data[band]['mag'],band)- data[band]['skybg']*3600**2*mc.area(gt.aper2deg(4)), band)} bgmodekeys={'gphot_cheese':'mag_bgsub_cheese', 'gphot_nomask':'mag_bgsub', 'gphot_sigma':'mag_bgsub_sigmaclip', 'mcat':'skybg'} for bgmode in dmag.keys(): for band in bands: fig = plt.figure(figsize=(8*scl,4*scl)) fig.subplots_adjust(left=0.12,right=0.95,wspace=0.02, bottom=0.15,top=0.9) dmag_err=gu.dmag_errors(100.,band,sigma=1.41) # Make a cut on crazy outliers in the MCAT. Also on det radius and expt. ix = ((data[band]['aper4']>0) & (data[band]['aper4']<30) & (data[band]['distance']<300) & (data[band]['t_eff']<300) & (np.isfinite(np.array(data[band][bgmodekeys[bgmode]]))))
def test_counts2mag_NUV(self): self.assertAlmostEqual(gt.counts2mag(10,'NUV'),-2.5*np.log10(10)+20.08)
def test_counts2mag_FUV(self): self.assertAlmostEqual(gt.counts2mag(10,'FUV'),-2.5*np.log10(10)+18.82)