XMM-LSS master catalogue¶

Preparation of Canada France Hawaii Telescope Legacy Survey (CFHTLS) deep data¶

CFHTLS has both a wide area across XMM-LSS and a smaller deep field. We will process each independently and add them both to the master catalogue, taking the deep photometry where both are available.

The catalogue is in dmu0_CFHTLS.

In the catalogue, we keep:

  • The position;
  • The stellarity (g band stellarity);
  • The aperture magnitude (3 arcsec).
  • The total magnitude (Kron like aperture magnitude).

We use the 2007 release, which we take as the date.

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
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
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "cfhtls-deep_ra"
DEC_COL = "cfhtls-deep_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'cfhtls': "cfhtls-deep_id",
        'raj2000': "cfhtls-deep_ra",
        'dej2000': "cfhtls-deep_dec",
        'gcl':  "cfhtls-deep_stellarity",
        'umaga': "m_cfhtls-deep_u",
        'e_umaga': "merr_cfhtls-deep_u",
        'gmaga': "m_cfhtls-deep_g",
        'e_gmaga': "merr_cfhtls-deep_g",
        'rmaga': "m_cfhtls-deep_r",
        'e_rmaga': "merr_cfhtls-deep_r",
        'imaga': "m_cfhtls-deep_i",
        'e_imaga': "merr_cfhtls-deep_i",
        'zmaga': "m_cfhtls-deep_z",
        'e_zmaga': "merr_cfhtls-deep_z",
        'ymaga': "m_cfhtls-deep_y",
        'e_ymaga': "merr_cfhtls-deep_y",
        'umag': "m_ap_cfhtls-deep_u",
        'e_umag': "merr_ap_cfhtls-deep_u",
        'gmag': "m_ap_cfhtls-deep_g",
        'e_gmag': "merr_ap_cfhtls-deep_g",
        'rmag': "m_ap_cfhtls-deep_r",
        'e_rmag': "merr_ap_cfhtls-deep_r",
        'imag': "m_ap_cfhtls-deep_i",
        'e_imag': "merr_ap_cfhtls-deep_i",
        'zmag': "m_ap_cfhtls-deep_z",
        'e_zmag': "merr_ap_cfhtls-deep_z",
        'ymag': "m_ap_cfhtls-deep_y",
        'e_ymag': "merr_ap_cfhtls-deep_y"        
    })


catalogue = Table.read("../../dmu0/dmu0_CFHTLS/data/CFHTLS-DEEP_XMM-LSS.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2007

# Clean table metadata
catalogue.meta = None
In [5]:
# Adding flux and band-flag columns
for col in catalogue.colnames:
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        
        #catalogue[col][catalogue[col] <= 0] = np.nan
        #catalogue[errcol][catalogue[errcol] <= 0] = 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:])))
        
# TODO: Set to True the flag columns for fluxes that should not be used for SED fitting.
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxcfhtls-deep_idcfhtls-deep_racfhtls-deep_deccfhtls-deep_stellaritym_cfhtls-deep_umerr_cfhtls-deep_um_cfhtls-deep_gmerr_cfhtls-deep_gm_cfhtls-deep_rmerr_cfhtls-deep_rm_cfhtls-deep_imerr_cfhtls-deep_im_cfhtls-deep_zmerr_cfhtls-deep_zm_cfhtls-deep_ymerr_cfhtls-deep_ym_ap_cfhtls-deep_umerr_ap_cfhtls-deep_um_ap_cfhtls-deep_gmerr_ap_cfhtls-deep_gm_ap_cfhtls-deep_rmerr_ap_cfhtls-deep_rm_ap_cfhtls-deep_imerr_ap_cfhtls-deep_im_ap_cfhtls-deep_zmerr_ap_cfhtls-deep_zm_ap_cfhtls-deep_ymerr_ap_cfhtls-deep_yf_cfhtls-deep_uferr_cfhtls-deep_uflag_cfhtls-deep_uf_cfhtls-deep_gferr_cfhtls-deep_gflag_cfhtls-deep_gf_cfhtls-deep_rferr_cfhtls-deep_rflag_cfhtls-deep_rf_cfhtls-deep_iferr_cfhtls-deep_iflag_cfhtls-deep_if_cfhtls-deep_zferr_cfhtls-deep_zflag_cfhtls-deep_zf_cfhtls-deep_yferr_cfhtls-deep_yflag_cfhtls-deep_yf_ap_cfhtls-deep_uferr_ap_cfhtls-deep_uf_ap_cfhtls-deep_gferr_ap_cfhtls-deep_gf_ap_cfhtls-deep_rferr_ap_cfhtls-deep_rf_ap_cfhtls-deep_iferr_ap_cfhtls-deep_if_ap_cfhtls-deep_zferr_ap_cfhtls-deep_zf_ap_cfhtls-deep_yferr_ap_cfhtls-deep_y
degdegmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmag
00100_000067635.998844-4.9927230.02nannannannannannan28.0368.52326.3024.565nannannannannannannannan27.8337.1126.716.652nannannannanFalsenannanFalsenannanFalse0.02216150.173968False0.1094460.460168FalsenannanFalsenannannannannannan0.02671770.1749630.07516240.460499nannan
10100_000039136.000543-4.9932760.528.7536.97nannannannan23.9190.30224.4590.647nannannannannannannannan23.9380.30824.4660.654nannan0.01144980.0735035FalsenannanFalsenannanFalse0.9826520.273327False0.5975860.356107FalsenannanFalsenannannannannannan0.9656060.2739220.5937450.357646nannan
20100_000131935.999772-4.9913750.028.3415.4nannan25.1021.0125.3381.39324.2050.65823.3920.00128.114.41nannan25.060.97225.3481.40624.2270.67223.3910.0010.0167340.083228FalsenannanFalse0.3305220.307466False0.265950.341214False0.7550920.457616False1.596610.00147054False0.02070140.0840841nannan0.3435580.3075690.2635120.3412410.7399460.4579791.598080.00147189
30100_000255235.998799-4.9889310.024.2870.198nannannannan24.2040.38325.4422.336nannan24.7820.315nannannannan24.8770.46624.761.154nannan0.7001640.127685FalsenannanFalsenannanFalse0.7557880.266609False0.2416570.519935FalsenannanFalse0.4438130.128762nannannannan0.406630.1745260.4528970.481372nannan
40100_000680835.998761-4.9811790.024.3350.206nannannannan26.5222.076nannannannan24.3360.208nannannannan26.5182.11326.776.959nannan0.6698850.127099FalsenannanFalsenannanFalse0.08937170.170885FalsenannanFalsenannanFalse0.6692670.128215nannannannan0.08970150.1745720.07112130.45585nannan
50100_000754336.000673-4.9798420.65nannannannan26.6631.68224.170.298nannan23.7880.111nannannannan27.1292.5924.20.307nannan23.7690.11nannanFalsenannanFalse0.07848740.121591False0.779830.214038FalsenannanFalse1.108660.113344Falsenannannannan0.05109750.1218920.7585770.214493nannan1.128240.114306
60100_000862435.998711-4.9778940.024.4410.234nannan26.5391.516nannan25.9873.44427.9110.00124.530.25nannan26.7631.779nannan26.666.29627.9480.0010.6075750.130946FalsenannanFalse0.08798320.12285FalsenannanFalse0.1462850.464023False0.02486572.29021e-05False0.5597570.128889nannan0.07158130.117287nannan0.07870460.4563940.02403252.21348e-05
70100_001001335.998711-4.9753930.023.6330.104nannan25.2951.083nannannannannannan24.0380.159nannan26.3581.224nannannannannannan1.278790.122492FalsenannanFalse0.2766940.275997FalsenannanFalsenannanFalsenannanFalse0.8806430.128965nannan0.1039440.117181nannannannannannan
80100_001027835.998689-4.9750020.024.3440.209nannannannannannan24.5810.922nannan24.3180.206nannannannannannan24.5390.894nannan0.6643550.127886FalsenannanFalsenannanFalsenannanFalse0.5340720.453531FalsenannanFalse0.6804550.129105nannannannannannan0.5551370.457102nannan
90100_001195535.998671-4.9719850.024.3990.222nannannannannannan24.6871.02nannan24.3690.217nannannannannannan24.7121.046nannan0.6315380.12913FalsenannanFalsenannanFalsenannanFalse0.4843950.455067FalsenannanFalse0.6492320.129758nannannannannannan0.4733690.456045nannan

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_cfhtls-deep_u',
            'merr_ap_cfhtls-deep_g',
            'merr_ap_cfhtls-deep_r',
            'merr_ap_cfhtls-deep_i',
            'merr_ap_cfhtls-deep_z',]
FLAG_NAME = 'cfhtls-deep_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 592457 sources.
The cleaned catalogue has 592457 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 [8]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_XMM-LSS.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [9]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)
In [10]:
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.10748285569093241 arcsec
Dec correction: -0.11697437952022938 arcsec
In [11]:
catalogue[RA_COL] +=  delta_ra.to(u.deg)
catalogue[DEC_COL] += delta_dec.to(u.deg)
In [12]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)

IV - Flagging Gaia objects¶

In [13]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [14]:
GAIA_FLAG_NAME = "cfhtls-deep_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

In [15]:
catalogue.write("{}/CFHTLS-DEEP.fits".format(OUT_DIR), overwrite=True)