XMM-LSS master catalogue¶

This notebook presents the merge of the pristine catalogues from CFHT Megacam. This has to be conducted separately on XMM-LSS due to the large amount of memory required on this field.

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 CFHTLS-WIDE¶

In [5]:
master_catalogue = cfhtls_wide
master_catalogue['cfhtls-wide_ra'].name = 'ra'
master_catalogue['cfhtls-wide_dec'].name = 'dec'
del cfhtls_wide

Add CFHTLS-DEEP¶

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

Add SpARCS¶

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

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 = 'megacam_ra'
master_catalogue['dec'].name = 'megacam_dec'
master_catalogue['flag_merged'].name = 'megacam_flag_merged'
In [12]:
master_catalogue[:10].show_in_notebook()
Out[12]:
<Table length=10>
idxcfhtls-wide_idmegacam_ramegacam_deccfhtls-wide_stellaritym_cfhtls-wide_umerr_cfhtls-wide_um_cfhtls-wide_gmerr_cfhtls-wide_gm_cfhtls-wide_rmerr_cfhtls-wide_rm_cfhtls-wide_imerr_cfhtls-wide_im_cfhtls-wide_zmerr_cfhtls-wide_zm_ap_cfhtls-wide_umerr_ap_cfhtls-wide_um_ap_cfhtls-wide_gmerr_ap_cfhtls-wide_gm_ap_cfhtls-wide_rmerr_ap_cfhtls-wide_rm_ap_cfhtls-wide_imerr_ap_cfhtls-wide_im_ap_cfhtls-wide_zmerr_ap_cfhtls-wide_zf_cfhtls-wide_uferr_cfhtls-wide_uflag_cfhtls-wide_uf_cfhtls-wide_gferr_cfhtls-wide_gflag_cfhtls-wide_gf_cfhtls-wide_rferr_cfhtls-wide_rflag_cfhtls-wide_rf_cfhtls-wide_iferr_cfhtls-wide_iflag_cfhtls-wide_if_cfhtls-wide_zferr_cfhtls-wide_zflag_cfhtls-wide_zf_ap_cfhtls-wide_uferr_ap_cfhtls-wide_uf_ap_cfhtls-wide_gferr_ap_cfhtls-wide_gf_ap_cfhtls-wide_rferr_ap_cfhtls-wide_rf_ap_cfhtls-wide_iferr_ap_cfhtls-wide_if_ap_cfhtls-wide_zferr_ap_cfhtls-wide_zcfhtls-wide_flag_cleanedcfhtls-wide_flag_gaiamegacam_flag_mergedcfhtls-deep_idcfhtls-deep_stellaritym_cfhtls-deep_umerr_cfhtls-deep_um_cfhtls-deep_gmerr_cfhtls-deep_gm_cfhtls-deep_rmerr_cfhtls-deep_rm_cfhtls-deep_imerr_cfhtls-deep_im_cfhtls-deep_zmerr_cfhtls-deep_zm_cfhtls-deep_ymerr_cfhtls-deep_ym_ap_cfhtls-deep_umerr_ap_cfhtls-deep_um_ap_cfhtls-deep_gmerr_ap_cfhtls-deep_gm_ap_cfhtls-deep_rmerr_ap_cfhtls-deep_rm_ap_cfhtls-deep_imerr_ap_cfhtls-deep_im_ap_cfhtls-deep_zmerr_ap_cfhtls-deep_zm_ap_cfhtls-deep_ymerr_ap_cfhtls-deep_yf_cfhtls-deep_uferr_cfhtls-deep_uflag_cfhtls-deep_uf_cfhtls-deep_gferr_cfhtls-deep_gflag_cfhtls-deep_gf_cfhtls-deep_rferr_cfhtls-deep_rflag_cfhtls-deep_rf_cfhtls-deep_iferr_cfhtls-deep_iflag_cfhtls-deep_if_cfhtls-deep_zferr_cfhtls-deep_zflag_cfhtls-deep_zf_cfhtls-deep_yferr_cfhtls-deep_yflag_cfhtls-deep_yf_ap_cfhtls-deep_uferr_ap_cfhtls-deep_uf_ap_cfhtls-deep_gferr_ap_cfhtls-deep_gf_ap_cfhtls-deep_rferr_ap_cfhtls-deep_rf_ap_cfhtls-deep_iferr_ap_cfhtls-deep_if_ap_cfhtls-deep_zferr_ap_cfhtls-deep_zf_ap_cfhtls-deep_yferr_ap_cfhtls-deep_ycfhtls-deep_flag_cleanedcfhtls-deep_flag_gaiasparcs_intidsparcs_stellaritym_ap_sparcs_umerr_ap_sparcs_uf_ap_sparcs_uferr_ap_sparcs_um_sparcs_umerr_sparcs_uf_sparcs_uferr_sparcs_uflag_sparcs_um_ap_sparcs_gmerr_ap_sparcs_gf_ap_sparcs_gferr_ap_sparcs_gm_sparcs_gmerr_sparcs_gf_sparcs_gferr_sparcs_gflag_sparcs_gm_ap_sparcs_rmerr_ap_sparcs_rf_ap_sparcs_rferr_ap_sparcs_rm_sparcs_rmerr_sparcs_rf_sparcs_rferr_sparcs_rflag_sparcs_rm_ap_sparcs_zmerr_ap_sparcs_zf_ap_sparcs_zferr_ap_sparcs_zm_sparcs_zmerr_sparcs_zf_sparcs_zferr_sparcs_zflag_sparcs_zm_ap_sparcs_ymerr_ap_sparcs_yf_ap_sparcs_yferr_ap_sparcs_ym_sparcs_ymerr_sparcs_yf_sparcs_yferr_sparcs_yflag_sparcs_ysparcs_flag_cleanedsparcs_flag_gaia
degdeg
01116_19748632.9905559476-4.71238015830.95999997854215.85400009160.001000000047515.26000022890.001000000047515.05200004580.001000000047514.72599983220.001000000047514.38399982450.001000000047515.96000003810.001000000047515.68000030520.001000000047515.39799976350.001000000047515.23299980160.001000000047514.63199996950.00100000004751653.48315431.52291429043False2857.589599612.63193750381False3460.985839843.18768596649False4673.045410164.30403470993False6403.240234385.89760303497False1499.684448241.381260395051940.884277341.787620544432516.517578122.317798376082929.543701172.698209524155095.652832034.69327020645False3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
11122_10577835.1308929476-6.18994715830.85000002384211.49699974060.001000000047511.63300037380.001000000047511.17199993130.001000000047511.56200027470.001000000047511.02900028230.001000000047515.24899959560.001000000047515.58399963380.001000000047515.27200031280.001000000047515.47399997710.001000000047514.82299995420.001000000047591453.429687584.2317276001False80686.273437574.3148040771False123367.25113.625442505False86138.976562579.3369369507False140734.21875129.621017456False2886.689697272.65873956682120.313232421.952880620962826.179931642.603008270262346.388671882.161103963854273.658203123.93618488312False0False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
21116_17844933.0483309476-4.80481815831.018.22400093080.001000000047517.33300018310.001000000047517.05400085450.001000000047516.80200004580.001000000047516.75900077820.001000000047518.28000068660.001000000047517.41099929810.001000000047517.10899925230.001000000047516.87100028990.001000000047516.83499908450.0010000000475186.3801116940.171662434936False423.4477539060.390009790659False547.519409180.504284083843False690.5574340820.636026918888False718.4549560550.661721467972False177.0107574460.16303293407394.0942687990.362974256277520.4753417970.479375511408648.0368652340.596864104271669.884948730.616986870766False3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
31112_08137936.1947699476-5.26860615831.018.67000007630.001000000047516.81299972530.001000000047515.95100021360.001000000047515.7200002670.001000000047515.14999961850.001000000047518.77400016780.001000000047516.8929996490.001000000047516.04299926760.001000000047515.84000015260.001000000047515.250.0010000000475123.5946807860.113834917545False683.5967407230.629615962505False1512.166992191.39275729656False1870.681396481.72296142578False3162.277587892.91256570816False112.3051757810.103436894715635.0383911130.5848919749261389.312988281.279604673391674.941894531.542678594592884.030273442.65629029274False3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
41106_03846333.9131679476-4.52110715831.016.75499916080.001000000047515.97099971770.001000000047515.4069995880.001000000047515.5139999390.001000000047515.27900028230.001000000047516.80200004580.001000000047516.07200050350.001000000047515.54199981690.001000000047515.6110000610.001000000047515.35000038150.0010000000475721.1079101560.664164960384False1484.567138671.36733710766False2495.744384772.29866552353False2261.517333982.082934618False2808.017089842.58627939224False690.5574340820.6360269188881352.69409181.245877504352203.941162112.029904842382068.235107421.904914975172630.2656252.42256450653False3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
51102_05695837.2280369476-4.38906315830.83999997377413.24100017550.001000000047513.05900001530.001000000047512.70600032810.001000000047512.64999961850.001000000047512.74300003050.001000000047514.19400024410.001000000047515.56700038910.001000000047515.0930004120.001000000047515.10200023650.001000000047514.27099990840.001000000047518348.466796916.8995628357False21697.005859419.9836807251False30033.070312527.6614818573False31622.775390629.1256523132False29026.841796926.7347106934False7627.809082037.025472164152153.77221681.983697533613332.726806643.069555044173305.215820313.044216394427105.586425786.54448747635False3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
61130_16923636.6150529476-6.73218215830.7200000286114.60200023650.001000000047514.60000038150.001000000047514.0139999390.001000000047514.10499954220.001000000047513.71399974820.001000000047514.88099956510.001000000047515.51700019840.001000000047515.00500011440.001000000047515.07999992370.001000000047514.2679996490.00100000004755238.412109384.82475614548False5248.072265624.83365345001False9003.260742198.29231071472False8279.420898447.62562942505False11868.613281210.931397438False4051.351806643.731433153152255.276123052.077186107643614.097412113.328706741333372.872314453.106530189517125.246582036.56259441376False3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
71124_10336933.9695109476-6.16763115831.017.78800010680.001000000047517.250.001000000047516.78400039670.001000000047516.91900062560.001000000047516.58600044250.001000000047517.84900093080.001000000047517.29400062560.001000000047516.83399963380.001000000047516.95499992370.001000000047516.64900016780.0010000000475278.4837951660.256493061781False457.0880126950.42099365592False702.1013183590.646659255028False620.0113525390.571051597595False842.5574951170.776024162769False263.2688293460.242479562759438.9343261720.404273450375670.5019531250.617555141449599.7908935550.552427887917795.0596313480.732276976109False3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
81113_07926435.7017499476-5.26924315830.95999997854215.29500007630.001000000047515.06999969480.001000000047514.8730001450.001000000047514.63599967960.001000000047514.63099956510.001000000047515.40200042720.001000000047515.65299987790.001000000047515.31099987030.001000000047515.15900039670.001000000047514.77700042720.00100000004752766.941162112.54844713211False3404.082519533.13527584076False4081.312011723.75902748108False5076.916503914.67601299286False5100.35156254.6975979805False2507.261962892.309273958211989.756713871.832633733752726.464355472.511166810993136.170410162.888519763954458.612304694.10653400421False3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
91102_05920937.2498539476-4.39871515831.017.94000053410.001000000047516.61599922180.001000000047516.01300048830.001000000047515.72900009160.001000000047515.68999958040.001000000047518.09399986270.001000000047516.72900009160.001000000047516.11700057980.001000000047515.87800025940.001000000047515.77799987790.0010000000475242.1026763920.222984805703False819.5966796880.754876494408False1428.235107421.31545317173False1855.238281251.70873773098False1923.091308591.77123260498False210.087326050.19349758327738.5839843750.6802610754971297.775878911.19529581071617.334472661.489620089531773.371826171.63333594799False3False-1nannannannannannannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannannannanFalse0-1nannannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalsenannannannannannannannanFalseFalse0
In [13]:
master_catalogue.add_column(Column(data=(np.char.array(master_catalogue['cfhtls-wide_id'].astype(str)) 
                                    +  np.char.array(master_catalogue['cfhtls-deep_id'].astype(str) )
                                    +  np.char.array(master_catalogue['sparcs_intid'].astype(str))), 
                              name="megacam_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)
['cfhtls-wide_id', 'cfhtls-deep_id', 'sparcs_intid', 'megacam_intid']

VII - Choosing between multiple values for the same filter¶

 VII.b CFHTLS-DEEP, CFHTLS-WIDE and SpARCS: CFHT Megacam fluxes¶

According to Mattia CFHTLenS is built on the same data as CFHTLS-WIDE and should not be included. I have therefore excluded it from the merge above.

CFHTLS-DEEP is prefferred to CFHTLS-WIDE which is prefferred to SpARCS

CFHTLS-WIDE u, g, r, i, z
CFHTLS-DEEP u, g, r, i, z, y
SpARCS u, g, r, z, y
In [15]:
megacam_origin = Table()
megacam_origin.add_column(master_catalogue['megacam_intid'])
In [16]:
megacam_stats = Table()
megacam_stats.add_column(Column(data=['u','g','r','i','z','y'], name="Band"))
for col in ["CFHTLS-DEEP", "CFHTLS-WIDE", "SpARCS"]:
    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)))
    megacam_stats.add_column(Column(data=np.full(6, 0), name="{} ap".format(col)))
    megacam_stats.add_column(Column(data=np.full(6, 0), name="use {} ap".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 [17]:
megacam_bands = ['u','g','r','i','z','y'] # Lowercase naming convention (k is Ks)
for band in megacam_bands:

    # Megacam total flux 
    has_cfhtls_deep = ~np.isnan(master_catalogue['f_cfhtls-deep_' + band])
    if band == 'y':
        has_cfhtls_wide = np.full(len(master_catalogue), False, dtype=bool)
    else:
        has_cfhtls_wide = ~np.isnan(master_catalogue['f_cfhtls-wide_' + band])
    if band == 'i':
        has_sparcs = np.full(len(master_catalogue), False, dtype=bool)
    else:
        has_sparcs = ~np.isnan(master_catalogue['f_sparcs_' + band])
    

    use_cfhtls_deep = has_cfhtls_deep 
    use_cfhtls_wide = has_cfhtls_wide & ~has_cfhtls_deep
    use_sparcs = has_sparcs & ~has_cfhtls_wide & ~has_cfhtls_deep

    f_megacam = np.full(len(master_catalogue), np.nan)
    f_megacam[use_cfhtls_deep] = master_catalogue['f_cfhtls-deep_' + band][use_cfhtls_deep]
    if not (band == 'y'):
        f_megacam[use_cfhtls_wide] = master_catalogue['f_cfhtls-wide_' + band][use_cfhtls_wide]
    if not (band == 'i'):
        f_megacam[use_sparcs] = master_catalogue['f_sparcs_' + band][use_sparcs]

    ferr_megacam = np.full(len(master_catalogue), np.nan)
    ferr_megacam[use_cfhtls_deep] = master_catalogue['ferr_cfhtls-deep_' + band][use_cfhtls_deep]
    if not (band == 'y'):
        ferr_megacam[use_cfhtls_wide] = master_catalogue['ferr_cfhtls-wide_' + band][use_cfhtls_wide]
    if not (band == 'i'):
        ferr_megacam[use_sparcs] = master_catalogue['ferr_sparcs_' + band][use_sparcs]
    
    m_megacam = np.full(len(master_catalogue), np.nan)
    m_megacam[use_cfhtls_deep] = master_catalogue['m_cfhtls-deep_' + band][use_cfhtls_deep]
    if not (band == 'y'):
        m_megacam[use_cfhtls_wide] = master_catalogue['m_cfhtls-wide_' + band][use_cfhtls_wide]
    if not (band == 'i'):
        m_megacam[use_sparcs] = master_catalogue['m_sparcs_' + band][use_sparcs]

    merr_megacam = np.full(len(master_catalogue), np.nan)
    merr_megacam[use_cfhtls_deep] = master_catalogue['merr_cfhtls-deep_' + band][use_cfhtls_deep]
    if not (band == 'y'):
        merr_megacam[use_cfhtls_wide] = master_catalogue['merr_cfhtls-wide_' + band][use_cfhtls_wide]
    if not (band == 'i'):
        merr_megacam[use_sparcs] = master_catalogue['merr_sparcs_' + band][use_sparcs]

    flag_megacam = np.full(len(master_catalogue), False, dtype=bool)
    flag_megacam[use_cfhtls_deep] = master_catalogue['flag_cfhtls-deep_' + band][use_cfhtls_deep]
    if not (band == 'y'):
        flag_megacam[use_cfhtls_wide] = master_catalogue['flag_cfhtls-wide_' + band][use_cfhtls_wide]
    if not (band == 'i'):
        flag_megacam[use_sparcs] = master_catalogue['flag_sparcs_' + band][use_sparcs]

    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_cfhtls_deep_columns = ['f_cfhtls-deep_' + band,
                               'ferr_cfhtls-deep_' + band,
                               'm_cfhtls-deep_' + band, 
                               'merr_cfhtls-deep_' + band,
                               'flag_cfhtls-deep_' + band]
    old_cfhtls_wide_columns = ['f_cfhtls-wide_' + band,
                               'ferr_cfhtls-wide_' + band,
                               'm_cfhtls-wide_' + band, 
                               'merr_cfhtls-wide_' + band,
                               'flag_cfhtls-wide_' + band]
    old_sparcs_columns =      ['f_sparcs_' + band,
                               'ferr_sparcs_' + band,
                               'm_sparcs_' + band, 
                               'merr_sparcs_' + band,
                               'flag_sparcs_' + band]
    
    if (band == 'i'):
        old_columns = old_cfhtls_deep_columns + old_cfhtls_wide_columns
    elif (band == 'y'):
        old_columns = old_cfhtls_deep_columns + old_sparcs_columns
    else:
        old_columns = old_cfhtls_deep_columns + old_cfhtls_wide_columns + old_sparcs_columns
    master_catalogue.remove_columns(old_columns)

    origin = np.full(len(master_catalogue), '     ', dtype='<U5')
    origin[use_cfhtls_deep] = "CFHTLS-DEEP"
    origin[use_cfhtls_wide] = "CFHTLS-WIDE"
    origin[use_sparcs] = "SpARCS"
    
    megacam_origin.add_column(Column(data=origin, name= 'f_megacam_' + band ))
    
    # Megacam aperture flux 
    has_ap_cfhtls_deep = ~np.isnan(master_catalogue['f_ap_cfhtls-deep_' + band])
    if band == 'y':
        has_ap_cfhtls_wide = np.full(len(master_catalogue), False, dtype=bool)
    else:
        has_ap_cfhtls_wide = ~np.isnan(master_catalogue['f_ap_cfhtls-wide_' + band])
    if band == 'i':
        has_ap_sparcs = np.full(len(master_catalogue), False, dtype=bool)
    else:
        has_ap_sparcs = ~np.isnan(master_catalogue['f_ap_sparcs_' + band])
    

    use_ap_cfhtls_deep = has_ap_cfhtls_deep 
    use_ap_cfhtls_wide = has_ap_cfhtls_wide & ~has_ap_cfhtls_deep
    use_ap_sparcs = has_ap_sparcs & ~has_ap_cfhtls_wide & ~has_ap_cfhtls_deep

    f_ap_megacam = np.full(len(master_catalogue), np.nan)
    f_ap_megacam[use_ap_cfhtls_deep] = master_catalogue['f_ap_cfhtls-deep_' + band][use_ap_cfhtls_deep]
    if not (band == 'y'):
        f_ap_megacam[use_ap_cfhtls_wide] = master_catalogue['f_ap_cfhtls-wide_' + band][use_ap_cfhtls_wide]
    if not (band == 'i'):
        f_ap_megacam[use_ap_sparcs] = master_catalogue['f_ap_sparcs_' + band][use_ap_sparcs]

    ferr_ap_megacam = np.full(len(master_catalogue), np.nan)
    ferr_ap_megacam[use_ap_cfhtls_deep] = master_catalogue['ferr_ap_cfhtls-deep_' + band][use_ap_cfhtls_deep]
    if not (band == 'y'):
        ferr_ap_megacam[use_ap_cfhtls_wide] = master_catalogue['ferr_ap_cfhtls-wide_' + band][use_ap_cfhtls_wide]
    if not (band == 'i'):
        ferr_ap_megacam[use_ap_sparcs] = master_catalogue['ferr_ap_sparcs_' + band][use_ap_sparcs]
    
    m_ap_megacam = np.full(len(master_catalogue), np.nan)
    m_ap_megacam[use_ap_cfhtls_deep] = master_catalogue['m_ap_cfhtls-deep_' + band][use_ap_cfhtls_deep]
    if not (band == 'y'):
        m_ap_megacam[use_ap_cfhtls_wide] = master_catalogue['m_ap_cfhtls-wide_' + band][use_ap_cfhtls_wide]
    if not (band == 'i'):
        m_ap_megacam[use_ap_sparcs] = master_catalogue['m_ap_sparcs_' + band][use_ap_sparcs]

    merr_ap_megacam = np.full(len(master_catalogue), np.nan)
    merr_ap_megacam[use_ap_cfhtls_deep] = master_catalogue['merr_ap_cfhtls-deep_' + band][use_ap_cfhtls_deep]
    if not (band == 'y'):
        merr_ap_megacam[use_ap_cfhtls_wide] = master_catalogue['merr_ap_cfhtls-wide_' + band][use_ap_cfhtls_wide]
    if not (band == 'i'):
        merr_ap_megacam[use_ap_sparcs] = master_catalogue['merr_ap_sparcs_' + band][use_ap_sparcs]



    master_catalogue.add_column(Column(data=f_ap_megacam, name="f_ap_megacam_" + band))
    master_catalogue.add_column(Column(data=ferr_ap_megacam, name="ferr_ap_megacam_" + band))
    master_catalogue.add_column(Column(data=m_ap_megacam, name="m_ap_megacam_" + band))
    master_catalogue.add_column(Column(data=merr_ap_megacam, name="merr_ap_megacam_" + band))


    old_ap_cfhtls_deep_columns = ['f_ap_cfhtls-deep_' + band,
                               'ferr_ap_cfhtls-deep_' + band,
                               'm_ap_cfhtls-deep_' + band, 
                               'merr_ap_cfhtls-deep_' + band]
    old_ap_cfhtls_wide_columns = ['f_ap_cfhtls-wide_' + band,
                               'ferr_ap_cfhtls-wide_' + band,
                               'm_ap_cfhtls-wide_' + band, 
                               'merr_ap_cfhtls-wide_' + band]
    old_ap_sparcs_columns =      ['f_ap_sparcs_' + band,
                               'ferr_ap_sparcs_' + band,
                               'm_ap_sparcs_' + band, 
                               'merr_ap_sparcs_' + band]
    
    if (band == 'i'):
        old_ap_columns = old_ap_cfhtls_deep_columns + old_ap_cfhtls_wide_columns
    elif (band == 'y'):
        old_ap_columns = old_ap_cfhtls_deep_columns + old_ap_sparcs_columns
    else:
        old_ap_columns = old_ap_cfhtls_deep_columns + old_ap_cfhtls_wide_columns + old_ap_sparcs_columns
    master_catalogue.remove_columns(old_ap_columns)

    origin_ap = np.full(len(master_catalogue), '     ', dtype='<U5')
    origin_ap[use_ap_cfhtls_deep] = "CFHTLS-DEEP"
    origin_ap[use_ap_cfhtls_wide] = "CFHTLS-WIDE"
    origin_ap[use_ap_sparcs] = "SpARCS"
    
    megacam_origin.add_column(Column(data=origin_ap, name= 'f_ap_megacam_' + band ))
    

   
    megacam_stats['CFHTLS-DEEP'][megacam_stats['Band'] == band] = np.sum(has_cfhtls_deep)
    megacam_stats['CFHTLS-WIDE'][megacam_stats['Band'] == band] = np.sum(has_cfhtls_wide)
    megacam_stats['SpARCS'][megacam_stats['Band'] == band] = np.sum(has_sparcs)
    megacam_stats['use CFHTLS-DEEP'][megacam_stats['Band'] == band] = np.sum(use_cfhtls_deep)
    megacam_stats['use CFHTLS-WIDE'][megacam_stats['Band'] == band] = np.sum(use_cfhtls_wide)
    megacam_stats['use SpARCS'][megacam_stats['Band'] == band] = np.sum(use_sparcs)
    megacam_stats['CFHTLS-DEEP ap'][megacam_stats['Band'] == band] = np.sum(has_ap_cfhtls_deep)
    megacam_stats['CFHTLS-WIDE ap'][megacam_stats['Band'] == band] = np.sum(has_ap_cfhtls_wide)
    megacam_stats['SpARCS ap'][megacam_stats['Band'] == band] = np.sum(has_ap_sparcs)
    megacam_stats['use CFHTLS-DEEP ap'][megacam_stats['Band'] == band] = np.sum(use_ap_cfhtls_deep)
    megacam_stats['use CFHTLS-WIDE ap'][megacam_stats['Band'] == band] = np.sum(use_ap_cfhtls_wide)
    megacam_stats['use SpARCS ap'][megacam_stats['Band'] == band] = np.sum(use_ap_sparcs)
In [18]:
megacam_stats.show_in_notebook()
Out[18]:
<Table length=6>
idxBandCFHTLS-DEEPuse CFHTLS-DEEPCFHTLS-DEEP apuse CFHTLS-DEEP apCFHTLS-WIDEuse CFHTLS-WIDECFHTLS-WIDE apuse CFHTLS-WIDE apSpARCSuse SpARCSSpARCS apuse SpARCS ap
0u481650.0481650.0485877.0485877.03115218.02928155.03163862.02974025.0396423.0375948.0385887.0365727.0
1g551595.0551595.0553969.0553969.03367177.03163292.03384048.03179110.0436976.0411025.0429994.0404289.0
2r561918.0561918.0565280.0565280.03366913.03163239.03397813.03192615.0446308.0418750.0442998.0415461.0
3i557674.0557674.0561376.0561376.03283920.03084634.03329406.03127407.00.00.00.00.0
4z499627.0499627.0506086.0506086.02864911.02688653.02971971.02789427.0413627.0391475.0389357.0367615.0
5y522629.0522629.0528982.0528982.00.00.00.00.0405761.0405761.0391629.0391629.0
In [19]:
megacam_origin.write("{}/xmm-lss_megacam_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)

XI - Saving the catalogue¶

In [20]:
master_catalogue.write("{}/megacam_merged_catalogue_xmm-lss.fits".format(TMP_DIR), overwrite=True)