This notebook presents the merge of the various pristine catalogues to produce HELP mater catalogue on GAMA-09.
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
cfhtlens = Table.read("{}/CFHTLENS.fits".format(TMP_DIR))
cfhtls = Table.read("{}/CFHTLS.fits".format(TMP_DIR))
decals = Table.read("{}/DECaLS.fits".format(TMP_DIR))
hsc = Table.read("{}/HSC-SSP.fits".format(TMP_DIR))
kids = Table.read("{}/KIDS.fits".format(TMP_DIR))
ps1 = Table.read("{}/PS1.fits".format(TMP_DIR))
las = Table.read("{}/UKIDSS-LAS.fits".format(TMP_DIR))
vhs = Table.read("{}/VISTA-VHS.fits".format(TMP_DIR))
viking = Table.read("{}/VISTA-VIKING.fits".format(TMP_DIR))
We first merge the optical catalogues and then add the infrared ones: CFHTLenS, CFHTLS, DECaLS, HSC, KIDS, PanSTARRS, UKIDSS-LAS, VISTA-VHS, and VISTA-VIKING.
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 = cfhtlens
master_catalogue['cfhtlens_ra'].name = 'ra'
master_catalogue['cfhtlens_dec'].name = 'dec'
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(cfhtls['cfhtls_ra'], cfhtls['cfhtls_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, cfhtls, "cfhtls_ra", "cfhtls_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(decals['decals_ra'], decals['decals_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, decals, "decals_ra", "decals_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(hsc['hsc_ra'], hsc['hsc_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, hsc, "hsc_ra", "hsc_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(kids['kids_ra'], kids['kids_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, kids, "kids_ra", "kids_dec", radius=0.8*u.arcsec)
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(las['las_ra'], las['las_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, las, "las_ra", "las_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(vhs['vhs_ra'], vhs['vhs_dec'])
)
# Given the graph above, we use 1 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, vhs, "vhs_ra", "vhs_dec", radius=1.*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(viking['viking_ra'], viking['viking_dec'])
)
# Given the graph above, we use 1 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, viking, "viking_ra", "viking_dec", radius=1.*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.
stellarity_columns = [column for column in master_catalogue.colnames
if 'stellarity' in column]
print(", ".join(stellarity_columns))
master_catalogue.add_column(Column(
data=np.nanmax([master_catalogue[column] for column in stellarity_columns], axis=0),
name="stellarity"
))
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), "GAMA-09", 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_GAMA-09/data/HELP-SPECZ_GAMA-09_20170202-2.fits")
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(specz['ra'], specz['dec'])
)
master_catalogue = specz_merge(master_catalogue, specz, radius=.8 * u.arcsec)
Both CFHTLenS and CFHTLS, and VISTA-VIKING and VISTA-VHS have measurements from the same camera and filters. We wish to choose the superior measurement where both are present.
CFHTLS is optimised for deep photometry so we take that for
megacam_origin = Table()
megacam_origin.add_column(master_catalogue['help_id'])
megacam_bands = ['u','g','r','i','z'] # Lowercase naming convention (k is Ks)
for band in megacam_bands:
print('For Megacam band ' + band + ':')
# Megacam total flux
has_cfhtls = ~np.isnan(master_catalogue['f_cfhtls_' + band])
has_cfhtlens = ~np.isnan(master_catalogue['f_cfhtlens_' + band])
has_both = has_cfhtls & has_cfhtlens
print("{} sources with CFHTLS flux".format(np.sum(has_cfhtls)))
print("{} sources with CFHTLenS flux".format(np.sum(has_cfhtlens)))
print("{} sources with CFHTLS and CFHTLenS flux".format(np.sum(has_both)))
use_cfhtls = has_cfhtls
use_cfhtlens = has_cfhtlens & ~has_both
print("{} sources for which we use CFHTLS".format(np.sum(use_cfhtls)))
print("{} sources for which we use CFHTLenS".format(np.sum(use_cfhtlens)))
f_megacam = np.full(len(master_catalogue), np.nan)
f_megacam[use_cfhtls] = master_catalogue['f_cfhtls_' + band][use_cfhtls]
f_megacam[use_cfhtlens] = master_catalogue['f_cfhtlens_' + band][use_cfhtlens]
ferr_megacam = np.full(len(master_catalogue), np.nan)
ferr_megacam[use_cfhtls] = master_catalogue['ferr_cfhtls_' + band][use_cfhtls]
ferr_megacam[use_cfhtlens] = master_catalogue['ferr_cfhtlens_' + band][use_cfhtlens]
m_megacam = np.full(len(master_catalogue), np.nan)
m_megacam[use_cfhtls] = master_catalogue['m_cfhtls_' + band][use_cfhtls]
m_megacam[use_cfhtlens] = master_catalogue['m_cfhtlens_' + band][use_cfhtlens]
merr_megacam = np.full(len(master_catalogue), np.nan)
merr_megacam[use_cfhtls] = master_catalogue['merr_cfhtls_' + band][use_cfhtls]
merr_megacam[use_cfhtlens] = master_catalogue['merr_cfhtlens_' + band][use_cfhtlens]
flag_megacam = np.full(len(master_catalogue), False, dtype=bool)
flag_megacam[use_cfhtls] = master_catalogue['flag_cfhtls_' + band][use_cfhtls]
flag_megacam[use_cfhtlens] = master_catalogue['flag_cfhtlens_' + band][use_cfhtlens]
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))
master_catalogue.remove_columns(['f_cfhtls_' + band,
'f_cfhtlens_' + band,
'ferr_cfhtls_' + band,
'ferr_cfhtlens_' + band,
'm_cfhtls_' + band,
'm_cfhtlens_' + band,
'merr_cfhtls_' + band,
'merr_cfhtlens_' + band,
'flag_cfhtls_' + band,
'flag_cfhtlens_' + band])
origin = np.full(len(master_catalogue), ' ', dtype='<U5')
origin[use_cfhtls] = "CFHTLS"
origin[use_cfhtlens] = "CFHTLenS"
megacam_origin.add_column(Column(data=origin, name= 'f_megacam_' + band ))
# There are no Megacam aperture flux in CFHTLenS
#Aperture flux only in CFHTLS
for band in megacam_bands:
master_catalogue['f_ap_cfhtls_' + band].name = 'f_ap_megacam_' + band
master_catalogue['ferr_ap_cfhtls_' + band].name = 'ferr_ap_megacam_' + band
master_catalogue['m_ap_cfhtls_' + band].name = 'm_ap_megacam_' + band
master_catalogue['merr_ap_cfhtls_' + band].name = 'merr_ap_megacam_' + band
megacam_origin.write("{}/gama-09_megacam_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX))
VIKING is deeper than VHS so we take the VIKING photometry if available.
vista_origin = Table()
vista_origin.add_column(master_catalogue['help_id'])
vista_bands = ['y','j','h','k'] # Lowercase naming convention (k is Ks)
for band in vista_bands:
print('For VISTA band ' + band + ':')
# VISTA total flux
has_viking = ~np.isnan(master_catalogue['f_viking_' + band])
has_vhs = ~np.isnan(master_catalogue['f_vhs_' + band])
has_both = has_viking & has_vhs
print("{} sources with VIKING flux".format(np.sum(has_viking)))
print("{} sources with VHS flux".format(np.sum(has_vhs)))
print("{} sources with VIKING and VHS flux".format(np.sum(has_both)))
use_viking = has_viking
use_vhs = has_vhs & ~has_both
print("{} sources for which we use VIKING".format(np.sum(use_viking)))
print("{} sources for which we use VHS".format(np.sum(use_vhs)))
f_vista = np.full(len(master_catalogue), np.nan)
f_vista[use_viking] = master_catalogue['f_viking_' + band][use_viking]
f_vista[use_vhs] = master_catalogue['f_vhs_' + band][use_vhs]
ferr_vista = np.full(len(master_catalogue), np.nan)
ferr_vista[use_viking] = master_catalogue['ferr_viking_' + band][use_viking]
ferr_vista[use_vhs] = master_catalogue['ferr_vhs_' + band][use_vhs]
m_vista = np.full(len(master_catalogue), np.nan)
m_vista[use_viking] = master_catalogue['m_viking_' + band][use_viking]
m_vista[use_vhs] = master_catalogue['m_vhs_' + band][use_vhs]
merr_vista = np.full(len(master_catalogue), np.nan)
merr_vista[use_viking] = master_catalogue['merr_viking_' + band][use_viking]
merr_vista[use_vhs] = master_catalogue['merr_vhs_' + band][use_vhs]
flag_vista = np.full(len(master_catalogue), False, dtype=bool)
flag_vista[use_viking] = master_catalogue['flag_viking_' + band][use_viking]
flag_vista[use_vhs] = master_catalogue['flag_vhs_' + band][use_vhs]
master_catalogue.add_column(Column(data=f_vista, name="f_vista_" + band))
master_catalogue.add_column(Column(data=ferr_vista, name="ferr_vista_" + band))
master_catalogue.add_column(Column(data=m_vista, name="m_vista_" + band))
master_catalogue.add_column(Column(data=merr_vista, name="merr_vista_" + band))
master_catalogue.add_column(Column(data=flag_vista, name="flag_vista_" + band))
master_catalogue.remove_columns(['f_viking_' + band,
'f_vhs_' + band,
'ferr_viking_' + band,
'ferr_vhs_' + band,
'm_viking_' + band,
'm_vhs_' + band,
'merr_viking_' + band,
'merr_vhs_' + band,
'flag_viking_' + band,
'flag_vhs_' + band])
origin = np.full(len(master_catalogue), ' ', dtype='<U5')
origin[use_viking] = "VIKING"
origin[use_vhs] = "VHS"
vista_origin.add_column(Column(data=origin, name= 'f_vista_' + band ))
# VISTA Aperture flux
has_ap_viking = ~np.isnan(master_catalogue['f_ap_viking_' + band])
has_ap_vhs = ~np.isnan(master_catalogue['f_ap_vhs_' + band])
has_ap_both = has_ap_viking & has_ap_vhs
print("{} sources with VIKING aperture flux".format(np.sum(has_ap_viking)))
print("{} sources with VHS aperture flux".format(np.sum(has_ap_vhs)))
print("{} sources with VIKING and VHS aperture flux".format(np.sum(has_ap_both)))
use_ap_viking = has_ap_viking
use_ap_vhs = has_ap_vhs & ~has_ap_both
print("{} sources for which we use VIKING aperture fluxes".format(np.sum(use_ap_viking)))
print("{} sources for which we use VHS aperture fluxes".format(np.sum(use_ap_vhs)))
f_ap_vista = np.full(len(master_catalogue), np.nan)
f_ap_vista[use_ap_viking] = master_catalogue['f_ap_viking_' + band][use_ap_viking]
f_ap_vista[use_ap_vhs] = master_catalogue['f_ap_vhs_' + band][use_ap_vhs]
ferr_ap_vista = np.full(len(master_catalogue), np.nan)
ferr_ap_vista[use_ap_viking] = master_catalogue['ferr_ap_viking_' + band][use_ap_viking]
ferr_ap_vista[use_ap_vhs] = master_catalogue['ferr_ap_vhs_' + band][use_ap_vhs]
m_ap_vista = np.full(len(master_catalogue), np.nan)
m_ap_vista[use_ap_viking] = master_catalogue['m_ap_viking_' + band][use_ap_viking]
m_ap_vista[use_ap_vhs] = master_catalogue['m_ap_vhs_' + band][use_ap_vhs]
merr_ap_vista = np.full(len(master_catalogue), np.nan)
merr_ap_vista[use_ap_viking] = master_catalogue['merr_ap_viking_' + band][use_ap_viking]
merr_ap_vista[use_ap_vhs] = master_catalogue['merr_ap_vhs_' + band][use_ap_vhs]
master_catalogue.add_column(Column(data=f_ap_vista, name="f_ap_vista_" + band))
master_catalogue.add_column(Column(data=ferr_ap_vista, name="ferr_ap_vista_" + band))
master_catalogue.add_column(Column(data=m_ap_vista, name="m_ap_vista_" + band))
master_catalogue.add_column(Column(data=merr_vista, name="merr_ap_vista_" + band))
master_catalogue.remove_columns(['f_ap_viking_' + band,
'f_ap_vhs_' + band,
'ferr_ap_viking_' + band,
'ferr_ap_vhs_' + band,
'm_ap_viking_' + band,
'm_ap_vhs_' + band,
'merr_ap_viking_' + band,
'merr_ap_vhs_' + band])
origin_ap = np.full(len(master_catalogue), ' ', dtype='<U5')
origin_ap[use_ap_viking] = "VIKING"
origin_ap[use_ap_vhs] = "VHS"
vista_origin.add_column(Column(data=origin_ap, name= 'f_ap_vista_' + band ))
#Z band only in viking
master_catalogue['f_ap_viking_z'].name = 'f_ap_vista_z'
master_catalogue['ferr_ap_viking_z'].name = 'ferr_ap_vista_z'
master_catalogue['f_viking_z'].name = 'f_vista_z'
master_catalogue['ferr_viking_z'].name = 'ferr_vista_z'
master_catalogue['m_ap_viking_z'].name = 'm_ap_vista_z'
master_catalogue['merr_ap_viking_z'].name = 'merr_ap_vista_z'
master_catalogue['m_viking_z'].name = 'm_vista_z'
master_catalogue['merr_viking_z'].name = 'merr_vista_z'
master_catalogue['flag_viking_z'].name = 'flag_vista_z'
vista_origin.write("{}/gama-09_vista_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX))
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.
cfhtlens_moc = MOC(filename="../../dmu0/dmu0_CFHTLenS/data/CFHTLenS_GAMA-09_MOC.fits")
cfhtls_moc = MOC(filename="../../dmu0/dmu0_CFHTLS/data/CFHTLS-WIDE_GAMA-09_MOC.fits")
decals_moc = MOC(filename="../../dmu0/dmu0_DECaLS/data/DECaLS_GAMA-09_MOC.fits")
hsc_moc = MOC(filename="../../dmu0/dmu0_HSC/data/HSC-PDR1_wide_GAMA-09_MOC.fits")
kids_moc = MOC(filename="../../dmu0/dmu0_KIDS/data/KIDS-DR3_GAMA-09_MOC.fits")
ps1_moc = MOC(filename="../../dmu0/dmu0_PanSTARRS1-3SS/data/PanSTARRS1-3SS_GAMA-09_MOC.fits")
las_moc = MOC(filename="../../dmu0/dmu0_UKIDSS-LAS/data/UKIDSS-LAS_GAMA-09_MOC.fits")
vhs_moc = MOC(filename="../../dmu0/dmu0_VISTA-VHS/data/VHS_GAMA-09_MOC.fits")
viking_moc = MOC(filename="../../dmu0/dmu0_VISTA-VIKING/data/VIKING_GAMA-09_MOC.fits")
was_observed_optical = inMoc(
master_catalogue['ra'], master_catalogue['dec'],
cfhtlens_moc + cfhtls_moc + decals_moc + hsc_moc + ps1_moc)
was_observed_nir = inMoc(
master_catalogue['ra'], master_catalogue['dec'],
las_moc + vhs_moc + viking_moc
)
was_observed_mir = np.zeros(len(master_catalogue), dtype=bool)
#was_observed_mir = inMoc(
# master_catalogue['ra'], master_catalogue['dec'],
#)
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 = (
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']) +
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']) +
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']) +
1 * ~np.isnan(master_catalogue['f_decam_g']) +
1 * ~np.isnan(master_catalogue['f_decam_r']) +
1 * ~np.isnan(master_catalogue['f_decam_z']) +
1 * ~np.isnan(master_catalogue['f_kids_u']) +
1 * ~np.isnan(master_catalogue['f_kids_g']) +
1 * ~np.isnan(master_catalogue['f_kids_r']) +
1 * ~np.isnan(master_catalogue['f_kids_i'])
)
nb_nir_flux = (
1 * ~np.isnan(master_catalogue['f_ukidss_y']) +
1 * ~np.isnan(master_catalogue['f_ukidss_j']) +
1 * ~np.isnan(master_catalogue['f_ukidss_h']) +
1 * ~np.isnan(master_catalogue['f_ukidss_k']) +
1 * ~np.isnan(master_catalogue['f_vista_z']) +
1 * ~np.isnan(master_catalogue['f_vista_y']) +
1 * ~np.isnan(master_catalogue['f_vista_h']) +
1 * ~np.isnan(master_catalogue['f_vista_j']) +
1 * ~np.isnan(master_catalogue['f_vista_k'])
)
nb_mir_flux = np.zeros(len(master_catalogue), dtype=bool)
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 catalogue. 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_GAMA-09.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]
master_catalogue['help_id', 'cfhtls_id', 'cfhtlens_id', 'decals_id', 'hsc_id',
'kids_id', 'ps1_id', 'las_id', 'vhs_id', 'viking_id', 'sdss_id',
'specz_id'].write(
"{}/master_list_cross_ident_gama-09{}.fits".format(OUT_DIR, SUFFIX))
master_catalogue.remove_columns(['cfhtls_id', 'cfhtlens_id', 'decals_id', 'hsc_id', 'kids_id',
'ps1_id', 'las_id', 'vhs_id', 'viking_id', 'sdss_id', 'specz_id'])
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"
))
# We use vista_ks as filter ID for VISTA Ks
for column in master_catalogue.colnames:
if "vista_k" in column:
master_catalogue[column].name = column.replace("vista_k", "vista_ks")
# We use omegacam_XXX for the KIDS bands
for column in master_catalogue.colnames:
if "_kids_" in column:
master_catalogue[column].name = column.replace("_kids_", "_omegacam_")
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", "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_gama-09{}.fits".format(OUT_DIR, SUFFIX))