Lockman SWIRE master catalogue

This notebook presents the merge of the various pristine catalogues to produce HELP mater catalogue on Lockman SWIRE.

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]:
wfc = Table.read("{}/INT-WFC.fits".format(TMP_DIR))
rcs = Table.read("{}/RCSLenS.fits".format(TMP_DIR))
ps1 = Table.read("{}/PS1.fits".format(TMP_DIR))
sparcs = Table.read("{}/SpARCS.fits".format(TMP_DIR))
dxs = Table.read("{}/UKIDSS-DXS.fits".format(TMP_DIR))
swire= Table.read("{}/SWIRE.fits".format(TMP_DIR))
servs = Table.read("{}/SERVS.fits".format(TMP_DIR))
uhs = Table.read("{}/UHS.fits".format(TMP_DIR))

II - Merging tables

We first merge the optical catalogues and then add the infrared ones: WFC, DXS, SpARCS, HSC, PS1, SERVS, SWIRE.

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.

WFC

In [5]:
master_catalogue = wfc
master_catalogue['wfc_ra'].name = 'ra'
master_catalogue['wfc_dec'].name = 'dec'

Add RCSLenS

In [6]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(rcs['rcs_ra'], rcs['rcs_dec'])
)
In [7]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, rcs, "rcs_ra", "rcs_dec", radius=0.8*u.arcsec)

Add PanSTARRS

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

In [10]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(sparcs['sparcs_ra'], sparcs['sparcs_dec'])
)
In [11]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, sparcs, "sparcs_ra", "sparcs_dec", radius=0.8*u.arcsec)

Add DXS

In [12]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(dxs['dxs_ra'], dxs['dxs_dec'])
)
In [13]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, dxs, "dxs_ra", "dxs_dec", radius=0.8*u.arcsec)

Add SERVS

In [14]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(servs['servs_ra'], servs['servs_dec'])
)
In [15]:
# Given the graph above, we use 1 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, servs, "servs_ra", "servs_dec", radius=1.*u.arcsec)

Add SWIRE

In [16]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(swire['swire_ra'], swire['swire_dec'])
)
In [17]:
# Given the graph above, we use 1 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, swire, "swire_ra", "swire_dec", radius=1.*u.arcsec)

Add UHS

In [18]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(uhs['uhs_ra'], uhs['uhs_dec'])
)
In [19]:
# Given the graph above, we use 1 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, uhs, "uhs_ra", "uhs_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 [20]:
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 [21]:
master_catalogue[:10].show_in_notebook()
Out[21]:
<Table length=10>
idxwfc_idradecwfc_stellaritym_ap_wfc_umerr_ap_wfc_um_wfc_umerr_wfc_um_ap_wfc_gmerr_ap_wfc_gm_wfc_gmerr_wfc_gm_ap_wfc_rmerr_ap_wfc_rm_wfc_rmerr_wfc_rm_ap_wfc_imerr_ap_wfc_im_wfc_imerr_wfc_im_ap_wfc_zmerr_ap_wfc_zm_wfc_zmerr_wfc_zf_ap_wfc_uferr_ap_wfc_uf_wfc_uferr_wfc_uflag_wfc_uf_ap_wfc_gferr_ap_wfc_gf_wfc_gferr_wfc_gflag_wfc_gf_ap_wfc_rferr_ap_wfc_rf_wfc_rferr_wfc_rflag_wfc_rf_ap_wfc_iferr_ap_wfc_if_wfc_iferr_wfc_iflag_wfc_if_ap_wfc_zferr_ap_wfc_zf_wfc_zferr_wfc_zflag_wfc_zwfc_flag_cleanedwfc_flag_gaiaflag_mergedrcs_idrcs_stellaritym_rcs_gmerr_rcs_gm_rcs_rmerr_rcs_rm_rcs_imerr_rcs_im_rcs_zmerr_rcs_zm_rcs_ymerr_rcs_yf_rcs_gferr_rcs_gflag_rcs_gf_rcs_rferr_rcs_rflag_rcs_rf_rcs_iferr_rcs_iflag_rcs_if_rcs_zferr_rcs_zflag_rcs_zf_rcs_yferr_rcs_yflag_rcs_yrcs_flag_cleanedrcs_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_gaiasparcs_intidsparcs_stellaritym_ap_cfht_megacam_umerr_ap_cfht_megacam_uf_ap_cfht_megacam_uferr_ap_cfht_megacam_um_cfht_megacam_umerr_cfht_megacam_uf_cfht_megacam_uferr_cfht_megacam_uflag_cfht_megacam_um_ap_cfht_megacam_gmerr_ap_cfht_megacam_gf_ap_cfht_megacam_gferr_ap_cfht_megacam_gm_cfht_megacam_gmerr_cfht_megacam_gf_cfht_megacam_gferr_cfht_megacam_gflag_cfht_megacam_gm_ap_cfht_megacam_rmerr_ap_cfht_megacam_rf_ap_cfht_megacam_rferr_ap_cfht_megacam_rm_cfht_megacam_rmerr_cfht_megacam_rf_cfht_megacam_rferr_cfht_megacam_rflag_cfht_megacam_rm_ap_cfht_megacam_zmerr_ap_cfht_megacam_zf_ap_cfht_megacam_zferr_ap_cfht_megacam_zm_cfht_megacam_zmerr_cfht_megacam_zf_cfht_megacam_zferr_cfht_megacam_zflag_cfht_megacam_zsparcs_flag_cleanedsparcs_flag_gaiadxs_idm_ap_ukidss_jmerr_ap_ukidss_jm_ukidss_jmerr_ukidss_jm_ap_ukidss_kmerr_ap_ukidss_km_ukidss_kmerr_ukidss_kdxs_stellarityf_ap_ukidss_jferr_ap_ukidss_jf_ukidss_jferr_ukidss_jflag_ukidss_jf_ap_ukidss_kferr_ap_ukidss_kf_ukidss_kferr_ukidss_kflag_ukidss_kdxs_flag_cleaneddxs_flag_gaiaservs_intidf_ap_servs_irac1ferr_ap_servs_irac1f_servs_irac1ferr_servs_irac1servs_stellarity_irac1f_ap_servs_irac2ferr_ap_servs_irac2f_servs_irac2ferr_servs_irac2servs_stellarity_irac2m_ap_servs_irac1merr_ap_servs_irac1m_servs_irac1merr_servs_irac1flag_servs_irac1m_ap_servs_irac2merr_ap_servs_irac2m_servs_irac2merr_servs_irac2flag_servs_irac2servs_flag_cleanedservs_flag_gaiaswire_intidf_ap_swire_irac1ferr_ap_swire_irac1f_swire_irac1ferr_swire_irac1swire_stellarity_irac1f_ap_swire_irac2ferr_ap_swire_irac2f_swire_irac2ferr_swire_irac2swire_stellarity_irac2f_ap_irac_i3ferr_ap_irac_i3f_irac_i3ferr_irac_i3swire_stellarity_irac3f_ap_irac_i4ferr_ap_irac_i4f_irac_i4ferr_irac_i4swire_stellarity_irac4m_ap_swire_irac1merr_ap_swire_irac1m_swire_irac1merr_swire_irac1flag_swire_irac1m_ap_swire_irac2merr_ap_swire_irac2m_swire_irac2merr_swire_irac2flag_swire_irac2m_ap_irac_i3merr_ap_irac_i3m_irac_i3merr_irac_i3flag_irac_i3m_ap_irac_i4merr_ap_irac_i4m_irac_i4merr_irac_i4flag_irac_i4swire_flag_cleanedswire_flag_gaiauhs_iduhs_stellaritym_uhs_jmerr_uhs_jm_ap_uhs_jmerr_ap_uhs_jf_uhs_jferr_uhs_jflag_uhs_jf_ap_uhs_jferr_ap_uhs_juhs_flag_cleaneduhs_flag_gaia
degdegmagmagmagmagmagmagmagmaguJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJy
0445739200939161.11998402857.54804516490.0nannannannannannannannan14.5630.01512.4770.01514.7210.02512.9680.025nannannannannannannannanFalsenannannannanFalse5430.075.018237085.1512.35False4694.61108.09723593.9543.27FalsenannannannanFalseFalse1True-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0
1445739200001161.31787017757.76978596490.0nannannannannannannannan13.9680.01510.5560.015nannannannannannannannannannannannanFalsenannannannanFalse9392.9129.768217570.03005.85FalsenannannannanFalsenannannannanFalseFalse0False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0
2445733201324162.37258098357.71554885590.0nannannannan14.3050.02411.7980.02414.1740.01611.7650.01614.0710.02211.0710.022nannannannannannannannanFalse6886.52152.22569310.61532.1False7769.62114.49771449.61052.92False8542.79173.1135394.02743.46FalsenannannannanFalseFalse2True-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0
3445733300776162.8535508158.06524735190.0nannannannan14.4980.02413.1130.02414.4690.01612.9260.01614.3710.02212.7830.022nannannannannannannannanFalse5765.01127.43420644.3456.338False5921.0787.256124524.5361.406False6480.37131.3127976.9566.889FalsenannannannanFalseFalse2False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0
4445733400548162.95197011657.88744474290.0nannannannan14.3070.02413.1290.02414.2460.01612.9050.01614.1930.02212.8210.022nannannannannannannannanFalse6873.84151.94520342.3449.663False7271.09107.15125003.5368.465False7634.84154.70327014.7547.392FalsenannannannanFalseFalse3True-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0
5445733100796162.80145620457.65766785290.0nannannannan18.7010.02418.8830.02418.5460.01618.6890.016nannannannannannannannannannannannanFalse120.1162.65514101.5782.24537False138.5482.04172121.4511.78976FalsenannannannanFalsenannannannanFalseFalse0False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0
6445733100980162.7446031557.75319157190.000171409nannannannan19.1480.02518.5590.02518.6270.01618.0550.01618.2570.02217.8520.022nannannannannannannannanFalse79.57921.83238136.8993.15221False128.5881.89494217.7713.20919False180.8013.66352262.5435.31984FalsenannannannanFalseFalse0True-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0
7445730400960162.66460977657.75833344990.00306748nannannannan19.2420.02618.4070.02618.6770.01617.7020.017nannannannannannannannannannannannanFalse72.97931.74763157.4713.77094False122.81.80965301.4394.71981FalsenannannannanFalsenannannannanFalseFalse0False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0
8445739100452161.95040496257.57696449590.000171409nannannannan19.1550.02618.7170.02618.4670.01618.0560.01617.7430.02617.6450.027nannannannannannannannanFalse79.06781.89343118.3592.83432False149.0052.19582217.573.20624False290.2686.95102317.6877.90022FalsenannannannanFalseFalse0False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0
9445730100005163.11880897657.62909296290.0nannannannan14.2610.02610.840.02614.1350.01610.6040.016nannannannannannannannannannannannanFalse7171.33171.731167494.04010.96False8053.78118.685208161.03067.58FalsenannannannanFalsenannannannanFalseFalse0False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0

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 [22]:
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 [23]:
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 [24]:
stellarity_columns = [column for column in master_catalogue.colnames
                      if 'stellarity' in column]

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 [25]:
master_catalogue.add_column(
    ebv(master_catalogue['ra'], master_catalogue['dec'])
)

V - Adding HELP unique identifiers and field columns

In [26]:
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), "Lockman SWIRE", dtype='<U18'),
                                   name="field"))
In [27]:
# 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 spec-z catalogue

In [28]:
specz =  Table.read("../../dmu23/dmu23_Lockman-SWIRE/data/Lockman_SWIRE-specz-v2.1.fits")
In [29]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(specz['ra'] * u.deg, specz['dec'] * u.deg)
)
In [30]:
master_catalogue = specz_merge(master_catalogue, specz, radius=1. * u.arcsec)

VII - Choosing between multiple values for the same filter

Both SERVS and SWIRE provide IRAC1 and IRAC2 fluxes. SERVS is deeper but tends to under-estimate flux of bright sources (Mattia said over 2000 µJy) as illustrated by this comparison of SWIRE, SERVS, and Spitzer-EIP fluxes.

In [31]:
seip = Table.read("../../dmu0/dmu0_SEIP/data/SEIP_Lockman-SWIRE.fits")
seip_coords = SkyCoord(seip['ra'], seip['dec'])
idx, d2d, _ = seip_coords.match_to_catalog_sky(SkyCoord(master_catalogue['ra'], master_catalogue['dec']))
mask = d2d <= 2 * u.arcsec
WARNING: UnitsWarning: 'e/count' did not parse as fits unit: At col 0, Unit 'e' not supported by the FITS standard.  [astropy.units.core]
WARNING: UnitsWarning: 'image' did not parse as fits unit: At col 0, Unit 'image' not supported by the FITS standard.  [astropy.units.core]
In [32]:
fig, ax = plt.subplots()
ax.scatter(seip['i1_f_ap1'][mask], master_catalogue[idx[mask]]['f_ap_servs_irac1'], label="SERVS", s=2.)
ax.scatter(seip['i1_f_ap1'][mask], master_catalogue[idx[mask]]['f_ap_swire_irac1'], label="SWIRE", s=2.)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel("SEIP flux [μJy]")
ax.set_ylabel("SERVS/SWIRE flux [μJy]")
ax.set_title("IRAC 1")
ax.legend()
ax.axvline(2000, color="black", linestyle="--", linewidth=1.)
ax.plot(seip['i1_f_ap1'][mask], seip['i1_f_ap1'][mask], linewidth=.1, color="black", alpha=.5);
In [33]:
fig, ax = plt.subplots()
ax.scatter(seip['i2_f_ap1'][mask], master_catalogue[idx[mask]]['f_ap_servs_irac2'], label="SERVS", s=2.)
ax.scatter(seip['i2_f_ap1'][mask], master_catalogue[idx[mask]]['f_ap_swire_irac2'], label="SWIRE", s=2.)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel("SEIP flux [μJy]")
ax.set_ylabel("SERVS/SWIRE flux [μJy]")
ax.set_title("IRAC 2")
ax.legend()
ax.axvline(2000, color="black", linestyle="--", linewidth=1.)

ax.plot(seip['i1_f_ap2'][mask], seip['i1_f_ap2'][mask], linewidth=.1, color="black", alpha=.5);

When both SWIRE and SERVS fluxes are provided, we use the SERVS flux below 2000 μJy and the SWIRE flux over.

We create a table indicating for each source the origin on the IRAC1 and IRAC2 fluxes that will be saved separately.

In [34]:
irac_origin = Table()
irac_origin.add_column(master_catalogue['help_id'])
In [35]:
# IRAC1 aperture flux and magnitudes
has_servs = ~np.isnan(master_catalogue['f_ap_servs_irac1'])
has_swire = ~np.isnan(master_catalogue['f_ap_swire_irac1'])
has_both = has_servs & has_swire

print("{} sources with SERVS flux".format(np.sum(has_servs)))
print("{} sources with SWIRE flux".format(np.sum(has_swire)))
print("{} sources with SERVS and SWIRE flux".format(np.sum(has_both)))

has_servs_above_limit = has_servs.copy()
has_servs_above_limit[has_servs] = master_catalogue['f_ap_servs_irac1'][has_servs] > 2000

use_swire = (has_swire & ~has_servs) | (has_both & has_servs_above_limit)
use_servs = (has_servs & ~(has_both & has_servs_above_limit))

print("{} sources for which we use SERVS".format(np.sum(use_servs)))
print("{} sources for which we use SWIRE".format(np.sum(use_swire)))

f_ap_irac = np.full(len(master_catalogue), np.nan)
f_ap_irac[use_servs] = master_catalogue['f_ap_servs_irac1'][use_servs]
f_ap_irac[use_swire] = master_catalogue['f_ap_swire_irac1'][use_swire]

ferr_ap_irac = np.full(len(master_catalogue), np.nan)
ferr_ap_irac[use_servs] = master_catalogue['ferr_ap_servs_irac1'][use_servs]
ferr_ap_irac[use_swire] = master_catalogue['ferr_ap_swire_irac1'][use_swire]

m_ap_irac = np.full(len(master_catalogue), np.nan)
m_ap_irac[use_servs] = master_catalogue['m_ap_servs_irac1'][use_servs]
m_ap_irac[use_swire] = master_catalogue['m_ap_swire_irac1'][use_swire]

merr_ap_irac = np.full(len(master_catalogue), np.nan)
merr_ap_irac[use_servs] = master_catalogue['merr_ap_servs_irac1'][use_servs]
merr_ap_irac[use_swire] = master_catalogue['merr_ap_swire_irac1'][use_swire]

master_catalogue.add_column(Column(data=f_ap_irac, name="f_ap_irac_i1"))
master_catalogue.add_column(Column(data=ferr_ap_irac, name="ferr_ap_irac_i1"))
master_catalogue.add_column(Column(data=m_ap_irac, name="m_ap_irac_i1"))
master_catalogue.add_column(Column(data=merr_ap_irac, name="merr_ap_irac_i1"))

master_catalogue.remove_columns(['f_ap_servs_irac1', 'f_ap_swire_irac1', 'ferr_ap_servs_irac1',
                                     'ferr_ap_swire_irac1', 'm_ap_servs_irac1', 'm_ap_swire_irac1',
                                     'merr_ap_servs_irac1', 'merr_ap_swire_irac1'])

origin = np.full(len(master_catalogue), '     ', dtype='<U5')
origin[use_servs] = "SERVS"
origin[use_swire] = "SWIRE"
irac_origin.add_column(Column(data=origin, name="IRAC1_app"))
684599 sources with SERVS flux
617006 sources with SWIRE flux
280721 sources with SERVS and SWIRE flux
683634 sources for which we use SERVS
337250 sources for which we use SWIRE
In [36]:
# IRAC1 total flux and magnitudes
has_servs = ~np.isnan(master_catalogue['f_servs_irac1'])
has_swire = ~np.isnan(master_catalogue['f_swire_irac1'])
has_both = has_servs & has_swire

print("{} sources with SERVS flux".format(np.sum(has_servs)))
print("{} sources with SWIRE flux".format(np.sum(has_swire)))
print("{} sources with SERVS and SWIRE flux".format(np.sum(has_both)))

has_servs_above_limit = has_servs.copy()
has_servs_above_limit[has_servs] = master_catalogue['f_servs_irac1'][has_servs] > 2000

use_swire = (has_swire & ~has_servs) | (has_both & has_servs_above_limit)
use_servs = (has_servs & ~(has_both & has_servs_above_limit))

print("{} sources for which we use SERVS".format(np.sum(use_servs)))
print("{} sources for which we use SWIRE".format(np.sum(use_swire)))

f_ap_irac = np.full(len(master_catalogue), np.nan)
f_ap_irac[use_servs] = master_catalogue['f_servs_irac1'][use_servs]
f_ap_irac[use_swire] = master_catalogue['f_swire_irac1'][use_swire]

ferr_ap_irac = np.full(len(master_catalogue), np.nan)
ferr_ap_irac[use_servs] = master_catalogue['ferr_servs_irac1'][use_servs]
ferr_ap_irac[use_swire] = master_catalogue['ferr_swire_irac1'][use_swire]

flag_irac = np.full(len(master_catalogue), False, dtype=bool)
flag_irac[use_servs] = master_catalogue['flag_servs_irac1'][use_servs]
flag_irac[use_swire] = master_catalogue['flag_swire_irac1'][use_swire]

m_ap_irac = np.full(len(master_catalogue), np.nan)
m_ap_irac[use_servs] = master_catalogue['m_servs_irac1'][use_servs]
m_ap_irac[use_swire] = master_catalogue['m_swire_irac1'][use_swire]

merr_ap_irac = np.full(len(master_catalogue), np.nan)
merr_ap_irac[use_servs] = master_catalogue['merr_servs_irac1'][use_servs]
merr_ap_irac[use_swire] = master_catalogue['merr_swire_irac1'][use_swire]

master_catalogue.add_column(Column(data=f_ap_irac, name="f_irac_i1"))
master_catalogue.add_column(Column(data=ferr_ap_irac, name="ferr_irac_i1"))
master_catalogue.add_column(Column(data=m_ap_irac, name="m_irac_i1"))
master_catalogue.add_column(Column(data=merr_ap_irac, name="merr_irac_i1"))
master_catalogue.add_column(Column(data=flag_irac, name="flag_irac_i1"))

master_catalogue.remove_columns(['f_servs_irac1', 'f_swire_irac1', 'ferr_servs_irac1',
                                 'ferr_swire_irac1', 'm_servs_irac1', 'flag_servs_irac1', 'm_swire_irac1',
                                 'merr_servs_irac1', 'merr_swire_irac1', 'flag_swire_irac1'])

origin = np.full(len(master_catalogue), '     ', dtype='<U5')
origin[use_servs] = "SERVS"
origin[use_swire] = "SWIRE"
irac_origin.add_column(Column(data=origin, name="IRAC1_total"))
684599 sources with SERVS flux
616836 sources with SWIRE flux
280717 sources with SERVS and SWIRE flux
683570 sources for which we use SERVS
337148 sources for which we use SWIRE
In [37]:
# IRAC2 aperture flux and magnitudes
has_servs = ~np.isnan(master_catalogue['f_ap_servs_irac2'])
has_swire = ~np.isnan(master_catalogue['f_ap_swire_irac2'])
has_both = has_servs & has_swire

print("{} sources with SERVS flux".format(np.sum(has_servs)))
print("{} sources with SWIRE flux".format(np.sum(has_swire)))
print("{} sources with SERVS and SWIRE flux".format(np.sum(has_both)))

has_servs_above_limit = has_servs.copy()
has_servs_above_limit[has_servs] = master_catalogue['f_ap_servs_irac2'][has_servs] > 2000

use_swire = (has_swire & ~has_servs) | (has_both & has_servs_above_limit)
use_servs = (has_servs & ~(has_both & has_servs_above_limit))

print("{} sources for which we use SERVS".format(np.sum(use_servs)))
print("{} sources for which we use SWIRE".format(np.sum(use_swire)))

f_ap_irac = np.full(len(master_catalogue), np.nan)
f_ap_irac[use_servs] = master_catalogue['f_ap_servs_irac2'][use_servs]
f_ap_irac[use_swire] = master_catalogue['f_ap_swire_irac2'][use_swire]

ferr_ap_irac = np.full(len(master_catalogue), np.nan)
ferr_ap_irac[use_servs] = master_catalogue['ferr_ap_servs_irac2'][use_servs]
ferr_ap_irac[use_swire] = master_catalogue['ferr_ap_swire_irac2'][use_swire]

m_ap_irac = np.full(len(master_catalogue), np.nan)
m_ap_irac[use_servs] = master_catalogue['m_ap_servs_irac2'][use_servs]
m_ap_irac[use_swire] = master_catalogue['m_ap_swire_irac2'][use_swire]

merr_ap_irac = np.full(len(master_catalogue), np.nan)
merr_ap_irac[use_servs] = master_catalogue['merr_ap_servs_irac2'][use_servs]
merr_ap_irac[use_swire] = master_catalogue['merr_ap_swire_irac2'][use_swire]

master_catalogue.add_column(Column(data=f_ap_irac, name="f_ap_irac_i2"))
master_catalogue.add_column(Column(data=ferr_ap_irac, name="ferr_ap_irac_i2"))
master_catalogue.add_column(Column(data=m_ap_irac, name="m_ap_irac_i2"))
master_catalogue.add_column(Column(data=merr_ap_irac, name="merr_ap_irac_i2"))

master_catalogue.remove_columns(['f_ap_servs_irac2', 'f_ap_swire_irac2', 'ferr_ap_servs_irac2',
                                 'ferr_ap_swire_irac2', 'm_ap_servs_irac2', 'm_ap_swire_irac2',
                                 'merr_ap_servs_irac2', 'merr_ap_swire_irac2'])

origin = np.full(len(master_catalogue), '     ', dtype='<U5')
origin[use_servs] = "SERVS"
origin[use_swire] = "SWIRE"
irac_origin.add_column(Column(data=origin, name="IRAC2_app"))
732936 sources with SERVS flux
441887 sources with SWIRE flux
197895 sources with SERVS and SWIRE flux
732316 sources for which we use SERVS
244612 sources for which we use SWIRE
In [38]:
# IRAC2 total flux and magnitudes
has_servs = ~np.isnan(master_catalogue['f_servs_irac2'])
has_swire = ~np.isnan(master_catalogue['f_swire_irac2'])
has_both = has_servs & has_swire

print("{} sources with SERVS flux".format(np.sum(has_servs)))
print("{} sources with SWIRE flux".format(np.sum(has_swire)))
print("{} sources with SERVS and SWIRE flux".format(np.sum(has_both)))

has_servs_above_limit = has_servs.copy()
has_servs_above_limit[has_servs] = master_catalogue['f_servs_irac2'][has_servs] > 2000

use_swire = (has_swire & ~has_servs) | (has_both & has_servs_above_limit)
use_servs = (has_servs & ~(has_both & has_servs_above_limit))

print("{} sources for which we use SERVS".format(np.sum(use_servs)))
print("{} sources for which we use SWIRE".format(np.sum(use_swire)))

f_irac = np.full(len(master_catalogue), np.nan)
f_irac[use_servs] = master_catalogue['f_servs_irac2'][use_servs]
f_irac[use_swire] = master_catalogue['f_swire_irac2'][use_swire]

ferr_irac = np.full(len(master_catalogue), np.nan)
ferr_irac[use_servs] = master_catalogue['ferr_servs_irac2'][use_servs]
ferr_irac[use_swire] = master_catalogue['ferr_swire_irac2'][use_swire]

flag_irac = np.full(len(master_catalogue), False, dtype=bool)
flag_irac[use_servs] = master_catalogue['flag_servs_irac2'][use_servs]
flag_irac[use_swire] = master_catalogue['flag_swire_irac2'][use_swire]

m_irac = np.full(len(master_catalogue), np.nan)
m_irac[use_servs] = master_catalogue['m_servs_irac2'][use_servs]
m_irac[use_swire] = master_catalogue['m_swire_irac2'][use_swire]

merr_irac = np.full(len(master_catalogue), np.nan)
merr_irac[use_servs] = master_catalogue['merr_servs_irac2'][use_servs]
merr_irac[use_swire] = master_catalogue['merr_swire_irac2'][use_swire]

master_catalogue.add_column(Column(data=f_irac, name="f_irac_i2"))
master_catalogue.add_column(Column(data=ferr_irac, name="ferr_irac_i2"))
master_catalogue.add_column(Column(data=m_irac, name="m_irac_i2"))
master_catalogue.add_column(Column(data=merr_irac, name="merr_irac_i2"))
master_catalogue.add_column(Column(data=flag_irac, name="flag_irac_i2"))

master_catalogue.remove_columns(['f_servs_irac2', 'f_swire_irac2', 'ferr_servs_irac2',
                                 'ferr_swire_irac2', 'm_servs_irac2', 'flag_servs_irac2', 'm_swire_irac2',
                                 'merr_servs_irac2', 'merr_swire_irac2', 'flag_swire_irac2'])

origin = np.full(len(master_catalogue), '     ', dtype='<U5')
origin[use_servs] = "SERVS"
origin[use_swire] = "SWIRE"
irac_origin.add_column(Column(data=origin, name="IRAC2_total"))
732936 sources with SERVS flux
441831 sources with SWIRE flux
197895 sources with SERVS and SWIRE flux
732273 sources for which we use SERVS
244599 sources for which we use SWIRE
In [39]:
irac_origin.write("{}/lockman-swire_irac_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)

UHS WFCAM J vs DXS WFCAM J

These both come from wfcam. If UHS is to be included (it currently is not) we will have to decide between the two. DXS is deeper so it would probably be a case of preferentially taking DXS J fluxes.

In [40]:
wfcam_origin = Table()
wfcam_origin.add_column(master_catalogue['help_id'])

#Total J flux
use_dxs = ~np.isnan(master_catalogue['f_ukidss_j'])
use_uhs = np.isnan(master_catalogue['f_ukidss_j']) & ~np.isnan(master_catalogue['f_uhs_j'])

f_wfcam = np.full(len(master_catalogue), np.nan)
f_wfcam[use_uhs] = master_catalogue['f_uhs_j'][use_uhs]
f_wfcam[use_dxs] = master_catalogue['f_ukidss_j'][use_dxs]

ferr_wfcam = np.full(len(master_catalogue), np.nan)
ferr_wfcam[use_uhs] = master_catalogue['ferr_uhs_j'][use_uhs]
ferr_wfcam[use_dxs] = master_catalogue['ferr_ukidss_j'][use_dxs]

m_wfcam = np.full(len(master_catalogue), np.nan)
m_wfcam[use_uhs] = master_catalogue['m_uhs_j'][use_uhs]
m_wfcam[use_dxs] = master_catalogue['m_ukidss_j'][use_dxs]

merr_wfcam = np.full(len(master_catalogue), np.nan)
merr_wfcam[use_uhs] = master_catalogue['merr_uhs_j'][use_uhs]
merr_wfcam[use_dxs] = master_catalogue['merr_ukidss_j'][use_dxs]

flag_wfcam = np.full(len(master_catalogue), np.nan)
flag_wfcam[use_uhs] = master_catalogue['flag_uhs_j'][use_uhs]
flag_wfcam[use_dxs] = master_catalogue['flag_ukidss_j'][use_dxs]

master_catalogue.add_column(Column(data=f_wfcam, name="f_wfcam_j"))
master_catalogue.add_column(Column(data=ferr_wfcam, name="ferr_wfcam_j"))
master_catalogue.add_column(Column(data=m_wfcam, name="m_wfcam_j"))
master_catalogue.add_column(Column(data=merr_wfcam, name="merr_wfcam_j"))
master_catalogue.add_column(Column(data=flag_wfcam, name="flag_wfcam_j"))

master_catalogue.remove_columns(['f_uhs_j', 'f_ukidss_j', 
                                 'ferr_uhs_j', 'ferr_ukidss_j', 
                                 'm_uhs_j', 'm_ukidss_j',
                                 'merr_uhs_j', 'merr_ukidss_j', 
                                 'flag_uhs_j',  'flag_ukidss_j'])

origin = np.full(len(master_catalogue), '     ', dtype='<U5')
origin[use_uhs] = "UHS"
origin[use_dxs] = "DXS"
wfcam_origin.add_column(Column(data=origin, name="wfcam_j"))

#Aperture J flux
use_ap_dxs = ~np.isnan(master_catalogue['f_ap_ukidss_j'])
use_ap_uhs = np.isnan(master_catalogue['f_ap_ukidss_j']) & ~np.isnan(master_catalogue['f_ap_uhs_j'])

f_ap_wfcam = np.full(len(master_catalogue), np.nan)
f_ap_wfcam[use_ap_uhs] = master_catalogue['f_ap_uhs_j'][use_ap_uhs]
f_ap_wfcam[use_ap_dxs] = master_catalogue['f_ap_ukidss_j'][use_ap_dxs]

ferr_ap_wfcam = np.full(len(master_catalogue), np.nan)
ferr_ap_wfcam[use_ap_uhs] = master_catalogue['ferr_ap_uhs_j'][use_ap_uhs]
ferr_ap_wfcam[use_ap_dxs] = master_catalogue['ferr_ap_ukidss_j'][use_ap_dxs]

m_ap_wfcam = np.full(len(master_catalogue), np.nan)
m_ap_wfcam[use_ap_uhs] = master_catalogue['m_ap_uhs_j'][use_ap_uhs]
m_ap_wfcam[use_ap_dxs] = master_catalogue['m_ap_ukidss_j'][use_ap_dxs]

merr_ap_wfcam = np.full(len(master_catalogue), np.nan)
merr_ap_wfcam[use_ap_uhs] = master_catalogue['merr_ap_uhs_j'][use_ap_uhs]
merr_ap_wfcam[use_ap_dxs] = master_catalogue['merr_ap_ukidss_j'][use_ap_dxs]


master_catalogue.add_column(Column(data=f_ap_wfcam, name="f_ap_wfcam_j"))
master_catalogue.add_column(Column(data=ferr_ap_wfcam, name="ferr_ap_wfcam_j"))
master_catalogue.add_column(Column(data=m_ap_wfcam, name="m_ap_wfcam_j"))
master_catalogue.add_column(Column(data=merr_ap_wfcam, name="merr_ap_wfcam_j"))
In [41]:
master_catalogue.remove_columns(['f_ap_uhs_j', 'f_ap_ukidss_j', 
                                 'ferr_ap_uhs_j', 'ferr_ap_ukidss_j', 
                                 'm_ap_uhs_j', 'm_ap_ukidss_j',
                                 'merr_ap_uhs_j', 'merr_ap_ukidss_j'])

origin = np.full(len(master_catalogue), '     ', dtype='<U5')
origin[use_ap_uhs] = "UHS"
origin[use_ap_dxs] = "DXS"
wfcam_origin.add_column(Column(data=origin, name="wfcam_ap_j"))
In [42]:
wfcam_origin.write("{}/lockman-swire_wfcam_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)
In [43]:
master_catalogue['m_ukidss_k'].name = 'm_wfcam_k'
master_catalogue['merr_ukidss_k'].name = 'merr_wfcam_k'
master_catalogue['f_ukidss_k'].name = 'f_wfcam_k'
master_catalogue['ferr_ukidss_k'].name = 'ferr_wfcam_k'
master_catalogue['flag_ukidss_k'].name = 'flag_wfcam_k'
master_catalogue['m_ap_ukidss_k'].name = 'm_ap_wfcam_k'
master_catalogue['merr_ap_ukidss_k'].name = 'merr_ap_wfcam_k'
master_catalogue['f_ap_ukidss_k'].name = 'f_ap_wfcam_k'
master_catalogue['ferr_ap_ukidss_k'].name = 'ferr_ap_wfcam_k'

CFHT Megacam SpARCS vs RCSLenS

SpARCS apears to be significantly deeper and contains both total and aperture magnitudes so we take SpARCS over RCSLenS if both are available

Survey Bands
SpARCS ugrz
RCSLenS grizy
In [44]:
megacam_origin = Table()
megacam_origin.add_column(master_catalogue['help_id'])
In [45]:
megacam_stats = Table()
megacam_stats.add_column(Column(data=['u','g','r','i','z','y'], name="Band"))
for col in [ "SpARCS", "RCSLenS"]:
    megacam_stats.add_column(Column(data=np.full(6, 0), name="{}".format(col)))
    megacam_stats.add_column(Column(data=np.full(6, 0), name="use {}".format(col)))
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/numpy/core/numeric.py:301: FutureWarning: in the future, full(6, 0) will return an array of dtype('int64')
  format(shape, fill_value, array(fill_value).dtype), FutureWarning)
In [46]:
megacam_bands = ['u','g','r','i','z','y'] # Lowercase naming convention (k is Ks)
for band in ['g', 'r', 'z']: #the bands in both catalogues

    # Megacam total flux 
    has_sparcs = ~np.isnan(master_catalogue['f_cfht_megacam_' + band])
    has_rcs = ~np.isnan(master_catalogue['f_rcs_' + band])   

    use_sparcs = has_sparcs 
    use_rcs = has_rcs & ~has_sparcs

    f_megacam = np.full(len(master_catalogue), np.nan)
    f_megacam[use_sparcs] = master_catalogue['f_cfht_megacam_' + band][use_sparcs]
    f_megacam[use_rcs] = master_catalogue['f_rcs_' + band][use_rcs]

    ferr_megacam = np.full(len(master_catalogue), np.nan)
    ferr_megacam[use_sparcs] = master_catalogue['ferr_cfht_megacam_' + band][use_sparcs]
    ferr_megacam[use_rcs] = master_catalogue['ferr_rcs_' + band][use_rcs]

    m_megacam = np.full(len(master_catalogue), np.nan)
    m_megacam[use_sparcs] = master_catalogue['m_cfht_megacam_' + band][use_sparcs]
    m_megacam[use_rcs] = master_catalogue['m_rcs_' + band][use_rcs]
    
    merr_megacam = np.full(len(master_catalogue), np.nan)
    merr_megacam[use_sparcs] = master_catalogue['merr_cfht_megacam_' + band][use_sparcs]
    merr_megacam[use_rcs] = master_catalogue['merr_rcs_' + band][use_rcs]
    
    flag_megacam = np.full(len(master_catalogue), np.nan)
    flag_megacam[use_sparcs] = master_catalogue['flag_cfht_megacam_' + band][use_sparcs]
    flag_megacam[use_rcs] = master_catalogue['flag_rcs_' + band][use_rcs]


    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_cfht_megacam_' + band,
                               'ferr_cfht_megacam_' + band,
                               'm_cfht_megacam_' + band, 
                               'merr_cfht_megacam_' + band,
                               'flag_cfht_megacam_' + band,
                               'f_rcs_' + band,
                               'ferr_rcs_' + band,
                               'm_rcs_' + band, 
                               'merr_rcs_' + band,
                               'flag_rcs_' + band]
    
    master_catalogue.remove_columns(old_columns)

    origin = np.full(len(master_catalogue), '     ', dtype='<U5')
    origin[use_sparcs] = "SpARCS"
    origin[use_rcs] = "RCSLenS"
    
    megacam_origin.add_column(Column(data=origin, name= 'f_megacam_' + band ))
    

    megacam_stats['RCSLenS'][megacam_stats['Band'] == band] = np.sum(has_rcs)
    megacam_stats['SpARCS'][megacam_stats['Band'] == band] = np.sum(has_sparcs)
    megacam_stats['use RCSLenS'][megacam_stats['Band'] == band] = np.sum(use_rcs)
    megacam_stats['use SpARCS'][megacam_stats['Band'] == band] = np.sum(use_sparcs)
In [47]:
#No aperture fluxes in rcs so just rename all the sparcs columns
for col in master_catalogue.colnames:
    if '_cfht_megacam_' in col:
        master_catalogue[col].name = col.replace('_cfht_megacam_','_megacam_')
        
    if ('_rcs_' in col) and ('_ap_rcs_' not in col):
        master_catalogue[col].name = col.replace('_rcs_','_megacam_')
        
    if '_ap_rcs_' in col:
        master_catalogue.remove_columns(col)
        
In [48]:
megacam_stats.show_in_notebook()
Out[48]:
<Table length=6>
idxBandSpARCSuse SpARCSRCSLenSuse RCSLenS
0u0.00.00.00.0
1g2473322.02473322.01593724.0681809.0
2r2511363.02511363.02038335.0928656.0
3i0.00.00.00.0
4z2219251.02219251.01249636.0547415.0
5y0.00.00.00.0
In [49]:
megacam_origin.write("{}/lockman-swire_megacam_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)
In [50]:
master_catalogue.colnames
Out[50]:
['wfc_id',
 'ra',
 'dec',
 'm_ap_wfc_u',
 'merr_ap_wfc_u',
 'm_wfc_u',
 'merr_wfc_u',
 'm_ap_wfc_g',
 'merr_ap_wfc_g',
 'm_wfc_g',
 'merr_wfc_g',
 'm_ap_wfc_r',
 'merr_ap_wfc_r',
 'm_wfc_r',
 'merr_wfc_r',
 'm_ap_wfc_i',
 'merr_ap_wfc_i',
 'm_wfc_i',
 'merr_wfc_i',
 'm_ap_wfc_z',
 'merr_ap_wfc_z',
 'm_wfc_z',
 'merr_wfc_z',
 'f_ap_wfc_u',
 'ferr_ap_wfc_u',
 'f_wfc_u',
 'ferr_wfc_u',
 'flag_wfc_u',
 'f_ap_wfc_g',
 'ferr_ap_wfc_g',
 'f_wfc_g',
 'ferr_wfc_g',
 'flag_wfc_g',
 'f_ap_wfc_r',
 'ferr_ap_wfc_r',
 'f_wfc_r',
 'ferr_wfc_r',
 'flag_wfc_r',
 'f_ap_wfc_i',
 'ferr_ap_wfc_i',
 'f_wfc_i',
 'ferr_wfc_i',
 'flag_wfc_i',
 'f_ap_wfc_z',
 'ferr_ap_wfc_z',
 'f_wfc_z',
 'ferr_wfc_z',
 'flag_wfc_z',
 'flag_merged',
 'rcs_id',
 'm_megacam_i',
 'merr_megacam_i',
 'm_megacam_y',
 'merr_megacam_y',
 'f_megacam_i',
 'ferr_megacam_i',
 'flag_megacam_i',
 'f_megacam_y',
 'ferr_megacam_y',
 'flag_megacam_y',
 'ps1_id',
 'm_ap_gpc1_g',
 'merr_ap_gpc1_g',
 'm_gpc1_g',
 'merr_gpc1_g',
 'm_ap_gpc1_r',
 'merr_ap_gpc1_r',
 'm_gpc1_r',
 'merr_gpc1_r',
 'm_ap_gpc1_i',
 'merr_ap_gpc1_i',
 'm_gpc1_i',
 'merr_gpc1_i',
 'm_ap_gpc1_z',
 'merr_ap_gpc1_z',
 'm_gpc1_z',
 'merr_gpc1_z',
 'm_ap_gpc1_y',
 'merr_ap_gpc1_y',
 'm_gpc1_y',
 'merr_gpc1_y',
 'f_ap_gpc1_g',
 'ferr_ap_gpc1_g',
 'f_gpc1_g',
 'ferr_gpc1_g',
 'flag_gpc1_g',
 'f_ap_gpc1_r',
 'ferr_ap_gpc1_r',
 'f_gpc1_r',
 'ferr_gpc1_r',
 'flag_gpc1_r',
 'f_ap_gpc1_i',
 'ferr_ap_gpc1_i',
 'f_gpc1_i',
 'ferr_gpc1_i',
 'flag_gpc1_i',
 'f_ap_gpc1_z',
 'ferr_ap_gpc1_z',
 'f_gpc1_z',
 'ferr_gpc1_z',
 'flag_gpc1_z',
 'f_ap_gpc1_y',
 'ferr_ap_gpc1_y',
 'f_gpc1_y',
 'ferr_gpc1_y',
 'flag_gpc1_y',
 'sparcs_intid',
 'm_ap_megacam_u',
 'merr_ap_megacam_u',
 'f_ap_megacam_u',
 'ferr_ap_megacam_u',
 'm_megacam_u',
 'merr_megacam_u',
 'f_megacam_u',
 'ferr_megacam_u',
 'flag_megacam_u',
 'm_ap_megacam_g',
 'merr_ap_megacam_g',
 'f_ap_megacam_g',
 'ferr_ap_megacam_g',
 'm_ap_megacam_r',
 'merr_ap_megacam_r',
 'f_ap_megacam_r',
 'ferr_ap_megacam_r',
 'm_ap_megacam_z',
 'merr_ap_megacam_z',
 'f_ap_megacam_z',
 'ferr_ap_megacam_z',
 'dxs_id',
 'm_ap_wfcam_k',
 'merr_ap_wfcam_k',
 'm_wfcam_k',
 'merr_wfcam_k',
 'f_ap_wfcam_k',
 'ferr_ap_wfcam_k',
 'f_wfcam_k',
 'ferr_wfcam_k',
 'flag_wfcam_k',
 'servs_intid',
 'swire_intid',
 'f_ap_irac_i3',
 'ferr_ap_irac_i3',
 'f_irac_i3',
 'ferr_irac_i3',
 'f_ap_irac_i4',
 'ferr_ap_irac_i4',
 'f_irac_i4',
 'ferr_irac_i4',
 'm_ap_irac_i3',
 'merr_ap_irac_i3',
 'm_irac_i3',
 'merr_irac_i3',
 'flag_irac_i3',
 'm_ap_irac_i4',
 'merr_ap_irac_i4',
 'm_irac_i4',
 'merr_irac_i4',
 'flag_irac_i4',
 'uhs_id',
 'flag_cleaned',
 'flag_gaia',
 'stellarity',
 'ebv',
 'help_id',
 'field',
 'specz_id',
 'zspec',
 'zspec_qual',
 'zspec_association_flag',
 'f_ap_irac_i1',
 'ferr_ap_irac_i1',
 'm_ap_irac_i1',
 'merr_ap_irac_i1',
 'f_irac_i1',
 'ferr_irac_i1',
 'm_irac_i1',
 'merr_irac_i1',
 'flag_irac_i1',
 'f_ap_irac_i2',
 'ferr_ap_irac_i2',
 'm_ap_irac_i2',
 'merr_ap_irac_i2',
 'f_irac_i2',
 'ferr_irac_i2',
 'm_irac_i2',
 'merr_irac_i2',
 'flag_irac_i2',
 'f_wfcam_j',
 'ferr_wfcam_j',
 'm_wfcam_j',
 'merr_wfcam_j',
 'flag_wfcam_j',
 'f_ap_wfcam_j',
 'ferr_ap_wfcam_j',
 'm_ap_wfcam_j',
 'merr_ap_wfcam_j',
 'f_megacam_g',
 'ferr_megacam_g',
 'm_megacam_g',
 'merr_megacam_g',
 'flag_megacam_g',
 'f_megacam_r',
 'ferr_megacam_r',
 'm_megacam_r',
 'merr_megacam_r',
 'flag_megacam_r',
 'f_megacam_z',
 'ferr_megacam_z',
 'm_megacam_z',
 'merr_megacam_z',
 'flag_megacam_z']

VIII.a Wavelenght domain coverage

We add a binary flag_optnir_obs indicating that a source was observed in a given wavelenght 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 [51]:
wfc_moc = MOC(filename="../../dmu0/dmu0_INTWFC/data/lh_intwfc_v2.1_HELP_coverage_MOC.fits")
sparcs_moc = MOC(filename="../../dmu0/dmu0_SpARCS/data/SpARCS_HELP_Lockman-SWIRE_MOC.fits")
rcs_moc = MOC(filename="../../dmu0/dmu0_RCSLenS/data/RCSLenS_Lockman-SWIRE_MOC.fits")
ps1_moc = MOC(filename="../../dmu0/dmu0_PanSTARRS1-3SS/data/PanSTARRS1-3SS_Lockman-SWIRE_MOC.fits")
dxs_moc = MOC(filename="../../dmu0/dmu0_UKIDSS-DXS_DR10plus/data/UKIDSS-DR10plus_Lockman-SWIRE_MOC.fits")
servs_moc = MOC(filename="../../dmu0/dmu0_DataFusion-Spitzer/data/DF-SERVS_Lockman-SWIRE_MOC.fits")
swire_moc = MOC(filename="../../dmu0/dmu0_DataFusion-Spitzer/data/DF-SWIRE_Lockman-SWIRE_MOC.fits")
uhs_moc = MOC(filename="../../dmu0/dmu0_UHS/data/UHS-DR1_Lockman-SWIRE_MOC.fits")
In [52]:
was_observed_optical = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    wfc_moc + sparcs_moc + rcs_moc + ps1_moc) 

was_observed_nir = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    dxs_moc  + uhs_moc
)

was_observed_mir = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    servs_moc + swire_moc
)
In [53]:
master_catalogue.add_column(
    Column(
        1 * was_observed_optical + 2 * was_observed_nir + 4 * was_observed_mir,
        name="flag_optnir_obs")
)

VIII.b Wavelenght domain detection

We add a binary flag_optnir_det indicating that a source was detected in a given wavelenght 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 [54]:
# 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_wfc_u']) +
    1 * ~np.isnan(master_catalogue['f_wfc_g']) +
    1 * ~np.isnan(master_catalogue['f_wfc_r']) +
    1 * ~np.isnan(master_catalogue['f_wfc_i']) +
    1 * ~np.isnan(master_catalogue['f_wfc_z']) +
    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_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_megacam_y']) 
)

nb_nir_flux = (
    1 * ~np.isnan(master_catalogue['f_wfcam_j']) +
    1 * ~np.isnan(master_catalogue['f_wfcam_k'])
)

nb_mir_flux = (
    1 * ~np.isnan(master_catalogue['f_irac_i1']) +
    1 * ~np.isnan(master_catalogue['f_irac_i2']) +
    1 * ~np.isnan(master_catalogue['f_irac_i3']) +
    1 * ~np.isnan(master_catalogue['f_irac_i4'])
)
In [55]:
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.

In [56]:
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)
['wfc_id', 'rcs_id', 'ps1_id', 'sparcs_intid', 'dxs_id', 'servs_intid', 'swire_intid', 'uhs_id', 'help_id', 'specz_id']
In [57]:
master_catalogue[id_names].write(
    "{}/master_list_cross_ident_lockman-swire{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)
id_names.remove('help_id')
master_catalogue.remove_columns(id_names)

X - Adding HEALPix index

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

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

XI - Saving the catalogue

In [59]:
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)] #No flag_{}   

columns += [ 'm_megacam_i', 'ferr_megacam_i', 'merr_megacam_i', 'flag_megacam_i', 'f_megacam_i',
             'm_megacam_y', 'ferr_megacam_y', 'merr_megacam_y', 'flag_megacam_y', 'f_megacam_y']
    
columns += ["stellarity", "flag_cleaned", "flag_merged", "flag_gaia", "flag_optnir_obs", "flag_optnir_det", 
            "zspec", "zspec_qual", "zspec_association_flag", "ebv"]
In [60]:
# 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: {'flag_wfc_u', 'flag_wfcam_j', 'flag_irac_i1', 'flag_gpc1_r', 'flag_megacam_z', 'flag_wfcam_k', 'flag_irac_i3', 'flag_gpc1_g', 'flag_megacam_u', 'flag_irac_i4', 'flag_wfc_r', 'flag_gpc1_z', 'flag_megacam_g', 'flag_gpc1_y', 'flag_irac_i2', 'flag_wfc_i', 'flag_wfc_g', 'flag_megacam_r', 'flag_wfc_z', 'flag_gpc1_i'}
In [61]:
master_catalogue[columns].write("{}/master_catalogue_lockman-swire{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)