In [1]:
import sys
print sys.executable
# Hack!, this avoids messing with NERSC's config file for jupyter hub
sys.path.append('/global/homes/k/kaylanb/repos/astrometry.net')
sys.path.append('/global/homes/k/kaylanb/repos/tractor')
sys.path
print sys.path
In [5]:
# Easy if pip, conda installable
#!/anaconda2/bin/pip install ...
#!/anaconda2/bin/conda install ...
Run legacy-zeropoints-qa.py like this "python legacy-zeropoints-qa.py" to analyze everything.
See below to walk through it step by step.
In [2]:
%matplotlib inline
%load_ext autoreload
%autoreload 2
import numpy as np
import matplotlib.pyplot as plt
import fitsio
import glob
import os
import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection
from astropy import units
from astropy.coordinates import SkyCoord
from astrometry.util.fits import fits_table, merge_tables
from tractor.brightness import NanoMaggies
In [3]:
import catalogues as cat
In [28]:
cut= np.all((np.all(v2.get('decam_nobs')[:,[4]] == 1,axis=1),\
),axis=0)
v2.get('decam_nobs')[:,4][cut]
Out[28]:
In [24]:
np.where(v2.get('decam_nobs')[:,4] == 1)
Out[24]:
In [ ]:
fits_funcs= cat.CatalogueFuncs()
v2=fits_funcs.stack('v2_cats.txt')
v3=fits_funcs.stack('v3_cats.txt')
In [29]:
cut= np.all((np.all(v2.get('decam_nobs')[:,[4]] == 1,axis=1),\
),axis=0)
v2.cut(cut)
cut= np.all((np.all(v3.get('decam_nobs')[:,[4]] == 1,axis=1),\
),axis=0)
v3.cut(cut)
mat=cat.Matcher()
imatch,imiss,d2d= mat.match_within(v2,v3) #,dist=1./3600)
fits_funcs.set_mags(v2)
fits_funcs.set_mags(v3)
In [9]:
import plots
In [30]:
k=plots.Kaylans(v2,v3,imatch,\
ref_name='v2',obs_name='v3',savefig=True)
In [31]:
d=plots.Dustins(v2,v3,imatch,d2d,\
ref_name='v2',obs_name='v3',savefig=True)
In [375]:
import plots
d=plots.Dustins(v2,v3,imatch,d2d,plot_all=False)
In [397]:
mat.match_within(self,ref,obs,dist=1./3600)
Out[397]:
In [456]:
# Take v2 and shift everything by 1/3 pix in dec
fits_funcs= cat.CatalogueFuncs()
v4=fits_funcs.stack('v2_cats.txt')
In [457]:
third_pix= (1./3)*0.262/3600
v4.set('dec',v4.get('dec')+third_pix)
fits_funcs.set_extra_data(v4)
mat=cat.Matcher()
imatch,imiss,d2d= mat.match_within(v2,v4) #,dist=1./3600)
In [460]:
a=plt.hist(d2d * 3600., 100,range=(0.01,0.2))
In [396]:
import plots
k=plots.Kaylans(v2,v3,imatch,plot_all=False)
for mytype in ['PSF','SIMP','DEV','COMP']:
k.stacked_confusion_matrix(v2[ imatch['ref'] ],v3[ imatch['obs'] ],\
ref_name='v2',obs_name='v3',savefig=True,\
band='z',mytype=mytype)
In [486]:
import plots
k=plots.Kaylans(v2,v3,imatch,plot_all=False)
# k.barchart(v2,v3,\
# ref_name='v2',obs_name='v3',savefig=True,prefix='alldata')
# k.barchart(v2[ imatch['ref']],v3[imatch['obs']],\
# ref_name='v2',obs_name='v3',savefig=True,prefix='matchedonly')
k.delta_mag_vs_mag(v2[ imatch['ref']],v3[imatch['obs']],\
ref_name='v2',obs_name='v3',savefig=True,ylim=[-0.2,0.2])
In [ ]:
In [480]:
import plots
d=plots.Dustins(v2,v3,imatch,d2d,plot_all=False)
d.match_distance(d2d,range=(0,0.2),prefix='',savefig=True)
# imatch_2,imiss_2,d2d_2= mat.match_within(v3,v2)
# d.match_/distance(d2d_2,range=(0,0.2),savefig=True,prefix='2_')
In [442]:
import catalogues
mat=catalogues.Matcher()
d={}
for key in ['v2_auto','v3_auto','v2v3_cross']:
d[key]={}
if key == 'v2v3_cross':
tup= mat.nearest_neighbors_within(v2,v3,within=1./3600,min_nn=1,max_nn=3)
elif key == 'v2_auto':
tup= mat.nearest_neighbors_within(v2,v2,within=1./3600,min_nn=2,max_nn=4)
elif key == 'v3_auto':
tup= mat.nearest_neighbors_within(v3,v3,within=1./3600,min_nn=2,max_nn=4)
d[key]['ref'],d[key]['obs'],d[key]['dist']= tup
In [443]:
d[key]['dist']
Out[443]:
In [444]:
key='v2v3_cross'
dists={}
for cnt,nn in enumerate(np.sort(d[key]['ref'].keys())):
if cnt == 0:
dists[nn]= d[key]['dist'][nn]
else:
dists[nn]= np.concatenate((d[key]['dist'][nn], dists[str(int(nn)-1)]))
print('nn=%s, len(dists[nn])=%d' % (nn,len(dists[nn])))
# if str(int(nn)-1) in d[key]['ref'].keys():
# distsplt.hist(d[key]['dist'][nn]*3600,20,range=(0.01,0.1),normed=True)
In [449]:
print dists['1']
np.histogram(dists['1']*3600,bins=bins,normed=True)
Out[449]:
In [455]:
key='v2v3_cross'
bins=np.linspace(0.01,0.1,num=20)
print bins
for nn in np.sort(d[key]['ref'].keys())[::-1]:
print nn
hist,bj= np.histogram(dists[nn]*3600,bins=bins,normed=True)
binc= (bins[1:]+bins[:-1])/2
plt.step(binc,hist, where='mid')
print binc,hist
plt.xlim((bins[0],bins[-1]))
plt.ylim()
# plt.hist(dists[nn]*3600,20,range=(0.01,0.1),normed=True)
Out[455]:
In [413]:
fig,ax=plt.subplots(1,3) #,figsize=(4,8),sharex=True)
plt.subplots_adjust(hspace=0)
# for cnt,key in zip(range(3),['v2_auto','v3_auto','v2v3_cross']):
cnt=0
key='v2_auto'
for nn in np.sort(d[key]['ref'].keys()):
ax[cnt].hist(d[key]['dist'][nn]*3600,100,range=(0,0.1),label='nn='+nn,\
normed=True)
ax[cnt].legend(loc='upper right')
# hist[band],bins= np.histogram(chi[band][imag],\
# range=(low,hi),bins=50,normed=True)
# db= (bins[1:]-bins[:-1])/2
# binc[band]= bins[:-1]+db
# ax[cnt].step(binc[band],hist[band], where='mid',c='b',lw=2) #label="%.1f < mag < %.1f" % (b_low,b_hi))
Out[413]:
In [377]:
d.match_distance(d2d,range=(0,0.15),savefig=False)
k.
In [363]:
fits_funcs= cat.CatalogueFuncs()
c40=fits_funcs.stack('cosmos_40_tractor_list.txt')
c41=fits_funcs.stack('cosmos_41_tractor_list.txt')
mat=cat.Matcher()
cmatch,imiss,c_d2d= mat.match_within(c40,c41) #,dist=1./3600)
fits_funcs.set_extra_data(c40)
fits_funcs.set_extra_data(c41)
In [369]:
import plots
e=plots.EnriqueCosmos(c40,c41,cmatch,ref_name='40',obs_name='41',savefig=False)
In [367]:
import plots
In [ ]: