From 68771376ec4477cd75e966a0e3c6b7c9d961718f Mon Sep 17 00:00:00 2001 From: evevkovacs Date: Fri, 30 Aug 2019 10:40:25 -0700 Subject: [PATCH 01/10] Initial commit for AGN number-density tests --- descqa/AGN_NumberDensities.py | 333 ++++++++++++++++++ descqa/configs/AGN_NumberDensity_SDSSg.yaml | 9 + descqa/configs/AGN_NumberDensity_SDSSi.yaml | 9 + .../AGNdata/SDSS/richards_2006_table2.dat | 25 ++ .../AGNdata/SDSS/richards_2006_table6.dat | 105 ++++++ 5 files changed, 481 insertions(+) create mode 100644 descqa/AGN_NumberDensities.py create mode 100644 descqa/configs/AGN_NumberDensity_SDSSg.yaml create mode 100644 descqa/configs/AGN_NumberDensity_SDSSi.yaml create mode 100644 descqa/data/AGNdata/SDSS/richards_2006_table2.dat create mode 100644 descqa/data/AGNdata/SDSS/richards_2006_table6.dat diff --git a/descqa/AGN_NumberDensities.py b/descqa/AGN_NumberDensities.py new file mode 100644 index 00000000..76387627 --- /dev/null +++ b/descqa/AGN_NumberDensities.py @@ -0,0 +1,333 @@ +from __future__ import unicode_literals, absolute_import, division +import os +import numpy as np +import re +from scipy.interpolate import interp1d +from .base import BaseValidationTest, TestResult +from .plotting import plt +from GCR import GCRQuery +try: + from itertools import zip_longest +except ImportError: + from itertools import izip_longest as zip_longest +import matplotlib.gridspec as gridspec + +possible_observations = { + 'SDSS': { + 'filename_template': 'AGNdata/SDSS/richards_2006_table2.dat', + 'usecols': {'g': {'dN/dm':(0, 1, 2, 5), + 'N {}'.format(self.z_lim[0]), 'redshift < {}'.format(self.z_lim[1])] + Mag_filters = ['{} < {}'.format(Mag_field_key, self.Mag_lim)] + + # retreive data from mock catalog + catalog_data = catalog_instance.get_quantities([mag_field_key], filters=z_filters+ Mag_filters) + d = GCRQuery(*((np.isfinite, col) for col in catalog_data)).filter(catalog_data) + mags = d[mag_field_key] + + ##################################################### + # caclulate the number densities of AGN + ##################################################### + + # get the total number of AGN in catalog + N_tot = len(mags) + + # define the apparent magnitude bins for plotting purposes + dmag = self.validation_data.get('bin_width', 0.25) + + mag_bins = np.arange(self.mag_lo, self.mag_hi + dmag, dmag) + mag_cen = (mag_bins[:-1] + mag_bins[1:])/2 + + # calculate differential binned data (validation data does not divide by bin width) + Ndm, _ = np.histogram(mags, bins=mag_bins) + dn = Ndm/sky_area + + # calculate N( 0) + x = val_mags[mask] + y = np.log10(val_data[mask]) + f = interp1d(x, y, fill_value='extrapolate') + val_mask = (mag_pts > validation_range[0]) & (mag_pts < validation_range[1]) + interp_data = 10**f(mag_pts[val_mask]) + + return mag_pts[val_mask], (cat_data[val_mask] - interp_data)/interp_data + + + def decorate_plot(self, ax, ylabel, scale='log', xlabel=None): + ax.set_ylabel(ylabel, size=self.font_size) + ax.legend(loc='best', fancybox=True, framealpha=0.5, fontsize=self.legend_size, numpoints=1) + ax.set_yscale(scale) + if xlabel: + ax.set_xlabel(xlabel) + else: + for axlabel in ax.get_xticklabels(): + axlabel.set_visible(False) + + + @staticmethod + def post_process_plot(fig): + fig.tight_layout() + fig.subplots_adjust(hspace=0) + + + @staticmethod + def save_quantities(keyname, results, filename, comment=''): + if keyname in results: + if keyname+'-' in results and keyname+'+' in results: + fields = ('mag', keyname, keyname+'-', keyname+'+') + header = ', '.join(('Data columns are: ', keyname, keyname+'-', keyname+'+')) + elif keyname+'+-' in results: + fields = ('mag', keyname, keyname+'+-') + header = ', '.join(('Data columns are: ', keyname, keyname+'+-')) + else: + fields = ('mag', keyname) + header = ', '.join(('Data columns are: ', keyname)) + np.savetxt(filename, np.vstack((results[k] for k in fields)).T, fmt='%12.4e', header=': '.join([comment, header])) + + + def conclude_test(self, output_dir): + """ + """ + self.post_process_plot(self.summary_fig) + self.summary_fig.savefig(os.path.join(output_dir, 'summary.png')) + print('saved') + plt.close(self.summary_fig) diff --git a/descqa/configs/AGN_NumberDensity_SDSSg.yaml b/descqa/configs/AGN_NumberDensity_SDSSg.yaml new file mode 100644 index 00000000..6f372ba4 --- /dev/null +++ b/descqa/configs/AGN_NumberDensity_SDSSg.yaml @@ -0,0 +1,9 @@ +subclass_name: AGN_NumberDensities.AGN_NumberDensity +band: g +rest_frame_band: i +Mag_lim: -22.5 +z_lim: [0.4, 2.1] +observation: 'SDSS' +validation_range: [15., 19.] +included_by_default: true +description: 'Plot N and N( Date: Fri, 30 Aug 2019 12:03:26 -0700 Subject: [PATCH 02/10] Fix travis issues --- descqa/AGN_NumberDensities.py | 77 ++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/descqa/AGN_NumberDensities.py b/descqa/AGN_NumberDensities.py index 76387627..0feec33c 100644 --- a/descqa/AGN_NumberDensities.py +++ b/descqa/AGN_NumberDensities.py @@ -1,9 +1,8 @@ from __future__ import unicode_literals, absolute_import, division import os -import numpy as np import re +import numpy as np from scipy.interpolate import interp1d -from .base import BaseValidationTest, TestResult from .plotting import plt from GCR import GCRQuery try: @@ -11,6 +10,7 @@ except ImportError: from itertools import izip_longest as zip_longest import matplotlib.gridspec as gridspec +from .base import BaseValidationTest, TestResult possible_observations = { 'SDSS': { @@ -67,11 +67,11 @@ def __init__(self, band='g', rest_frame_band='i', Mag_lim=-22.5, z_lim=[0.4, 2.1 # catalog quantities needed possible_mag_fields = ('mag_{}_agnonly_sdss', 'mag_{}_agnonly_lsst', - ) + ) self.possible_mag_fields = [f.format(band) for f in possible_mag_fields] possible_Mag_fields = ('Mag_true_{}_agnonly_sdss_z0', 'Mag_true_{}_agnonly_lsst_z0', - ) + ) self.possible_Mag_fields = [f.format(rest_frame_band) for f in possible_Mag_fields] # attach some attributes to the test @@ -82,9 +82,9 @@ def __init__(self, band='g', rest_frame_band='i', Mag_lim=-22.5, z_lim=[0.4, 2.1 self.font_size = kwargs.get('font_size', 18) self.title_size = kwargs.get('title_size', 20) self.legend_size = kwargs.get('legend_size', 16) - self.no_title = kwargs.get('no_title', False) + self.no_title = kwargs.get('no_title', False) self.nrows = kwargs.get('nrows', 1) - self.ncolumns = kwargs.get('ncolumns', 2) + self.ncolumns = kwargs.get('ncolumns', 2) self.mag_lo = kwargs.get('mag_lo', 14) self.mag_hi = kwargs.get('mag_hi', 24) self.validation_range = kwargs.get('validation_range', (16., 19.)) @@ -92,12 +92,15 @@ def __init__(self, band='g', rest_frame_band='i', Mag_lim=-22.5, z_lim=[0.4, 2.1 self.figx_p = kwargs.get('figx_p', 11) self.figy_p = kwargs.get('figy_p', 7) self.msize = kwargs.get('msize', 6) - + # set color of lines in plots - colors = plt.cm.jet(np.linspace(0,1,2)) # pylint: disable=no-member - if band == 'g': self.line_color = colors[0] - elif band == 'i': self.line_color = colors[1] - else: self.line_color='black' + colors = plt.cm.jet(np.linspace(0, 1, 2)) # pylint: disable=no-member + if band == 'g': + self.line_color = colors[0] + elif band == 'i': + self.line_color = colors[1] + else: + self.line_color = 'black' # check for validation observation if not observation: @@ -128,7 +131,6 @@ def get_validation_data(self, band, observation): save_keys = [k for k in data_args.keys() if 'cols' not in k and 'file' not in k and 'skip' not in k] validation_data = dict(zip(save_keys, [data_args[k] for k in save_keys])) validation_data['data'] = {} - print(validation_data) for k, v in data_args['usecols'][band].items(): data = np.genfromtxt(data_path, unpack=True, usecols=v, skip_header=data_args['skiprows'], @@ -141,17 +143,16 @@ def get_validation_data(self, band, observation): def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): """ """ - mag_field_key = catalog_instance.first_available(*self.possible_mag_fields) Mag_field_key = catalog_instance.first_available(*self.possible_Mag_fields) if not mag_field_key: - return TestResult(skipped=True, + return TestResult(skipped=True, summary='Catalog is missing requested quantity: {}'.format(self.possible_mag_fields)) if not Mag_field_key: return TestResult(skipped=True, summary='Catalog is missing requested quantity: {}'.format(self.possible_Mag_fields)) - + # check to see if catalog is a light cone # this is required since we must be able to calculate the angular area if not catalog_instance.lightcone: @@ -162,10 +163,10 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): sky_area = catalog_instance.sky_area except AttributeError: return TestResult(skipped=True, summary="Catalog needs an attribute 'sky_area'.") - + filtername = mag_field_key.split('_')[(-1 if mag_field_key.startswith('m') else -2)].upper() #extract filtername filelabel = '_'.join((filtername, self.band)) - + z_filters = ['redshift > {}'.format(self.z_lim[0]), 'redshift < {}'.format(self.z_lim[1])] Mag_filters = ['{} < {}'.format(Mag_field_key, self.Mag_lim)] @@ -173,14 +174,14 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): catalog_data = catalog_instance.get_quantities([mag_field_key], filters=z_filters+ Mag_filters) d = GCRQuery(*((np.isfinite, col) for col in catalog_data)).filter(catalog_data) mags = d[mag_field_key] - + ##################################################### # caclulate the number densities of AGN ##################################################### # get the total number of AGN in catalog N_tot = len(mags) - + # define the apparent magnitude bins for plotting purposes dmag = self.validation_data.get('bin_width', 0.25) @@ -190,7 +191,7 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): # calculate differential binned data (validation data does not divide by bin width) Ndm, _ = np.histogram(mags, bins=mag_bins) dn = Ndm/sky_area - + # calculate N( 0) x = val_mags[mask] y = np.log10(val_data[mask]) @@ -293,6 +299,8 @@ def get_frac_diff(mag_pts, cat_data, val_mags, val_data, validation_range): def decorate_plot(self, ax, ylabel, scale='log', xlabel=None): + """ + """ ax.set_ylabel(ylabel, size=self.font_size) ax.legend(loc='best', fancybox=True, framealpha=0.5, fontsize=self.legend_size, numpoints=1) ax.set_yscale(scale) @@ -301,16 +309,20 @@ def decorate_plot(self, ax, ylabel, scale='log', xlabel=None): else: for axlabel in ax.get_xticklabels(): axlabel.set_visible(False) - - + + @staticmethod def post_process_plot(fig): + """ + """ fig.tight_layout() fig.subplots_adjust(hspace=0) @staticmethod def save_quantities(keyname, results, filename, comment=''): + """ + """ if keyname in results: if keyname+'-' in results and keyname+'+' in results: fields = ('mag', keyname, keyname+'-', keyname+'+') @@ -326,6 +338,7 @@ def save_quantities(keyname, results, filename, comment=''): def conclude_test(self, output_dir): """ + output_dir: output directory """ self.post_process_plot(self.summary_fig) self.summary_fig.savefig(os.path.join(output_dir, 'summary.png')) From 2374aa7c2dfbac90927faa99ac406ebfa45a5930 Mon Sep 17 00:00:00 2001 From: evevkovacs Date: Fri, 30 Aug 2019 12:49:38 -0700 Subject: [PATCH 03/10] More travis issues fixed --- descqa/AGN_NumberDensities.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/descqa/AGN_NumberDensities.py b/descqa/AGN_NumberDensities.py index 0feec33c..6b72d846 100644 --- a/descqa/AGN_NumberDensities.py +++ b/descqa/AGN_NumberDensities.py @@ -3,13 +3,12 @@ import re import numpy as np from scipy.interpolate import interp1d -from .plotting import plt from GCR import GCRQuery try: from itertools import zip_longest except ImportError: from itertools import izip_longest as zip_longest -import matplotlib.gridspec as gridspec +from .plotting import plt from .base import BaseValidationTest, TestResult possible_observations = { @@ -63,7 +62,8 @@ def __init__(self, band='g', rest_frame_band='i', Mag_lim=-22.5, z_lim=[0.4, 2.1 string indicating which obsrvational data to use for validating """ # pylint: disable=super-init-not-called - + # pylint: disable=too-many-instance-attributes + # catalog quantities needed possible_mag_fields = ('mag_{}_agnonly_sdss', 'mag_{}_agnonly_lsst', @@ -131,18 +131,19 @@ def get_validation_data(self, band, observation): save_keys = [k for k in data_args.keys() if 'cols' not in k and 'file' not in k and 'skip' not in k] validation_data = dict(zip(save_keys, [data_args[k] for k in save_keys])) validation_data['data'] = {} - + for k, v in data_args['usecols'][band].items(): data = np.genfromtxt(data_path, unpack=True, usecols=v, skip_header=data_args['skiprows'], missing_values=data_args['missing_values']) validation_data['data'][k] = dict(zip(data_args['colnames'], data)) - + return validation_data def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): """ """ + mag_field_key = catalog_instance.first_available(*self.possible_mag_fields) Mag_field_key = catalog_instance.first_available(*self.possible_Mag_fields) if not mag_field_key: @@ -211,15 +212,15 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): [mag_cen, mag_bins[1:]], [dn, n_cum], [dmag, self.band], - self.validation_data['data'].items()): + self.validation_data['data'].items()): # plot ax[0].plot(mag_pts, cat_data, label=catalog_name, color=self.line_color) - ax[0].errorbar(val_data['mag'], val_data['n'], yerr=val_data['err'], label=self.validation_data['label'], + ax[0].errorbar(val_data['mag'], val_data['n'], yerr=val_data['err'], label=self.validation_data['label'], color=self.validation_data['color'], ms=self.msize, fmt='o') summary_ax[0].plot(mag_pts, cat_data, label=catalog_name, color=self.line_color) if self.first_pass: summary_ax[0].errorbar(val_data['mag'], val_data['n'], yerr=val_data['err'], - label=self.validation_data['label'], + label=self.validation_data['label'], color=self.validation_data['color'], ms=self.msize, fmt='o') self.decorate_plot(summary_ax[0], self.validation_data['ytitle'][k].format(ytit), scale='log') @@ -283,7 +284,7 @@ def setup_subplots(self): return fig, axs - + @staticmethod def get_frac_diff(mag_pts, cat_data, val_mags, val_data, validation_range): """ @@ -294,7 +295,7 @@ def get_frac_diff(mag_pts, cat_data, val_mags, val_data, validation_range): f = interp1d(x, y, fill_value='extrapolate') val_mask = (mag_pts > validation_range[0]) & (mag_pts < validation_range[1]) interp_data = 10**f(mag_pts[val_mask]) - + return mag_pts[val_mask], (cat_data[val_mask] - interp_data)/interp_data From 0c225bc5f672fa9d4dd4a49997d83f1ff1b05e96 Mon Sep 17 00:00:00 2001 From: evevkovacs Date: Mon, 9 Sep 2019 14:05:01 -0700 Subject: [PATCH 04/10] Updates to implement agn-fraction choices --- descqa/AGN_NumberDensities.py | 82 +++++++++++++------ descqa/configs/AGN_NumberDensity_SDSSg.yaml | 6 +- .../AGN_NumberDensity_SDSSg_frac.01.yaml | 11 +++ descqa/configs/AGN_NumberDensity_SDSSi.yaml | 2 + .../AGN_NumberDensity_SDSSi_frac.01.yaml | 11 +++ .../AGNdata/SDSS/richards_2006_table2.dat | 41 +++++----- .../SDSS/richards_2006_table2.dat.original | 25 ++++++ 7 files changed, 132 insertions(+), 46 deletions(-) create mode 100644 descqa/configs/AGN_NumberDensity_SDSSg_frac.01.yaml create mode 100644 descqa/configs/AGN_NumberDensity_SDSSi_frac.01.yaml create mode 100644 descqa/data/AGNdata/SDSS/richards_2006_table2.dat.original diff --git a/descqa/AGN_NumberDensities.py b/descqa/AGN_NumberDensities.py index 6b72d846..082361a3 100644 --- a/descqa/AGN_NumberDensities.py +++ b/descqa/AGN_NumberDensities.py @@ -27,7 +27,7 @@ 'bin-width': 0.25, 'label': 'SDSS DR3', 'color': 'r', - 'title': 'Richards et. al. (2006) $\\rm M_{}<{}$, $\\rm {} {}'.format(self.z_lim[0]), 'redshift < {}'.format(self.z_lim[1])] Mag_filters = ['{} < {}'.format(Mag_field_key, self.Mag_lim)] - + # retreive data from mock catalog - catalog_data = catalog_instance.get_quantities([mag_field_key], filters=z_filters+ Mag_filters) + catalog_data = catalog_instance.get_quantities([mag_field_key, mag_agn_key], filters=z_filters+ Mag_filters) d = GCRQuery(*((np.isfinite, col) for col in catalog_data)).filter(catalog_data) - mags = d[mag_field_key] + + #select point-like sources according to specified agn_flux_fraction + N_all = len(d[mag_field_key]) + fluxid = 'AGN+galaxy' + if self.agn_flux_fraction > 0. and self.agn_flux_fraction < 1.: + point_like_mask = (d[mag_agn_key] - d[mag_field_key] < -2.5*np.log10(self.agn_flux_fraction)) + mags = d[mag_field_key][point_like_mask] + elif self.agn_flux_fraction == 0.: + mags = d[mag_field_key] + else: + mags = d[mag_agn_key] + fluxid = 'AGN' ##################################################### # caclulate the number densities of AGN ##################################################### - # get the total number of AGN in catalog + # get the total number of AGN passing cut and save for txt file N_tot = len(mags) - + total_txt = '{}/{} with AGN magnitude fraction > {}'.format(N_tot, N_all, self.agn_flux_fraction) + # define the apparent magnitude bins for plotting purposes dmag = self.validation_data.get('bin_width', 0.25) @@ -191,6 +217,7 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): # calculate differential binned data (validation data does not divide by bin width) Ndm, _ = np.histogram(mags, bins=mag_bins) + print(Ndm) dn = Ndm/sky_area # calculate N( {}$'.format(self.agn_flux_fraction), + 'No AGN extinction' if self.no_agn_extinction else 'AGN extinction')) + for ax, summary_ax, mag_pts, cat_data, ytit, (k, val_data) in zip(axs, self.summary_axs, [mag_cen, mag_bins[1:]], [dn, n_cum], @@ -225,17 +255,20 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): self.decorate_plot(summary_ax[0], self.validation_data['ytitle'][k].format(ytit), scale='log') #decorate - self.decorate_plot(ax[0], self.validation_data['ytitle'][k].format(ytit), scale='log') - + self.decorate_plot(ax[0], self.validation_data['ytitle'][k].format(ytit), scale='log', + legend_title=legend_title) + # get fractional diffrence between the mock catalog and validation data mag_val_pts, delta = self.get_frac_diff(mag_pts, cat_data, val_data['mag'], val_data['n'], self.validation_range) ax[1].plot(mag_val_pts, delta, color=self.line_color, label='Frac. Diff.') summary_ax[1].plot(mag_val_pts, delta, color=self.line_color, label='Frac. Diff.') - self.decorate_plot(ax[1], ylabel=r'$\Delta n/n$', scale='linear', xlabel=r'$\rm m_{}$'.format(self.band)) + self.decorate_plot(ax[1], ylabel=r'$\Delta n/n$', scale='linear', + xlabel=r'$\rm m_{}^{{{}}}$'.format(self.band, fluxid), + legend_title=legend_title) if self.first_pass: self.decorate_plot(summary_ax[1], ylabel=r'$\Delta n/n$', scale='linear', - xlabel=r'$\rm m_{}$'.format(self.band)) + xlabel='$\\rm m_{}^{{{}}}$'.format(self.band, fluxid)) #save plotted points N_tot_data = np.sum(val_data['N_Q']) # total number of AGN @@ -253,7 +286,7 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): #save results for catalog and validation data in txt files for filename, dtype, ntot in zip_longest((filelabel, re.sub(' ', '_', self.validation_data['label'])), ('catalog', 'data'), - (N_tot, N_tot_data)): + (total_txt, N_tot_data)): if filename and dtype: with open(os.path.join(output_dir, 'Nagn_' + filename + '.txt'), 'ab') as f_handle: for key, value in results[dtype].items(): @@ -299,14 +332,15 @@ def get_frac_diff(mag_pts, cat_data, val_mags, val_data, validation_range): return mag_pts[val_mask], (cat_data[val_mask] - interp_data)/interp_data - def decorate_plot(self, ax, ylabel, scale='log', xlabel=None): + def decorate_plot(self, ax, ylabel, scale='log', xlabel=None, legend_title=''): """ """ ax.set_ylabel(ylabel, size=self.font_size) - ax.legend(loc='best', fancybox=True, framealpha=0.5, fontsize=self.legend_size, numpoints=1) + ax.legend(loc='upper left', fancybox=True, framealpha=0.5, title=legend_title, + fontsize=self.legend_size, numpoints=1) ax.set_yscale(scale) if xlabel: - ax.set_xlabel(xlabel) + ax.set_xlabel(xlabel, size=self.font_size) else: for axlabel in ax.get_xticklabels(): axlabel.set_visible(False) @@ -318,7 +352,7 @@ def post_process_plot(fig): """ fig.tight_layout() fig.subplots_adjust(hspace=0) - + fig.subplots_adjust(top=0.94) @staticmethod def save_quantities(keyname, results, filename, comment=''): diff --git a/descqa/configs/AGN_NumberDensity_SDSSg.yaml b/descqa/configs/AGN_NumberDensity_SDSSg.yaml index 6f372ba4..fe156fcf 100644 --- a/descqa/configs/AGN_NumberDensity_SDSSg.yaml +++ b/descqa/configs/AGN_NumberDensity_SDSSg.yaml @@ -2,8 +2,10 @@ subclass_name: AGN_NumberDensities.AGN_NumberDensity band: g rest_frame_band: i Mag_lim: -22.5 -z_lim: [0.4, 2.1] +z_lim: [0.3, 2.2] observation: 'SDSS' -validation_range: [15., 19.] +validation_range: [15.5, 19.] +agn_flux_fraction: 0.5 +no_agn_extinction: true included_by_default: true description: 'Plot N and N( Date: Mon, 9 Sep 2019 14:07:00 -0700 Subject: [PATCH 05/10] Remove extra print statement --- descqa/AGN_NumberDensities.py | 1 - 1 file changed, 1 deletion(-) diff --git a/descqa/AGN_NumberDensities.py b/descqa/AGN_NumberDensities.py index 082361a3..51295ed6 100644 --- a/descqa/AGN_NumberDensities.py +++ b/descqa/AGN_NumberDensities.py @@ -217,7 +217,6 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): # calculate differential binned data (validation data does not divide by bin width) Ndm, _ = np.histogram(mags, bins=mag_bins) - print(Ndm) dn = Ndm/sky_area # calculate N( Date: Wed, 18 Sep 2019 14:19:23 -0700 Subject: [PATCH 06/10] Added duty-cycle option --- descqa/AGN_NumberDensities.py | 37 +++++++++++++------ descqa/configs/AGN_NumberDensity_SDSSg.yaml | 3 +- .../AGN_NumberDensity_SDSSg_frac.5.yaml | 12 ++++++ descqa/configs/AGN_NumberDensity_SDSSi.yaml | 3 +- .../AGN_NumberDensity_SDSSi_frac.5.yaml | 12 ++++++ 5 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 descqa/configs/AGN_NumberDensity_SDSSg_frac.5.yaml create mode 100644 descqa/configs/AGN_NumberDensity_SDSSi_frac.5.yaml diff --git a/descqa/AGN_NumberDensities.py b/descqa/AGN_NumberDensities.py index 51295ed6..c89c02ec 100644 --- a/descqa/AGN_NumberDensities.py +++ b/descqa/AGN_NumberDensities.py @@ -41,7 +41,7 @@ class AGN_NumberDensity(BaseValidationTest): """ AGN number desnsity test """ - def __init__(self, band='g', rest_frame_band='i', Mag_lim=-22.5, z_lim=[0.4, 2.1], + def __init__(self, band='g', rest_frame_band='i', Mag_lim=-22.5, z_lim=(0.4, 2.1), observation='SDSS', **kwargs): """ parameters @@ -83,13 +83,15 @@ def __init__(self, band='g', rest_frame_band='i', Mag_lim=-22.5, z_lim=[0.4, 2.1 'mag_{}_agnonly_{}lsst', ) self.possible_agn_mag_fields = [f.format(band, noagnext) for f in possible_agn_mag_fields] + self.duty_cycle_quantity = 'duty_cycle_on' # attach some attributes to the test self.band = band self.rest_frame_band = rest_frame_band self.Mag_lim = Mag_lim self.z_lim = list(z_lim) - self.agn_flux_fraction = kwargs.get('agn_flux_fraction', 0.5) + self.duty_cycle_on = kwargs.get('duty_cycle_on', True) + self.agn_flux_fraction = kwargs.get('agn_flux_fraction', 0.) self.font_size = kwargs.get('font_size', 18) self.title_size = kwargs.get('title_size', 20) self.legend_size = kwargs.get('legend_size', 16) @@ -158,6 +160,7 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): mag_field_key = catalog_instance.first_available(*self.possible_mag_fields) Mag_field_key = catalog_instance.first_available(*self.possible_Mag_fields) mag_agn_key = catalog_instance.first_available(*self.possible_agn_mag_fields) + duty_cycle_key = catalog_instance.first_available(self.duty_cycle_quantity) if not mag_field_key: return TestResult(skipped=True, summary='Catalog is missing requested quantity: {}'.format(self.possible_mag_fields)) @@ -167,7 +170,10 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): if not mag_agn_key: return TestResult(skipped=True, summary='Catalog is missing requested quantity: {}'.format(self.possible_agn_mag_fields)) - + if self.duty_cycle_on and not duty_cycle_key: + return TestResult(skipped=True, + summary='Catalog is missing requested quantity: {}'.format(self.duty_cycle_quantity)) + # check to see if catalog is a light cone # this is required since we must be able to calculate the angular area if not catalog_instance.lightcone: @@ -184,9 +190,10 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): z_filters = ['redshift > {}'.format(self.z_lim[0]), 'redshift < {}'.format(self.z_lim[1])] Mag_filters = ['{} < {}'.format(Mag_field_key, self.Mag_lim)] + filters = z_filters + Mag_filters + [duty_cycle_key] if self.duty_cycle_on else z_filters + Mag_filters # retreive data from mock catalog - catalog_data = catalog_instance.get_quantities([mag_field_key, mag_agn_key], filters=z_filters+ Mag_filters) + catalog_data = catalog_instance.get_quantities([mag_field_key, mag_agn_key], filters=filters) d = GCRQuery(*((np.isfinite, col) for col in catalog_data)).filter(catalog_data) #select point-like sources according to specified agn_flux_fraction @@ -200,15 +207,21 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): else: mags = d[mag_agn_key] fluxid = 'AGN' - + ##################################################### # caclulate the number densities of AGN ##################################################### # get the total number of AGN passing cut and save for txt file N_tot = len(mags) - total_txt = '{}/{} with AGN magnitude fraction > {}'.format(N_tot, N_all, self.agn_flux_fraction) - + if self.agn_flux_fraction > 0.: + total_txt = '{}/{} with AGN magnitude fraction > {}'.format(N_tot, N_all, self.agn_flux_fraction) + fraction_txt = '$\\rm F_{{AGN}}/F_{{Total}} > {}$'.format(self.agn_flux_fraction) + else: + total_txt = '{} AGN'.format(N_tot) + fraction_txt = '' + fraction_txt = '$\\rm F_{{AGN}}/F_{{Total}} > {}$'.format(self.agn_flux_fraction) + # define the apparent magnitude bins for plotting purposes dmag = self.validation_data.get('bin_width', 0.25) @@ -234,8 +247,9 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir): results = {'catalog':{}, 'data':{}} colname = 'n' - legend_title = '; '.join(('$\\rm F_{{AGN}}/F_{{AGN+galaxy}} > {}$'.format(self.agn_flux_fraction), - 'No AGN extinction' if self.no_agn_extinction else 'AGN extinction')) + legend_title = '; '.join(('Duty-cycle on' if self.duty_cycle_on else 'No duty-cycle', + fraction_txt, + 'No AGN ext.' if self.no_agn_extinction else 'AGN ext.')) for ax, summary_ax, mag_pts, cat_data, ytit, (k, val_data) in zip(axs, self.summary_axs, [mag_cen, mag_bins[1:]], @@ -335,8 +349,9 @@ def decorate_plot(self, ax, ylabel, scale='log', xlabel=None, legend_title=''): """ """ ax.set_ylabel(ylabel, size=self.font_size) - ax.legend(loc='upper left', fancybox=True, framealpha=0.5, title=legend_title, - fontsize=self.legend_size, numpoints=1) + leg = ax.legend(loc='upper left', fancybox=True, framealpha=0.5, + fontsize=self.legend_size, numpoints=1) + leg.set_title(legend_title, prop={'size':'medium'}) ax.set_yscale(scale) if xlabel: ax.set_xlabel(xlabel, size=self.font_size) diff --git a/descqa/configs/AGN_NumberDensity_SDSSg.yaml b/descqa/configs/AGN_NumberDensity_SDSSg.yaml index fe156fcf..ff40a80b 100644 --- a/descqa/configs/AGN_NumberDensity_SDSSg.yaml +++ b/descqa/configs/AGN_NumberDensity_SDSSg.yaml @@ -5,7 +5,8 @@ Mag_lim: -22.5 z_lim: [0.3, 2.2] observation: 'SDSS' validation_range: [15.5, 19.] -agn_flux_fraction: 0.5 +agn_flux_fraction: 0. +duty_cycle_on: true no_agn_extinction: true included_by_default: true description: 'Plot N and N( Date: Wed, 18 Sep 2019 16:24:02 -0500 Subject: [PATCH 07/10] Delete AGN_NumberDensity_SDSSg_frac.01.yaml --- descqa/configs/AGN_NumberDensity_SDSSg_frac.01.yaml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 descqa/configs/AGN_NumberDensity_SDSSg_frac.01.yaml diff --git a/descqa/configs/AGN_NumberDensity_SDSSg_frac.01.yaml b/descqa/configs/AGN_NumberDensity_SDSSg_frac.01.yaml deleted file mode 100644 index 7595566d..00000000 --- a/descqa/configs/AGN_NumberDensity_SDSSg_frac.01.yaml +++ /dev/null @@ -1,11 +0,0 @@ -subclass_name: AGN_NumberDensities.AGN_NumberDensity -band: g -rest_frame_band: i -Mag_lim: -22.5 -z_lim: [0.3, 2.2] -observation: 'SDSS' -validation_range: [15.5, 19.] -agn_flux_fraction: 0.01 -no_agn_extinction: true -included_by_default: false -description: 'Plot N and N( Date: Wed, 18 Sep 2019 16:24:21 -0500 Subject: [PATCH 08/10] Delete AGN_NumberDensity_SDSSi_frac.01.yaml --- descqa/configs/AGN_NumberDensity_SDSSi_frac.01.yaml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 descqa/configs/AGN_NumberDensity_SDSSi_frac.01.yaml diff --git a/descqa/configs/AGN_NumberDensity_SDSSi_frac.01.yaml b/descqa/configs/AGN_NumberDensity_SDSSi_frac.01.yaml deleted file mode 100644 index 7cf34991..00000000 --- a/descqa/configs/AGN_NumberDensity_SDSSi_frac.01.yaml +++ /dev/null @@ -1,11 +0,0 @@ -subclass_name: AGN_NumberDensities.AGN_NumberDensity -band: i -rest_frame_band: i -Mag_lim: -22.5 -z_lim: [0.3, 2.2] -observation: 'SDSS' -validation_range: [15.5, 19.] -agn_flux_fraction: 0.01 -no_agn_extinction: true -included_by_default: false -description: 'Plot N and N( Date: Fri, 20 Sep 2019 17:08:35 -0700 Subject: [PATCH 09/10] Minor change to adjust for not using extinction as default in reader --- descqa/AGN_NumberDensities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/descqa/AGN_NumberDensities.py b/descqa/AGN_NumberDensities.py index c89c02ec..93608e70 100644 --- a/descqa/AGN_NumberDensities.py +++ b/descqa/AGN_NumberDensities.py @@ -66,7 +66,7 @@ def __init__(self, band='g', rest_frame_band='i', Mag_lim=-22.5, z_lim=(0.4, 2.1 self.no_agn_extinction = kwargs.get('no_agn_extinction', True) # catalog quantities needed - noagnext = 'no_agn_extinction_' if self.no_agn_extinction else '' + noagnext = '' if self.no_agn_extinction else 'extincted_agn_' possible_mag_fields = ('mag_{}_{}sdss', 'mag_{}_{}lsst', ) From 35b4cef3a13929f45521136b085650466a74dbe2 Mon Sep 17 00:00:00 2001 From: evevkovacs Date: Fri, 31 Jan 2020 11:31:05 -0800 Subject: [PATCH 10/10] Cosmetic changes for DC2 paper plots --- descqa/AGN_NumberDensities.py | 75 ++++++++++++------- .../configs/AGN_NumberDensity_SDSSg_fig.yaml | 15 ++++ .../configs/AGN_NumberDensity_SDSSi_fig.yaml | 15 ++++ 3 files changed, 77 insertions(+), 28 deletions(-) create mode 100644 descqa/configs/AGN_NumberDensity_SDSSg_fig.yaml create mode 100644 descqa/configs/AGN_NumberDensity_SDSSi_fig.yaml diff --git a/descqa/AGN_NumberDensities.py b/descqa/AGN_NumberDensities.py index 93608e70..b2f5b031 100644 --- a/descqa/AGN_NumberDensities.py +++ b/descqa/AGN_NumberDensities.py @@ -14,20 +14,20 @@ possible_observations = { 'SDSS': { 'filename_template': 'AGNdata/SDSS/richards_2006_table2.dat', - 'usecols': {'g': {'dN/dm':(0, 1, 2, 5), - 'N