In [1]:
import numpy as np
import warnings
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from desisim.templates import QSO
%pylab inline
In [2]:
seed = 123
nmodel = 10
In [3]:
qso = QSO(minwave=3000, maxwave=5e4)
In [4]:
flux, wave, meta = qso.make_templates(nmodel=nmodel, zrange=(2.0, 4.0), seed=seed,
nocolorcuts=True, lyaforest=False)
In [5]:
flux_forest, _, meta_forest = qso.make_templates(nmodel=nmodel, zrange=(2.0, 4.0), seed=seed,
nocolorcuts=True, lyaforest=True)
In [6]:
meta
Out[6]:
In [7]:
meta_forest
Out[7]:
In [8]:
for ii in range(nmodel):
plt.plot(wave, flux_forest[ii, :])
plt.plot(wave, flux[ii, :])
plt.xlim(3000, 6300)
plt.show()
In [18]:
for ii in range(nmodel):
plt.plot(wave, flux[ii, :])
#plt.xlim(3000, 200)
plt.xscale('log')
plt.show()
In [10]:
flux1, _, meta1 = qso.make_templates(nmodel=100, seed=1, lyaforest=True, nocolorcuts=True)
flux2, _, meta2 = qso.make_templates(nmodel=100, seed=1, lyaforest=True, nocolorcuts=False)
In [11]:
fail = np.where(np.sum(flux2, axis=1) == 0)[0]
fail
Out[11]:
In [12]:
def qso_colorbox(ax, plottype='grz'):
"""Draw the QSO selection boxes."""
rmaglim = 22.7
xlim = ax.get_xlim()
ylim = ax.get_ylim()
if plottype == 'grz-r':
verts = [(xlim[0]-0.05, 17.0),
(22.7, 17.0),
(22.7, ylim[1]+0.05),
(xlim[0]-0.05, ylim[1]+0.05)
]
if plottype == 'rW1-rz':
verts = None
ax.axvline(x=-0.3, ls='--', color='k')
ax.axvline(x=1.3, ls='--', color='k')
if plottype == 'gr-rz':
verts = [(-0.3, 1.3),
(1.1, 1.3),
(1.1, ylim[0]-0.05),
(-0.3, ylim[0]-0.05)
]
if verts:
ax.add_patch(Polygon(verts, fill=False, ls='--', color='k'))
In [13]:
def flux2colors(cat):
"""Convert DECam/WISE fluxes to magnitudes and colors."""
colors = dict()
with warnings.catch_warnings(): # ignore missing fluxes (e.g., for QSOs)
warnings.simplefilter('ignore')
for ii, band in zip((1, 2, 4), ('g', 'r', 'z')):
colors[band] = 22.5 - 2.5 * np.log10(cat['DECAM_FLUX'][..., ii].data)
colors['grz'] = 22.5-2.5*np.log10((cat['DECAM_FLUX'][..., 1] +
0.8 * cat['DECAM_FLUX'][..., 2] +
0.5 * cat['DECAM_FLUX'][..., 4]).data / 2.3)
colors['gr'] = colors['g'] - colors['r']
colors['rz'] = colors['r'] - colors['z']
return colors
In [14]:
nocuts = flux2colors(meta1)
cuts = flux2colors(meta2)
In [15]:
fig, ax = plt.subplots()
ax.scatter(nocuts['rz'], nocuts['gr'], s=14, label='No Color-cuts')
ax.scatter(cuts['rz'], cuts['gr'], s=14, marker='s', alpha=0.7, label='With Color-cuts')
ax.set_xlabel('$r - z$')
ax.set_ylabel('$g - r$')
ax.set_xlim(-1, 2.2)
ax.set_ylim(-1, 2.0)
ax.legend(loc='upper right')
qso_colorbox(ax, 'gr-rz')
In [ ]: