This notebook presents the merge of the various pristine catalogues to produce HELP mater catalogue on EGS.
from herschelhelp_internal import git_version
print("This notebook was run with herschelhelp_internal version: \n{}".format(git_version()))
%matplotlib inline
#%config InlineBackend.figure_format = 'svg'
import matplotlib.pyplot as plt
plt.rc('figure', figsize=(10, 6))
import os
import time
from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.table import Column, Table
import numpy as np
from pymoc import MOC
from herschelhelp_internal.masterlist import merge_catalogues, nb_merge_dist_plot, specz_merge
from herschelhelp_internal.utils import coords_to_hpidx, ebv, gen_help_id, inMoc
TMP_DIR = os.environ.get('TMP_DIR', "./data_tmp")
OUT_DIR = os.environ.get('OUT_DIR', "./data")
SUFFIX = os.environ.get('SUFFIX', time.strftime("_%Y%m%d"))
try:
os.makedirs(OUT_DIR)
except FileExistsError:
pass
aegis = Table.read("{}/AEGIS.fits".format(TMP_DIR))
candels = Table.read("{}/CANDELS-EGS.fits".format(TMP_DIR))
wirds = Table.read("{}/CFHT-WIRDS.fits".format(TMP_DIR))
cfhtls_wide = Table.read("{}/CFHTLS-WIDE.fits".format(TMP_DIR))
cfhtls_deep = Table.read("{}/CFHTLS-DEEP.fits".format(TMP_DIR))
cfhtlens = Table.read("{}/CFHTLENS.fits".format(TMP_DIR))
deep = Table.read("{}/DEEP2.fits".format(TMP_DIR))
irac = Table.read("{}/IRAC-EGS.fits".format(TMP_DIR))
hsc = Table.read("{}/HSC.fits".format(TMP_DIR))
ps1 = Table.read("{}/PS1.fits".format(TMP_DIR))
legacy = Table.read("{}/LegacySurvey.fits".format(TMP_DIR))
uhs = Table.read("{}/UHS.fits".format(TMP_DIR))
We first merge the optical catalogues and then add the infrared ones.
At every step, we look at the distribution of the distances separating the sources from one catalogue to the other (within a maximum radius) to determine the best cross-matching radius.
master_catalogue = hsc
master_catalogue['hsc_ra'].name = 'ra'
master_catalogue['hsc_dec'].name = 'dec'
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(ps1['ps1_ra'], ps1['ps1_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, ps1, "ps1_ra", "ps1_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(aegis['aegis_ra'], aegis['aegis_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, aegis, "aegis_ra", "aegis_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(candels['candels-egs_ra'], candels['candels-egs_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, candels, "candels-egs_ra", "candels-egs_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(wirds['wirds_ra'], wirds['wirds_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, wirds, "wirds_ra", "wirds_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(cfhtls_wide['cfhtls-wide_ra'], cfhtls_wide['cfhtls-wide_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue,
cfhtls_wide,
"cfhtls-wide_ra",
"cfhtls-wide_dec",
radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(cfhtls_deep['cfhtls-deep_ra'], cfhtls_deep['cfhtls-deep_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue,
cfhtls_deep,
"cfhtls-deep_ra",
"cfhtls-deep_dec",
radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(cfhtlens['cfhtlens_ra'], cfhtlens['cfhtlens_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, cfhtlens, "cfhtlens_ra", "cfhtlens_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(deep['deep2_ra'], deep['deep2_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, deep, "deep2_ra", "deep2_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(irac['irac-egs_ra'], irac['irac-egs_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, irac, "irac-egs_ra", "irac-egs_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(legacy['legacy_ra'], legacy['legacy_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, legacy, "legacy_ra", "legacy_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(uhs['uhs_ra'], uhs['uhs_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, uhs, "uhs_ra", "uhs_dec", radius=0.8*u.arcsec)
When we merge the catalogues, astropy masks the non-existent values (e.g. when a row comes only from a catalogue and has no counterparts in the other, the columns from the latest are masked for that row). We indicate to use NaN for masked values for floats columns, False for flag columns and -1 for ID columns.
for col in master_catalogue.colnames:
if "m_" in col or "merr_" in col or "f_" in col or "ferr_" in col or "stellarity" in col:
master_catalogue[col].fill_value = np.nan
elif "flag" in col:
master_catalogue[col].fill_value = 0
elif "id" in col:
master_catalogue[col].fill_value = -1
master_catalogue = master_catalogue.filled()
master_catalogue[:10].show_in_notebook()
Each pristine catalogue contains a flag indicating if the source was associated to a another nearby source that was removed during the cleaning process. We merge these flags in a single one.
flag_cleaned_columns = [column for column in master_catalogue.colnames
if 'flag_cleaned' in column]
flag_column = np.zeros(len(master_catalogue), dtype=bool)
for column in flag_cleaned_columns:
flag_column |= master_catalogue[column]
master_catalogue.add_column(Column(data=flag_column, name="flag_cleaned"))
master_catalogue.remove_columns(flag_cleaned_columns)
Each pristine catalogue contains a flag indicating the probability of a source being a Gaia object (0: not a Gaia object, 1: possibly, 2: probably, 3: definitely). We merge these flags taking the highest value.
flag_gaia_columns = [column for column in master_catalogue.colnames
if 'flag_gaia' in column]
master_catalogue.add_column(Column(
data=np.max([master_catalogue[column] for column in flag_gaia_columns], axis=0),
name="flag_gaia"
))
master_catalogue.remove_columns(flag_gaia_columns)
Each prisitine catalogue may contain one or several stellarity columns indicating the probability (0 to 1) of each source being a star. We merge these columns taking the highest value. We keep trace of the origin of the stellarity.
stellarity_columns = [column for column in master_catalogue.colnames
if 'stellarity' in column]
print(", ".join(stellarity_columns))
# We create an masked array with all the stellarities and get the maximum value, as well as its
# origin. Some sources may not have an associated stellarity.
stellarity_array = np.array([master_catalogue[column] for column in stellarity_columns])
stellarity_array = np.ma.masked_array(stellarity_array, np.isnan(stellarity_array))
max_stellarity = np.max(stellarity_array, axis=0)
max_stellarity.fill_value = np.nan
no_stellarity_mask = max_stellarity.mask
master_catalogue.add_column(Column(data=max_stellarity.filled(), name="stellarity"))
stellarity_origin = np.full(len(master_catalogue), "NO_INFORMATION", dtype="S20")
stellarity_origin[~no_stellarity_mask] = np.array(stellarity_columns)[np.argmax(stellarity_array, axis=0)[~no_stellarity_mask]]
master_catalogue.add_column(Column(data=stellarity_origin, name="stellarity_origin"))
master_catalogue.remove_columns(stellarity_columns)
master_catalogue.add_column(
ebv(master_catalogue['ra'], master_catalogue['dec'])
)
master_catalogue.add_column(Column(gen_help_id(master_catalogue['ra'], master_catalogue['dec']),
name="help_id"))
master_catalogue.add_column(Column(np.full(len(master_catalogue), "EGS", dtype='<U18'),
name="field"))
# Check that the HELP Ids are unique
if len(master_catalogue) != len(np.unique(master_catalogue['help_id'])):
print("The HELP IDs are not unique!!!")
else:
print("OK!")
specz = Table.read("../../dmu23/dmu23_EGS/data/EGS-specz-v2.1.csv")
for col in specz.colnames:
specz[col].name = specz[col].name.lower()
specz['objid'].name = 'specz_id'
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(specz['ra'] * u.deg, specz['dec'] * u.deg)
)
master_catalogue = specz_merge(master_catalogue, specz, radius=1. * u.arcsec)
There are many different bands to choose between here.
CFHT-WIRDS is the only survey that has J, H and Ks so we take them directly. After that we need to select ugriz bands from between CFHTLS, CFHT-WIRDS and CFHTLenS. We take these in order of depth.
Survey | Bands | Notes |
---|---|---|
CFHTLS-DEEP | u, g, r, i, z | |
CFHTLS-WIDE | u, g, r, i, z | |
CFHT-WIRDS | u, g, r, i, z | Ks selected so may have unique objects |
CFHTLenS | u, g, r, i, z | Reprocessing of CFHTLS-WIDE so not used |
CANDELS-EGS | u, g, r, i, z | Priors from very deep data so may have unique objects |
megacam_origin = Table()
megacam_origin.add_column(master_catalogue['help_id'])
megacam_stats = Table()
megacam_stats.add_column(Column(data=['u','g','r','i','z'], name="Band"))
for col in ["CFHTLS-DEEP", "CFHTLS-WIDE", "CFHT-WIRDS", "CFHTLenS", "CANDELS"]:
megacam_stats.add_column(Column(data=np.full(5, 0), name="{}".format(col)))
megacam_stats.add_column(Column(data=np.full(5, 0), name="use {}".format(col)))
megacam_stats.add_column(Column(data=np.full(5, 0), name="{} ap".format(col)))
megacam_stats.add_column(Column(data=np.full(5, 0), name="use {} ap".format(col)))
megacam_bands = ['u','g','r','i','z']
for band in megacam_bands:
# Megacam total flux
has_cfhtls_deep = ~np.isnan(master_catalogue['f_cfhtls-deep_' + band])
has_cfhtls_wide = ~np.isnan(master_catalogue['f_cfhtls-wide_' + band])
has_wirds = ~np.isnan(master_catalogue['f_wirds_' + band])
has_cfhtlens = ~np.isnan(master_catalogue['f_cfhtlens_' + band])
has_candels = ~np.isnan(master_catalogue['f_candels-megacam_' + band])
use_cfhtls_deep = has_cfhtls_deep
use_cfhtls_wide = has_cfhtls_wide & ~has_cfhtls_deep
use_wirds = has_wirds & ~has_cfhtls_deep & ~has_cfhtls_wide
use_cfhtlens = np.zeros(len(master_catalogue), dtype=bool) #We still merge CFHTLenS to keep ids in cross id
use_candels = has_candels & ~has_cfhtls_deep & ~has_cfhtls_wide & ~has_wirds & ~has_cfhtlens
f_megacam = np.full(len(master_catalogue), np.nan)
f_megacam[use_cfhtls_deep] = master_catalogue['f_cfhtls-deep_' + band][use_cfhtls_deep]
f_megacam[use_cfhtls_wide] = master_catalogue['f_cfhtls-wide_' + band][use_cfhtls_wide]
f_megacam[use_wirds] = master_catalogue['f_wirds_' + band][use_wirds]
f_megacam[use_cfhtlens] = master_catalogue['f_cfhtlens_' + band][use_cfhtlens]
f_megacam[use_candels] = master_catalogue['f_candels-megacam_' + band][use_candels]
ferr_megacam = np.full(len(master_catalogue), np.nan)
ferr_megacam[use_cfhtls_deep] = master_catalogue['ferr_cfhtls-deep_' + band][use_cfhtls_deep]
ferr_megacam[use_cfhtls_wide] = master_catalogue['ferr_cfhtls-wide_' + band][use_cfhtls_wide]
ferr_megacam[use_wirds] = master_catalogue['ferr_wirds_' + band][use_wirds]
ferr_megacam[use_cfhtlens] = master_catalogue['ferr_cfhtlens_' + band][use_cfhtlens]
ferr_megacam[use_candels] = master_catalogue['ferr_candels-megacam_' + band][use_candels]
m_megacam = np.full(len(master_catalogue), np.nan)
m_megacam[use_cfhtls_deep] = master_catalogue['m_cfhtls-deep_' + band][use_cfhtls_deep]
m_megacam[use_cfhtls_wide] = master_catalogue['m_cfhtls-wide_' + band][use_cfhtls_wide]
m_megacam[use_wirds] = master_catalogue['m_wirds_' + band][use_wirds]
m_megacam[use_cfhtlens] = master_catalogue['m_cfhtlens_' + band][use_cfhtlens]
m_megacam[use_candels] = master_catalogue['m_candels-megacam_' + band][use_candels]
merr_megacam = np.full(len(master_catalogue), np.nan)
merr_megacam[use_cfhtls_deep] = master_catalogue['merr_cfhtls-deep_' + band][use_cfhtls_deep]
merr_megacam[use_cfhtls_wide] = master_catalogue['merr_cfhtls-wide_' + band][use_cfhtls_wide]
merr_megacam[use_wirds] = master_catalogue['merr_wirds_' + band][use_wirds]
merr_megacam[use_cfhtlens] = master_catalogue['merr_cfhtlens_' + band][use_cfhtlens]
merr_megacam[use_candels] = master_catalogue['merr_candels-megacam_' + band][use_candels]
flag_megacam = np.full(len(master_catalogue), False, dtype=bool)
flag_megacam[use_cfhtls_deep] = master_catalogue['flag_cfhtls-deep_' + band][use_cfhtls_deep]
flag_megacam[use_cfhtls_wide] = master_catalogue['flag_cfhtls-wide_' + band][use_cfhtls_wide]
flag_megacam[use_wirds] = master_catalogue['flag_wirds_' + band][use_wirds]
flag_megacam[use_cfhtlens] = master_catalogue['flag_cfhtlens_' + band][use_cfhtlens]
flag_megacam[use_candels] = master_catalogue['flag_candels-megacam_' + band][use_candels]
master_catalogue.add_column(Column(data=f_megacam, name="f_megacam_" + band))
master_catalogue.add_column(Column(data=ferr_megacam, name="ferr_megacam_" + band))
master_catalogue.add_column(Column(data=m_megacam, name="m_megacam_" + band))
master_catalogue.add_column(Column(data=merr_megacam, name="merr_megacam_" + band))
master_catalogue.add_column(Column(data=flag_megacam, name="flag_megacam_" + band))
old_columns = ['f_cfhtls-deep_' + band,
'ferr_cfhtls-deep_' + band,
'm_cfhtls-deep_' + band,
'merr_cfhtls-deep_' + band,
'flag_cfhtls-deep_' + band,
'f_cfhtls-wide_' + band,
'ferr_cfhtls-wide_' + band,
'm_cfhtls-wide_' + band,
'merr_cfhtls-wide_' + band,
'flag_cfhtls-wide_' + band,
'f_wirds_' + band,
'ferr_wirds_' + band,
'm_wirds_' + band,
'merr_wirds_' + band,
'flag_wirds_' + band,
'f_cfhtlens_' + band,
'ferr_cfhtlens_' + band,
'm_cfhtlens_' + band,
'merr_cfhtlens_' + band,
'flag_cfhtlens_' + band,
'f_candels-megacam_' + band,
'ferr_candels-megacam_' + band,
'm_candels-megacam_' + band,
'merr_candels-megacam_' + band,
'flag_candels-megacam_' + band,]
master_catalogue.remove_columns(old_columns)
origin = np.full(len(master_catalogue), ' ', dtype='<U5')
origin[use_cfhtls_deep] = "CFHTLS-DEEP"
origin[use_cfhtls_wide] = "CFHTLS-WIDE"
origin[use_wirds] = "CFHT-WIRDS"
origin[use_cfhtlens] = "CFHTLenS"
origin[use_candels] = "CANDELS"
megacam_origin.add_column(Column(data=origin, name= 'f_megacam_' + band ))
# Megacam aperture flux
has_ap_cfhtls_deep = ~np.isnan(master_catalogue['f_ap_cfhtls-deep_' + band])
has_ap_cfhtls_wide = ~np.isnan(master_catalogue['f_ap_cfhtls-wide_' + band])
has_ap_wirds = ~np.isnan(master_catalogue['f_ap_wirds_' + band])
has_ap_cfhtlens = ~np.isnan(master_catalogue['f_ap_cfhtlens_' + band])
has_ap_candels = ~np.isnan(master_catalogue['f_ap_candels-megacam_' + band])
use_ap_cfhtls_deep = has_ap_cfhtls_deep
use_ap_cfhtls_wide = has_ap_cfhtls_wide & ~has_ap_cfhtls_deep
use_ap_wirds = has_ap_wirds & ~has_ap_cfhtls_deep & ~has_ap_cfhtls_wide
use_ap_cfhtlens = has_ap_cfhtlens & ~has_ap_cfhtls_deep & ~has_ap_cfhtls_wide & ~has_ap_wirds
use_ap_candels = has_ap_candels & ~has_ap_cfhtls_deep & ~has_ap_cfhtls_wide & ~has_ap_wirds & ~has_ap_cfhtlens
f_ap_megacam = np.full(len(master_catalogue), np.nan)
f_ap_megacam[use_ap_cfhtls_deep] = master_catalogue['f_ap_cfhtls-deep_' + band][use_ap_cfhtls_deep]
f_ap_megacam[use_ap_cfhtls_wide] = master_catalogue['f_ap_cfhtls-wide_' + band][use_ap_cfhtls_wide]
f_ap_megacam[use_ap_wirds] = master_catalogue['f_ap_wirds_' + band][use_ap_wirds]
f_ap_megacam[use_ap_cfhtlens] = master_catalogue['f_ap_cfhtlens_' + band][use_ap_cfhtlens]
f_ap_megacam[use_ap_candels] = master_catalogue['f_ap_candels-megacam_' + band][use_ap_candels]
ferr_ap_megacam = np.full(len(master_catalogue), np.nan)
ferr_ap_megacam[use_ap_cfhtls_deep] = master_catalogue['ferr_ap_cfhtls-deep_' + band][use_ap_cfhtls_deep]
ferr_ap_megacam[use_ap_cfhtls_wide] = master_catalogue['ferr_ap_cfhtls-wide_' + band][use_ap_cfhtls_wide]
ferr_ap_megacam[use_ap_wirds] = master_catalogue['ferr_ap_wirds_' + band][use_ap_wirds]
ferr_ap_megacam[use_ap_cfhtlens] = master_catalogue['ferr_ap_cfhtlens_' + band][use_ap_cfhtlens]
ferr_ap_megacam[use_ap_candels] = master_catalogue['ferr_ap_candels-megacam_' + band][use_ap_candels]
m_ap_megacam = np.full(len(master_catalogue), np.nan)
m_ap_megacam[use_ap_cfhtls_deep] = master_catalogue['m_ap_cfhtls-deep_' + band][use_ap_cfhtls_deep]
m_ap_megacam[use_ap_cfhtls_wide] = master_catalogue['m_ap_cfhtls-wide_' + band][use_ap_cfhtls_wide]
m_ap_megacam[use_ap_wirds] = master_catalogue['m_ap_wirds_' + band][use_ap_wirds]
m_ap_megacam[use_ap_cfhtlens] = master_catalogue['m_ap_cfhtlens_' + band][use_ap_cfhtlens]
m_ap_megacam[use_ap_candels] = master_catalogue['m_ap_candels-megacam_' + band][use_ap_candels]
merr_ap_megacam = np.full(len(master_catalogue), np.nan)
merr_ap_megacam[use_ap_cfhtls_deep] = master_catalogue['merr_ap_cfhtls-deep_' + band][use_ap_cfhtls_deep]
merr_ap_megacam[use_ap_cfhtls_wide] = master_catalogue['merr_ap_cfhtls-wide_' + band][use_ap_cfhtls_wide]
merr_ap_megacam[use_ap_wirds] = master_catalogue['merr_ap_wirds_' + band][use_ap_wirds]
merr_ap_megacam[use_ap_cfhtlens] = master_catalogue['merr_ap_cfhtlens_' + band][use_ap_cfhtlens]
merr_ap_megacam[use_ap_candels] = master_catalogue['merr_ap_candels-megacam_' + band][use_ap_candels]
master_catalogue.add_column(Column(data=f_ap_megacam, name="f_ap_megacam_" + band))
master_catalogue.add_column(Column(data=ferr_ap_megacam, name="ferr_ap_megacam_" + band))
master_catalogue.add_column(Column(data=m_ap_megacam, name="m_ap_megacam_" + band))
master_catalogue.add_column(Column(data=merr_ap_megacam, name="merr_ap_megacam_" + band))
old_ap_columns = ['f_ap_cfhtls-deep_' + band,
'ferr_ap_cfhtls-deep_' + band,
'm_ap_cfhtls-deep_' + band,
'merr_ap_cfhtls-deep_' + band,
'f_ap_cfhtls-wide_' + band,
'ferr_ap_cfhtls-wide_' + band,
'm_ap_cfhtls-wide_' + band,
'merr_ap_cfhtls-wide_' + band,
'f_ap_wirds_' + band,
'ferr_ap_wirds_' + band,
'm_ap_wirds_' + band,
'merr_ap_wirds_' + band,
'f_ap_cfhtlens_' + band,
'ferr_ap_cfhtlens_' + band,
'm_ap_cfhtlens_' + band,
'merr_ap_cfhtlens_' + band,
'f_ap_candels-megacam_' + band,
'ferr_ap_candels-megacam_' + band,
'm_ap_candels-megacam_' + band,
'merr_ap_candels-megacam_' + band]
master_catalogue.remove_columns(old_ap_columns)
origin_ap = np.full(len(master_catalogue), ' ', dtype='<U5')
origin_ap[use_ap_cfhtls_deep] = "CFHTLS-DEEP"
origin_ap[use_ap_cfhtls_wide] = "CFHTLS-WIDE"
origin_ap[use_ap_wirds] = "CFHT-WIRDS"
origin_ap[use_ap_cfhtlens] = "CFHTLenS"
origin_ap[use_ap_candels] = "CANDELS"
megacam_origin.add_column(Column(data=origin_ap, name= 'f_ap_megacam_' + band ))
megacam_stats['CFHTLS-DEEP'][megacam_stats['Band'] == band] = np.sum(has_cfhtls_deep)
megacam_stats['CFHTLS-WIDE'][megacam_stats['Band'] == band] = np.sum(has_cfhtls_wide)
megacam_stats['CFHT-WIRDS'][megacam_stats['Band'] == band] = np.sum(has_wirds)
megacam_stats['CFHTLenS'][megacam_stats['Band'] == band] = np.sum(has_cfhtlens)
megacam_stats['CANDELS'][megacam_stats['Band'] == band] = np.sum(has_candels)
megacam_stats['use CFHTLS-DEEP'][megacam_stats['Band'] == band] = np.sum(use_cfhtls_deep)
megacam_stats['use CFHTLS-WIDE'][megacam_stats['Band'] == band] = np.sum(use_cfhtls_wide)
megacam_stats['use CFHT-WIRDS'][megacam_stats['Band'] == band] = np.sum(use_wirds)
megacam_stats['use CFHTLenS'][megacam_stats['Band'] == band] = np.sum(use_cfhtlens)
megacam_stats['use CANDELS'][megacam_stats['Band'] == band] = np.sum(use_candels)
megacam_stats['CFHTLS-DEEP ap'][megacam_stats['Band'] == band] = np.sum(has_ap_cfhtls_deep)
megacam_stats['CFHTLS-WIDE ap'][megacam_stats['Band'] == band] = np.sum(has_ap_cfhtls_wide)
megacam_stats['CFHT-WIRDS ap'][megacam_stats['Band'] == band] = np.sum(has_ap_wirds)
megacam_stats['CFHTLenS ap'][megacam_stats['Band'] == band] = np.sum(has_ap_cfhtlens)
megacam_stats['CANDELS ap'][megacam_stats['Band'] == band] = np.sum(has_ap_candels)
megacam_stats['use CFHTLS-DEEP ap'][megacam_stats['Band'] == band] = np.sum(use_ap_cfhtls_deep)
megacam_stats['use CFHTLS-WIDE ap'][megacam_stats['Band'] == band] = np.sum(use_ap_cfhtls_wide)
megacam_stats['use CFHT-WIRDS ap'][megacam_stats['Band'] == band] = np.sum(use_ap_wirds)
megacam_stats['use CFHTLenS ap'][megacam_stats['Band'] == band] = np.sum(use_ap_cfhtlens)
megacam_stats['use CANDELS ap'][megacam_stats['Band'] == band] = np.sum(use_ap_candels)
megacam_stats.show_in_notebook()
megacam_origin.write("{}/egs_megacam_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)
We have WIRCAM J,H, and Ks from both CFHT-WIRDS (Ks prior and blind) and CANDELS-EGS. Since the CANDELS will have very deep priors the WIRCAM fluxes are worth keepting to constrain photo-z. We therefor take the CFHT-WIRDS fluxes if they are there but keep all the CANDELS fluxes for sources that only have those.
wircam_origin = Table()
wircam_origin.add_column(master_catalogue['help_id'])
wircam_stats = Table()
wircam_stats.add_column(Column(data=['j', 'h', 'k'], name="Band"))
for col in ["CFHT-WIRDS", "CANDELS"]:
wircam_stats.add_column(Column(data=np.full(3, 0), name="{}".format(col)))
wircam_stats.add_column(Column(data=np.full(3, 0), name="use {}".format(col)))
wircam_stats.add_column(Column(data=np.full(3, 0), name="{} ap".format(col)))
wircam_stats.add_column(Column(data=np.full(3, 0), name="use {} ap".format(col)))
wircam_bands = ['j', 'h', 'k']
for band in wircam_bands:
# wircam total flux
has_wirds = ~np.isnan(master_catalogue['f_wirds_' + band])
has_candels = ~np.isnan(master_catalogue['f_candels-wircam_' + band])
use_wirds = has_wirds
use_candels = has_candels & ~has_wirds
f_wircam = np.full(len(master_catalogue), np.nan)
f_wircam[use_wirds] = master_catalogue['f_wirds_' + band][use_wirds]
f_wircam[use_candels] = master_catalogue['f_candels-wircam_' + band][use_candels]
ferr_wircam = np.full(len(master_catalogue), np.nan)
ferr_wircam[use_wirds] = master_catalogue['ferr_wirds_' + band][use_wirds]
ferr_wircam[use_candels] = master_catalogue['ferr_candels-wircam_' + band][use_candels]
m_wircam = np.full(len(master_catalogue), np.nan)
m_wircam[use_wirds] = master_catalogue['m_wirds_' + band][use_wirds]
m_wircam[use_candels] = master_catalogue['m_candels-wircam_' + band][use_candels]
merr_wircam = np.full(len(master_catalogue), np.nan)
merr_wircam[use_wirds] = master_catalogue['merr_wirds_' + band][use_wirds]
merr_wircam[use_candels] = master_catalogue['merr_candels-wircam_' + band][use_candels]
flag_wircam = np.full(len(master_catalogue), False, dtype=bool)
flag_wircam[use_wirds] = master_catalogue['flag_wirds_' + band][use_wirds]
flag_wircam[use_candels] = master_catalogue['flag_candels-wircam_' + band][use_candels]
master_catalogue.add_column(Column(data=f_wircam, name="f_wircam_" + band))
master_catalogue.add_column(Column(data=ferr_wircam, name="ferr_wircam_" + band))
master_catalogue.add_column(Column(data=m_wircam, name="m_wircam_" + band))
master_catalogue.add_column(Column(data=merr_wircam, name="merr_wircam_" + band))
master_catalogue.add_column(Column(data=flag_wircam, name="flag_wircam_" + band))
old_columns = ['f_wirds_' + band,
'ferr_wirds_' + band,
'm_wirds_' + band,
'merr_wirds_' + band,
'flag_wirds_' + band,
'f_candels-wircam_' + band,
'ferr_candels-wircam_' + band,
'm_candels-wircam_' + band,
'merr_candels-wircam_' + band,
'flag_candels-wircam_' + band,]
master_catalogue.remove_columns(old_columns)
origin = np.full(len(master_catalogue), ' ', dtype='<U5')
origin[use_wirds] = "CFHT-WIRDS"
origin[use_candels] = "CANDELS"
wircam_origin.add_column(Column(data=origin, name= 'f_wircam_' + band ))
# wircam aperture flux
has_ap_wirds = ~np.isnan(master_catalogue['f_ap_wirds_' + band])
has_ap_candels = ~np.isnan(master_catalogue['f_ap_candels-wircam_' + band])
use_ap_wirds = has_ap_wirds
use_ap_candels = has_ap_candels & ~has_ap_wirds
f_ap_wircam = np.full(len(master_catalogue), np.nan)
f_ap_wircam[use_ap_wirds] = master_catalogue['f_ap_wirds_' + band][use_ap_wirds]
f_ap_wircam[use_ap_candels] = master_catalogue['f_ap_candels-wircam_' + band][use_ap_candels]
ferr_ap_wircam = np.full(len(master_catalogue), np.nan)
ferr_ap_wircam[use_ap_wirds] = master_catalogue['ferr_ap_wirds_' + band][use_ap_wirds]
ferr_ap_wircam[use_ap_candels] = master_catalogue['ferr_ap_candels-wircam_' + band][use_ap_candels]
m_ap_wircam = np.full(len(master_catalogue), np.nan)
m_ap_wircam[use_ap_wirds] = master_catalogue['m_ap_wirds_' + band][use_ap_wirds]
m_ap_wircam[use_ap_candels] = master_catalogue['m_ap_candels-wircam_' + band][use_ap_candels]
merr_ap_wircam = np.full(len(master_catalogue), np.nan)
merr_ap_wircam[use_ap_wirds] = master_catalogue['merr_ap_wirds_' + band][use_ap_wirds]
merr_ap_wircam[use_ap_candels] = master_catalogue['merr_ap_candels-wircam_' + band][use_ap_candels]
master_catalogue.add_column(Column(data=f_ap_wircam, name="f_ap_wircam_" + band))
master_catalogue.add_column(Column(data=ferr_ap_wircam, name="ferr_ap_wircam_" + band))
master_catalogue.add_column(Column(data=m_ap_wircam, name="m_ap_wircam_" + band))
master_catalogue.add_column(Column(data=merr_ap_wircam, name="merr_ap_wircam_" + band))
old_ap_columns = ['f_ap_wirds_' + band,
'ferr_ap_wirds_' + band,
'm_ap_wirds_' + band,
'merr_ap_wirds_' + band,
'f_ap_candels-wircam_' + band,
'ferr_ap_candels-wircam_' + band,
'm_ap_candels-wircam_' + band,
'merr_ap_candels-wircam_' + band]
master_catalogue.remove_columns(old_ap_columns)
origin_ap = np.full(len(master_catalogue), ' ', dtype='<U5')
origin_ap[use_ap_wirds] = "CFHT-WIRDS"
origin_ap[use_ap_candels] = "CANDELS"
wircam_origin.add_column(Column(data=origin_ap, name= 'f_ap_wircam_' + band ))
wircam_stats['CFHT-WIRDS'][wircam_stats['Band'] == band] = np.sum(has_wirds)
wircam_stats['CANDELS'][wircam_stats['Band'] == band] = np.sum(has_candels)
wircam_stats['use CFHT-WIRDS'][wircam_stats['Band'] == band] = np.sum(use_wirds)
wircam_stats['use CANDELS'][wircam_stats['Band'] == band] = np.sum(use_candels)
wircam_stats['CFHT-WIRDS ap'][wircam_stats['Band'] == band] = np.sum(has_ap_wirds)
wircam_stats['CANDELS ap'][wircam_stats['Band'] == band] = np.sum(has_ap_candels)
wircam_stats['use CFHT-WIRDS ap'][wircam_stats['Band'] == band] = np.sum(use_ap_wirds)
wircam_stats['use CANDELS ap'][wircam_stats['Band'] == band] = np.sum(use_ap_candels)
wircam_stats.show_in_notebook()
wircam_origin.write("{}/egs_wircam_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)
We add a binary flag_optnir_obs
indicating that a source was observed in a given wavelength domain:
It's an integer binary flag, so a source observed both in optical and near-infrared by not in mid-infrared would have this flag at 1 + 2 = 3.
Note 1: The observation flag is based on the creation of multi-order coverage maps from the catalogues, this may not be accurate, especially on the edges of the coverage.
Note 2: Being on the observation coverage does not mean having fluxes in that wavelength domain. For sources observed in one domain but having no flux in it, one must take into consideration de different depths in the catalogue we are using.
aegis_moc = MOC(filename="../../dmu0/dmu0_AEGIS/data/EGS_Palomar_20160804_MOC.fits")
candels_moc = MOC(filename="../../dmu0/dmu0_CANDELS-EGS/data/hlsp_candels_hst_wfc3_egs-tot-multiband_f160w_v1_MOC.fits")
wirds_moc = MOC(filename="../../dmu0/dmu0_CFHT-WIRDS/data/EGS_Ks-priors_MOC.fits")
cfhtls_deep_moc = MOC(filename="../../dmu0/dmu0_CFHTLS/data/CFHTLS-DEEP_EGS_MOC.fits")
cfhtls_wide_moc = MOC(filename="../../dmu0/dmu0_CFHTLS/data/CFHTLS-WIDE_EGS_MOC.fits")
cfhtlens_moc = MOC(filename="../../dmu0/dmu0_CFHTLenS/data/CFHTLenS_EGS_MOC.fits")
deep_moc = MOC(filename="../../dmu0/dmu0_DEEP2/data/DEEP2_EGS_MOC.fits")
irac_moc = MOC(filename="../../dmu0/dmu0_IRAC-EGS/data/IRAC_EGS_MOC.fits")
hsc_moc = MOC(filename="../../dmu0/dmu0_HSC/data/HSC-PDR1_wide_EGS_MOC.fits")
ps1_moc = MOC(filename="../../dmu0/dmu0_PanSTARRS1-3SS/data/PanSTARRS1-3SS_EGS_MOC.fits")
legacy_moc = MOC(filename="../../dmu0/dmu0_LegacySurvey/data/LegacySurvey-dr4_EGS_MOC.fits")
uhs_moc = MOC(filename="../../dmu0/dmu0_UHS/data/UHS-DR1_EGS_MOC.fits")
was_observed_optical = inMoc(
master_catalogue['ra'], master_catalogue['dec'],
aegis_moc + candels_moc + cfhtls_deep_moc + cfhtls_wide_moc + cfhtlens_moc + deep_moc + hsc_moc + ps1_moc + legacy_moc)
was_observed_nir = inMoc(
master_catalogue['ra'], master_catalogue['dec'],
wirds_moc + uhs_moc
)
was_observed_mir = inMoc(
master_catalogue['ra'], master_catalogue['dec'],
irac_moc
)
master_catalogue.add_column(
Column(
1 * was_observed_optical + 2 * was_observed_nir + 4 * was_observed_mir,
name="flag_optnir_obs")
)
We add a binary flag_optnir_det
indicating that a source was detected in a given wavelength domain:
It's an integer binary flag, so a source detected both in optical and near-infrared by not in mid-infrared would have this flag at 1 + 2 = 3.
Note 1: We use the total flux columns to know if the source has flux, in some catalogues, we may have aperture flux and no total flux.
To get rid of artefacts (chip edges, star flares, etc.) we consider that a source is detected in one wavelength domain when it has a flux value in at least two bands. That means that good sources will be excluded from this flag when they are on the coverage of only one band.
# SpARCS is a catalogue of sources detected in r (with fluxes measured at
# this prior position in the other bands). Thus, we are only using the r
# CFHT band.
# Check to use catalogue flags from HSC and PanSTARRS.
nb_optical_flux = (
#HSC
1 * ~np.isnan(master_catalogue['f_suprime_g']) +
1 * ~np.isnan(master_catalogue['f_suprime_r']) +
1 * ~np.isnan(master_catalogue['f_suprime_i']) +
1 * ~np.isnan(master_catalogue['f_suprime_z']) +
1 * ~np.isnan(master_catalogue['f_suprime_y']) +
#PS1
1 * ~np.isnan(master_catalogue['f_gpc1_g']) +
1 * ~np.isnan(master_catalogue['f_gpc1_r']) +
1 * ~np.isnan(master_catalogue['f_gpc1_i']) +
1 * ~np.isnan(master_catalogue['f_gpc1_z']) +
1 * ~np.isnan(master_catalogue['f_gpc1_y']) +
#CFHT
1 * ~np.isnan(master_catalogue['f_megacam_u']) +
1 * ~np.isnan(master_catalogue['f_megacam_g']) +
1 * ~np.isnan(master_catalogue['f_megacam_r']) +
1 * ~np.isnan(master_catalogue['f_megacam_i']) +
1 * ~np.isnan(master_catalogue['f_megacam_z'])
)
nb_nir_flux = (
1 * ~np.isnan(master_catalogue['f_uhs_j']) +
1 * ~np.isnan(master_catalogue['f_wircam_j']) +
1 * ~np.isnan(master_catalogue['f_wircam_h']) +
1 * ~np.isnan(master_catalogue['f_wircam_k'])
)
nb_mir_flux = (
1 * ~np.isnan(master_catalogue['f_irac-egs_i1']) +
1 * ~np.isnan(master_catalogue['f_irac-egs_i2']) +
1 * ~np.isnan(master_catalogue['f_irac-egs_i3']) +
1 * ~np.isnan(master_catalogue['f_irac-egs_i4'])
)
has_optical_flux = nb_optical_flux >= 2
has_nir_flux = nb_nir_flux >= 2
has_mir_flux = nb_mir_flux >= 2
master_catalogue.add_column(
Column(
1 * has_optical_flux + 2 * has_nir_flux + 4 * has_mir_flux,
name="flag_optnir_det")
)
We are producing a table associating to each HELP identifier, the identifiers of the sources in the pristine catalogues. This can be used to easily get additional information from them.
For convenience, we also cross-match the master list with the SDSS catalogue and add the objID associated with each source, if any. TODO: should we correct the astrometry with respect to Gaia positions?
#
# Addind SDSS ids
#
sdss = Table.read("../../dmu0/dmu0_SDSS-DR13/data/SDSS-DR13_EGS.fits")['objID', 'ra', 'dec']
sdss_coords = SkyCoord(sdss['ra'] * u.deg, sdss['dec'] * u.deg)
idx_ml, d2d, _ = sdss_coords.match_to_catalog_sky(SkyCoord(master_catalogue['ra'], master_catalogue['dec']))
idx_sdss = np.arange(len(sdss))
# Limit the cross-match to 1 arcsec
mask = d2d <= 1. * u.arcsec
idx_ml = idx_ml[mask]
idx_sdss = idx_sdss[mask]
d2d = d2d[mask]
nb_orig_matches = len(idx_ml)
# In case of multiple associations of one master list object to an SDSS object, we keep only the
# association to the nearest one.
sort_idx = np.argsort(d2d)
idx_ml = idx_ml[sort_idx]
idx_sdss = idx_sdss[sort_idx]
_, unique_idx = np.unique(idx_ml, return_index=True)
idx_ml = idx_ml[unique_idx]
idx_sdss = idx_sdss[unique_idx]
print("{} master list rows had multiple associations.".format(nb_orig_matches - len(idx_ml)))
# Adding the ObjID to the master list
master_catalogue.add_column(Column(data=np.full(len(master_catalogue), -1, dtype='>i8'), name="sdss_id"))
master_catalogue['sdss_id'][idx_ml] = sdss['objID'][idx_sdss]
id_names = []
for col in master_catalogue.colnames:
if '_id' in col:
id_names += [col]
if '_intid' in col:
id_names += [col]
print(id_names)
master_catalogue[id_names].write(
"{}/master_list_cross_ident_egs{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)
id_names.remove('help_id')
master_catalogue.remove_columns(id_names)
We are adding a column with a HEALPix index at order 13 associated with each source.
master_catalogue.add_column(Column(
data=coords_to_hpidx(master_catalogue['ra'], master_catalogue['dec'], order=13),
name="hp_idx"
))
columns = ["help_id", "field", "ra", "dec", "hp_idx"]
bands = [column[5:] for column in master_catalogue.colnames if 'f_ap' in column]
for band in bands:
columns += ["f_ap_{}".format(band), "ferr_ap_{}".format(band),
"m_ap_{}".format(band), "merr_ap_{}".format(band),
"f_{}".format(band), "ferr_{}".format(band),
"m_{}".format(band), "merr_{}".format(band),
"flag_{}".format(band)]
columns += ["stellarity", "stellarity_origin", "flag_cleaned", "flag_merged", "flag_gaia", "flag_optnir_obs",
"flag_optnir_det", "zspec", "zspec_qual", "zspec_association_flag", "ebv"]
# We check for columns in the master catalogue that we will not save to disk.
print("Missing columns: {}".format(set(master_catalogue.colnames) - set(columns)))
master_catalogue[columns].write("{}/master_catalogue_egs{}.fits".format(OUT_DIR, SUFFIX))