In [3]:
%matplotlib inline
from astropy.table import Table
from astropy.coordinates import SkyCoord
from astropy import units as u
from astropy.table import hstack
import matplotlib.pyplot as plt
import numpy as np
from astroML.plotting import hist
# for astroML installation see https://www.astroml.org/user_guide/installation.html
In [17]:
## automatically reload any modules read below that might have changed (e.g. plots)
%load_ext autoreload
%autoreload 2
# importing ZI tools:
import ZItools as zit
In [ ]:
# robust standard deviation
def sigG(arr):
return 0.741*(np.quantile(arr, 0.75)-np.quantile(arr, 0.25))
In [12]:
### code for generating new quantities, such as dra, ddec, colors, differences in mags, etc
def derivedColumns(matches):
matches['dra'] = (matches['ra']-matches['raDES'])*3600
matches['ddec'] = (matches['dec']-matches['decDES'])*3600
ra = matches['ra']
matches['raW'] = np.where(ra > 180, ra-360, ra)
matches['dg'] = matches['g_mMed'] - matches['gDES']
matches['dr'] = matches['r_mMed'] - matches['rDES']
matches['di'] = matches['i_mMed'] - matches['iDES']
matches['dz'] = matches['z_mMed'] - matches['zDES']
matches['gr'] = matches['g_mMed'] - matches['r_mMed']
matches['ri'] = matches['r_mMed'] - matches['i_mMed']
matches['gi'] = matches['g_mMed'] - matches['i_mMed']
matches['iz'] = matches['i_mMed'] - matches['z_mMed']
matches['dgr'] = matches['dg'] - matches['dr']
matches['dri'] = matches['dr'] - matches['di']
matches['diz'] = matches['di'] - matches['dz']
matches['drz'] = matches['dr'] - matches['dz']
matches['dgi'] = matches['dg'] - matches['di']
return
In [ ]:
def doOneColor(d, kw):
print('=========== WORKING ON:', kw['Ystr'], '===================')
xVec = d[kw['Xstr']]
yVec = d[kw['Ystr']]
#
# this is where the useable range of color specified by Xstr is defined
# it's really a hack - these limits should be passed via kw...
xMin = 0.5
xMax = 3.1
xBin, nPts, medianBin, sigGbin = zit.fitMedians(xVec, yVec, xMin, xMax, 52, 0)
fig,ax = plt.subplots(1,1,figsize=(8,6))
ax.scatter(xVec, yVec, s=0.01, c='blue')
ax.scatter(xBin, medianBin, s=5.2, c='yellow')
ax.set_xlim(0.4,3.2)
ax.set_ylim(-0.5,0.5)
ax.set_xlabel(kw['Xstr'])
ax.set_ylabel(kw['Ystr'])
# THERE IS NO ANALYTIC COLOR TERM: linear interpolation of the binned medians!
d['colorfit'] = np.interp(xVec, xBin, medianBin)
# the following line corrects the trend given by the binned medians
d['colorresid'] = d[kw['Ystr']] - d['colorfit']
# note that we only use the restricted range of color for ZP analysis
# 0.3 mag limit is to reject gross outliers
goodC = d[(np.abs(d['colorresid'])<0.3)&(xVec>xMin)&(xVec<xMax)]
### plots
# RA
print(' stats for RA binning medians:')
plotNameRoot = kw['plotNameRoot'] + kw['Ystr']
plotName = plotNameRoot + '_RA.png'
Ylabel =kw['Ystr'] + ' residuals'
kwOC = {"Xstr":'raW', "Xmin":-45, "Xmax":47, "Xlabel":'R.A. (deg)', \
"Ystr":'colorresid', "Ymin":-0.07, "Ymax":0.07, "Ylabel":Ylabel, \
"XminBin":-43, "XmaxBin":45, "nBin":56, \
"plotName":plotName, "Nsigma":3, "offset":0.01, "symbSize":kw['symbSize']}
zit.plotdelMag(goodC, kwOC)
print('made plot', plotName)
# Dec
print('-----------')
print(' stats for Dec binning medians:')
plotName = plotNameRoot + '_Dec.png'
kwOC = {"Xstr":'dec', "Xmin":-1.3, "Xmax":1.3, "Xlabel":'Declination (deg)', \
"Ystr":'colorresid', "Ymin":-0.07, "Ymax":0.07, "Ylabel":Ylabel, \
"XminBin":-1.26, "XmaxBin":1.26, "nBin":52, \
"plotName":plotName, "Nsigma":3, "offset":0.01, "symbSize":kw['symbSize']}
zit.plotdelMag(goodC, kwOC)
print('made plot', plotName)
# r SDSS
print('-----------')
print(' stats for SDSS r binning medians:')
plotName = plotNameRoot + '_rmag.png'
kwOC = {"Xstr":'r_mMed', "Xmin":14.3, "Xmax":22.2, "Xlabel":'SDSS r (mag)', \
"Ystr":'colorresid', "Ymin":-0.07, "Ymax":0.07, "Ylabel":Ylabel, \
"XminBin":14.5, "XmaxBin":21.5, "nBin":55, \
"plotName":plotName, "Nsigma":3, "offset":0.01, "symbSize":kw['symbSize']}
zit.plotdelMag(goodC, kwOC)
print('made plot', plotName)
print('------------------------------------------------------------------')
In [5]:
ZIdataDir = "/Users/ivezic/Work/Science/CalibrationV2/Data"
# Doug's match of v3.2 and DES catalog
DEScatalog = ZIdataDir + "/" + "match_stripe82calibStars_v3.2_des_dr1_cleaned.csv"
colnamesSDSSDES = ['calib_fla', 'ra', 'dec', 'raRMS', 'decRMS', 'nEpochs', 'AR_val',
'u_Nobs', 'u_mMed', 'u_mMean', 'u_mErr', 'u_rms_scatt', 'u_chi2',
'g_Nobs', 'g_mMed', 'g_mMean', 'g_mErr', 'g_rms_scatt', 'g_chi2',
'r_Nobs', 'r_mMed', 'r_mMean', 'r_mErr', 'r_rms_scatt', 'r_chi2',
'i_Nobs', 'i_mMed', 'i_mMean', 'i_mErr', 'i_rms_scatt', 'i_chi2',
'z_Nobs', 'z_mMed', 'z_mMean', 'z_mErr', 'z_rms_scatt', 'z_chi2',
'idDES', 'raDES', 'decDES',
'gDES', 'rDES', 'iDES', 'zDES', 'yDES',
'gErrDES', 'rErrDES', 'iErrDES', 'zErrDES', 'yErrDES',
'gNobsDES', 'rNobsDES', 'iNobsDES', 'zNobsDES', 'yNobsDES', 'sep']
In [6]:
sdssDES = Table.read(DEScatalog, format='csv', names=colnamesSDSSDES)
print(np.size(sdssDES))
In [13]:
derivedColumns(sdssDES)
In [14]:
sdssDESbright = sdssDES[(sdssDES['r_mMed']>14)&(sdssDES['r_mMed']<20)]
print(np.size(sdssDES), np.size(sdssDESbright))
In [18]:
keywords = {"Xstr":'gi', "plotNameRoot":'colorResidDES2_', "symbSize":0.05}
for color in ('dg', 'dr', 'di', 'dz', 'dgr', 'dri', 'diz'):
keywords["Ystr"] = color
doOneColor(sdssDES, keywords)
In [19]:
keywords = {"Xstr":'gi', "plotNameRoot":'colorResidDES2bright_', "symbSize":0.05}
for color in ('dg', 'dr', 'di', 'dz', 'dgr', 'dri', 'diz'):
keywords["Ystr"] = color
doOneColor(sdssDESbright, keywords)
In [ ]: