XMM-LSS master catalogue¶

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

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]:
#candels = Table.read("{}/CANDELS.fits".format(TMP_DIR))           # 1.1
#cfht_wirds = Table.read("{}/CFHT-WIRDS.fits".format(TMP_DIR))     # 1.3
#cfhtls_wide = Table.read("{}/CFHTLS-WIDE.fits".format(TMP_DIR))   # 1.4a
#cfhtls_deep = Table.read("{}/CFHTLS-DEEP.fits".format(TMP_DIR))   # 1.4b
#We no longer use CFHTLenS as it is the same raw data set as CFHTLS-WIDE
# cfhtlens = Table.read("{}/CFHTLENS.fits".format(TMP_DIR))         # 1.5
#decals = Table.read("{}/DECaLS.fits".format(TMP_DIR))             # 1.6
#servs = Table.read("{}/SERVS.fits".format(TMP_DIR))               # 1.8
#swire = Table.read("{}/SWIRE.fits".format(TMP_DIR))               # 1.7
hsc_wide = Table.read("{}/HSC-WIDE.fits".format(TMP_DIR))         # 1.9a
hsc_deep = Table.read("{}/HSC-DEEP.fits".format(TMP_DIR))         # 1.9b
hsc_udeep = Table.read("{}/HSC-UDEEP.fits".format(TMP_DIR))       # 1.9c
#ps1 = Table.read("{}/PS1.fits".format(TMP_DIR))                   # 1.10
#sxds = Table.read("{}/SXDS.fits".format(TMP_DIR))                 # 1.11
#sparcs = Table.read("{}/SpARCS.fits".format(TMP_DIR))             # 1.12
#dxs = Table.read("{}/UKIDSS-DXS.fits".format(TMP_DIR))            # 1.13
#uds = Table.read("{}/UKIDSS-UDS.fits".format(TMP_DIR))            # 1.14
#vipers = Table.read("{}/VIPERS.fits".format(TMP_DIR))             # 1.15
#vhs = Table.read("{}/VISTA-VHS.fits".format(TMP_DIR))             # 1.16
#video = Table.read("{}/VISTA-VIDEO.fits".format(TMP_DIR))         # 1.17
#viking = Table.read("{}/VISTA-VIKING.fits".format(TMP_DIR))       # 1.18

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.

Start with HSC-WIDE¶

In [5]:
master_catalogue = hsc_wide
master_catalogue['hsc-wide_ra'].name = 'ra'
master_catalogue['hsc-wide_dec'].name = 'dec'

Add HSC-DEEP¶

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

Add HSC-UDEEP¶

In [8]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(hsc_udeep['hsc-udeep_ra'], hsc_udeep['hsc-udeep_dec'])
)
In [9]:
master_catalogue = merge_catalogues(master_catalogue, hsc_udeep, "hsc-udeep_ra", "hsc-udeep_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 [10]:
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 [11]:
#Since this is not the final merged catalogue. We rename column names to make them unique
master_catalogue['ra'].name = 'hsc_ra'
master_catalogue['dec'].name = 'hsc_dec'
master_catalogue['flag_merged'].name = 'hsc_flag_merged'
In [12]:
master_catalogue[:10].show_in_notebook()
Out[12]:
<Table length=10>
idxhsc-wide_idhsc_rahsc_decm_ap_hsc-wide_gmerr_ap_hsc-wide_gm_hsc-wide_gmerr_hsc-wide_gm_ap_hsc-wide_rmerr_ap_hsc-wide_rm_hsc-wide_rmerr_hsc-wide_rm_ap_hsc-wide_imerr_ap_hsc-wide_im_hsc-wide_imerr_hsc-wide_im_ap_hsc-wide_zmerr_ap_hsc-wide_zm_hsc-wide_zmerr_hsc-wide_zm_ap_hsc-wide_ymerr_ap_hsc-wide_ym_hsc-wide_ymerr_hsc-wide_yhsc-wide_stellarityf_ap_hsc-wide_gferr_ap_hsc-wide_gf_hsc-wide_gferr_hsc-wide_gflag_hsc-wide_gf_ap_hsc-wide_rferr_ap_hsc-wide_rf_hsc-wide_rferr_hsc-wide_rflag_hsc-wide_rf_ap_hsc-wide_iferr_ap_hsc-wide_if_hsc-wide_iferr_hsc-wide_iflag_hsc-wide_if_ap_hsc-wide_zferr_ap_hsc-wide_zf_hsc-wide_zferr_hsc-wide_zflag_hsc-wide_zf_ap_hsc-wide_yferr_ap_hsc-wide_yf_hsc-wide_yferr_hsc-wide_yflag_hsc-wide_yhsc-wide_flag_cleanedhsc-wide_flag_gaiahsc_flag_mergedhsc-deep_idm_ap_hsc-deep_gmerr_ap_hsc-deep_gm_hsc-deep_gmerr_hsc-deep_gm_ap_hsc-deep_rmerr_ap_hsc-deep_rm_hsc-deep_rmerr_hsc-deep_rm_ap_hsc-deep_imerr_ap_hsc-deep_im_hsc-deep_imerr_hsc-deep_im_ap_hsc-deep_zmerr_ap_hsc-deep_zm_hsc-deep_zmerr_hsc-deep_zm_ap_hsc-deep_ymerr_ap_hsc-deep_ym_hsc-deep_ymerr_hsc-deep_yhsc-deep_stellarityf_ap_hsc-deep_gferr_ap_hsc-deep_gf_hsc-deep_gferr_hsc-deep_gflag_hsc-deep_gf_ap_hsc-deep_rferr_ap_hsc-deep_rf_hsc-deep_rferr_hsc-deep_rflag_hsc-deep_rf_ap_hsc-deep_iferr_ap_hsc-deep_if_hsc-deep_iferr_hsc-deep_iflag_hsc-deep_if_ap_hsc-deep_zferr_ap_hsc-deep_zf_hsc-deep_zferr_hsc-deep_zflag_hsc-deep_zf_ap_hsc-deep_yferr_ap_hsc-deep_yf_hsc-deep_yferr_hsc-deep_yflag_hsc-deep_yhsc-deep_flag_cleanedhsc-deep_flag_gaiahsc-udeep_idm_ap_hsc-udeep_gmerr_ap_hsc-udeep_gm_hsc-udeep_gmerr_hsc-udeep_gm_ap_hsc-udeep_rmerr_ap_hsc-udeep_rm_hsc-udeep_rmerr_hsc-udeep_rm_ap_hsc-udeep_imerr_ap_hsc-udeep_im_hsc-udeep_imerr_hsc-udeep_im_ap_hsc-udeep_zmerr_ap_hsc-udeep_zm_hsc-udeep_zmerr_hsc-udeep_zm_ap_hsc-udeep_ymerr_ap_hsc-udeep_ym_hsc-udeep_ymerr_hsc-udeep_ym_ap_hsc-udeep_n921merr_ap_hsc-udeep_n921m_hsc-udeep_n921merr_hsc-udeep_n921m_ap_hsc-udeep_n816merr_ap_hsc-udeep_n816m_hsc-udeep_n816merr_hsc-udeep_n816hsc-udeep_stellarityf_ap_hsc-udeep_gferr_ap_hsc-udeep_gf_hsc-udeep_gferr_hsc-udeep_gflag_hsc-udeep_gf_ap_hsc-udeep_rferr_ap_hsc-udeep_rf_hsc-udeep_rferr_hsc-udeep_rflag_hsc-udeep_rf_ap_hsc-udeep_iferr_ap_hsc-udeep_if_hsc-udeep_iferr_hsc-udeep_iflag_hsc-udeep_if_ap_hsc-udeep_zferr_ap_hsc-udeep_zf_hsc-udeep_zferr_hsc-udeep_zflag_hsc-udeep_zf_ap_hsc-udeep_yferr_ap_hsc-udeep_yf_hsc-udeep_yferr_hsc-udeep_yflag_hsc-udeep_yf_ap_hsc-udeep_n921ferr_ap_hsc-udeep_n921f_hsc-udeep_n921ferr_hsc-udeep_n921flag_hsc-udeep_n921f_ap_hsc-udeep_n816ferr_ap_hsc-udeep_n816f_hsc-udeep_n816ferr_hsc-udeep_n816flag_hsc-udeep_n816hsc-udeep_flag_cleanedhsc-udeep_flag_gaia
degdeg
03749006085720055934.9726111128-5.416603968618.19542312620.00034829817013816.94024276730.00023904538829817.30807113650.00024776230566216.07739257810.00017302628839416.86113357540.00014561988064115.63289356230.00010984019900216.56562423710.00019991846056715.34885597230.00017121617565916.37762832640.00027522104210215.15138721470.000284483452560.0191.3509216310.0613843128085607.9987182620.133862435818False433.2827758790.09887406229971345.993286130.214501649141False653.9529418950.08770873397592026.946777340.205059230328False858.5194702150.1580806523562633.039306640.415219575167False1020.818603520.258765190843158.238769530.827518343925FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
13854929857664454334.3202154982-4.1304148703218.04457473750.00041723984759316.87487792970.00028112891595817.16765975950.00031998904887616.0275573730.0002240876638116.69177627560.00015150020772115.57211112980.00010782140452616.40353012080.0001813991111715.28750705720.00015842526045216.18896102910.00023161989520315.08132934570.0002467407321090.0219.8720397950.0844950899482645.726440430.167197495699False493.1010742190.1453271508221409.213500980.290850907564False764.3448486330.1066542714832143.656982420.212880536914False996.7536621090.1665323674682786.102539060.406534284353False1214.550048830.2590997517113368.745605470.765569746494FalseFalse0False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
23748526767369725733.974499974-4.7282017702618.18273544310.0003648322017417.16830444340.00026594739756517.26713180540.00025697343517116.29336547850.00019506060925816.80125045780.00015856981917815.82149696350.00012383848661616.48783493040.00017849053256215.53880882260.0001628144673316.27545738220.00024152752303115.31787109380.0002574611862660.0193.6001892090.0650540962815492.8082275390.120711706579False449.9323425290.1064905673271103.198242190.198197796941False691.0344848630.100924335421703.730834960.194326624274False922.2866210940.1516201049092210.427246090.331470519304False1121.545288090.2494934350252709.263916020.642449140549FalseFalse0False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
33642919105018226736.4515092143-6.0249307572718.11347198490.00034677446819816.62465667720.00021609895338817.19094467160.0002174251276315.79340171810.00014305367949416.83705139160.00016399385640415.40161418910.00011350182467116.54805755620.00020610025967515.13417530060.00017628872592516.39900588990.00028585197287614.92207145690.0002701056073420.0206.3530883790.0659073367715813.0873413090.161832422018False482.6384277340.0966512113811748.393066410.230363547802False668.6199951170.1009909808642508.154052730.262200057507False872.5228881840.1656269729143208.704833980.520990729332False1000.915527340.2635204195983900.958007810.970466554165FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
43855878186444189136.4573989967-4.0068759216118.10585784910.00028424902120616.59295272830.0001682490110417.31001663210.00024644646327915.88395309450.00016496641910616.93716812130.00016455442528215.51981639860.00010725444735716.64084625240.00020973254868315.27674770360.00018768533482216.35415267940.00025739660486615.08200073240.000286054186290.0207.8053588870.0544040724635837.17968750.129731923342False432.5071105960.09817287325861608.490478520.244393527508False609.7230834960.09240975975992249.433593750.222210302949False801.0530395510.1547400653362813.848876950.486414819956False1043.130615230.2472960650923366.661865230.8869997859FalseFalse0False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
53748071930333485832.7099242551-5.1677932464218.59483718870.0004656337259816.80094909670.00026469727163217.51274871830.00028620605007715.91829395290.00018528405053116.97933387760.00016503925144215.45567131040.00013015362492316.61885643010.0002294846781315.14287662510.00020064775890216.3959808350.00028968509286614.90541648860.0002892105258070.0132.4539947510.0568048134446691.2260742190.16851760447False358.8396301270.0945921018721558.411865230.265947520733False586.4975585940.08915159851312386.334472660.286064058542False817.4425659180.1727772802113183.091308590.588246166706False1003.708129880.2677991986273961.258056641.0551712513FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
63748952398628889635.7589699154-4.8966403075318.22815704350.00031437847064817.57477569580.00025995945907217.4384193420.00023497418442316.79898452760.00019601749954716.99864578250.00016819803568116.34753417970.00014441835810416.75257492070.00023973807401516.10522460940.00024204824876516.51024055480.00028842029860215.92663955690.0003588413819670.0185.6679992680.0537607781589338.91406250.081146709621False384.2661743160.0831625834107692.4779052730.125019133091False576.1578369140.08925613015891049.508789060.139599591494False722.7197875980.1595815122131311.927734380.29247418046False903.4487915040.239996582271546.47863770.511119067669FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
73748909878452921236.2035776729-5.3738760654618.30027008060.00037252041511217.01689147950.00025120508507817.34489440920.00024646506062716.15534973140.00016793567920116.89227104190.00017128323088415.70420360570.00012082856119416.56440353390.00021951162489115.41570758820.00019026859081416.34288787840.00026505911955615.21074867250.0002872420300260.0173.7367858890.0596097819507566.556457520.131083279848False418.8342285160.09507650882011252.736938480.19376643002False635.464843750.100249469281898.09704590.2112339288False859.4852294920.1737687289712475.807128910.433870017529False1054.010131840.2573138773442990.200927730.791086614132FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
83854901940376923234.7406805615-4.3231889796118.1618957520.00034403227618916.78841400150.00021000757988117.28404617310.00022956542670716.03664016720.00015946262283316.87563133240.00017269117233815.63409233090.00011610258661716.59142684940.00021842322894415.41103553770.00018924810865416.37438774110.00026879587676415.19425392150.00029052796890.0197.3520202640.0625340342522699.2529296880.135252386332False442.9772033690.09366202354431397.474243160.205247744918False645.2785644530.1026344224812024.710205080.216511234641False838.3569946290.1686566621072486.48315430.433403849602False1023.870056150.2534796595573035.976318360.812385201454FalseFalse3False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
93748044442542614933.0207055779-5.2092502544618.59989166260.00056857720483116.72332000730.00032825148082317.48013687130.00032055596238915.76178169250.00020425043476316.9329700470.00017299744649815.19781875610.00012577026791416.5071945190.00021747712162314.86883926390.00018216611351816.22264671330.00026434729807114.63874244690.0002660623576960.0131.8388061520.0690412148833742.4577636720.22446782887False369.7813415530.1091753318911800.060791020.338630318642False612.0850830080.09752751886843026.024169920.350530713797False905.9872436520.1814727187164096.983398440.687396764755False1177.44653320.2866762876515064.106445311.24097192287FalseFalse0False-1nannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
In [13]:
master_catalogue.add_column(Column(data=(np.char.array(master_catalogue['hsc-wide_id'].astype(str)) 
                                    +  np.char.array(master_catalogue['hsc-deep_id'].astype(str) )
                                    +  np.char.array(master_catalogue['hsc-udeep_id'].astype(str))), 
                              name="hsc_intid"))
In [14]:
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)
['hsc-wide_id', 'hsc-deep_id', 'hsc-udeep_id', 'hsc_intid']

VII - Choosing between multiple values for the same filter¶

 VII. e HSC wide, deep and udeep¶

Here we straightforwardly take the deepest

Survey Bands observed
HSC-WIDE grizy
HSC-DEEP grizy
HSC-UDEEP grizy n921 n816
In [15]:
suprime_origin = Table()
suprime_origin.add_column(master_catalogue['hsc_intid'])
In [16]:
suprime_stats = Table()
suprime_stats.add_column(Column(data=['g','r','i','z','y'], name="Band"))
for col in ["HSC-UDEEP",  "HSC-DEEP", "HSC-WIDE"]:
    suprime_stats.add_column(Column(data=np.full(5, 0), name="{}".format(col)))
    suprime_stats.add_column(Column(data=np.full(5, 0), name="use {}".format(col)))
    suprime_stats.add_column(Column(data=np.full(5, 0), name="{} ap".format(col)))
    suprime_stats.add_column(Column(data=np.full(5, 0), name="use {} ap".format(col)))
    
#n921 and n816 only in udeep so we can just rename those columns
for col in master_catalogue.colnames:
    if ('n921' in col) or ('n816' in col):
        master_catalogue[col].name = col.replace('hsc-udeep', 'suprime')
/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 [17]:
suprime_bands = ['g','r','i','z','y'] # Lowercase naming convention (k is Ks)
for band in suprime_bands:

    # Suprime total flux 
    has_hsc_udeep = ~np.isnan(master_catalogue['f_hsc-udeep_' + band])
    has_hsc_deep  = ~np.isnan(master_catalogue['f_hsc-deep_' + band])
    has_hsc_wide  = ~np.isnan(master_catalogue['f_hsc-wide_' + band])
    

    use_hsc_udeep = has_hsc_udeep
    use_hsc_deep = has_hsc_deep & ~has_hsc_udeep
    use_hsc_wide = has_hsc_wide & ~has_hsc_deep & ~has_hsc_udeep

    f_suprime = np.full(len(master_catalogue), np.nan)
    f_suprime[use_hsc_udeep] = master_catalogue['f_hsc-udeep_' + band][use_hsc_udeep]
    f_suprime[use_hsc_deep] = master_catalogue['f_hsc-deep_' + band][use_hsc_deep]
    f_suprime[use_hsc_wide] = master_catalogue['f_hsc-wide_' + band][use_hsc_wide]

    ferr_suprime = np.full(len(master_catalogue), np.nan)
    ferr_suprime[use_hsc_udeep] = master_catalogue['ferr_hsc-udeep_' + band][use_hsc_udeep]
    ferr_suprime[use_hsc_deep] = master_catalogue['ferr_hsc-deep_' + band][use_hsc_deep]
    ferr_suprime[use_hsc_wide] = master_catalogue['ferr_hsc-wide_' + band][use_hsc_wide]
    
    m_suprime = np.full(len(master_catalogue), np.nan)
    m_suprime[use_hsc_udeep] = master_catalogue['m_hsc-udeep_' + band][use_hsc_udeep]
    m_suprime[use_hsc_deep] = master_catalogue['m_hsc-deep_' + band][use_hsc_deep]
    m_suprime[use_hsc_wide] = master_catalogue['m_hsc-wide_' + band][use_hsc_wide]

    merr_suprime = np.full(len(master_catalogue), np.nan)
    merr_suprime[use_hsc_udeep] = master_catalogue['merr_hsc-udeep_' + band][use_hsc_udeep]
    merr_suprime[use_hsc_deep] = master_catalogue['merr_hsc-deep_' + band][use_hsc_deep]
    merr_suprime[use_hsc_wide] = master_catalogue['merr_hsc-wide_' + band][use_hsc_wide]

    flag_suprime = np.full(len(master_catalogue), False, dtype=bool)
    flag_suprime[use_hsc_udeep] = master_catalogue['flag_hsc-udeep_' + band][use_hsc_udeep]
    flag_suprime[use_hsc_deep] = master_catalogue['flag_hsc-deep_' + band][use_hsc_deep]
    flag_suprime[use_hsc_wide] = master_catalogue['flag_hsc-wide_' + band][use_hsc_wide]

    master_catalogue.add_column(Column(data=f_suprime, name="f_suprime_" + band))
    master_catalogue.add_column(Column(data=ferr_suprime, name="ferr_suprime_" + band))
    master_catalogue.add_column(Column(data=m_suprime, name="m_suprime_" + band))
    master_catalogue.add_column(Column(data=merr_suprime, name="merr_suprime_" + band))
    master_catalogue.add_column(Column(data=flag_suprime, name="flag_suprime_" + band))

    old_hsc_udeep_columns = ['f_hsc-udeep_' + band,
                               'ferr_hsc-udeep_' + band,
                               'm_hsc-udeep_' + band, 
                               'merr_hsc-udeep_' + band,
                               'flag_hsc-udeep_' + band]
    old_hsc_deep_columns = ['f_hsc-deep_' + band,
                               'ferr_hsc-deep_' + band,
                               'm_hsc-deep_' + band, 
                               'merr_hsc-deep_' + band,
                               'flag_hsc-deep_' + band]
    old_hsc_wide_columns =      ['f_hsc-wide_' + band,
                               'ferr_hsc-wide_' + band,
                               'm_hsc-wide_' + band, 
                               'merr_hsc-wide_' + band,
                               'flag_hsc-wide_' + band]
    
    old_columns = old_hsc_udeep_columns + old_hsc_deep_columns + old_hsc_wide_columns
    master_catalogue.remove_columns(old_columns)

    origin = np.full(len(master_catalogue), '     ', dtype='<U5')
    origin[use_hsc_udeep] = "HSC-UDEEP"
    origin[use_hsc_deep] = "HSC-DEEP"
    origin[use_hsc_wide] = "HSC-WIDE"
    
    suprime_origin.add_column(Column(data=origin, name= 'f_suprime_' + band ))
    
  
    # Suprime aperture flux 
    has_ap_hsc_udeep = ~np.isnan(master_catalogue['f_ap_hsc-udeep_' + band])
    has_ap_hsc_deep  = ~np.isnan(master_catalogue['f_ap_hsc-deep_' + band])
    has_ap_hsc_wide  = ~np.isnan(master_catalogue['f_ap_hsc-wide_' + band])
    

    use_ap_hsc_udeep = has_ap_hsc_udeep
    use_ap_hsc_deep = has_ap_hsc_deep & ~has_ap_hsc_udeep
    use_ap_hsc_wide = has_ap_hsc_wide & ~has_ap_hsc_deep & ~has_ap_hsc_udeep

    f_ap_suprime = np.full(len(master_catalogue), np.nan)
    f_ap_suprime[use_ap_hsc_udeep] = master_catalogue['f_ap_hsc-udeep_' + band][use_ap_hsc_udeep]
    f_ap_suprime[use_ap_hsc_deep] = master_catalogue['f_ap_hsc-deep_' + band][use_ap_hsc_deep]
    f_ap_suprime[use_ap_hsc_wide] = master_catalogue['f_ap_hsc-wide_' + band][use_ap_hsc_wide]

    ferr_ap_suprime = np.full(len(master_catalogue), np.nan)
    ferr_ap_suprime[use_ap_hsc_udeep] = master_catalogue['ferr_ap_hsc-udeep_' + band][use_ap_hsc_udeep]
    ferr_ap_suprime[use_ap_hsc_deep] = master_catalogue['ferr_ap_hsc-deep_' + band][use_ap_hsc_deep]
    ferr_ap_suprime[use_ap_hsc_wide] = master_catalogue['ferr_ap_hsc-wide_' + band][use_ap_hsc_wide]
    
    m_ap_suprime = np.full(len(master_catalogue), np.nan)
    m_ap_suprime[use_ap_hsc_udeep] = master_catalogue['m_ap_hsc-udeep_' + band][use_ap_hsc_udeep]
    m_ap_suprime[use_ap_hsc_deep] = master_catalogue['m_ap_hsc-deep_' + band][use_ap_hsc_deep]
    m_ap_suprime[use_ap_hsc_wide] = master_catalogue['m_ap_hsc-wide_' + band][use_ap_hsc_wide]

    merr_ap_suprime = np.full(len(master_catalogue), np.nan)
    merr_ap_suprime[use_ap_hsc_udeep] = master_catalogue['merr_ap_hsc-udeep_' + band][use_ap_hsc_udeep]
    merr_ap_suprime[use_ap_hsc_deep] = master_catalogue['merr_ap_hsc-deep_' + band][use_ap_hsc_deep]
    merr_ap_suprime[use_ap_hsc_wide] = master_catalogue['merr_ap_hsc-wide_' + band][use_ap_hsc_wide]


    master_catalogue.add_column(Column(data=f_ap_suprime, name="f_ap_suprime_" + band))
    master_catalogue.add_column(Column(data=ferr_ap_suprime, name="ferr_ap_suprime_" + band))
    master_catalogue.add_column(Column(data=m_ap_suprime, name="m_ap_suprime_" + band))
    master_catalogue.add_column(Column(data=merr_ap_suprime, name="merr_ap_suprime_" + band))


    old_ap_hsc_udeep_columns = ['f_ap_hsc-udeep_' + band,
                               'ferr_ap_hsc-udeep_' + band,
                               'm_ap_hsc-udeep_' + band, 
                               'merr_ap_hsc-udeep_' + band]
    old_ap_hsc_deep_columns = ['f_ap_hsc-deep_' + band,
                               'ferr_ap_hsc-deep_' + band,
                               'm_ap_hsc-deep_' + band, 
                               'merr_ap_hsc-deep_' + band]
    old_ap_hsc_wide_columns =      ['f_ap_hsc-wide_' + band,
                               'ferr_ap_hsc-wide_' + band,
                               'm_ap_hsc-wide_' + band, 
                               'merr_ap_hsc-wide_' + band]
    
    old_ap_columns = old_ap_hsc_udeep_columns + old_ap_hsc_deep_columns + old_ap_hsc_wide_columns
    master_catalogue.remove_columns(old_ap_columns)

    origin_ap = np.full(len(master_catalogue), '     ', dtype='<U5')
    origin_ap[use_ap_hsc_udeep] = "HSC-UDEEP"
    origin_ap[use_ap_hsc_deep] = "HSC-DEEP"
    origin_ap[use_ap_hsc_wide] = "HSC-WIDE"
    
    suprime_origin.add_column(Column(data=origin_ap, name= 'f_ap_suprime_' + band ))

   
    suprime_stats['HSC-UDEEP'][suprime_stats['Band'] == band] = np.sum(has_hsc_udeep)
    suprime_stats['HSC-DEEP'][suprime_stats['Band'] == band] = np.sum(has_hsc_deep)
    suprime_stats['HSC-WIDE'][suprime_stats['Band'] == band] = np.sum(has_hsc_wide)
    suprime_stats['use HSC-UDEEP'][suprime_stats['Band'] == band] = np.sum(use_hsc_udeep)
    suprime_stats['use HSC-DEEP'][suprime_stats['Band'] == band] = np.sum(use_hsc_deep)
    suprime_stats['use HSC-WIDE'][suprime_stats['Band'] == band] = np.sum(use_hsc_wide)
    suprime_stats['HSC-UDEEP ap'][suprime_stats['Band'] == band] = np.sum(has_ap_hsc_udeep)
    suprime_stats['HSC-DEEP ap'][suprime_stats['Band'] == band] = np.sum(has_ap_hsc_deep)
    suprime_stats['HSC-WIDE ap'][suprime_stats['Band'] == band] = np.sum(has_ap_hsc_wide)
    suprime_stats['use HSC-UDEEP ap'][suprime_stats['Band'] == band] = np.sum(use_ap_hsc_udeep)
    suprime_stats['use HSC-DEEP ap'][suprime_stats['Band'] == band] = np.sum(use_ap_hsc_deep)
    suprime_stats['use HSC-WIDE ap'][suprime_stats['Band'] == band] = np.sum(use_ap_hsc_wide)
In [18]:
suprime_stats.show_in_notebook()
Out[18]:
<Table length=5>
idxBandHSC-UDEEPuse HSC-UDEEPHSC-UDEEP apuse HSC-UDEEP apHSC-DEEPuse HSC-DEEPHSC-DEEP apuse HSC-DEEP apHSC-WIDEuse HSC-WIDEHSC-WIDE apuse HSC-WIDE ap
0g998673.0998673.01095018.01095018.01919139.01772037.02174733.02000686.03829925.01960251.04307858.02092471.0
1r1000644.01000644.01108590.01108590.01917464.01773982.02205170.02032086.03818027.01965600.04341941.02102626.0
2i1005311.01005311.01121186.01121186.01882446.01738286.02147614.01973255.03878046.02016292.04412774.02162473.0
3z951892.0951892.01080498.01080498.01755293.01629563.02007279.01854794.03684114.01956526.04278480.02140701.0
4y894655.0894655.01022098.01022098.01613267.01491772.01889370.01734977.03353727.01840796.03929006.02011078.0
In [19]:
suprime_origin.write("{}/xmm-lss_suprime_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)

XI - Saving the catalogue¶

In [20]:
columns = ["help_id", "field", "ra", "dec", "hp_idx"]

bands = [column[5:] for column in master_catalogue.colnames if 'f_ap' in column]
for band in bands:
    columns += ["f_ap_{}".format(band), "ferr_ap_{}".format(band),
                "m_ap_{}".format(band), "merr_ap_{}".format(band),
                "f_{}".format(band), "ferr_{}".format(band),
                "m_{}".format(band), "merr_{}".format(band),
                "flag_{}".format(band)]    
    
columns += ["stellarity", "stellarity_origin", "flag_cleaned", 
            "flag_merged", "flag_gaia", "flag_optnir_obs", "flag_optnir_det", 
            "zspec", "zspec_qual", "zspec_association_flag", "ebv"]
In [21]:
# 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: {'hsc-wide_flag_cleaned', 'hsc-udeep_flag_cleaned', 'hsc-udeep_flag_gaia', 'hsc-wide_id', 'hsc_intid', 'hsc-deep_stellarity', 'hsc-deep_flag_gaia', 'hsc_dec', 'hsc_flag_merged', 'hsc-wide_stellarity', 'hsc-wide_flag_gaia', 'hsc-udeep_id', 'hsc-deep_id', 'hsc_ra', 'hsc-udeep_stellarity', 'hsc-deep_flag_cleaned'}
In [22]:
master_catalogue.write("{}/hsc_merged_catalogue_xmm-lss.fits".format(TMP_DIR), overwrite=True)