In [1]:
%matplotlib inline
In [2]:
import os
import numpy as np
import matplotlib.pyplot as plt
import eazy
print(eazy.__version__)
# Symlink templates & filters from the eazy-code repository
print('EAZYCODE = '+os.getenv('EAZYCODE'))
eazy.symlink_eazy_inputs()
In [3]:
# quiet numpy/astropy warnings
import warnings
from astropy.utils.exceptions import AstropyWarning
np.seterr(all='ignore')
warnings.simplefilter('ignore', category=AstropyWarning)
In [4]:
params = {}
params['CATALOG_FILE'] = os.path.join(os.getenv('EAZYCODE'), 'inputs/hdfn_fs99_eazy.cat')
params['MAIN_OUTPUT_FILE'] = 'hdfn.eazypy'
# Galactic extinction
params['MW_EBV'] = 0.0103
params['Z_STEP'] = 0.01
params['Z_MIN'] = 0.01
params['Z_MAX'] = 6.
params['PRIOR_ABZP'] = 25
params['PRIOR_FILTER'] = 28 # K
params['PRIOR_FILE'] = 'templates/prior_K_TAO.dat'
params['TEMPLATES_FILE'] = 'templates/fsps_full/tweak_fsps_QSF_12_v3.param'
params['FIX_ZSPEC'] = False
In [5]:
translate_file = os.path.join(os.getenv('EAZYCODE'), 'inputs/zphot.translate')
self = eazy.photoz.PhotoZ(param_file=None, translate_file=translate_file, zeropoint_file=None,
params=params, load_prior=True, load_products=False)
In [6]:
NITER = 3
NBIN = np.minimum(self.NOBJ//100, 180)
self.param.params['VERBOSITY'] = 1.
for iter in range(NITER):
print('Iteration: ', iter)
sn = self.fnu/self.efnu
clip = (sn > 1).sum(axis=1) > 4 # Generally make this higher to ensure reasonable fits
self.iterate_zp_templates(idx=self.idx[clip], update_templates=False,
update_zeropoints=True, iter=iter, n_proc=8,
save_templates=False, error_residuals=(iter > 0),
NBIN=NBIN, get_spatial_offset=False)
In [7]:
# Turn off error corrections derived above
self.efnu = self.efnu_orig*1
# Full catalog
sample = np.isfinite(self.cat['z_spec'])
self.fit_parallel(self.idx[sample], n_proc=8)
In [8]:
# Show zspec-zphot comparison
fig = self.zphot_zspec()
In [9]:
# Derived parameters (z params, RF colors, masses, SFR, etc.)
zout, hdu = self.standard_output(rf_pad_width=0.5, rf_max_err=2,
prior=True, beta_prior=True)
# 'zout' also saved to [MAIN_OUTPUT_FILE].zout.fits
In [10]:
# Show UVJ diagram
uv = -2.5*np.log10(zout['restU']/zout['restV'])
vj = -2.5*np.log10(zout['restV']/zout['restJ'])
ssfr = zout['SFR']/zout['mass']
sel = (zout['z_phot'] > 0.2) & (zout['z_phot'] < 1)
plt.scatter(vj[sel], uv[sel], c=np.log10(ssfr)[sel],
vmin=-13, vmax=-8, alpha=0.5)
plt.xlim(-0.2, 2.3); plt.ylim(0, 2.4); plt.grid()
plt.xlabel(r'$(V-J)_0$'); plt.ylabel(r'$(U-V)_0$')
Out[10]:
In [11]:
# Show brightest objects with z_spec > 1
imag = params['PRIOR_ABZP'] - 2.5*np.log10(self.cat['f_f814w'])
sel = (self.cat['z_spec'] > 1.1)
so = np.argsort(imag[sel])
ids = self.cat['id'][sel][so]
for i in range(4):
fig, data = self.show_fit(ids[i], xlim=[0.2, 3], show_components=True,
logpz=True, zr=[0,4])
In [12]:
# Compare forced fit at z_spec
for i in range(4):
ix = np.where(self.cat['id'] == ids[i])[0][0]
fig, data = self.show_fit(ids[i], xlim=[0.2, 3],
show_components=False,
template_color='steelblue', logpz=True, zr=[0,4])
# Now show with z_spec
axes = fig.axes[:1]
res = self.show_fit(ids[i], xlim=[0.2, 3], axes=axes,
zshow=self.cat['z_spec'][ix],
show_components=False,
template_color='r')
axes[0].legend(loc='upper left')