HATLAS-SGP master catalogue

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

In [1]:
from herschelhelp_internal import git_version
print("This notebook was run with herschelhelp_internal version: \n{}".format(git_version()))
This notebook was run with herschelhelp_internal version: 
44f1ae0 (Thu Nov 30 18:27:54 2017 +0000)
In [2]:
%matplotlib inline
#%config InlineBackend.figure_format = 'svg'

import matplotlib.pyplot as plt
plt.rc('figure', figsize=(10, 6))

import os
import time

from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.table import Column, Table
import numpy as np
from pymoc import MOC

from herschelhelp_internal.masterlist import merge_catalogues, nb_merge_dist_plot, specz_merge
from herschelhelp_internal.utils import coords_to_hpidx, ebv, gen_help_id, inMoc
In [3]:
TMP_DIR = os.environ.get('TMP_DIR', "./data_tmp")
OUT_DIR = os.environ.get('OUT_DIR', "./data")
SUFFIX = os.environ.get('SUFFIX', time.strftime("_%Y%m%d"))

try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

I - Reading the prepared pristine catalogues

In [4]:
atlas = Table.read("{}/ATLAS.fits".format(TMP_DIR))
kids = Table.read("{}/KIDS.fits".format(TMP_DIR))
ps1 = Table.read("{}/PS1.fits".format(TMP_DIR))
viking = Table.read("{}/VISTA-VIKING.fits".format(TMP_DIR))

II - Merging tables

We first merge the optical catalogues and then add the infrared ones: CFHTLenS, CFHTLS, DECaLS, HSC, KIDS, PanSTARRS, UKIDSS-LAS, VISTA-VHS, and VISTA-VIKING.

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.

ATLAS

In [5]:
master_catalogue = atlas
master_catalogue['atlas_ra'].name = 'ra'
master_catalogue['atlas_dec'].name = 'dec'

Add KIDS

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

Add PanSTARRS

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

Add VIKING

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

Cleaning

When we merge the catalogues, astropy masks the non-existent values (e.g. when a row comes only from a catalogue and has no counterparts in the other, the columns from the latest are masked for that row). We indicate to use NaN for masked values for floats columns, False for flag columns and -1 for ID columns.

In [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].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>
idxatlas_idradecatlas_stellaritym_ap_atlas_umerr_ap_atlas_um_atlas_umerr_atlas_um_ap_atlas_ulmerr_ap_atlas_ulm_atlas_ulmerr_atlas_ulm_ap_atlas_gmerr_ap_atlas_gm_atlas_gmerr_atlas_gm_ap_atlas_rmerr_ap_atlas_rm_atlas_rmerr_atlas_rm_ap_atlas_imerr_ap_atlas_im_atlas_imerr_atlas_im_ap_atlas_zmerr_ap_atlas_zm_atlas_zmerr_atlas_zf_ap_atlas_uferr_ap_atlas_uf_atlas_uferr_atlas_uflag_atlas_uf_ap_atlas_ulferr_ap_atlas_ulf_atlas_ulferr_atlas_ulflag_atlas_ulf_ap_atlas_gferr_ap_atlas_gf_atlas_gferr_atlas_gflag_atlas_gf_ap_atlas_rferr_ap_atlas_rf_atlas_rferr_atlas_rflag_atlas_rf_ap_atlas_iferr_ap_atlas_if_atlas_iferr_atlas_iflag_atlas_if_ap_atlas_zferr_ap_atlas_zf_atlas_zferr_atlas_zflag_atlas_zatlas_flag_cleanedatlas_flag_gaiaflag_mergedkids_idkids_stellaritym_kids_umerr_kids_um_kids_gmerr_kids_gm_kids_rmerr_kids_rm_kids_imerr_kids_if_ap_kids_uferr_ap_kids_uf_ap_kids_gferr_ap_kids_gf_ap_kids_rferr_ap_kids_rf_ap_kids_iferr_ap_kids_if_kids_uferr_kids_uflag_kids_uf_kids_gferr_kids_gflag_kids_gf_kids_rferr_kids_rflag_kids_rf_kids_iferr_kids_iflag_kids_im_ap_kids_umerr_ap_kids_um_ap_kids_gmerr_ap_kids_gm_ap_kids_rmerr_ap_kids_rm_ap_kids_imerr_ap_kids_ikids_flag_cleanedkids_flag_gaiaps1_idm_ap_gpc1_gmerr_ap_gpc1_gm_gpc1_gmerr_gpc1_gm_ap_gpc1_rmerr_ap_gpc1_rm_gpc1_rmerr_gpc1_rm_ap_gpc1_imerr_ap_gpc1_im_gpc1_imerr_gpc1_im_ap_gpc1_zmerr_ap_gpc1_zm_gpc1_zmerr_gpc1_zm_ap_gpc1_ymerr_ap_gpc1_ym_gpc1_ymerr_gpc1_yf_ap_gpc1_gferr_ap_gpc1_gf_gpc1_gferr_gpc1_gflag_gpc1_gf_ap_gpc1_rferr_ap_gpc1_rf_gpc1_rferr_gpc1_rflag_gpc1_rf_ap_gpc1_iferr_ap_gpc1_if_gpc1_iferr_gpc1_iflag_gpc1_if_ap_gpc1_zferr_ap_gpc1_zf_gpc1_zferr_gpc1_zflag_gpc1_zf_ap_gpc1_yferr_ap_gpc1_yf_gpc1_yferr_gpc1_yflag_gpc1_yps1_flag_cleanedps1_flag_gaiaviking_idviking_stellaritym_vista_zmerr_vista_zm_ap_vista_zmerr_ap_vista_zm_vista_ymerr_vista_ym_ap_vista_ymerr_ap_vista_ym_vista_jmerr_vista_jm_ap_vista_jmerr_ap_vista_jm_vista_hmerr_vista_hm_ap_vista_hmerr_ap_vista_hm_vista_kmerr_vista_km_ap_vista_kmerr_ap_vista_kf_vista_zferr_vista_zflag_vista_zf_ap_vista_zferr_ap_vista_zf_vista_yferr_vista_yflag_vista_yf_ap_vista_yferr_ap_vista_yf_vista_jferr_vista_jflag_vista_jf_ap_vista_jferr_ap_vista_jf_vista_hferr_vista_hflag_vista_hf_ap_vista_hferr_ap_vista_hf_vista_kferr_vista_kflag_vista_kf_ap_vista_kferr_ap_vista_kviking_flag_cleanedviking_flag_gaia
degdegmagmagmagmagmagmagmagmaguJyuJyuJyuJyuJyuJyuJyuJy
073020805815519.8749571434-28.07347971750.9999989913.6698340.001252553913.6619180.001113095313.6717870.00125385413.6870570.001093773310.3251140.0002019118810.495129.1247828e-059.4798050.000212158669.73226457.5528027e-059.16943550.000230866438.73204715.801312e-058.23237710.000229138128.66444680.0001072757612361.364139314.260623155212451.819024712.7655881531False12339.148757514.249769841312166.823277712.256887436False269125.22133150.0486021893230118.74667119.3397214939False586243.445342114.555103949464616.04114732.3204962187False780235.668111165.9060667461167296.4372562.3710510833False1849477.95894390.3212406811242285.11054122.743516138FalseTrue3True-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
1730244166129340.813431421-31.94822571280.9999809312.1151520.0005662048412.1962690.0005080598112.1460490.0005742029212.6326070.0005978558910.1310350.0002112245110.8504890.000106450859.58919240.0002093539510.649160.000114482589.46112730.0002290633710.227880.00011636061nannannannan51753.437352926.989103418948027.767547722.474131698False50301.437919726.602440267832133.438459417.6941372727False321799.97053762.604563426165883.96216216.2640692058False530057.568471102.206820773199680.65840521.0547984401False596415.717489125.828901689294339.12873531.5449373581FalsenannannannanFalseTrue3False-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
2730211950982341.549624302-30.06665807130.9999989912.8244930.0008375470112.8159080.0006771251812.832610.0008411251512.743840.0006489693210.7604840.0002115520311.1059550.0001173085310.1502770.0002021631810.3771649.6312666e-0510.1724340.0002293641610.7172040.0001525745810.1163390.0002737091311.9052720.0005576142626927.919479720.77244762327141.684633216.9270565099False26727.356100920.705813540129004.407623117.3365966886False180221.41698835.115534131104.62118414.1652183283False316147.09824758.8663272435256527.77836322.7558721252False309760.75916365.4376413119187550.57501526.3558036346False326185.31122682.229824669562790.10365532.247849FalseTrue3False-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
373017792014723.9661106217-32.16306708430.9999989911.4585350.0004251767212.2863180.0005752270211.4688090.0004266745211.4883870.0003706350110.5230180.0002119214310.9206840.000113775589.92940330.000213375110.6121720.000113627639.61594870.0002348467810.5151660.0001415781610.0654150.0002824320110.4056950.000249086394751.479500437.104890757644205.143018923.4200467627False93859.103130336.884915138992181.80335831.4678680325False224281.16328643.7767338302155498.57017516.294878934False387470.53286376.1479292433206600.41996921.6217493487False517154.752408111.861544114225909.03477629.4581550572False341848.75298988.9249432776249874.53561457.3254564667FalseTrue3False-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
473023684145016.4312524322-31.9512583740.9999989910.2657920.0002710232210.1055660.0001963729211.8637490.0005112841610.8581370.000276937569.75941280.0002121626610.0980817.4834075e-059.51394270.0002108305810.0701958.5924941e-059.14377590.000229169549.43615157.932671e-058.42527770.0002294470210.1957240.00022307591284238.69464170.9521207202329437.92967959.584167799False65237.964186230.7212171547164719.57004342.0148426589False453142.58728788.5481540146331716.90144422.8634979405False568097.554806110.31439907340347.05732326.9349964492False798894.883977168.625097208610294.42117444.5896971575False1548420.52696327.225410795303186.87730362.2929292198FalseFalse2False-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
5730196943452350.851313992-31.03983216060.9999809313.3755440.001037039113.3658660.0008859895813.3803470.00103859512.9956660.0007111313811.0673860.0002144058812.2741280.00020792404nannannannan9.75689510.0002289721211.3866560.000205127369.18603710.0002462432610.4229880.0002395903416209.977050915.482932169116355.114917613.3462081611False16138.426921915.437718145123000.305259415.0646526733False135845.60741126.826126708744704.24864648.56109241176FalsenannannannanFalse454194.59319195.7856046798101236.61140219.1265601546False768396.114277174.271027642245926.20044654.2687456876FalseTrue3False-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
67301494761047.15168343576-29.07723799810.9999989913.4140830.0009921862513.606120.001011155913.4268590.0009987036513.4242720.000889787810.0115510.0002144871110.6255940.000100992269.28002830.000213194139.38471226.3181928e-058.75764180.000232203599.08181386.7823537e-058.02189250.000229180828.25632678.4385174e-0515644.684163914.296696052913108.469864812.208035972False15461.670005614.222263384115498.554684912.7014506984False359235.79156370.9670050638204062.12271518.9813095143False704674.701196138.36925507639904.43477337.237770784False1140100.87767243.830421788845813.24170452.8360806635False2245137.79026473.9111743071809128.10294140.608362405FalseTrue3False-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
7730240128354339.45716753-30.04283592030.9999989912.6223420.0007676642312.4606020.0005796937612.6250820.0007687845513.2451710.0008268019910.7573020.0002147538611.6447940.0001606260910.0378260.0002038830111.0020930.000145804411.7352620.0002387651311.9908060.000285848579.91713910.0002815774611.3943860.000388238232438.68197822.935604167737649.498875120.1017332474False32356.921850922.911183670118278.123188413.9190243076False180750.3720935.751630951179814.610756811.8079408189False350646.57402365.8455328694144265.60454519.3735456358False73433.664332516.14885672458033.344504815.278802039False391872.114216101.6290643100518.40761535.9434321783FalseTrue3False-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
873016908207925.1999841208-28.27974867260.9999989912.9161310.0009053513112.911780.0007846874712.9438960.0009177183413.2313520.000877582539.93367390.000215919410.6065750.000102609629.32902240.000216838699.50203516.9480535e-058.99433420.000229425259.18726927.4246695e-057.8339520.000236410688.87552450.000115303324748.426967820.636707772624847.803274917.9581005049False24123.571187820.3904443918512.249718314.9631437845False385949.46211176.7534286175207668.20067119.6260887899False673582.879282134.52515308574362.34504136.7557081015False916782.511244193.723904495767524.62830552.4861994406False2669434.07572581.2486700641022798.77688108.619454425FalseFalse3False-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
973014989878322.3792388871-32.02382114820.9999989911.7627390.0005049015211.5646430.0003916426511.8023560.0005141714411.8045590.000428045029.99107360.000216778249.87258437.1833776e-059.52093980.000215633769.03204635.6259134e-059.3653240.000229047778.79934886.1007235e-057.77756120.000233301789.68509390.0001704419171598.578496533.295593307485929.601945430.9962004323False69033.135565832.691980396468893.206720127.1607356549False366075.41214773.090667148408287.68435227.0128654942False564448.183842112.102814361885485.55316245.8828306287False651433.967367137.4270258961097136.0362161.6477885645False2811742.33566604.184044831485246.53175476.1753594756FalseFalse2False-1nannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0

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)

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 [15]:
flag_gaia_columns = [column for column in master_catalogue.colnames
                     if 'flag_gaia' in column]

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

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

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

print(", ".join(stellarity_columns))
atlas_stellarity, kids_stellarity, viking_stellarity
In [17]:
# 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 [18]:
master_catalogue.add_column(
    ebv(master_catalogue['ra'], master_catalogue['dec'])
)

V - Adding HELP unique identifiers and field columns

In [19]:
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), "HATLAS-SGP", dtype='<U18'),
                                   name="field"))
In [20]:
# Check that the HELP Ids are unique
if len(master_catalogue) != len(np.unique(master_catalogue['help_id'])):
    print("The HELP IDs are not unique!!!")
else:
    print("OK!")
OK!

VI - Choosing between multiple values for the same filter

ATLAS and KIDS

The ATLAS and KIDS surveys are both on the VLT Survey Telescope (VST). KIDS is significantly deeper so we take KIDS fluxes if available.

Survey Bands observed
ATLAS u, ul, griz
KIDS ugri
In [21]:
omegacam_origin = Table()
omegacam_origin.add_column(master_catalogue['help_id'])
In [22]:
omegacam_stats = Table()
omegacam_stats.add_column(Column(data=['u', 'g','r','i'], name="Band"))
for col in ["ATLAS",  "KIDS"]:
    omegacam_stats.add_column(Column(data=np.full(4, 0), name="{}".format(col)))
    omegacam_stats.add_column(Column(data=np.full(4, 0), name="use {}".format(col)))
    omegacam_stats.add_column(Column(data=np.full(4, 0), name="{} ap".format(col)))
    omegacam_stats.add_column(Column(data=np.full(4, 0), name="use {} ap".format(col)))
    
#ul and z only in ATLAS so we can just rename those columns
for col in master_catalogue.colnames:
    if ('atlas_ul' in col) or ('atlas_z' in col):
        master_catalogue[col].name = col.replace('atlas', 'omegacam')
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/numpy/core/numeric.py:301: FutureWarning: in the future, full(4, 0) will return an array of dtype('int64')
  format(shape, fill_value, array(fill_value).dtype), FutureWarning)
In [23]:
omegacam_bands = ['u','g','r','i']
for band in omegacam_bands:

    # omegacam total flux 
    has_kids = ~np.isnan(master_catalogue['f_kids_' + band])
    has_atlas  = ~np.isnan(master_catalogue['f_atlas_' + band])

    

    use_kids = has_kids
    use_atlas = has_atlas & ~has_kids


    f_omegacam = np.full(len(master_catalogue), np.nan)
    f_omegacam[use_kids] = master_catalogue['f_kids_' + band][use_kids]
    f_omegacam[use_atlas] = master_catalogue['f_atlas_' + band][use_atlas]
  

    ferr_omegacam = np.full(len(master_catalogue), np.nan)
    ferr_omegacam[use_kids] = master_catalogue['ferr_kids_' + band][use_kids]
    ferr_omegacam[use_atlas] = master_catalogue['ferr_atlas_' + band][use_atlas]

    
    m_omegacam = np.full(len(master_catalogue), np.nan)
    m_omegacam[use_kids] = master_catalogue['m_kids_' + band][use_kids]
    m_omegacam[use_atlas] = master_catalogue['m_atlas_' + band][use_atlas]
   

    merr_omegacam = np.full(len(master_catalogue), np.nan)
    merr_omegacam[use_kids] = master_catalogue['merr_kids_' + band][use_kids]
    merr_omegacam[use_atlas] = master_catalogue['merr_atlas_' + band][use_atlas]


    flag_omegacam = np.full(len(master_catalogue), False, dtype=bool)
    flag_omegacam[use_kids] = master_catalogue['flag_kids_' + band][use_kids]
    flag_omegacam[use_atlas] = master_catalogue['flag_atlas_' + band][use_atlas]


    master_catalogue.add_column(Column(data=f_omegacam, name="f_omegacam_" + band))
    master_catalogue.add_column(Column(data=ferr_omegacam, name="ferr_omegacam_" + band))
    master_catalogue.add_column(Column(data=m_omegacam, name="m_omegacam_" + band))
    master_catalogue.add_column(Column(data=merr_omegacam, name="merr_omegacam_" + band))
    master_catalogue.add_column(Column(data=flag_omegacam, name="flag_omegacam_" + band))

    old_kids_columns = ['f_kids_' + band,
                               'ferr_kids_' + band,
                               'm_kids_' + band, 
                               'merr_kids_' + band,
                               'flag_kids_' + band]
    old_atlas_columns = ['f_atlas_' + band,
                               'ferr_atlas_' + band,
                               'm_atlas_' + band, 
                               'merr_atlas_' + band,
                               'flag_atlas_' + band]

    
    old_columns = old_kids_columns + old_atlas_columns 
    master_catalogue.remove_columns(old_columns)

    origin = np.full(len(master_catalogue), '     ', dtype='<U5')
    origin[use_kids] = "kids"
    origin[use_atlas] = "atlas"
   
    
    omegacam_origin.add_column(Column(data=origin, name= 'f_omegacam_' + band ))
    
  
    # omegacam aperture flux 
    has_ap_kids = ~np.isnan(master_catalogue['f_ap_kids_' + band])
    has_ap_atlas  = ~np.isnan(master_catalogue['f_ap_atlas_' + band])
  
    

    use_ap_kids = has_ap_kids
    use_ap_atlas = has_ap_atlas & ~has_ap_kids


    f_ap_omegacam = np.full(len(master_catalogue), np.nan)
    f_ap_omegacam[use_ap_kids] = master_catalogue['f_ap_kids_' + band][use_ap_kids]
    f_ap_omegacam[use_ap_atlas] = master_catalogue['f_ap_atlas_' + band][use_ap_atlas]
  

    ferr_ap_omegacam = np.full(len(master_catalogue), np.nan)
    ferr_ap_omegacam[use_ap_kids] = master_catalogue['ferr_ap_kids_' + band][use_ap_kids]
    ferr_ap_omegacam[use_ap_atlas] = master_catalogue['ferr_ap_atlas_' + band][use_ap_atlas]
   
    
    m_ap_omegacam = np.full(len(master_catalogue), np.nan)
    m_ap_omegacam[use_ap_kids] = master_catalogue['m_ap_kids_' + band][use_ap_kids]
    m_ap_omegacam[use_ap_atlas] = master_catalogue['m_ap_atlas_' + band][use_ap_atlas]
   

    merr_ap_omegacam = np.full(len(master_catalogue), np.nan)
    merr_ap_omegacam[use_ap_kids] = master_catalogue['merr_ap_kids_' + band][use_ap_kids]
    merr_ap_omegacam[use_ap_atlas] = master_catalogue['merr_ap_atlas_' + band][use_ap_atlas]



    master_catalogue.add_column(Column(data=f_ap_omegacam, name="f_ap_omegacam_" + band))
    master_catalogue.add_column(Column(data=ferr_ap_omegacam, name="ferr_ap_omegacam_" + band))
    master_catalogue.add_column(Column(data=m_ap_omegacam, name="m_ap_omegacam_" + band))
    master_catalogue.add_column(Column(data=merr_ap_omegacam, name="merr_ap_omegacam_" + band))


    old_ap_kids_columns = ['f_ap_kids_' + band,
                               'ferr_ap_kids_' + band,
                               'm_ap_kids_' + band, 
                               'merr_ap_kids_' + band]
    old_ap_atlas_columns = ['f_ap_atlas_' + band,
                               'ferr_ap_atlas_' + band,
                               'm_ap_atlas_' + band, 
                               'merr_ap_atlas_' + band]

    
    old_ap_columns = old_ap_kids_columns + old_ap_atlas_columns 
    master_catalogue.remove_columns(old_ap_columns)

    origin_ap = np.full(len(master_catalogue), '     ', dtype='<U5')
    origin_ap[use_ap_kids] = "kids"
    origin_ap[use_ap_atlas] = "atlas"
  
    
    omegacam_origin.add_column(Column(data=origin_ap, name= 'f_ap_omegacam_' + band ))

   
    omegacam_stats['KIDS'][omegacam_stats['Band'] == band] = np.sum(has_kids)
    omegacam_stats['ATLAS'][omegacam_stats['Band'] == band] = np.sum(has_atlas)

    omegacam_stats['use KIDS'][omegacam_stats['Band'] == band] = np.sum(use_kids)
    omegacam_stats['use ATLAS'][omegacam_stats['Band'] == band] = np.sum(use_atlas)

    omegacam_stats['KIDS ap'][omegacam_stats['Band'] == band] = np.sum(has_ap_kids)
    omegacam_stats['ATLAS ap'][omegacam_stats['Band'] == band] = np.sum(has_ap_atlas)
   
    omegacam_stats['use KIDS ap'][omegacam_stats['Band'] == band] = np.sum(use_ap_kids)
    omegacam_stats['use ATLAS ap'][omegacam_stats['Band'] == band] = np.sum(use_ap_atlas)
In [24]:
omegacam_stats.show_in_notebook()
Out[24]:
<Table length=4>
idxBandATLASuse ATLASATLAS apuse ATLAS apKIDSuse KIDSKIDS apuse KIDS ap
0u1050318.0895887.0916026.0761965.06705188.06705188.06705188.06705188.0
1g3618643.02658537.03580843.02620748.08819714.08819714.08819714.08819714.0
2r4487236.03372392.04469703.03354910.09604235.09604235.09604235.09604235.0
3i4155027.03041240.04152537.03038758.08261916.08261916.08261916.08261916.0
In [25]:
omegacam_origin.write("{}/hatlas-sgp_omegacam_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX))

VII.a Wavelength domain coverage

We add a binary flag_optnir_obs indicating that a source was observed in a given wavelength domain:

  • 1 for observation in optical;
  • 2 for observation in near-infrared;
  • 4 for observation in mid-infrared (IRAC).

It's an integer binary flag, so a source observed both in optical and near-infrared by not in mid-infrared would have this flag at 1 + 2 = 3.

Note 1: The observation flag is based on the creation of multi-order coverage maps from the catalogues, this may not be accurate, especially on the edges of the coverage.

Note 2: Being on the observation coverage does not mean having fluxes in that wavelength domain. For sources observed in one domain but having no flux in it, one must take into consideration de different depths in the catalogue we are using.

In [26]:
atlas_moc = MOC(filename="../../dmu0/dmu0_ATLAS/data/ATLAS_HATLAS-SGP_MOC.fits")
kids_moc = MOC(filename="../../dmu0/dmu0_KIDS/data/KIDS-DR3_HATLAS-SGP_MOC.fits")
ps1_moc = MOC(filename="../../dmu0/dmu0_PanSTARRS1-3SS/data/PanSTARRS1-3SS_HATLAS-SGP_MOC.fits")
viking_moc = MOC(filename="../../dmu0/dmu0_VISTA-VIKING/data/VIKING_SGP_MOC.fits")
In [27]:
was_observed_optical = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    atlas_moc + kids_moc + ps1_moc) 

was_observed_nir = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    viking_moc
)

was_observed_mir = np.zeros(len(master_catalogue), dtype=bool)

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

VII.b Wavelength domain detection

We add a binary flag_optnir_det indicating that a source was detected in a given wavelength domain:

  • 1 for detection in optical;
  • 2 for detection in near-infrared;
  • 4 for detection in mid-infrared (IRAC).

It's an integer binary flag, so a source detected both in optical and near-infrared by not in mid-infrared would have this flag at 1 + 2 = 3.

Note 1: We use the total flux columns to know if the source has flux, in some catalogues, we may have aperture flux and no total flux.

To get rid of artefacts (chip edges, star flares, etc.) we consider that a source is detected in one wavelength domain when it has a flux value in at least two bands. That means that good sources will be excluded from this flag when they are on the coverage of only one band.

In [29]:
# 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 = (
    #Omegacam - to be merged
    1 * ~np.isnan(master_catalogue['f_omegacam_ul']) +
    1 * ~np.isnan(master_catalogue['f_omegacam_u']) +
    1 * ~np.isnan(master_catalogue['f_omegacam_g']) +
    1 * ~np.isnan(master_catalogue['f_omegacam_r']) +
    1 * ~np.isnan(master_catalogue['f_omegacam_i']) +
    1 * ~np.isnan(master_catalogue['f_omegacam_z']) +
    # 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']) 
)

nb_nir_flux = (
    1 * ~np.isnan(master_catalogue['f_vista_z']) +
    1 * ~np.isnan(master_catalogue['f_vista_y']) +
    1 * ~np.isnan(master_catalogue['f_vista_j']) +
    1 * ~np.isnan(master_catalogue['f_vista_h']) +
    1 * ~np.isnan(master_catalogue['f_vista_k'])
)

nb_mir_flux = np.zeros(len(master_catalogue), dtype=bool)
In [30]:
has_optical_flux = nb_optical_flux >= 2
has_nir_flux = nb_nir_flux >= 2
has_mir_flux = nb_mir_flux >= 2

master_catalogue.add_column(
    Column(
        1 * has_optical_flux + 2 * has_nir_flux + 4 * has_mir_flux,
        name="flag_optnir_det")
)

VIII - Cross-identification table

We are producing a table associating to each HELP identifier, the identifiers of the sources in the pristine catalogue. This can be used to easily get additional information from them.

In [31]:
master_catalogue['help_id', 'atlas_id',
                 'kids_id', 'ps1_id', 'viking_id'].write(
    "{}/master_list_cross_ident_hatlas-sgp{}.fits".format(OUT_DIR, SUFFIX))
master_catalogue.remove_columns(['atlas_id', 'kids_id',
                                 'ps1_id', 'viking_id'])

IX - Adding HEALPix index

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

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

X - Saving the catalogue

In [33]:
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", "flag_cleaned", "flag_merged", "flag_gaia", "flag_optnir_obs", "flag_optnir_det", "ebv"]
In [34]:
# 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: {'stellarity_origin'}
In [35]:
master_catalogue[columns].write("{}/master_catalogue_hatlas-sgp{}.fits".format(OUT_DIR, SUFFIX))