ELAIS-N2 master catalogue

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

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
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))
swire= Table.read("{}/SWIRE.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 SWIRE

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

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 [14]:
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 [15]:
master_catalogue[:10].show_in_notebook()
Out[15]:
<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_gaiaswire_intidf_ap_irac_i1ferr_ap_irac_i1f_irac_i1ferr_irac_i1swire_stellarityf_ap_irac_i2ferr_ap_irac_i2f_irac_i2ferr_irac_i2f_ap_irac_i3ferr_ap_irac_i3f_irac_i3ferr_irac_i3f_ap_irac_i4ferr_ap_irac_i4f_irac_i4ferr_irac_i4m_ap_irac_i1merr_ap_irac_i1m_irac_i1merr_irac_i1flag_irac_i1m_ap_irac_i2merr_ap_irac_i2m_irac_i2merr_irac_i2flag_irac_i2m_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_gaia
degdegmagmagmagmagmagmagmagmaguJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJy
0220090301969250.82843744440.74598491030.015.6050.02315.5950.02314.9730.02214.0740.02214.8830.01613.4850.01614.4020.01913.190.01913.2110.03412.8910.0342079.744.05592098.9444.4635False3722.275.42218519.22172.622749582False4043.8959.59314655.5215.971112251False6297.96110.21219230.9336.534278467False18862.5590.68273752925327.9793.149FalseFalse2True-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
1220090302902250.68531609140.88710845530.013.8790.02313.8310.023nannannannan14.7390.01613.240.01614.3770.02213.1560.022nannannannan10195.3215.97510656.1225.737FalsenannannannanFalse4617.4268.044918365.4270.642250776False6444.66130.58619842.7402.066722512FalsenannannannanFalseFalse2False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
2220090301149250.95157192940.82512769130.014.6510.02314.6510.023nannannannan14.9540.01613.6910.01614.7810.02213.5210.022nannannannan5007.26106.0735007.26106.073FalsenannannannanFalse3787.9155.820712122.7178.64690721False4442.2290.011514177.5287.275288254FalsenannannannanFalseFalse2False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
3314999200495247.28221455941.63170241130.015.2970.02615.2960.02615.0130.0214.2240.0214.6740.01613.7380.01614.8010.02413.6430.02413.7860.04413.6010.0442761.8566.13772764.466.1986False3587.5766.08547419.93136.680211872False4902.372.24311609.1171.078547835False4361.1496.402212670.7280.08312732False11107.1450.11975988713170.4533.738FalseFalse2False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
4314999102182247.44769434341.35909419230.013.8280.02613.8070.02614.830.0213.120.0214.5420.01612.8950.01614.3470.02413.0020.02412.9840.04412.890.04410685.6255.88710894.3260.885False4246.1978.217820511.6377.837978303False5536.0581.582225234.8371.873617172False6625.21146.44922866.5505.460008979False23248.8942.16750562225351.31027.37FalseFalse2False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
5314988102790247.34497517841.69641781030.014.2290.02714.1660.02714.9040.02912.2580.02914.6220.01611.5420.01614.1750.02211.4040.02212.6320.0611.1220.067385.84183.677827.08194.643False3966.43105.94345373.21211.91835031False5142.875.787287740.51292.99104214False7762.47157.28999632.22018.82232726False32151.41776.75213665129181.07138.83FalseFalse3False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
6314988402536247.73883291641.88108874730.015.9670.02715.2350.027nannannannan18.7870.01618.9960.018nannannannannannannannan1490.0537.05442924.1572.7176FalsenannannannanFalse110.9681.6352991.53771.51756753621FalsenannannannanFalsenannannannanFalseFalse0False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
7314988101417247.5565983941.79530593630.019.8270.02819.8690.02817.0250.02917.0270.02915.8740.01615.8730.01614.780.02214.7060.02213.8410.0614.8470.0642.57941.0980840.96381.05641False562.34115.0201561.30614.9924727157False1623.323.92191624.823.9439252764False4446.3190.09454759.9296.4490724728False10558.4583.4812112154180.23231.008FalseFalse2False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
8314999101430247.57189841341.46031435330.020.5750.02920.6640.0317.4550.0217.4750.0216.1180.01616.120.01615.0030.02414.9010.02414.0070.04413.9590.04421.37960.57104919.6970.544248False378.4426.97117371.5356.84392696712False1296.5819.10711294.1919.0719533712False3620.7680.03623977.4187.9198163748False9061.49367.2215305279471.09383.821FalseFalse2False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
9219995402361248.89081642540.34975873330.014.2710.02914.210.02914.9780.02113.0390.02114.8230.01612.9380.016nannannannan13.1660.03612.0210.0367105.59189.797516.23200.758False3705.171.66322100.4427.459560335False4273.6662.97924254.9357.433795929FalsenannannannanFalse19660.7651.89534425756441.71871.45FalseFalse2False-1nannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0

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

V - Adding HELP unique identifiers and field columns

In [20]:
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), "ELAIS-N2", dtype='<U18'),
                                   name="field"))
In [21]:
# 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 - Choosing between multiple values for the same filter

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 [22]:
megacam_origin = Table()
megacam_origin.add_column(master_catalogue['help_id'])
In [23]:
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 [24]:
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 [25]:
#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 [26]:
megacam_stats.show_in_notebook()
Out[26]:
<Table length=6>
idxBandSpARCSuse SpARCSRCSLenSuse RCSLenS
0u0.00.00.00.0
1g772195.0772195.0718659.0342382.0
2r782280.0782280.0896254.0453907.0
3i0.00.00.00.0
4z708094.0708094.0548673.0262486.0
5y0.00.00.00.0
In [27]:
megacam_origin.write("{}/lockman-swire_megacam_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)

VII.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 [28]:
wfc_moc = MOC(filename="../../dmu0/dmu0_INTWFC/data/en2_intwfc_v2.1_HELP_coverage_MOC.fits")
sparcs_moc = MOC(filename="../../dmu0/dmu0_SpARCS/data/SpARCS_HELP_ELAIS-N2_MOC.fits")
rcs_moc = MOC(filename="../../dmu0/dmu0_RCSLenS/data/RCSLenS_ELAIS-N2_MOC.fits")
ps1_moc = MOC(filename="../../dmu0/dmu0_PanSTARRS1-3SS/data/PanSTARRS1-3SS_ELAIS-N2_MOC.fits")
swire_moc = MOC(filename="../../dmu0/dmu0_DataFusion-Spitzer/data/DF-SWIRE_ELAIS-N2_MOC.fits")
In [29]:
was_observed_optical = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    wfc_moc + sparcs_moc + ps1_moc) 

#There are seemingly no MIR observations in ELAIS N2
#was_observed_nir = inMoc(
#    master_catalogue['ra'], master_catalogue['dec'],
#    
#)

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

VII.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 [31]:
# 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.zeros(len(master_catalogue), dtype=bool) 
)

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 [32]:
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")
)

VIII - 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 [33]:
master_catalogue['help_id', 
                 'wfc_id', 
                 'rcs_id', 
                 'swire_intid', 
                 'sparcs_intid',
                 'ps1_id'].write(
    "{}/master_list_cross_ident_elais-n2{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)
master_catalogue.remove_columns(['wfc_id', 
                                 'rcs_id', 
                                 'swire_intid',
                                 'sparcs_intid', 
                                 'ps1_id'])

IX - Adding HEALPix index

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

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

IX - Saving the catalogue

In [35]:
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 += ['m_rcs_g', 'merr_rcs_g', 'f_rcs_g', 'ferr_rcs_g',
#            'm_rcs_r', 'merr_rcs_r', 'f_rcs_r', 'ferr_rcs_r',
#            'm_rcs_i', 'merr_rcs_i', 'f_rcs_i', 'ferr_rcs_i',
#            'm_rcs_z', 'merr_rcs_z', 'f_rcs_z', 'ferr_rcs_z',
#            'm_rcs_y', 'merr_rcs_y', 'f_rcs_y', 'ferr_rcs_y']

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", "ebv"]
In [36]:
# 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_megacam_z', 'flag_wfc_r', 'flag_wfc_g', 'flag_megacam_u', 'flag_wfc_z', 'flag_irac_i4', 'flag_gpc1_g', 'flag_wfc_u', 'flag_wfc_i', 'flag_megacam_g', 'flag_gpc1_i', 'flag_irac_i2', 'flag_megacam_r', 'flag_gpc1_z', 'flag_gpc1_r', 'flag_gpc1_y', 'flag_irac_i3', 'flag_irac_i1'}
In [37]:
master_catalogue[columns].write("{}/master_catalogue_elais-n2{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)