HDF-N master catalogue

This notebook presents the merge of the various pristine catalogues to produce the HELP master catalogue on HDF-N.

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: 
33f5ec7 (Wed Dec 6 16:56:17 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]:
#threed = Table.read("{}/CANDELS-3D-HST.fits".format(TMP_DIR))       # 1.1
#acs =   Table.read("{}/ACS.fits".format(TMP_DIR))                   # 1.2 GOODS-ACS
hawaii =  Table.read("{}/Hawaii.fits".format(TMP_DIR))              # 1.3 Hawaii-HDFN
ultra =  Table.read("{}/Ultradeep.fits".format(TMP_DIR))            # 1.4 Ultradeep_Ks_GOODS-N
ps1 = Table.read("{}/PS1.fits".format(TMP_DIR))                     # 1.5 PanSTARRS
candels_gn =  Table.read("{}/CANDELS-GOODS-N.fits".format(TMP_DIR)) # 1.6 CANDELS-GOODS-N
WARNING: UnitsWarning: '0 galaxy, 1 star' did not parse as fits unit: At col 2, Unit 'galaxy' not supported by the FITS standard.  [astropy.units.core]

II - Merging tables

We first merge the optical catalogues and then add the infrared ones. We start with PanSTARRS because it coevrs the whole field.

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.

PanSTARRS

In [5]:
master_catalogue = ps1
master_catalogue['ps1_ra'].name = 'ra'
master_catalogue['ps1_dec'].name = 'dec'

CANDELS-GOODS-N

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

Ultradeep

In [8]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(ultra['ultradeep_ra'], ultra['ultradeep_dec'])
)
In [9]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, ultra, "ultradeep_ra", "ultradeep_dec", radius=0.8*u.arcsec)

Hawaii

In [10]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(hawaii['hawaii_ra'], hawaii['hawaii_dec'])
)
In [11]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, hawaii, "hawaii_ra", "hawaii_dec", radius=0.8*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 [12]:
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] = master_catalogue[col].astype(float)
        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 [13]:
master_catalogue[:10].show_in_notebook()
Out[13]:
<Table length=10>
idxps1_idradecm_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_gaiaflag_mergedcandels-gn_idcandels-gn_stellarityf_acs_f435wferr_acs_f435wf_acs_f606wferr_acs_f606wf_acs_f775wferr_acs_f775wf_acs_f814wferr_acs_f814wf_acs_f850lpferr_acs_f850lpf_acs_f105wferr_acs_f105wf_acs_f125wferr_acs_f125wf_acs_f140wferr_acs_f140wf_acs_f160wferr_acs_f160wf_moircs_kferr_moircs_kf_candels-wircam_kferr_candels-wircam_kf_candels-irac_i1ferr_candels-irac_i1f_candels-irac_i2ferr_candels-irac_i2f_candels-irac_i3ferr_candels-irac_i3f_candels-irac_i4ferr_candels-irac_i4m_acs_f435wmerr_acs_f435wflag_acs_f435wm_acs_f606wmerr_acs_f606wflag_acs_f606wm_acs_f775wmerr_acs_f775wflag_acs_f775wm_acs_f814wmerr_acs_f814wflag_acs_f814wm_acs_f850lpmerr_acs_f850lpflag_acs_f850lpm_acs_f105wmerr_acs_f105wflag_acs_f105wm_acs_f125wmerr_acs_f125wflag_acs_f125wm_acs_f140wmerr_acs_f140wflag_acs_f140wm_acs_f160wmerr_acs_f160wflag_acs_f160wm_moircs_kmerr_moircs_kflag_moircs_km_candels-wircam_kmerr_candels-wircam_kflag_candels-wircam_km_candels-irac_i1merr_candels-irac_i1flag_candels-irac_i1m_candels-irac_i2merr_candels-irac_i2flag_candels-irac_i2m_candels-irac_i3merr_candels-irac_i3flag_candels-irac_i3m_candels-irac_i4merr_candels-irac_i4flag_candels-irac_i4candels-gn_flag_cleanedcandels-gn_flag_gaiaultradeep_idf_ultradeep-wircam_kferr_ultradeep-wircam_kf_ultradeep-irac_i1ferr_ultradeep-irac_i1f_ultradeep-irac_i2ferr_ultradeep-irac_i2f_ultradeep-irac_i3ferr_ultradeep-irac_i3f_ultradeep-irac_i4ferr_ultradeep-irac_i4m_ultradeep-wircam_kmerr_ultradeep-wircam_kflag_ultradeep-wircam_km_ultradeep-irac_i1merr_ultradeep-irac_i1flag_ultradeep-irac_i1m_ultradeep-irac_i2merr_ultradeep-irac_i2flag_ultradeep-irac_i2m_ultradeep-irac_i3merr_ultradeep-irac_i3flag_ultradeep-irac_i3m_ultradeep-irac_i4merr_ultradeep-irac_i4flag_ultradeep-irac_i4ultradeep_flag_cleanedultradeep_flag_gaiahawaii_idm_ap_mosaic_umerr_ap_mosaic_um_mosaic_umerr_mosaic_um_ap_suprime_bmerr_ap_suprime_bm_suprime_bmerr_suprime_bm_ap_suprime_vmerr_ap_suprime_vm_suprime_vmerr_suprime_vm_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_quirc_hkmerr_ap_quirc_hkm_quirc_hkmerr_quirc_hkf_ap_mosaic_uferr_ap_mosaic_uf_mosaic_uferr_mosaic_uflag_mosaic_uf_ap_suprime_bferr_ap_suprime_bf_suprime_bferr_suprime_bflag_suprime_bf_ap_suprime_vferr_ap_suprime_vf_suprime_vferr_suprime_vflag_suprime_vf_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_quirc_hkferr_ap_quirc_hkf_quirc_hkferr_quirc_hkflag_quirc_hkhawaii_flag_cleanedhawaii_flag_gaia
degdeg
0182231893921992736189.39211408761.8600144331nannan9.337710380550.39174100756611.19439983370.012.95219993590.010.46350002290.012.46860027310.012.6522998810.066550999879812.45600032810.13014699518710.40200042720.26212599873510.50150012970.254988998175nannan668214.426684241096.310165False120848.1667280.023939.77286660.0False236919.0545330.037373.16607480.0False31555.86196151934.2397871637809.40724394532.20655351False250726.26381560532.0813874228770.46141253727.5541811FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
1183141887446216712188.74456256762.621649393113.72449970250.00066899997182213.77309989930.0015109999803813.42210006710.0002119999990113.4694995880.0032820000778913.3304996490.0010860000038513.33419990540.0010860000038513.33520030980.0015670000575513.41040039060.0033960000146213.31540012360.0020079999230813.37909984590.0028979999478911754.39061997.2427233788811239.837702415.6422844457False15529.5893983.0322954347314866.206626344.9380715976False16896.631802116.90073714216839.145047516.84323642False16823.636496324.28088815915697.838030849.1001939038False17133.257835631.686868564716156.975322143.1254971847FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
2183141894117361384189.41162934762.617179493114.77630043030.0016659999964814.84539985660.0020910000894213.9601001740.00073500000871714.01010036470.0021150000393413.6489000320.0019259999971813.70800018310.0023900000378513.53499984740.0022430000826713.58570003510.0024470000062113.44060039520.0020659998990613.51840019230.003488000016664461.489013666.84589926034186.393595898.06250113518False9461.498621296.40505634679035.6594486617.6013473675False12602.01485422.354859741211934.381779426.2708130939False13995.875192728.913790547513357.340161330.1043764723False15267.215715329.051316506214211.500120945.6553925725FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
3183151896152897299189.61526489762.630448833115.19909954070.0031159999780415.24629974370.0053349998779614.64739990230.00074899999890514.70250034330.002023000037314.42899990080.0019039999460814.4886999130.0012219999916914.32999992370.0015059999423114.39550018310.0034159999340814.26830005650.0036299999337614.36429977420.001903999946083022.457367298.674277461522893.8772293214.2196922213False5023.889043033.465752427924775.291226578.89757041087False6143.2761738910.77314862735814.602555036.54435602567False6729.767035749.334706462926335.7776382119.9339543985False7123.2793702423.81564097146520.4878549611.4346454229FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
4182771899391593788189.93911159762.310826393116.08580017090.0038499999791416.1415004730.0080049997195615.58880043030.00084599998081115.63969993590.00075100001413415.41310024260.0014260000316415.47589969640.0032480000518315.3423004150.0018139999592715.40919971470.00320299994215.29570007320.0034159999340815.39039993290.005320999771361335.610829084.736050655381268.819401439.35484964773False2110.959143661.644848340882014.280858211.39327117062False2481.760699763.259531017642342.287072487.00699534516False2648.987042684.425810216582490.692506487.3477221436False2765.158120628.699884848962534.1949833312.4196382765FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
5183251894072041815189.40711272762.709187023115.54979991910.0054729999974415.6023998260.001296999980715.19799995420.00086099997861315.26290035250.0012349999742615.08129978180.0030920000281215.14290046690.0023590000346315.0544004440.0018670000135915.10729980470.0029529999010315.01550006870.0042730001732715.10179996490.002862999914212188.1648246411.03014344292084.683214642.49032322704False3025.519931432.399268427122849.967181793.2417721549False3368.83769029.593901527073183.023267226.91581616667False3453.343842965.938268405783289.122723338.94580012519False3579.3154292914.08667720813305.826175148.7172003792FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
6183071896006252444189.60056402762.559736773114.09370040890.0017630000365914.13640022280.001104000024513.55070018770.00093300000298813.59099960330.0010740000288913.39789962770.003246000036613.44139957430.0093529997393513.34020042420.0036329999566113.38920021060.0056940000504313.28769969940.0017780000343913.35840034480.001918000052688366.0380681113.58463073778043.404520738.17870745123False13794.943463511.854336473513292.300740213.1486187128False15879.621586747.474931779815255.9820934131.421606757False16746.337142956.035196990516007.367503983.9485235687False17576.00308928.7824371716467.962222729.091368854FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
7182241891931461754189.19325617761.867501703114.88510036470.0023719999007914.92469978330.00091000000247714.34619998930.00097599998116514.39980030060.0037410000804814.1635999680.0046500000171414.22430038450.0061750002205414.08699989320.0017529999604414.15789985660.0043870001114.02429962160.0029829998966314.08520030980.002266000024974036.080819988.817596081453891.527346543.26164852887False6630.098862235.959989485766310.7340710421.7441921566False7844.4050900533.596083147417.8807306942.1883464392False8417.8279047313.59119454567885.6964851531.8627592929False8918.2604495424.50242506658431.7918351517.5976820385FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
8182711883352854935188.33531290762.261862413113.26239967350.0010860000038513.31779956820.0010860000038512.86030006410.0010860000038513.39900016780.0010860000038512.87189960480.0059580001980112.92000007630.0035250000655713.8457002640.0015200000489113.44480037690.001400999957712.70049953460.001927000004812.7692003250.0030519999563717990.371459617.994742543217095.43565617.0995892988False26054.333888526.060664256415863.533602415.8673879326False25777.4621644141.45436433524660.391639580.063538238False10512.836119314.717673911415208.271228119.6242763701False30185.62595353.574432814828334.781631279.6489533305FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
9183161895594883740189.55952015762.635805253113.06700038910.0011889999732413.12069988250.0021599999163312.95769977570.0010860000038512.9953002930.0010860000038512.6855001450.0021430000197112.75150012970.0054139997810112.66930007930.0010860000038512.73840045930.0010860000038512.68309974670.0016860000323512.7413997650.0040790000930421537.725838123.586167001620498.403937340.7802103268False23818.811623923.824598831623008.053725423.013643945False30605.532634360.408464552728800.494734143.61303556False31065.615900131.073163848929150.084383129.1571669192False30673.271682947.631401461129069.6694862109.211780927FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannan0.0nannanFalsenannanFalsenannanFalsenannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0

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

combining the flag_merged column which contains information regarding multiple associations

In [15]:
master_catalogue['flag_merged'].name = 'flag_merged_tmp'
flag_merged_columns = [column for column in master_catalogue.colnames
                        if 'flag_merged' in column]

flag_merged_column = np.zeros(len(master_catalogue), dtype=bool)
for column in flag_merged_columns:
    flag_merged_column |= master_catalogue[column]
    
master_catalogue.add_column(Column(data=flag_merged_column, name="flag_merged"))
master_catalogue.remove_columns(flag_merged_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 [16]:
flag_gaia_columns = [column for column in master_catalogue.colnames
                     if 'flag_gaia' in column]

master_catalogue.add_column(Column(
    data=np.max([master_catalogue[column] for column in flag_gaia_columns], axis=0),
    name="flag_gaia"
))
master_catalogue.remove_columns(flag_gaia_columns)

Each prisitine catalogue may contain one or several stellarity columns indicating the probability (0 to 1) of each source being a star. We merge these columns taking the highest value. We keep trace of the origin of the stellarity.

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

print(", ".join(stellarity_columns))
candels-gn_stellarity
In [18]:
# We create an masked array with all the stellarities and get the maximum value, as well as its
# origin.  Some sources may not have an associated stellarity.
stellarity_array = np.array([master_catalogue[column] for column in stellarity_columns])
stellarity_array = np.ma.masked_array(stellarity_array, np.isnan(stellarity_array))

max_stellarity = np.max(stellarity_array, axis=0)
max_stellarity.fill_value = np.nan

no_stellarity_mask = max_stellarity.mask

master_catalogue.add_column(Column(data=max_stellarity.filled(), name="stellarity"))

stellarity_origin = np.full(len(master_catalogue), "NO_INFORMATION", dtype="S20")
stellarity_origin[~no_stellarity_mask] = np.array(stellarity_columns)[np.argmax(stellarity_array, axis=0)[~no_stellarity_mask]]

master_catalogue.add_column(Column(data=stellarity_origin, name="stellarity_origin"))

master_catalogue.remove_columns(stellarity_columns)

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), "HDF-N", 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 - Cross-matching with spec-z catalogue

In [22]:
#specz =  Table.read("../../dmu23/dmu23_HDF-N/data/HDF-N-specz-v2.8.fits")
In [23]:
#specz['objid'].name = 'specz_id'
In [24]:
#nb_merge_dist_plot(
#    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
#    SkyCoord(specz['ra'] * u.deg, specz['dec'] * u.deg)
#)
In [25]:
#master_catalogue = specz_merge(master_catalogue, specz, radius=1. * u.arcsec)

VII - Choosing between multiple values for the same filter

We have to choose between the various HST catalogues which may contains different objects depending on the prior catalogue. The CANDELS-GOODS-N catalogue is taken as a base and any missing wircam or IRAC fluxes are taken from the Ultradeep Ks selected catalogues

In [26]:
bands = [
    ['candels-wircam_k', 'ultradeep-wircam_k', 'wircam_k'],
    ['candels-irac_i1',  'ultradeep-irac_i1',  'irac_i1'],
    ['candels-irac_i2',  'ultradeep-irac_i2',  'irac_i2'],
    ['candels-irac_i3',  'ultradeep-irac_i3',  'irac_i3'],
    ['candels-irac_i4',  'ultradeep-irac_i4',  'irac_i4'],
    
]
In [27]:
ir_origin = Table()
ir_origin.add_column(master_catalogue['help_id'])
In [28]:
ir_stats = Table()
ir_stats.add_column(Column(data=np.array(bands)[:,2], name="Band"))
for col in ["CANDELS-GOODS-N", "Ultradeep"]:
    ir_stats.add_column(Column(data=np.full(5, 0), name="{}".format(col), dtype=str))
    ir_stats.add_column(Column(data=np.full(5, 0), name="use {}".format(col), dtype=str))
  
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/numpy/core/numeric.py:301: FutureWarning: in the future, full(5, 0) will return an array of dtype('int64')
  format(shape, fill_value, array(fill_value).dtype), FutureWarning)
In [29]:
ir_stats.show_in_notebook()
Out[29]:
<Table length=5>
idxBandCANDELS-GOODS-Nuse CANDELS-GOODS-NUltradeepuse Ultradeep
0wircam_k0.00.00.00.0
1irac_i10.00.00.00.0
2irac_i20.00.00.00.0
3irac_i30.00.00.00.0
4irac_i40.00.00.00.0
In [30]:
for band in bands:

    # total flux 
    has_candels = ~np.isnan(master_catalogue['f_' + band[0]])
    has_ultradeep = ~np.isnan(master_catalogue['f_' + band[1]])
    

    use_candels = has_candels
    use_ultradeep = has_ultradeep & ~has_candels

    f_ir = np.full(len(master_catalogue), np.nan)
    f_ir[use_candels] = master_catalogue['f_' + band[0]][use_candels]
    f_ir[use_ultradeep] = master_catalogue['f_' + band[1]][use_ultradeep]

    ferr_ir = np.full(len(master_catalogue), np.nan)
    ferr_ir[use_candels] = master_catalogue['ferr_' + band[0]][use_candels]
    ferr_ir[use_ultradeep] = master_catalogue['ferr_' + band[1]][use_ultradeep]

    m_ir = np.full(len(master_catalogue), np.nan)
    m_ir[use_candels] = master_catalogue['m_' + band[0]][use_candels]
    m_ir[use_ultradeep] = master_catalogue['m_' + band[1]][use_ultradeep]
    
    merr_ir = np.full(len(master_catalogue), np.nan)
    merr_ir[use_candels] = master_catalogue['merr_' + band[0]][use_candels]
    merr_ir[use_ultradeep] = master_catalogue['merr_' + band[1]][use_ultradeep]
    
    flag_ir = np.full(len(master_catalogue), np.nan)
    flag_ir[use_candels] = master_catalogue['flag_' + band[0]][use_candels]
    flag_ir[use_ultradeep] = master_catalogue['flag_' + band[1]][use_ultradeep]

    master_catalogue.add_column(Column(data=f_ir, name="f_" + band[2]))
    master_catalogue.add_column(Column(data=ferr_ir, name="ferr_" + band[2]))
    master_catalogue.add_column(Column(data=m_ir, name="m_" + band[2]))
    master_catalogue.add_column(Column(data=merr_ir, name="merr_" + band[2]))
    master_catalogue.add_column(Column(data=flag_ir, name="flag_" + band[2]))
 
    master_catalogue.remove_columns(['f_' + band[0], 'f_' + band[1],
                                    'ferr_' + band[0], 'ferr_' + band[1],
                                    'm_' + band[0], 'm_' + band[1],
                                    'merr_' + band[0], 'merr_' + band[1],
                                    'flag_' + band[0], 'flag_' + band[1],])

    origin = np.full(len(master_catalogue), '     ', dtype='<U5')
    origin[use_candels] = "CANDELS-GOODS-N"
    origin[use_ultradeep] = "Ultradeep"
   
    
    ir_origin.add_column(Column(data=origin, name= 'f_' + band[2] ))
    
    #Aperture fluxes

    #has_ap_candels = ~np.isnan(master_catalogue['f_ap_' + band[0]])
    #has_ap_ultradeep = ~np.isnan(master_catalogue['f_ap_' + band[1]])
    

    #use_ap_candels = has_ap_candels
    #use_ap_ultradeep = has_ap_ultradeep & ~has_ap_candels

    #f_ap_ir = np.full(len(master_catalogue), np.nan)
    #f_ap_ir[use_ap_candels] = master_catalogue['f_ap_' + band[0]][use_ap_candels]
    #f_ap_ir[use_ap_ultradeep] = master_catalogue['f_ap_' + band[1]][use_ap_ultradeep]

    #ferr_ap_ir = np.full(len(master_catalogue), np.nan)
    #ferr_ap_ir[use_ap_candels] = master_catalogue['ferr_ap_' + band[0]][use_ap_candels]
    #ferr_ap_ir[use_ap_ultradeep] = master_catalogue['ferr_ap_' + band[1]][use_ap_ultradeep]

    #m_ap_ir = np.full(len(master_catalogue), np.nan)
    #m_ap_ir[use_ap_candels] = master_catalogue['m_ap_' + band[0]][use_ap_candels]
    #m_ap_ir[use_ap_ultradeep] = master_catalogue['m_ap_' + band[1]][use_ap_ultradeep]
    
    #merr_ap_ir = np.full(len(master_catalogue), np.nan)
    #merr_ap_ir[use_ap_candels] = master_catalogue['merr_ap_' + band[0]][use_ap_candels]
    #merr_ap_ir[use_ap_ultradeep] = master_catalogue['merr_ap_' + band[1]][use_ap_ultradeep]
    


    #master_catalogue.add_column(Column(data=f_ap_ir, name="f_ap_" + band[2]))
    #master_catalogue.add_column(Column(data=ferr_ap_ir, name="ferr_ap_" + band[2]))
    #master_catalogue.add_column(Column(data=m_ap_ir, name="m_ap_" + band[2]))
    #master_catalogue.add_column(Column(data=merr_ap_ir, name="merr_ap_" + band[2]))

 
    #master_catalogue.remove_columns(['f_ap_' + band[0], 'f_ap_' + band[1],
    #                                'ferr_ap_' + band[0], 'ferr_ap_' + band[1],
    #                                'm_ap_' + band[0], 'm_ap_' + band[1],
     #                               'merr_ap_' + band[0], 'merr_ap_' + band[1],
     #                               'flag_ap_' + band[0], 'flag_ap_' + band[1],])

    #origin_ap = np.full(len(master_catalogue), '     ', dtype='<U5')
    #origin_ap[use_ap_candels] = "CANDELS-GOODS-N"
    #origin_ap[use_ap_ultradeep] = "Ultradeep"
   
    
    #ir_origin.add_column(Column(data=origin_ap, name= 'f_ap_' + band[2] ))
    

    

   
    ir_stats['CANDELS-GOODS-N'][ir_stats['Band'] == band[0]] = np.sum(has_candels)
    ir_stats['Ultradeep'][ir_stats['Band'] == band[0]] = np.sum(has_ultradeep)
 
    ir_stats['use CANDELS-GOODS-N'][ir_stats['Band'] == band[0]] = np.sum(use_candels)
    ir_stats['use Ultradeep'][ir_stats['Band'] == band[0]] = np.sum(use_ultradeep)
In [31]:
ir_stats.show_in_notebook()
Out[31]:
<Table length=5>
idxBandCANDELS-GOODS-Nuse CANDELS-GOODS-NUltradeepuse Ultradeep
0wircam_k0.00.00.00.0
1irac_i10.00.00.00.0
2irac_i20.00.00.00.0
3irac_i30.00.00.00.0
4irac_i40.00.00.00.0
In [32]:
ir_origin.write("{}/hdf-n_wircam_irac_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 the different depths in the catalogue we are using.

In [33]:
candels_gn_moc =   MOC(filename="../../dmu0/dmu0_CANDELS-3D-HST/data/CANDELS-3D-HST_XMM-LSS_MOC.fits")
ultra_moc = MOC(filename="../../dmu0/dmu0_Ultradeep-Ks-GOODS-N/data/Ultradeep_Ks_GOODS-N_HELP-coverage_MOC.fits")
ps1_moc = MOC(filename="../../dmu0/dmu0_PanSTARRS1-3SS/data/PanSTARRS1-3SS_XMM-LSS_MOC.fits")       
hawaii_moc = MOC(filename="../../dmu0/dmu0_Hawaii-HDFN/data/R_MOC.fits")
In [34]:
was_observed_optical = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
      ps1_moc + hawaii_moc)

was_observed_nir = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    candels_gn_moc + ultra_moc
)

was_observed_mir = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    candels_gn_moc + ultra_moc
)
In [35]:
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 [36]:
# 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 = (
    # PanSTARRS
    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_suprime_r']) 
)

nb_nir_flux = (
    1 * ~np.isnan(master_catalogue['f_wircam_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 [37]:
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 catalogues. This can be used to easily get additional information from them.

For convenience, we also cross-match the master list with the SDSS catalogue and add the objID associated with each source, if any. TODO: should we correct the astrometry with respect to Gaia positions?

In [38]:
#
# Addind SDSS ids
#
sdss = Table.read("../../dmu0/dmu0_SDSS-DR13/data/SDSS-DR13_HDF-N.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]
8 master list rows had multiple associations.
In [39]:
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)
['ps1_id', 'candels-gn_id', 'ultradeep_id', 'hawaii_id', 'help_id', 'sdss_id']
In [40]:
master_catalogue[id_names].write(
    "{}/master_list_cross_ident_hdf-n{}.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 [41]:
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 [42]:
columns = ["help_id", "field", "ra", "dec", "hp_idx"]

bands = [column[5:] for column in master_catalogue.colnames if 'f_ap' in column]


bands_no_ap = (set([column[5:] for column in master_catalogue.colnames if 'flag' in column]) 
               - set(bands) 
               - set(['cleaned', 'gaia', 'merged', 'optnir_det', 'optnir_obs'])
              )

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)
               ]    

for band in bands_no_ap:
    columns += ["f_{}".format(band), "ferr_{}".format(band),
                "m_{}".format(band), "merr_{}".format(band),
                #"flag_{}".format(band)
               ] 

columns += ["stellarity", "stellarity_origin", "flag_cleaned", "flag_merged", "flag_gaia", 
            "flag_optnir_obs", "flag_optnir_det", "ebv"] # "zspec", "zspec_qual", "zspec_association_flag",
In [43]:
# 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_acs_f140w', 'flag_acs_f606w', 'flag_gpc1_g', 'flag_acs_f435w', 'flag_irac_i4', 'flag_gpc1_i', 'flag_mosaic_u', 'flag_suprime_r', 'flag_acs_f105w', 'flag_moircs_k', 'flag_acs_f814w', 'flag_quirc_hk', 'flag_suprime_b', 'flag_suprime_v', 'flag_gpc1_z', 'flag_irac_i2', 'flag_gpc1_r', 'flag_gpc1_y', 'flag_acs_f775w', 'flag_acs_f160w', 'flag_suprime_i', 'flag_acs_f125w', 'flag_irac_i3', 'flag_suprime_z', 'flag_wircam_k', 'flag_irac_i1', 'flag_acs_f850lp'}
In [44]:
#master_catalogue[columns].write("{}/master_catalogue_hdf-n{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)
master_catalogue.write("{}/master_catalogue_hdf-n{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)