Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifications to run catalogs with or without agn contributions #177

Merged
merged 4 commits into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions descqa/ColorDistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self, **kwargs): # pylint: disable=W0231
self.color_transformation_q = kwargs.get('color_transformation_q', True)
self.Mag_r_limit = kwargs.get('Mag_r_limit', None)
self.rest_frame = kwargs.get('rest_frame', bool(self.Mag_r_limit and not self.obs_r_mag_limit))
self.exclude_agn = kwargs.get('exclude_agn', False)

# bins of color distribution
self.bins = np.linspace(-1, 4, 2000)
Expand Down Expand Up @@ -111,12 +112,17 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir):
if self.rest_frame:
possible_names = ('Mag_{}_lsst', 'Mag_{}_sdss', 'Mag_true_{}_lsst_z0', 'Mag_true_{}_sdss_z0')
else:
possible_names = ('mag_{}_sdss', 'mag_{}_des', 'mag_true_{}_sdss', 'mag_true_{}_des')
possible_lsst_names = (('mag_{}_noagn_lsst', 'mag_true_{}_noagn_lsst')
if self.exclude_agn else ('mag_{}_lsst', 'mag_true_{}_lsst'))
possible_names = ('mag_{}_sdss', 'mag_{}_des', 'mag_true_{}_sdss', 'mag_true_{}_des') + possible_lsst_names

labels = {band: catalog_instance.first_available(*(n.format(band) for n in possible_names)) for band in bands}
labels = {k: v for k, v in labels.items() if v}

if len(labels) < 2:
return TestResult(skipped=True, summary='magnitudes in mock catalog do not have at least two needed bands.')
filters = set((v.rpartition('_')[-1] for v in labels.values()))

if len(filters) > 1:
return TestResult(skipped=True, summary='magnitudes in mock catalog have mixed filters.')
filter_this = filters.pop()
Expand All @@ -135,13 +141,14 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir):
color_trans = None
if self.color_transformation_q:
color_trans_name = None
if self.validation_catalog == 'DEEP2':
if self.validation_catalog == 'DEEP2' and filter_this != 'lsst':
color_trans_name = '{}2cfht'.format(filter_this)
elif self.validation_catalog == 'SDSS' and filter_this == 'des':
color_trans_name = 'des2sdss'
if color_trans_name:
color_trans = color_transformation[color_trans_name]

filter_title = r'\mathrm{{{}}}'.format(filter_this.upper())
if color_trans:
data_transformed = {}
for band in bands:
Expand All @@ -150,6 +157,8 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir):
except KeyError:
continue

filter_title = (r'{}\rightarrow\mathrm{{{}}}'.format(filter_title, self.validation_catalog)
if data_transformed else filter_title)
data_transformed['redshift'] = data['redshift']
data = data_transformed
del data_transformed
Expand Down Expand Up @@ -180,7 +189,8 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir):
mock_color_dist[color]['binctr'] + color_shift[color], mock_color_dist[color]['cdf'],
self.obs_color_dist[color]['binctr'], self.obs_color_dist[color]['cdf'])

self.make_plots(mock_color_dist, color_shift, cvm_omega, cvm_omega_shift, catalog_name, output_dir)
self.make_plots(mock_color_dist, color_shift, cvm_omega, cvm_omega_shift, catalog_name,
output_dir, filter_title)

# Write to summary file
fn = os.path.join(output_dir, self.summary_output_file)
Expand All @@ -206,19 +216,19 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir):
return TestResult(inspect_only=True)


def make_plots(self, mock_color_dist, color_shift, cvm_omega, cvm_omega_shift, catalog_name, output_dir):
def make_plots(self, mock_color_dist, color_shift, cvm_omega, cvm_omega_shift, catalog_name,
output_dir, filter_title):
available_colors = [c for c in self.colors if c in mock_color_dist]
print(available_colors)

nrows = int(np.ceil(len(available_colors)/2.))
fig_pdf, axes_pdf = plt.subplots(nrows, 2, figsize=(8, 3.5*nrows))
fig_cdf, axes_cdf = plt.subplots(nrows, 2, figsize=(8, 3.5*nrows))
title = ''
if self.obs_r_mag_limit:
title = '$m_r < {:2.1f}, {:.1f} < z < {:.1f}$'.format(self.obs_r_mag_limit, self.zlo, self.zhi)
title = '$m_r^{{{}}} < {:2.1f}, {:.1f} < z < {:.1f}$'.format(filter_title, self.obs_r_mag_limit, self.zlo, self.zhi)
elif self.Mag_r_limit:
title = '$M_r < {:2.1f}, {:.1f} < z < {:.1f}$'.format(self.Mag_r_limit, self.zlo, self.zhi)
title = '$M_r^{{{}}} < {:2.1f}, {:.1f} < z < {:.1f}$'.format(filter_title, self.Mag_r_limit, self.zlo, self.zhi)

print(mock_color_dist.keys())
for ax_cdf, ax_pdf, color in zip(axes_cdf.flat, axes_pdf.flat, available_colors):

if color not in mock_color_dist or (self.validation_catalog and color not in self.obs_color_dist):
Expand All @@ -231,11 +241,11 @@ def make_plots(self, mock_color_dist, color_shift, cvm_omega, cvm_omega_shift, c
opdf_smooth = self.obs_color_dist[color]['pdf_smooth']
ocdf = self.obs_color_dist[color]['cdf']
xmin = np.min([mbinctr[find_first_true(mcdf > 0.001)],
mbinctr[find_first_true(mcdf > 0.001)] + color_shift[color],
obinctr[find_first_true(ocdf > 0.001)]])
mbinctr[find_first_true(mcdf > 0.001)] + color_shift[color],
obinctr[find_first_true(ocdf > 0.001)]])
xmax = np.max([mbinctr[find_first_true(mcdf > 0.999)],
mbinctr[find_first_true(mcdf > 0.999)] + color_shift[color],
obinctr[find_first_true(ocdf > 0.999)]])
mbinctr[find_first_true(mcdf > 0.999)] + color_shift[color],
obinctr[find_first_true(ocdf > 0.999)]])
else:
xmin = np.min(mbinctr[find_first_true(mcdf > 0.001)])
xmax = np.max(mbinctr[find_first_true(mcdf > 0.999)])
Expand All @@ -246,30 +256,30 @@ def make_plots(self, mock_color_dist, color_shift, cvm_omega, cvm_omega_shift, c
catalog_label = catalog_name+'\n'+r'$\omega={:.3}$'.format(cvm_omega[color])
else:
catalog_label = catalog_name
ax_pdf.step(mbinctr, mpdf_smooth, where="mid", label= catalog_label, color='C1')
ax_pdf.step(mbinctr, mpdf_smooth, where="mid", label=catalog_label, color='C1')
if self.validation_catalog:
# validation data
ax_pdf.step(obinctr, opdf_smooth, where="mid", label=self.validation_catalog, color='C0')
# color distribution after constant shift
ax_pdf.step(mbinctr + color_shift[color], mpdf_smooth,
label=catalog_name+' shifted\n'+r'$\omega={:.3}$'.format(cvm_omega_shift[color]),
linestyle='--', color='C2')
label=catalog_name+' shifted\n'+r'$\omega={:.3}$'.format(cvm_omega_shift[color]),
linestyle='--', color='C2')
ax_pdf.set_xlabel('${}$'.format(color))
ax_pdf.set_xlim(xmin, xmax)
ax_pdf.set_ylim(ymin=0.)
ax_pdf.set_ylim(bottom=0.)
ax_pdf.set_title(title)
ax_pdf.legend(loc='upper left', frameon=False)

# Plot CDF
# catalog distribution
ax_cdf.step(mbinctr, mcdf, where="mid", label= catalog_label, color='C1')
ax_cdf.step(mbinctr, mcdf, where="mid", label=catalog_label, color='C1')
if self.validation_catalog:
# validation distribution
ax_cdf.step(obinctr, ocdf, label=self.validation_catalog, color='C0')
# color distribution after constant shift
ax_cdf.step(mbinctr + color_shift[color], mcdf, where="mid",
label=catalog_name+' shifted\n'+r'$\omega={:.3}$'.format(cvm_omega_shift[color]),
linestyle='--', color='C2')
label=catalog_name+' shifted\n'+r'$\omega={:.3}$'.format(cvm_omega_shift[color]),
linestyle='--', color='C2')
ax_cdf.set_xlabel('${}$'.format(color))
ax_cdf.set_title(title)
ax_cdf.set_xlim(xmin, xmax)
Expand Down
10 changes: 10 additions & 0 deletions descqa/configs/Color_Dist_DEEP2_noagn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
subclass_name: ColorDistribution.ColorDistribution
obs_r_mag_limit: 24.0
zlo: 0.85
zhi: 0.95
validation_catalog: DEEP2
exclude_agn: true
plot_pdf_q: true
plot_cdf_q: false
color_transformation_q: true
description: Compare the mock galaxy color distribution with DEEP2
10 changes: 10 additions & 0 deletions descqa/configs/Color_Dist_SDSS_noagn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
subclass_name: ColorDistribution.ColorDistribution
obs_r_mag_limit: 17.7
zlo: 0.05
zhi: 0.1
validation_catalog: SDSS
exclude_agn: true
plot_pdf_q: true
plot_cdf_q: false
color_transformation_q: true
description: Compare the mock galaxy color distribution with SDSS