EGS master catalogue

Preparation of Canada France Hawaii Telescope WIRDS Survey (CFHT-WIRDS) data

The catalogue is in dmu0_CFHT-WIRDS.

In the catalogue, we keep:

  • The position;
  • The stellarity;
  • The aperture magnitude (3 arcsec).
  • The total magnitude (Kron like aperture magnitude).
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))

from collections import OrderedDict
import os

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

from herschelhelp_internal.flagging import  gaia_flag_column
from herschelhelp_internal.masterlist import nb_astcor_diag_plot, remove_duplicates
from herschelhelp_internal.utils import astrometric_correction, mag_to_flux
from herschelhelp_internal.masterlist import merge_catalogues, nb_merge_dist_plot
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "wirds_ra"
DEC_COL = "wirds_dec"

I - Column selection

In [4]:
#We have to import and combine the H, J and Ks catalogues separately. 
#Fluxes are given in counts sowe compute them fresh from the magnitudes

epoch = 2007



imported_columns = OrderedDict({
        'id': "wirds_id",
        'ra': "wirds_ra",
        'dec': "wirds_dec",
# ugriz are ks selected from cfhtls
        'utot': "m_wirds_u",
        'uterr': "merr_wirds_u",
        'u': "m_ap_wirds_u",
        'uerr': "merr_ap_wirds_u",
        'gtot': "m_wirds_g",
        'gterr': "merr_wirds_g",
        'g': "m_ap_wirds_g",
        'gerr': "merr_ap_wirds_g",
        'rtot': "m_wirds_r",
        'rterr': "merr_wirds_r",
        'r': "m_ap_wirds_r",
        'rerr': "merr_ap_wirds_r",
        'itot': "m_wirds_i",
        'iterr': "merr_wirds_i",
        'i': "m_ap_wirds_i",
        'ierr': "merr_ap_wirds_i",
        'ztot': "m_wirds_z",
        'zterr': "merr_wirds_z",
        'z': "m_ap_wirds_z",
        'zerr': "merr_ap_wirds_z",
        'jtot': "m_wirds_j", 
        'jterr': "merr_wirds_j",
        'j': "m_ap_wirds_j",
        'jerr': "merr_ap_wirds_j",
        'htot': "m_wirds_h",
        'hterr': "merr_wirds_h",
        'h': "m_ap_wirds_h",
        'herr': "merr_ap_wirds_h",
        'kstot': "m_wirds_k",
        'ksterr': "merr_wirds_k",
        'ks': "m_ap_wirds_k",
        'kserr': "merr_ap_wirds_k"
        
    })


catalogue = Table.read("../../dmu0/dmu0_CFHT-WIRDS/data/EGS_Ks-priors.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

for col in catalogue.colnames:
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        #catalogue_h[col].name = imported_columns_h[col]
        
        #REplace 99.0 with nan
        catalogue[col][catalogue[col] > 90.] = np.nan
        catalogue[errcol][catalogue[errcol] > 90.] = np.nan  
        #Replace -99.0 with nan
        catalogue[col][catalogue[col] < -90.] = np.nan
        catalogue[errcol][catalogue[errcol] < -90.] = np.nan 
    
        flux, error = mag_to_flux(np.array(catalogue[col]), np.array(catalogue[errcol]))
        
        # Fluxes are added in µJy
        catalogue.add_column(Column(flux * 1.e6, name="f{}".format(col[1:])))
        catalogue.add_column(Column(error * 1.e6, name="f{}".format(errcol[1:])))

        # Band-flag column
        if "ap" not in col:
            catalogue.add_column(Column(np.zeros(len(catalogue), dtype=bool), name="flag{}".format(col[1:])))
# Clean table metadata
catalogue.meta = None
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/table/column.py:1096: MaskedArrayFutureWarning: setting an item on a masked array which has a shared mask will not copy the mask and also change the original mask array in the future.
Check the NumPy 1.11 release notes for more information.
  ma.MaskedArray.__setitem__(self, index, value)
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/ipykernel/__main__.py:63: RuntimeWarning: invalid value encountered in less
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/ipykernel/__main__.py:64: RuntimeWarning: invalid value encountered in less
In [5]:
catalogue[:10].show_in_notebook()
Out[5]:
<Table masked=True length=10>
idxwirds_idwirds_rawirds_decm_wirds_umerr_wirds_um_ap_wirds_umerr_ap_wirds_um_wirds_gmerr_wirds_gm_ap_wirds_gmerr_ap_wirds_gm_wirds_rmerr_wirds_rm_ap_wirds_rmerr_ap_wirds_rm_wirds_imerr_wirds_im_ap_wirds_imerr_ap_wirds_im_wirds_zmerr_wirds_zm_ap_wirds_zmerr_ap_wirds_zm_wirds_jmerr_wirds_jm_ap_wirds_jmerr_ap_wirds_jm_wirds_hmerr_wirds_hm_ap_wirds_hmerr_ap_wirds_hm_wirds_kmerr_wirds_km_ap_wirds_kmerr_ap_wirds_kf_wirds_uferr_wirds_uflag_wirds_uf_ap_wirds_uferr_ap_wirds_uf_wirds_gferr_wirds_gflag_wirds_gf_ap_wirds_gferr_ap_wirds_gf_wirds_rferr_wirds_rflag_wirds_rf_ap_wirds_rferr_ap_wirds_rf_wirds_iferr_wirds_iflag_wirds_if_ap_wirds_iferr_ap_wirds_if_wirds_zferr_wirds_zflag_wirds_zf_ap_wirds_zferr_ap_wirds_zf_wirds_jferr_wirds_jflag_wirds_jf_ap_wirds_jferr_ap_wirds_jf_wirds_hferr_wirds_hflag_wirds_hf_ap_wirds_hferr_ap_wirds_hf_wirds_kferr_wirds_kflag_wirds_kf_ap_wirds_kferr_ap_wirds_k
01214.872756252.405630513.49620.023.91860.010311.72670.021.85350.001211.21380.020.96750.000711.23140.020.30670.000510.23680.019.91160.001nannannannannannannannannannannannan14505.10.0False0.9830150.0093255150545774015.00.0False6.585670.00727874648874118708.00.0False14.89360.00960225206654116799.00.0False27.37280.0126056556837291931.00.0False39.38760.0362773425877nannanFalsenannannannanFalsenannannannanFalsenannan
12214.778634752.381782226.72940.442826.64430.11123.74980.020624.51040.011422.15880.006322.90830.003520.85970.002721.57050.001520.41590.004821.10320.002519.94630.021721.2610.017919.8470.053420.81710.034919.02680.016619.98740.00990.07383110.0301108272396False0.07985090.008163539497731.148370.0217882813786False0.5699530.005984389781594.971410.0288466930215False2.492760.0080356985563416.44830.0409034255426False8.546730.011807741429924.75370.109435184277False13.14380.030264623092138.14870.762456320444False11.36580.18738243043141.80222.05596907836False17.10640.54987077637688.97741.36039038334False36.73160.334927243239
23214.771704152.381526221.49950.004322.71670.003620.21830.00121.31370.000819.33990.000620.33480.000518.84270.000519.77880.000318.57820.00119.49540.000718.3390.006220.05390.005617.99110.009419.38240.005917.73610.005118.85220.00319.124310.0361363211596False2.973860.0098604831691829.69480.0273499008472False10.82730.0079778496001466.68690.0368525303202False26.67350.0122835936054105.4190.0485473792651False44.51230.0122992129036134.4990.123878446175False57.78830.0372574882931167.6480.957341602771False34.54930.178198254434230.9721.99969260138False64.12680.348471639518292.1191.3721641124False104.5010.298371497774
34214.748855352.380077724.7990.060127.57760.221124.39020.029827.19590.111723.94690.026526.67190.092323.63260.027426.45480.104423.82650.091527.74520.9547nannannannannannannannannannannannan0.4369180.024185221622False0.03380340.006883735314030.6366780.0174747794631False0.04804410.004942748921620.9577240.0233755486079False0.07784670.006617858900881.279260.0322838705642False0.0950780.009142311074581.070040.0901771750819False0.02896810.0254719899724nannanFalsenannannannanFalsenannannannanFalsenannan
45214.495575152.381876921.67880.002722.72790.003120.68680.000821.66040.000920.03480.000620.93520.000619.68020.000620.52050.000519.46920.001320.28560.001119.22510.006119.99210.004618.95980.015919.70920.013318.82110.008119.47830.00567.735350.0192361939753False2.943340.0084038349086819.28770.0142116798088False7.867550.0065216555867735.16250.0194315303816False15.34330.0084790404798748.74380.0269368349109False22.48020.010352508979859.19970.0708824674803False27.910.028276660123174.12420.416452354693False36.57290.15495067709794.6411.385964988False47.45920.581363016317107.5370.802269736596False58.70560.302791257855
56214.779629252.380143824.78720.087130.19522.928124.27040.0387nannan23.68360.0298nannan22.73550.017327.45420.307322.61480.04226.9550.5286nannannannannannannannannannannannan0.4416920.0354334544767False0.003033330.008180537067610.7109520.0253411704421Falsenannan1.220560.0335005712714Falsenannan2.92280.0465716503186False0.03787210.01071908669673.266480.126358662328False0.05997910.0292013368622nannanFalsenannannannanFalsenannannannanFalsenannan
67214.675487552.381492823.7310.016724.3260.011522.76910.00523.31110.003321.54750.002222.07440.001520.49750.001220.9790.000820.12010.002320.60570.001419.42740.01220.03750.006419.16270.014719.65580.008518.91410.015419.31970.00631.168420.0179717932724False0.675460.007154402368312.833740.013049844938False1.720120.005228168174658.72970.0176887793714False5.373280.0074234671956222.96150.025377975544False14.73670.010858391033332.50570.0688594476742False20.78360.026799312399861.52330.679980628775False35.07520.20675463601978.5091.06294900761False49.85170.3902784865298.70961.40008982853False67.93910.394217755093
78214.482807652.385568323.29340.011724.01640.008722.04590.002822.75150.002221.21060.001721.89240.001320.77920.001621.45470.001120.55320.003621.22220.002520.40670.018621.00310.011720.10360.027320.59120.015519.92270.023320.55440.01521.74840.0188408962799False0.8983390.007198385571885.516190.0142256894833False2.880050.0058357749367111.90580.0186416565157False6.353890.007607791485517.71410.0261045235675False9.508670.0096335910711821.81320.0723265911802False11.77930.027122857773124.96430.427669650162False14.41320.15531792714733.00350.829847461864False21.0630.30069560762138.9870.836664038798False21.78910.305041848333
89214.744473652.380591826.19150.194828.46870.50125.04180.048726.27180.047924.70540.047825.8160.042124.40450.0525.61520.048223.95560.092625.37130.1076nannannannannannannannannannannannan0.1211710.0217402423743False0.01487710.006864882427850.3493660.0156705680013False0.1125330.00496467923270.4762550.0209673398274False0.1712380.006639837702950.6283480.0289364862738False0.2060250.009146243021970.9500780.0810300384728False0.2579170.0255604148947nannanFalsenannannannanFalsenannannannanFalsenannan
910214.780626552.380494123.58680.012724.02730.010723.07770.005623.51440.004622.45820.004222.90640.003521.80870.003222.27670.002721.63660.007322.08680.006nannannannannannannannannannannannan1.334380.0156084338073False0.8893650.008764748565682.132650.01099976962False1.426390.006043286498433.773290.0145963659634False2.497120.008049765256156.863090.0202276467462False4.459850.01109071531578.041920.0540702360468False5.312270.0293566663458nannanFalsenannannannanFalsenannannannanFalsenannan

II - Removal of duplicated sources

We remove duplicated objects from the input catalogues.

In [6]:
SORT_COLS = [#'merr_ap_wirds_u',
             #'merr_ap_wirds_g',
             #'merr_ap_wirds_r',
             #'merr_ap_wirds_i',
             #'merr_ap_wirds_z',
             'merr_ap_wirds_k',
            'merr_ap_wirds_j',
            'merr_ap_wirds_h']
FLAG_NAME = 'wirds_flag_cleaned'

nb_orig_sources = len(catalogue)

catalogue = remove_duplicates(catalogue, RA_COL, DEC_COL, sort_col=SORT_COLS,flag_name=FLAG_NAME)

nb_sources = len(catalogue)

print("The initial catalogue had {} sources.".format(nb_orig_sources))
print("The cleaned catalogue has {} sources ({} removed).".format(nb_sources, nb_orig_sources - nb_sources))
print("The cleaned catalogue has {} sources flagged as having been cleaned".format(np.sum(catalogue[FLAG_NAME])))
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/astropy/table/column.py:1096: MaskedArrayFutureWarning: setting an item on a masked array which has a shared mask will not copy the mask and also change the original mask array in the future.
Check the NumPy 1.11 release notes for more information.
  ma.MaskedArray.__setitem__(self, index, value)
The initial catalogue had 100317 sources.
The cleaned catalogue has 100317 sources (0 removed).
The cleaned catalogue has 0 sources flagged as having been cleaned

III - Astrometry correction

We match the astrometry to the Gaia one. We limit the Gaia catalogue to sources with a g band flux between the 30th and the 70th percentile. Some quick tests show that this give the lower dispersion in the results.

In [7]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_EGS.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [8]:
nb_astcor_diag_plot(catalogue[RA_COL].to(u.deg), catalogue[DEC_COL].to(u.deg), 
                    gaia_coords.ra, gaia_coords.dec)
In [9]:
delta_ra, delta_dec =  astrometric_correction(
    SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]),
    gaia_coords
)

print("RA correction: {}".format(delta_ra))
print("Dec correction: {}".format(delta_dec))
RA correction: -0.08794029236014467 arcsec
Dec correction: -0.0733593735006366 arcsec
In [10]:
catalogue[RA_COL] +=  delta_ra.to(u.deg)
catalogue[DEC_COL] +=  delta_dec.to(u.deg)
In [11]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)

IV - Flagging Gaia objects

In [12]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [13]:
GAIA_FLAG_NAME = "cfht-wirds_flag_gaia"

catalogue['flag_gaia'].name = GAIA_FLAG_NAME
print("{} sources flagged.".format(np.sum(catalogue[GAIA_FLAG_NAME] > 0)))
1193 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

In [14]:
catalogue.write("{}/CFHT-WIRDS.fits".format(OUT_DIR), overwrite=True)