Bootes master catalogue¶

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

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]:
decals = Table.read("{}/DECaLS.fits".format(TMP_DIR))
datafusion = Table.read("{}/Datafusion.fits".format(TMP_DIR))
ibis = Table.read("{}/IBIS.fits".format(TMP_DIR))
legacy = Table.read("{}/LegacySurvey.fits".format(TMP_DIR))
ndwfs = Table.read("{}/NDWFS.fits".format(TMP_DIR))
ps1 = Table.read("{}/PS1.fits".format(TMP_DIR))
#sdwfs = Table.read("{}/SDWFS.fits".format(TMP_DIR)) #We use DataFusion instead
uhs = Table.read("{}/UHS.fits".format(TMP_DIR))
zbootes = Table.read("{}/zBootes.fits".format(TMP_DIR))

II - Merging tables¶

We first merge the optical catalogues and then add the infrared ones.

At every step, we look at the distribution of the distances separating the sources from one catalogue to the other (within a maximum radius) to determine the best cross-matching radius.

PanSTARRS¶

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

Add DECaLS¶

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

Add Legacy Survey¶

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

Add IBIS¶

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

Add NDWFS¶

In [12]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(ndwfs['ndwfs_ra'], ndwfs['ndwfs_dec'])
)
In [13]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, ndwfs, "ndwfs_ra", "ndwfs_dec", radius=0.8*u.arcsec)

Add UHS¶

In [14]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(uhs['uhs_ra'], uhs['uhs_dec'])
)
In [15]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, uhs, "uhs_ra", "uhs_dec", radius=0.8*u.arcsec)

Add zBootes¶

In [16]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(zbootes['zbootes_ra'], zbootes['zbootes_dec'])
)
In [17]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, zbootes, "zbootes_ra", "zbootes_dec", radius=0.8*u.arcsec)

Add SDWFS¶

nb_merge_dist_plot( SkyCoord(master_catalogue['ra'], master_catalogue['dec']), SkyCoord(sdwfs['sdwfs_ra'], sdwfs['sdwfs_dec']) )

Given the graph above, we use 1 arc-second radius¶

master_catalogue = merge_catalogues(master_catalogue, sdwfs, "sdwfs_ra", "sdwfs_dec", radius=1.*u.arcsec)

Add Datafusion¶

In [18]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(datafusion['datafusion_ra'], datafusion['datafusion_dec'])
)
In [19]:
# Given the graph above, we use 1 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, datafusion, "datafusion_ra", "datafusion_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 [20]:
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 [21]:
master_catalogue[:10].show_in_notebook()
Out[21]:
<Table length=10>
idxps1_idradecm_ap_gpc1_gmerr_ap_gpc1_gm_gpc1_gmerr_gpc1_gm_ap_gpc1_rmerr_ap_gpc1_rm_gpc1_rmerr_gpc1_rm_ap_gpc1_imerr_ap_gpc1_im_gpc1_imerr_gpc1_im_ap_gpc1_zmerr_ap_gpc1_zm_gpc1_zmerr_gpc1_zm_ap_gpc1_ymerr_ap_gpc1_ym_gpc1_ymerr_gpc1_yf_ap_gpc1_gferr_ap_gpc1_gf_gpc1_gferr_gpc1_gflag_gpc1_gf_ap_gpc1_rferr_ap_gpc1_rf_gpc1_rferr_gpc1_rflag_gpc1_rf_ap_gpc1_iferr_ap_gpc1_if_gpc1_iferr_gpc1_iflag_gpc1_if_ap_gpc1_zferr_ap_gpc1_zf_gpc1_zferr_gpc1_zflag_gpc1_zf_ap_gpc1_yferr_ap_gpc1_yf_gpc1_yferr_gpc1_yflag_gpc1_yps1_flag_cleanedps1_flag_gaiaflag_mergeddecals_idf_decam_gf_decam_rf_decam_zferr_decam_gferr_decam_rferr_decam_zf_ap_decam_gf_ap_decam_rf_ap_decam_zferr_ap_decam_gferr_ap_decam_rferr_ap_decam_zm_decam_gmerr_decam_gflag_decam_gm_decam_rmerr_decam_rflag_decam_rm_decam_zmerr_decam_zflag_decam_zm_ap_decam_gmerr_ap_decam_gm_ap_decam_rmerr_ap_decam_rm_ap_decam_zmerr_ap_decam_zdecals_stellaritydecals_flag_cleaneddecals_flag_gaialegacy_idf_bass_gferr_bass_gf_ap_bass_gferr_ap_bass_gf_bass_rferr_bass_rf_ap_bass_rferr_ap_bass_rf_bass_zferr_bass_zf_ap_bass_zferr_ap_bass_zlegacy_stellaritym_bass_gmerr_bass_gflag_bass_gm_ap_bass_gmerr_ap_bass_gm_bass_rmerr_bass_rflag_bass_rm_ap_bass_rmerr_ap_bass_rm_bass_zmerr_bass_zflag_bass_zm_ap_bass_zmerr_ap_bass_zlegacy_flag_cleanedlegacy_flag_gaiaibis_idibis_stellaritym_newfirm_jmerr_newfirm_jm_ap_newfirm_jmerr_ap_newfirm_jm_newfirm_hmerr_newfirm_hm_ap_newfirm_hmerr_ap_newfirm_hm_newfirm_kmerr_newfirm_km_ap_newfirm_kmerr_ap_newfirm_kf_newfirm_jferr_newfirm_jflag_newfirm_jf_ap_newfirm_jferr_ap_newfirm_jf_newfirm_hferr_newfirm_hflag_newfirm_hf_ap_newfirm_hferr_ap_newfirm_hf_newfirm_kferr_newfirm_kflag_newfirm_kf_ap_newfirm_kferr_ap_newfirm_kibis_flag_cleanedibis_flag_gaiandwfs_idndwfs_stellaritym_ap_mosaic_rmerr_ap_mosaic_rm_mosaic_rmerr_mosaic_rm_ap_mosaic_imerr_ap_mosaic_im_mosaic_imerr_mosaic_im_ap_mosaic_bmerr_ap_mosaic_bm_mosaic_bmerr_mosaic_bm_ap_mosaic_kmerr_ap_mosaic_km_mosaic_kmerr_mosaic_kf_ap_mosaic_rferr_ap_mosaic_rf_mosaic_rferr_mosaic_rflag_mosaic_rf_ap_mosaic_iferr_ap_mosaic_if_mosaic_iferr_mosaic_iflag_mosaic_if_ap_mosaic_bferr_ap_mosaic_bf_mosaic_bferr_mosaic_bflag_mosaic_bf_ap_mosaic_kferr_ap_mosaic_kf_mosaic_kferr_mosaic_kflag_mosaic_kndwfs_flag_cleanedndwfs_flag_gaiauhs_iduhs_stellaritym_wfcam_jmerr_wfcam_jm_ap_wfcam_jmerr_ap_wfcam_jf_wfcam_jferr_wfcam_jflag_wfcam_jf_ap_wfcam_jferr_ap_wfcam_juhs_flag_cleaneduhs_flag_gaiazbootes_idzbootes_stellaritym_ap_90prime_zmerr_ap_90prime_zm_90prime_zmerr_90prime_zf_ap_90prime_zferr_ap_90prime_zf_90prime_zferr_90prime_zflag_90prime_zwfc_flag_cleanedzbootes_flag_gaiadatafusion_intiddatafusion_stellarityf_ap_irac_i1ferr_ap_irac_i1f_irac_i1ferr_irac_i1f_ap_irac_i2ferr_ap_irac_i2f_irac_i2ferr_irac_i2f_ap_irac_i3ferr_ap_irac_i3f_irac_i3ferr_irac_i3f_ap_irac_i4ferr_ap_irac_i4f_irac_i4ferr_irac_i4m_ap_irac_i1merr_ap_irac_i1m_irac_i1merr_irac_i1flag_irac_i1m_ap_irac_i2merr_ap_irac_i2m_irac_i2merr_irac_i2flag_irac_i2m_ap_irac_i3merr_ap_irac_i3m_irac_i3merr_irac_i3flag_irac_i3m_ap_irac_i4merr_ap_irac_i4m_irac_i4merr_irac_i4flag_irac_i4datafusion_flag_cleaneddatafusion_flag_gaia
degdeguJyuJyuJyuJyuJyuJymagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmaguJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJy
0150292199054805142219.90563756635.245638794112.69909954070.0010860000038514.14610004430.001219999976469.380689620970.010.28929996490.014.11919975280.074989996850514.60799980160.10395699739513.13000011440.17569200694614.14599990840.13489900529412.6848001480.0010860000038513.36740016940.0020369999110730224.573672930.23191727547971.865858948.95767877832False642279.634580.0278150.6082890.0False8171.84459257564.4157370595209.54842507498.803493591False20323.56796723288.725593577972.60112594990.568387405False30625.271026630.632711985816332.021096930.6412601663FalseFalse0False-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
1147042185485050439218.54838365632.533216384112.90299987790.0010860000038513.94180011750.001219999976469.244199752810.09.572549819950.012.64820003510.16843900084512.44359970090.12545999884611.8364000320.0010860000038511.857799530.0010860000038511.045299530.12740199267910.92850017550.12156300246725049.556944125.05564318349622.3234850210.8122344762False728316.4159410.0538245.0841080.0False31675.2452364914.0358732538243.71909894419.17376706False66902.136519666.918391594265596.427565165.6123653943False138637.33071116267.9222769154383.16133117285.3042383FalseFalse0False-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
2148432178563450118217.85634342633.691283724114.08889961240.0015450000064413.56569957730.0010860000038512.84549999240.012.84529972080.0nannannannannannannannan12.6489000320.03589599952112.46720027920.03570599853998403.1120580211.957608235713605.677391913.6089831354False26411.92181830.026416.79413060.0FalsenannannannanFalsenannannannanFalse31654.83012151046.5541831437421.38768881230.65622047FalseFalse2False-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
3148572188406089286218.84060036633.815543054114.75329971310.0018119999440415.1548004150.02822699956614.96240043640.014.60270023350.0188340004534nannannannan14.06120014190.010123999789413.79660034180.01472999993716.380909919740.002744999947036.751029968260.01834500022234557.0113977.605258404543148.3270006881.8502915278False3758.718707090.05235.0388213890.8109383321FalsenannannannanFalse8620.2516285580.379953518410999.1687046149.223866366False10177380.977825730.84522977237490.6003122287.316283FalseFalse0False-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
4148612172599144113217.26024942633.844676164113.47509956360.0027379998937213.02499961850.031346999108813.54829978940.012.49499988560.019236000254813.95259952550.0018820000113914.66479969020.00149099994451nannan11.39879989620.046567998826512.15200042720.0011330000124912.54300022130.001193000003714789.727579837.296603322622387.2192514646.356029066False13825.47573210.036475.3985372646.235036171False9527.08828716.514122114944.018918176.78943181625Falsenannan100110.5947524293.81468399False50026.466556352.204197469534897.949632238.3456440504FalseFalse0False-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
5149412164869384895216.48684857634.511863414120.80470085140.01418800000120.51199913020.022512000054124.29809951780.024.29850006117.100799560523.19499969480.36055600643223.93829917911.367089986822.75119972230.49723699688922.22150039671.4721299409920.25060081480.3530920147920.14579963680.27429699897817.30293034270.22610830756522.65689269990.469775224821False0.69304301840.00.69278739232910.911691332False1.914256463080.6356946213890.9653400584651.21549481541False2.880846451431.319347583454.692452026746.36241021984False28.82436005519.3739633276431.74535187338.02004640922FalseFalse0False-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
6149912170289453574217.02914164634.927499044115.24069976810.015333999879715.61019992830.089689999818813.51420021060.014.41440010070.54317802190814.57199954990.11269400268815.30609989170.13882400095513.71590042110.0036140000447613.31879997250.0035270000807913.65330028530.053954001516113.0790004730.09094999730592908.8417355941.08196689772069.7601865170.977802839False14266.58130490.06226.442183013114.99840723False5385.17945261558.9547673262738.79826034350.18720997False11847.857758439.436981360217079.691065755.4831565023False12551.0449764623.70500008921300.99109391784.34234219FalseFalse2True-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
7147492203624686868220.36253347632.913813764113.77989959720.047460999339813.8238000870.29232901334810.96889972690.012.98209953310.014.75090026860.23555099964113.95289993290.076489999890314.81180000310.24015800654915.47039985660.10411400347913.75559997560.14483299851413.41930007930.056903999298811169.6653384488.2617683110727.04160912888.20201075False148744.2236380.023289.50117760.0False4567.09339241990.8331409829524.45264494670.99667357False4317.97375948955.1085851822354.18212248225.748505592False11422.46957051523.7131368315569.6900939816.015557281FalseFalse0False-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
8150742169177050441216.91767834635.616607664122.07349967960.098186001181622.14119911190.224584996721.46509933470.020.88719940191.6196999549921.92230033870.15705299377422.11479949950.45998400449823.25209999081.5700299739822.1016006471.1072200536720.67379951480.18573300540420.21969985960.2100110054025.377744046770.4863236401415.052663260341.04514554887False9.418034263680.016.036893284623.9238179747False6.181300605980.8941322591395.177024260782.19330288556False1.8161846622.626295729235.240343327035.34403586653False19.52001711393.3392194422729.65651099355.73637837916FalseFalse0False-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0
9149642198013901347219.80142161634.700636084122.05410003660.09893999993822.26469993590.50642502307922.58309936520.021.710300445611.149499893224.90719985966.3208599090621.83679962160.95909202098822.49550056460.73786497116121.07519912720.49344399571420.82069969180.33857899904320.94659996031.359130024915.474695707030.498893184684.509413136292.10334668919False3.363258542140.07.5141493326777.1633172172False0.395475930132.302352947986.687751868435.90766838874False3.645858206152.4777206915913.48715501546.12962488718False17.04983275575.3168672859615.183084738119.0062616019FalseFalse0False-1nannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannannannannannannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0-1nannannannannannannanFalsenannanFalse0-1nannannannannannannannannanFalseFalse0-1nannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalseFalse0

III - Merging flags and stellarity¶

Each pristine catalogue contains a flag indicating if the source was associated to a another nearby source that was removed during the cleaning process. We merge these flags in a single one.

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

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

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

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

print(", ".join(stellarity_columns))
decals_stellarity, legacy_stellarity, ibis_stellarity, ndwfs_stellarity, uhs_stellarity, zbootes_stellarity, datafusion_stellarity
In [25]:
master_catalogue.add_column(Column(
    data=np.nanmax([master_catalogue[column] for column in stellarity_columns], axis=0),
    name="stellarity"
))
master_catalogue.remove_columns(stellarity_columns)
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/numpy/lib/nanfunctions.py:343: RuntimeWarning: All-NaN slice encountered
  warnings.warn("All-NaN slice encountered", RuntimeWarning)

IV - Adding E(B-V) column¶

In [26]:
master_catalogue.add_column(
    ebv(master_catalogue['ra'], master_catalogue['dec'])
)

V - Adding HELP unique identifiers and field columns¶

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

VI - Cross-matching with spec-z catalogue¶

specz = Table.read("../../dmu23/dmu23_Bootes/data/Bootes-specz-v2.1.fits")

nb_merge_dist_plot( SkyCoord(master_catalogue['ra'], master_catalogue['dec']), SkyCoord(specz['ra'] u.deg, specz['dec'] u.deg) )

master_catalogue = specz_merge(master_catalogue, specz, radius=1. * u.arcsec)

VII - Choosing between multiple values for the same filter¶

We take DataFusion Spitzer instead of SDWFS which is shallower.

VIII.a Wavelength domain coverage¶

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

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

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

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

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

In [29]:
decals_moc = MOC(filename="../../dmu0/dmu0_DECaLS/data/DECaLS_Bootes_MOC.fits")
datafusion_moc = MOC(filename="../../dmu0/dmu0_DataFusion-Spitzer/data/Datafusion-Bootes_MOC.fits")
ibis_moc = MOC(filename="../../dmu0/dmu0_IBIS/data/IBIS_MLselected_20160801_MOC.fits")
legacy_moc = MOC(filename="../../dmu0/dmu0_LegacySurvey/data/LegacySurvey-dr4_Bootes_MOC.fits")
ndwfs_moc = MOC(filename="../../dmu0/dmu0_NDWFS/data/NDWFS_MLselected_20160801_MOC.fits")
ps1_moc = MOC(filename="../../dmu0/dmu0_PanSTARRS1-3SS/data/PanSTARRS1-3SS_Bootes_v2_MOC.fits")
#sdwfs_moc = MOC(filename="../../dmu0/dmu0_SDWFS/data/SDWFS_MLselected_20160801_MOC.fits")
uhs_moc = MOC(filename="../../dmu0/dmu0_UHS/data/UHS-DR1_Bootes_MOC.fits")
zbootes_moc = MOC(filename="../../dmu0/dmu0_zBootes/data/zBootes_MLselected_20160801_MOC.fits")
In [30]:
was_observed_optical = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    decals_moc + ps1_moc + zbootes_moc + legacy_moc + ndwfs_moc) 

was_observed_nir = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    ibis_moc + uhs_moc 
)

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

VIII.b Wavelength domain detection¶

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

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

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

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

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

In [32]:
#[column[5:] for column in master_catalogue.colnames if 'flag' in column]
In [33]:
# SpARCS is a catalogue of sources detected in r (with fluxes measured at 
# this prior position in the other bands).  Thus, we are only using the r
# CFHT band.
# Check to use catalogue flags from HSC and PanSTARRS.
nb_optical_flux = (
  
    
    1 * ~np.isnan(master_catalogue['f_90prime_z']) +
    
    1 * ~np.isnan(master_catalogue['f_mosaic_r']) +
    1 * ~np.isnan(master_catalogue['f_mosaic_i']) +
    1 * ~np.isnan(master_catalogue['f_mosaic_b']) +
    
    1 * ~np.isnan(master_catalogue['f_bass_g']) +
    1 * ~np.isnan(master_catalogue['f_bass_r']) +
    1 * ~np.isnan(master_catalogue['f_bass_z']) +

    1 * ~np.isnan(master_catalogue['f_gpc1_g']) +
    1 * ~np.isnan(master_catalogue['f_gpc1_r']) +
    1 * ~np.isnan(master_catalogue['f_gpc1_i']) +
    1 * ~np.isnan(master_catalogue['f_gpc1_z']) +
    1 * ~np.isnan(master_catalogue['f_gpc1_y'])
)

nb_nir_flux = (
    1 * ~np.isnan(master_catalogue['f_newfirm_j']) +
    1 * ~np.isnan(master_catalogue['f_newfirm_h']) +
    1 * ~np.isnan(master_catalogue['f_newfirm_k']) +
    
    1 * ~np.isnan(master_catalogue['f_wfcam_j']) 

)

nb_mir_flux = (
    1 * ~np.isnan(master_catalogue['f_irac_i1']) +
    1 * ~np.isnan(master_catalogue['f_irac_i2']) +
    1 * ~np.isnan(master_catalogue['f_irac_i3']) +
    1 * ~np.isnan(master_catalogue['f_irac_i4'])
)
In [34]:
has_optical_flux = nb_optical_flux >= 2
has_nir_flux = nb_nir_flux >= 2
has_mir_flux = nb_mir_flux >= 2

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

IX - Cross-identification table¶

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

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

In [35]:
#
# Addind SDSS ids
#
sdss = Table.read("../../dmu0/dmu0_SDSS-DR13/data/SDSS-DR13_Bootes.fits")['objID', 'ra', 'dec']
sdss_coords = SkyCoord(sdss['ra'] * u.deg, sdss['dec'] * u.deg)
idx_ml, d2d, _ = sdss_coords.match_to_catalog_sky(SkyCoord(master_catalogue['ra'], master_catalogue['dec']))
idx_sdss = np.arange(len(sdss))

# Limit the cross-match to 1 arcsec
mask = d2d <= 1. * u.arcsec
idx_ml = idx_ml[mask]
idx_sdss = idx_sdss[mask]
d2d = d2d[mask]
nb_orig_matches = len(idx_ml)

# In case of multiple associations of one master list object to an SDSS object, we keep only the
# association to the nearest one.
sort_idx = np.argsort(d2d)
idx_ml = idx_ml[sort_idx]
idx_sdss = idx_sdss[sort_idx]
_, unique_idx = np.unique(idx_ml, return_index=True)
idx_ml = idx_ml[unique_idx]
idx_sdss = idx_sdss[unique_idx]
print("{} master list rows had multiple associations.".format(nb_orig_matches - len(idx_ml)))

# Adding the ObjID to the master list
master_catalogue.add_column(Column(data=np.full(len(master_catalogue), -1, dtype='>i8'), name="sdss_id"))
master_catalogue['sdss_id'][idx_ml] = sdss['objID'][idx_sdss]
235 master list rows had multiple associations.
In [36]:
id_names = []
for col in master_catalogue.colnames:
    if '_id' in col:
        id_names += [col]
    if '_intid' in col:
        id_names += [col]
        
print(id_names)
['ps1_id', 'decals_id', 'legacy_id', 'ibis_id', 'ndwfs_id', 'uhs_id', 'zbootes_id', 'datafusion_intid', 'help_id', 'sdss_id']
In [37]:
master_catalogue[id_names].write(
    "{}/master_list_cross_ident_bootes{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)
id_names.remove('help_id')
master_catalogue.remove_columns(id_names)

X - Adding HEALPix index¶

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

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

XI - Saving the catalogue¶

In [39]:
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"] #"zspec", "zspec_qual", "zspec_association_flag", "stellarity_origin",
In [40]:
# We check for columns in the master catalogue that we will not save to disk.
print("Missing columns: {}".format(set(master_catalogue.colnames) - set(columns)))
Missing columns: {'flag_bass_z', 'flag_gpc1_i', 'flag_irac_i3', 'flag_90prime_z', 'flag_decam_r', 'flag_mosaic_b', 'flag_mosaic_i', 'flag_newfirm_h', 'flag_decam_g', 'flag_decam_z', 'flag_irac_i2', 'flag_irac_i1', 'flag_newfirm_j', 'flag_mosaic_k', 'flag_wfcam_j', 'flag_gpc1_g', 'flag_irac_i4', 'flag_bass_r', 'flag_newfirm_k', 'flag_bass_g', 'flag_mosaic_r', 'flag_gpc1_r', 'flag_gpc1_y', 'flag_gpc1_z'}
In [41]:
master_catalogue[columns].write("{}/HELP_master_catalogue_bootes{}.fits".format(OUT_DIR, SUFFIX), overwrite=True)