XMM-LSS 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: 
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))

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_h = OrderedDict({
        'NUMBER': "wirds_h_id",
        'ALPHA_J2000': "wirds_h_ra",
        'DELTA_J2000': "wirds_h_dec",
        'CLASS_STAR':  "wirds_h_stellarity",
        'MAG_APER': "m_ap_wirds_h",
        'MAGERR_APER': "merr_ap_wirds_h",
        'MAG_AUTO': "m_wirds_h",
        'MAGERR_AUTO': "merr_wirds_h"
        #'FLUX_APER': "f_ap_wirds_h",
        #'FLUXERR_APER': "ferr_ap_wirds_h",
        #'FLUX_AUTO': "f_wirds_h",
        #'FLUXERR_AUTO': "ferr_wirds_h"
        
    })


catalogue_h = Table.read("../../dmu0/dmu0_CFHT-WIRDS/data/XMM-LSS_H.fits")[list(imported_columns_h)]
for column in imported_columns_h:
    catalogue_h[column].name = imported_columns_h[column]

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

        # Band-flag column
        if "ap" not in col:
            catalogue_h.add_column(Column(np.zeros(len(catalogue_h), dtype=bool), name="flag{}".format(col[1:])))
        
# Clean table metadata
catalogue_h.meta = None



imported_columns_j = OrderedDict({
        'NUMBER': "wirds_j_id",
        'ALPHA_J2000': "wirds_j_ra",
        'DELTA_J2000': "wirds_j_dec",
        'CLASS_STAR':  "wirds_j_stellarity",
        'MAG_APER': "m_ap_wirds_j",
        'MAGERR_APER': "merr_ap_wirds_j",
        'MAG_AUTO': "m_wirds_j",
        'MAGERR_AUTO': "merr_wirds_j"
        #'FLUX_APER': "f_ap_wirds_j",
        #'FLUXERR_APER': "ferr_ap_wirds_j",
        #'FLUX_AUTO': "f_wirds_j",
        #'FLUXERR_AUTO': "ferr_wirds_j"
        
    })


catalogue_j = Table.read("../../dmu0/dmu0_CFHT-WIRDS/data/XMM-LSS_J.fits")[list(imported_columns_j)]
for column in imported_columns_j:
    catalogue_j[column].name = imported_columns_j[column]
    
for col in catalogue_j.colnames:
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        #catalogue_h[col].name = imported_columns_h[col]
    
        flux, error = mag_to_flux(np.array(catalogue_j[col]), np.array(catalogue_j[errcol]))
        
        # Fluxes are added in µJy
        catalogue_j.add_column(Column(flux * 1.e6, name="f{}".format(col[1:])))
        catalogue_j.add_column(Column(error * 1.e6, name="f{}".format(errcol[1:])))

        # Band-flag column
        if "ap" not in col:
            catalogue_j.add_column(Column(np.zeros(len(catalogue_j), dtype=bool), name="flag{}".format(col[1:])))
# Clean table metadata
catalogue_j.meta = None



imported_columns_ks = OrderedDict({
        'NUMBER': "wirds_ks_id",
        'ALPHA_J2000': "wirds_ks_ra",
        'DELTA_J2000': "wirds_ks_dec",
        'CLASS_STAR':  "wirds_ks_stellarity",
        'MAG_APER': "m_ap_wirds_ks",
        'MAGERR_APER': "merr_ap_wirds_ks",
        'MAG_AUTO': "m_wirds_ks",
        'MAGERR_AUTO': "merr_wirds_ks"
        #'FLUX_APER': "f_ap_wirds_ks",
        #'FLUXERR_APER': "ferr_ap_wirds_ks",
        #'FLUX_AUTO': "f_wirds_ks",
        #'FLUXERR_AUTO': "ferr_wirds_ks"
        
    })


catalogue_ks = Table.read("../../dmu0/dmu0_CFHT-WIRDS/data/XMM-LSS_Ks.fits")[list(imported_columns_ks)]
for column in imported_columns_ks:
    catalogue_ks[column].name = imported_columns_ks[column]

for col in catalogue_ks.colnames:
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        #catalogue_h[col].name = imported_columns_h[col]
    
        flux, error = mag_to_flux(np.array(catalogue_ks[col]), np.array(catalogue_ks[errcol]))
        
        # Fluxes are added in µJy
        catalogue_ks.add_column(Column(flux * 1.e6, name="f{}".format(col[1:])))
        catalogue_ks.add_column(Column(error * 1.e6, name="f{}".format(errcol[1:])))

        # Band-flag column
        if "ap" not in col:
            catalogue_ks.add_column(Column(np.zeros(len(catalogue_ks), dtype=bool), name="flag{}".format(col[1:])))
# Clean table metadata
catalogue_ks.meta = None

Merging different bands¶

CFHT-WIRDS has indivdual extractions from each band. We must therefore merge them as if they were individual catalogues (they have different

In [5]:
catalogue_ks[:10].show_in_notebook()
Out[5]:
<Table length=10>
idxwirds_ks_idwirds_ks_rawirds_ks_decwirds_ks_stellaritym_ap_wirds_ksmerr_ap_wirds_ksm_wirds_ksmerr_wirds_ksf_ap_wirds_ksferr_ap_wirds_ksf_wirds_ksferr_wirds_ksflag_wirds_ks
degdegmagmagmagmag
0136.1272184-4.98291280.0318.48510.002517.72190.0035146.5412865230.337423781855295.9647576410.954077654593False
1236.3189399-4.98334570.8814.96080.000214.59390.00043764.263356010.6934029351725277.642884141.94435549299False
2336.109353-4.98834850.0319.20570.005118.1180.007975.46055586160.354458876113205.4944041351.49521199123False
3436.3271727-4.98834730.7917.66580.00417.02850.0053311.6592347761.14819505294560.5314696472.73622338106False
4536.1194884-4.98950780.0320.21790.023918.57710.018429.70571431160.653903378128134.6356278682.2816735243False
5636.2733342-4.98822140.9817.55890.001717.38920.0022343.9061957020.538473830135402.0869703550.814738728343False
6736.0932817-4.98957670.0521.32230.062520.24860.053310.74187266720.61835189686128.87752709411.41762997989False
7836.1681386-4.98927770.0521.87770.064621.51960.0836.44050616080.3832023802518.95694690890.684721196715False
8936.2517296-4.9893440.9917.28120.00117.17560.0016444.1401143030.409068162558489.5082323630.721365989592False
91036.1722684-4.99017990.7919.84690.017219.65160.034141.80613320530.66228379230550.04492007621.57177384996False
In [6]:
nb_merge_dist_plot(
    SkyCoord(catalogue_ks['wirds_ks_ra'], catalogue_ks['wirds_ks_dec']),
    SkyCoord(catalogue_j['wirds_j_ra'], catalogue_j['wirds_j_dec'])
)
In [7]:
catalogue = catalogue_ks
catalogue_ks['wirds_ks_ra'].name = 'ra'
catalogue_ks['wirds_ks_dec'].name = 'dec'
# Given the graph above, we use 0.8 arc-second radius
catalogue = merge_catalogues(catalogue, catalogue_j, "wirds_j_ra", "wirds_j_dec", radius=0.8*u.arcsec)
In [8]:
nb_merge_dist_plot(
    SkyCoord(catalogue['ra'], catalogue['dec']),
    SkyCoord(catalogue_h['wirds_h_ra'], catalogue_h['wirds_h_dec'])
)
In [9]:
# Given the graph above, we use 0.8 arc-second radius
catalogue = merge_catalogues(catalogue, catalogue_h, "wirds_h_ra", "wirds_h_dec", radius=0.8*u.arcsec)
In [10]:
#rename radec colums
catalogue['ra'].name = 'wirds_ra'
catalogue['dec'].name = 'wirds_dec'
In [11]:
    
for col in catalogue.colnames:
    if "m_" in col or "merr_" in col or "f_" in col or "ferr_" in col or "stellarity" in col:
        catalogue[col].fill_value = np.nan
    elif "flag" in col:
        catalogue[col].fill_value = 0
    elif "id" in col:
        catalogue[col].fill_value = 999999
        
catalogue =  catalogue.filled()

Generate internal id¶

Since every source has an independent id we combine them in 6 digit groups so that each iondividual id can be retrieved from the final integer

In [12]:
wirds_intid = catalogue['wirds_ks_id'] + catalogue['wirds_j_id']*10**6 + catalogue['wirds_h_id']*10**12
In [13]:
catalogue.add_column(Column(data=wirds_intid, name="wirds_intid"))
catalogue.remove_columns(['wirds_ks_id','wirds_j_id','wirds_h_id'])
In [14]:
stellarity_columns = [column for column in catalogue.colnames
                      if 'stellarity' in column]

print(", ".join(stellarity_columns))
wirds_ks_stellarity, wirds_j_stellarity, wirds_h_stellarity
In [15]:
# 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([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

catalogue.add_column(Column(data=max_stellarity.filled(), name="wirds_stellarity"))

catalogue.remove_columns(stellarity_columns)
catalogue['flag_merged'].name = 'wirds_flag_merged'
In [16]:
catalogue[:10].show_in_notebook()
Out[16]:
<Table length=10>
idxwirds_rawirds_decm_ap_wirds_ksmerr_ap_wirds_ksm_wirds_ksmerr_wirds_ksf_ap_wirds_ksferr_ap_wirds_ksf_wirds_ksferr_wirds_ksflag_wirds_kswirds_flag_mergedm_ap_wirds_jmerr_ap_wirds_jm_wirds_jmerr_wirds_jf_ap_wirds_jferr_ap_wirds_jf_wirds_jferr_wirds_jflag_wirds_jm_ap_wirds_hmerr_ap_wirds_hm_wirds_hmerr_wirds_hf_ap_wirds_hferr_ap_wirds_hf_wirds_hferr_wirds_hflag_wirds_hwirds_intidwirds_stellarity
degdegmagmagmagmagmagmagmagmagmagmagmagmag
036.1681386-4.989277721.87770.064621.51960.0836.44050616080.3832023802518.95694690890.684721196715FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000080.05
136.092669-4.989006423.11390.184322.95990.21112.062718672510.3501394258362.377059211790.46217230061FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000120.92
236.3662705-4.988792521.49750.063320.72010.19399.14113241470.53294131605318.70509852113.34051548373FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000130.03
336.1028248-4.989996324.97622.015425.02812.57840.3711248200290.6889011888970.3538017689670.840206375275FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000220.66
436.1120225-4.989865524.19020.862524.07681.22330.7654555917930.6080716890790.8497281384480.957389490383FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000250.67
536.3662624-4.989423121.69250.067920.67440.1577.638357835780.47768923498819.50922421492.82107954798FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000270.18
636.1716434-4.989549422.65070.119721.08870.08173.160239521510.34840937335113.320483841.002346173FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000290.71
736.2785494-4.98943921.52360.060420.33430.11258.924009008120.49644668910226.68578606232.76508319318FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000300.03
836.1501808-4.989773623.9980.417824.41880.77470.9136923736810.3515961538830.6201260851350.442475507447FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000310.93
936.1276522-4.988905522.28750.087621.92920.11564.415704473530.3562704367666.142144083740.653963506944FalseFalsenannannannannannannannanFalsenannannannannannannannanFalse9999999999990000330.16

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [17]:
SORT_COLS = ['merr_ap_wirds_ks',
            '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])))
The initial catalogue had 245786 sources.
The cleaned catalogue has 245776 sources (10 removed).
The cleaned catalogue has 10 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 [18]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_XMM-LSS.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [19]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)
In [20]:
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.11769722784862324 arcsec
Dec correction: -0.10338543637189446 arcsec
In [21]:
catalogue[RA_COL] = catalogue[RA_COL] + delta_ra.to(u.deg)
catalogue[DEC_COL] = catalogue[DEC_COL] + delta_dec.to(u.deg)
In [22]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)

IV - Flagging Gaia objects¶

In [23]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [24]:
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)))
1667 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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