GAMA-09 master catalogue

This notebook presents the merge of the various pristine catalogues to produce HELP mater catalogue on GAMA-09.

In [1]:
from herschelhelp_internal import git_version
print("This notebook was run with herschelhelp_internal version: \n{}".format(git_version()))
This notebook was run with herschelhelp_internal version: 
44f1ae0 (Thu Nov 30 18:27:54 2017 +0000)
In [2]:
%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
In [3]:
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

I - Reading the prepared pristine catalogues

In [4]:
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))

II - Merging tables

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.

CFHTLenS

In [5]:
master_catalogue = cfhtlens
master_catalogue['cfhtlens_ra'].name = 'ra'
master_catalogue['cfhtlens_dec'].name = 'dec'

Add CFHTLS

In [6]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(cfhtls['cfhtls_ra'], cfhtls['cfhtls_dec'])
)
In [7]:
# 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)

Add DECaLS

In [8]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(decals['decals_ra'], decals['decals_dec'])
)
In [9]:
# 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)

Add HSC-PSS

In [10]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(hsc['hsc_ra'], hsc['hsc_dec'])
)
In [11]:
# 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)

Add KIDS

In [12]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(kids['kids_ra'], kids['kids_dec'])
)
In [13]:
# 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)

Add PanSTARRS

In [14]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(ps1['ps1_ra'], ps1['ps1_dec'])
)
In [15]:
# 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)

Add UKIDSS LAS

In [16]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(las['las_ra'], las['las_dec'])
)
In [17]:
# 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)

Add VHS

In [18]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(vhs['vhs_ra'], vhs['vhs_dec'])
)
In [19]:
# 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)

Add VIKING

In [20]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(viking['viking_ra'], viking['viking_dec'])
)
In [21]:
# 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)

Cleaning

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.

In [22]:
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()
In [23]:
master_catalogue[:10].show_in_notebook()
Out[23]:
<Table length=10>
idxcfhtlens_idradeccfhtlens_stellaritym_cfhtlens_umerr_cfhtlens_um_cfhtlens_gmerr_cfhtlens_gm_cfhtlens_rmerr_cfhtlens_rm_cfhtlens_imerr_cfhtlens_im_cfhtlens_zmerr_cfhtlens_zf_cfhtlens_uferr_cfhtlens_uflag_cfhtlens_uf_cfhtlens_gferr_cfhtlens_gflag_cfhtlens_gf_cfhtlens_rferr_cfhtlens_rflag_cfhtlens_rf_cfhtlens_iferr_cfhtlens_iflag_cfhtlens_if_cfhtlens_zferr_cfhtlens_zflag_cfhtlens_zcfhtlens_flag_cleanedcfhtlens_flag_gaiaflag_mergedcfhtls_idcfhtls_stellaritym_cfhtls_umerr_cfhtls_um_cfhtls_gmerr_cfhtls_gm_cfhtls_rmerr_cfhtls_rm_cfhtls_imerr_cfhtls_im_cfhtls_zmerr_cfhtls_zm_ap_cfhtls_umerr_ap_cfhtls_um_ap_cfhtls_gmerr_ap_cfhtls_gm_ap_cfhtls_rmerr_ap_cfhtls_rm_ap_cfhtls_imerr_ap_cfhtls_im_ap_cfhtls_zmerr_ap_cfhtls_zf_cfhtls_uferr_cfhtls_uflag_cfhtls_uf_cfhtls_gferr_cfhtls_gflag_cfhtls_gf_cfhtls_rferr_cfhtls_rflag_cfhtls_rf_cfhtls_iferr_cfhtls_iflag_cfhtls_if_cfhtls_zferr_cfhtls_zflag_cfhtls_zf_ap_cfhtls_uferr_ap_cfhtls_uf_ap_cfhtls_gferr_ap_cfhtls_gf_ap_cfhtls_rferr_ap_cfhtls_rf_ap_cfhtls_iferr_ap_cfhtls_if_ap_cfhtls_zferr_ap_cfhtls_zcfhtls_flag_cleanedcfhtls_flag_gaiadecals_idf_decam_gf_decam_rf_decam_zferr_decam_gferr_decam_rferr_decam_zf_ap_decam_gf_ap_decam_rf_ap_decam_zferr_ap_decam_gferr_ap_decam_rferr_ap_decam_zm_decam_gmerr_decam_gflag_decam_gm_decam_rmerr_decam_rflag_decam_rm_decam_zmerr_decam_zflag_decam_zm_ap_decam_gmerr_ap_decam_gm_ap_decam_rmerr_ap_decam_rm_ap_decam_zmerr_ap_decam_zdecals_stellaritydecals_flag_cleaneddecals_flag_gaiahsc_idm_ap_suprime_gmerr_ap_suprime_gm_suprime_gmerr_suprime_gm_ap_suprime_rmerr_ap_suprime_rm_suprime_rmerr_suprime_rm_ap_suprime_imerr_ap_suprime_im_suprime_imerr_suprime_im_ap_suprime_zmerr_ap_suprime_zm_suprime_zmerr_suprime_zm_ap_suprime_ymerr_ap_suprime_ym_suprime_ymerr_suprime_yhsc_stellarityf_ap_suprime_gferr_ap_suprime_gf_suprime_gferr_suprime_gflag_suprime_gf_ap_suprime_rferr_ap_suprime_rf_suprime_rferr_suprime_rflag_suprime_rf_ap_suprime_iferr_ap_suprime_if_suprime_iferr_suprime_iflag_suprime_if_ap_suprime_zferr_ap_suprime_zf_suprime_zferr_suprime_zflag_suprime_zf_ap_suprime_yferr_ap_suprime_yf_suprime_yferr_suprime_yflag_suprime_yhsc_flag_cleanedhsc_flag_gaiakids_idkids_stellaritym_kids_umerr_kids_um_kids_gmerr_kids_gm_kids_rmerr_kids_rm_kids_imerr_kids_if_ap_kids_uferr_ap_kids_uf_ap_kids_gferr_ap_kids_gf_ap_kids_rferr_ap_kids_rf_ap_kids_iferr_ap_kids_if_kids_uferr_kids_uflag_kids_uf_kids_gferr_kids_gflag_kids_gf_kids_rferr_kids_rflag_kids_rf_kids_iferr_kids_iflag_kids_im_ap_kids_umerr_ap_kids_um_ap_kids_gmerr_ap_kids_gm_ap_kids_rmerr_ap_kids_rm_ap_kids_imerr_ap_kids_ikids_flag_cleanedkids_flag_gaiaps1_idm_ap_gpc1_gmerr_ap_gpc1_gm_gpc1_gmerr_gpc1_gm_ap_gpc1_rmerr_ap_gpc1_rm_gpc1_rmerr_gpc1_rm_ap_gpc1_imerr_ap_gpc1_im_gpc1_imerr_gpc1_im_ap_gpc1_zmerr_ap_gpc1_zm_gpc1_zmerr_gpc1_zm_ap_gpc1_ymerr_ap_gpc1_ym_gpc1_ymerr_gpc1_yf_ap_gpc1_gferr_ap_gpc1_gf_gpc1_gferr_gpc1_gflag_gpc1_gf_ap_gpc1_rferr_ap_gpc1_rf_gpc1_rferr_gpc1_rflag_gpc1_rf_ap_gpc1_iferr_ap_gpc1_if_gpc1_iferr_gpc1_iflag_gpc1_if_ap_gpc1_zferr_ap_gpc1_zf_gpc1_zferr_gpc1_zflag_gpc1_zf_ap_gpc1_yferr_ap_gpc1_yf_gpc1_yferr_gpc1_yflag_gpc1_yps1_flag_cleanedps1_flag_gaialas_idm_ukidss_ymerr_ukidss_ym_ap_ukidss_ymerr_ap_ukidss_ym_ukidss_jmerr_ukidss_jm_ap_ukidss_jmerr_ap_ukidss_jm_ap_ukidss_hmerr_ap_ukidss_hm_ukidss_hmerr_ukidss_hm_ap_ukidss_kmerr_ap_ukidss_km_ukidss_kmerr_ukidss_klas_stellarityf_ukidss_yferr_ukidss_yflag_ukidss_yf_ap_ukidss_yferr_ap_ukidss_yf_ukidss_jferr_ukidss_jflag_ukidss_jf_ap_ukidss_jferr_ap_ukidss_jf_ap_ukidss_hferr_ap_ukidss_hf_ukidss_hferr_ukidss_hflag_ukidss_hf_ap_ukidss_kferr_ap_ukidss_kf_ukidss_kferr_ukidss_kflag_ukidss_klas_flag_cleanedlas_flag_gaiavhs_idvhs_stellaritym_vhs_ymerr_vhs_ym_ap_vhs_ymerr_ap_vhs_ym_vhs_jmerr_vhs_jm_ap_vhs_jmerr_ap_vhs_jm_vhs_hmerr_vhs_hm_ap_vhs_hmerr_ap_vhs_hm_vhs_kmerr_vhs_km_ap_vhs_kmerr_ap_vhs_kf_vhs_yferr_vhs_yflag_vhs_yf_ap_vhs_yferr_ap_vhs_yf_vhs_jferr_vhs_jflag_vhs_jf_ap_vhs_jferr_ap_vhs_jf_vhs_hferr_vhs_hflag_vhs_hf_ap_vhs_hferr_ap_vhs_hf_vhs_kferr_vhs_kflag_vhs_kf_ap_vhs_kferr_ap_vhs_kvhs_flag_cleanedvhs_flag_gaiaviking_idviking_stellaritym_viking_zmerr_viking_zm_ap_viking_zmerr_ap_viking_zm_viking_ymerr_viking_ym_ap_viking_ymerr_ap_viking_ym_viking_jmerr_viking_jm_ap_viking_jmerr_ap_viking_jm_viking_hmerr_viking_hm_ap_viking_hmerr_ap_viking_hm_viking_kmerr_viking_km_ap_viking_kmerr_ap_viking_kf_viking_zferr_viking_zflag_viking_zf_ap_viking_zferr_ap_viking_zf_viking_yferr_viking_yflag_viking_yf_ap_viking_yferr_ap_viking_yf_viking_jferr_viking_jflag_viking_jf_ap_viking_jferr_ap_viking_jf_viking_hferr_viking_hflag_viking_hf_ap_viking_hferr_ap_viking_hf_viking_kferr_viking_kflag_viking_kf_ap_viking_kferr_ap_viking_kviking_flag_cleanedviking_flag_gaia
degdegmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmaguJyuJyuJyuJyuJyuJyuJyuJy
0W2p3p3_84208136.570071167-1.469221775430.52438319.79440.001518.31210.000517.7660.0006nannan17.42340.000643.87730.0606187False171.8540.0791418False284.1840.157046FalsenannanFalse389.6180.215311FalseFalse2True-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
1W2p3p3_150700136.660929267-1.080120259430.9829120.22560.001719.53820.000819.30590.001119.14430.000819.08020.001229.49580.0461833False55.55450.0409341False68.80810.0697121False79.85090.0588363False84.70710.0936218FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
2W2p1p3_180414134.283874467-0.9808037949260.00038077719.51530.002218.88930.001118.71730.001518.54330.001318.76770.004856.73870.114968False100.990.102317False118.3260.163473False138.8930.166302False112.9590.499386FalseFalse0False-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
3W2m1p3_85804132.382215567-1.495096358430.028528221.53980.005320.58470.001519.55650.001119.25410.001518.96810.0028.791830.0429172False21.18950.0292743False54.62610.0553437False72.17040.0997071False93.92050.173008FalseFalse0True-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
4W2m1p2_205391132.217795867-1.987024800430.026268622.40170.005321.61450.002221.23040.002821.04910.002220.99060.00533.974850.0194031False8.207290.0166302False11.69070.030149False13.81530.0279935False14.58010.0711723FalseFalse0False-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
5W2m0p3_124333133.470380767-1.356366537430.046883322.04280.005421.6750.00321.13860.002520.79690.002420.88590.00715.531960.0275137False7.762480.0214485False12.72210.0292938False17.42770.0385236False16.05610.104996FalseFalse2False-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
6W2p2p2_133751135.708474867-2.057977137430.13805622.96890.006322.05660.002621.32030.002120.69650.001920.27570.0032.357430.013679False5.46210.01308False10.76170.0208149False19.11610.0334525False28.16570.0778246FalseFalse0False-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
7W2m1p3_157146132.781176867-1.100725478430.025308222.33680.006621.42970.002220.87120.001920.4420.002120.16140.00394.219680.0256507False9.730150.019716False16.2750.0284806False24.16570.0467407False31.29250.112404FalseFalse0True-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
8W2p3p3_89016136.018186067-1.440058984430.0003255522.89280.008221.98790.003921.53230.004221.26090.00421.1390.00712.52860.0190972False5.818890.0209016False8.852780.0342456False11.36680.041877False12.71740.0831637FalseFalse0False-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
9W2p2p3_167403135.679377467-1.009100614430.027707422.52870.008321.90270.002921.54640.00420.98360.00420.84010.00693.536060.0270317False6.29390.016811False8.738550.032194False14.67440.0540624False16.74790.106435FalseFalse0False-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannanFalse0-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0

III - Merging flags and stellarity

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.

In [24]:
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.

In [25]:
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.

In [26]:
stellarity_columns = [column for column in master_catalogue.colnames
                      if 'stellarity' in column]

print(", ".join(stellarity_columns))
cfhtlens_stellarity, cfhtls_stellarity, decals_stellarity, hsc_stellarity, kids_stellarity, las_stellarity, vhs_stellarity, viking_stellarity
In [27]:
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)
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/numpy/lib/nanfunctions.py:343: RuntimeWarning: All-NaN slice encountered
  warnings.warn("All-NaN slice encountered", RuntimeWarning)

IV - Adding E(B-V) column

In [28]:
master_catalogue.add_column(
    ebv(master_catalogue['ra'], master_catalogue['dec'])
)

V - Adding HELP unique identifiers and field columns

In [29]:
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"))
In [30]:
# 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!")
OK!

VI - Cross-matching with the spec-z catalogue

In [31]:
specz = Table.read("../../dmu23/dmu23_GAMA-09/data/HELP-SPECZ_GAMA-09_20170202-2.fits")
In [32]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(specz['ra'], specz['dec'])
)
In [33]:
master_catalogue = specz_merge(master_catalogue, specz, radius=.8 * u.arcsec)

VII - Choosing between multiple values for the same filter

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.

VII.a CFHTLenS and CFHTLS

CFHTLS is optimised for deep photometry so we take that for

In [34]:
megacam_origin = Table()
megacam_origin.add_column(master_catalogue['help_id'])
In [35]:
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
    
For Megacam band u:
898336 sources with CFHTLS flux
403760 sources with CFHTLenS flux
386292 sources with CFHTLS and CFHTLenS flux
898336 sources for which we use CFHTLS
17468 sources for which we use CFHTLenS
For Megacam band g:
968859 sources with CFHTLS flux
506111 sources with CFHTLenS flux
486700 sources with CFHTLS and CFHTLenS flux
968859 sources for which we use CFHTLS
19411 sources for which we use CFHTLenS
For Megacam band r:
984214 sources with CFHTLS flux
509786 sources with CFHTLenS flux
489579 sources with CFHTLS and CFHTLenS flux
984214 sources for which we use CFHTLS
20207 sources for which we use CFHTLenS
For Megacam band i:
959749 sources with CFHTLS flux
529203 sources with CFHTLenS flux
498878 sources with CFHTLS and CFHTLenS flux
959749 sources for which we use CFHTLS
30325 sources for which we use CFHTLenS
For Megacam band z:
846472 sources with CFHTLS flux
421512 sources with CFHTLenS flux
396727 sources with CFHTLS and CFHTLenS flux
846472 sources for which we use CFHTLS
24785 sources for which we use CFHTLenS
In [36]:
#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
In [37]:
megacam_origin.write("{}/gama-09_megacam_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX))

VII.b VISTA-VIKING and VISTA-VHS

VIKING is deeper than VHS so we take the VIKING photometry if available.

In [38]:
vista_origin = Table()
vista_origin.add_column(master_catalogue['help_id'])
In [39]:
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 ))
                  
For VISTA band y:
1386617 sources with VIKING flux
157730 sources with VHS flux
65293 sources with VIKING and VHS flux
1386617 sources for which we use VIKING
92437 sources for which we use VHS
1386533 sources with VIKING aperture flux
157725 sources with VHS aperture flux
65293 sources with VIKING and VHS aperture flux
1386533 sources for which we use VIKING aperture fluxes
92432 sources for which we use VHS aperture fluxes
For VISTA band j:
1614888 sources with VIKING flux
431419 sources with VHS flux
278769 sources with VIKING and VHS flux
1614888 sources for which we use VIKING
152650 sources for which we use VHS
1614759 sources with VIKING aperture flux
431399 sources with VHS aperture flux
278747 sources with VIKING and VHS aperture flux
1614759 sources for which we use VIKING aperture fluxes
152652 sources for which we use VHS aperture fluxes
For VISTA band h:
1616502 sources with VIKING flux
122508 sources with VHS flux
77750 sources with VIKING and VHS flux
1616502 sources for which we use VIKING
44758 sources for which we use VHS
1610310 sources with VIKING aperture flux
122497 sources with VHS aperture flux
77727 sources with VIKING and VHS aperture flux
1610310 sources for which we use VIKING aperture fluxes
44770 sources for which we use VHS aperture fluxes
For VISTA band k:
1364692 sources with VIKING flux
307880 sources with VHS flux
204046 sources with VIKING and VHS flux
1364692 sources for which we use VIKING
103834 sources for which we use VHS
1364254 sources with VIKING aperture flux
307839 sources with VHS aperture flux
203983 sources with VIKING and VHS aperture flux
1364254 sources for which we use VIKING aperture fluxes
103856 sources for which we use VHS aperture fluxes
In [40]:
      
#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'
In [41]:
vista_origin.write("{}/gama-09_vista_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX))

VIII.a Wavelength domain coverage

We add a binary flag_optnir_obs indicating that a source was observed in a given wavelength domain:

  • 1 for observation in optical;
  • 2 for observation in near-infrared;
  • 4 for observation in mid-infrared (IRAC).

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.

In [42]:
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")
In [43]:
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'],   
#)
In [44]:
master_catalogue.add_column(
    Column(
        1 * was_observed_optical + 2 * was_observed_nir + 4 * was_observed_mir,
        name="flag_optnir_obs")
)

VIII.b Wavelength domain detection

We add a binary flag_optnir_det indicating that a source was detected in a given wavelength domain:

  • 1 for detection in optical;
  • 2 for detection in near-infrared;
  • 4 for detection in mid-infrared (IRAC).

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.

In [45]:
# 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)
In [46]:
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")
)

IX - Cross-identification table

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?

In [47]:
#
# 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]
910 master list rows had multiple associations.
In [48]:
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'])

X - Adding HEALPix index

We are adding a column with a HEALPix index at order 13 associated with each source.

In [49]:
master_catalogue.add_column(Column(
    data=coords_to_hpidx(master_catalogue['ra'], master_catalogue['dec'], order=13),
    name="hp_idx"
))

XI - Renaming some columns

In [50]:
# 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")
In [51]:
# 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_")

XI - Saving the catalogue

In [52]:
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"]
In [53]:
# 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)))
Missing columns: set()
In [54]:
master_catalogue[columns].write("{}/master_catalogue_gama-09{}.fits".format(OUT_DIR, SUFFIX))