def check_radius(args): """Checks the radius value.""" if not (args.radius or args.suggest or args.aperradius): print "Must specify an aperture radius." raise SystemExit if args.radius and args.aperradius: print "Must not specify both --aperture and --mcataper." raise SystemExit if args.aperradius and not args.radius: args.radius = aper2deg(args.aperradius) return args
def datamaker( band, skypos, outfile, maglimit=20.0, margin=0.005, searchradius=0.1, radius=gt.aper2deg(4), annulus=[0.0083, 0.025] ): extant_objids = file_setup(outfile) if extant_objids == False: print "NOT RUNNING!!*!" return False uniques = dt.find_unique_sources(band, skypos[0], skypos[1], searchradius, maglimit=maglimit) if uniques is None: print "No sources at this position." return for pos in uniques: mcat = dt.get_mcat_data(pos, margin) if not mcat: print "Nothing at {pos}.".format(pos=pos) continue extant_objids = file_setup(outfile) for i, objid in enumerate(mcat["objid"]): if objid in extant_objids: print "Already processed." continue exp = dt.exp_from_objid(objid) if exp[band]["t0"] < 0: print "skip" continue data = gAperture( band, [mcat["ra"][i], mcat["dec"][i]], radius, annulus=annulus, verbose=0, coadd=True, trange=[exp[band]["t0"], exp[band]["t1"]], ) if data["mag_bgsub_cheese"] and np.isfinite(data["mag_bgsub_cheese"]): csv_construct = construct_row(i, band, objid, mcat, data) print csv_construct with open(outfile, "ab") as csvfile: spreadsheet = csv.writer(csvfile, delimiter=",", quotechar="|", quoting=csv.QUOTE_MINIMAL) spreadsheet.writerow(csv_construct) else: print "no exp" return
def datamaker(band,skypos,outfile,maglimit=20.,detsize=0.5, radius=gt.aper2deg(4),annulus=[0.0083,0.025]): """Note: If you wanted to change the default annulus, then a good starting point would be [0.0083,0.025] (i.e. 30" to 90"). """ extant_objids = file_setup(outfile) if extant_objids==False: print 'NOT RUNNING!!*!' return False uniques = dt.find_unique_sources(band,skypos[0],skypos[1], detsize,maglimit=maglimit) for pos in uniques: mcat = dt.get_mcat_data(pos,0.005) if not mcat: print 'Nothing at {pos}.'.format(pos=pos) continue extant_objids = file_setup(outfile) for i,objid in enumerate(mcat['objid']): if objid in extant_objids: print 'Already processed.' continue exp = dt.exp_from_objid(objid) if exp[band]['t0']<0: print 'skip' continue data = gAperture(band,[mcat['ra'][i],mcat['dec'][i]],radius, annulus=annulus,verbose=0,coadd=True, trange=[exp[band]['t0'],exp[band]['t1']]) if (data['mag_bgsub_cheese'] and np.isfinite(data['mag_bgsub_cheese'])): csv_construct = construct_row(i,band,objid,mcat,data) print csv_construct with open(outfile,'ab') as csvfile: spreadsheet = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) spreadsheet.writerow(csv_construct) else: print 'no exp' return
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]]))))
base = 'calrun_' data = {} for band in bands: 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""" dmag = {'gphot_cheese':(lambda band: data[band]['aper4']-data[band]['mag_bgsub_cheese']), 'gphot_nomask':(lambda band: data[band]['aper4']-data[band]['mag_bgsub']), '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)} 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)) plt.subplot(1,2,1) plt.title('{band} {d}Mag vs. AB Mag (n={n},{bg}_bg)'.format( d=r'$\Delta$',band=band,n=ix.shape[0],bg=bgmode)) plt.xlabel('AB Magnitude (MCAT)') plt.ylabel(r'{d}Magnitude (MCAT-gPhoton)'.format(d=r'$\Delta$')) plt.axis([13,23,-1.3,1.3])