XMM-LSS master catalogue¶

Preparation of Canada France Hawaii Telescope Legacy Survey (CFHTLS) wide 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-wide_ra"
DEC_COL = "cfhtls-wide_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'cfhtls': "cfhtls-wide_id",
        'raj2000': "cfhtls-wide_ra",
        'dej2000': "cfhtls-wide_dec",
        'gcl':  "cfhtls-wide_stellarity",
        'umaga': "m_cfhtls-wide_u",
        'e_umaga': "merr_cfhtls-wide_u",
        'gmaga': "m_cfhtls-wide_g",
        'e_gmaga': "merr_cfhtls-wide_g",
        'rmaga': "m_cfhtls-wide_r",
        'e_rmaga': "merr_cfhtls-wide_r",
        'imaga': "m_cfhtls-wide_i",
        'e_imaga': "merr_cfhtls-wide_i",
        'zmaga': "m_cfhtls-wide_z",
        'e_zmaga': "merr_cfhtls-wide_z",
        'umag': "m_ap_cfhtls-wide_u",
        'e_umag': "merr_ap_cfhtls-wide_u",
        'gmag': "m_ap_cfhtls-wide_g",
        'e_gmag': "merr_ap_cfhtls-wide_g",
        'rmag': "m_ap_cfhtls-wide_r",
        'e_rmag': "merr_ap_cfhtls-wide_r",
        'imag': "m_ap_cfhtls-wide_i",
        'e_imag': "merr_ap_cfhtls-wide_i",
        'zmag': "m_ap_cfhtls-wide_z",
        'e_zmag': "merr_ap_cfhtls-wide_z"
        
    })


catalogue = Table.read("../../dmu0/dmu0_CFHTLS/data/CFHTLS-WIDE_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-wide_idcfhtls-wide_racfhtls-wide_deccfhtls-wide_stellaritym_cfhtls-wide_umerr_cfhtls-wide_um_cfhtls-wide_gmerr_cfhtls-wide_gm_cfhtls-wide_rmerr_cfhtls-wide_rm_cfhtls-wide_imerr_cfhtls-wide_im_cfhtls-wide_zmerr_cfhtls-wide_zm_ap_cfhtls-wide_umerr_ap_cfhtls-wide_um_ap_cfhtls-wide_gmerr_ap_cfhtls-wide_gm_ap_cfhtls-wide_rmerr_ap_cfhtls-wide_rm_ap_cfhtls-wide_imerr_ap_cfhtls-wide_im_ap_cfhtls-wide_zmerr_ap_cfhtls-wide_zf_cfhtls-wide_uferr_cfhtls-wide_uflag_cfhtls-wide_uf_cfhtls-wide_gferr_cfhtls-wide_gflag_cfhtls-wide_gf_cfhtls-wide_rferr_cfhtls-wide_rflag_cfhtls-wide_rf_cfhtls-wide_iferr_cfhtls-wide_iflag_cfhtls-wide_if_cfhtls-wide_zferr_cfhtls-wide_zflag_cfhtls-wide_zf_ap_cfhtls-wide_uferr_ap_cfhtls-wide_uf_ap_cfhtls-wide_gferr_ap_cfhtls-wide_gf_ap_cfhtls-wide_rferr_ap_cfhtls-wide_rf_ap_cfhtls-wide_iferr_ap_cfhtls-wide_if_ap_cfhtls-wide_zferr_ap_cfhtls-wide_z
degdegmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmag
01125_13526432.857965-5.9957530.825.460.25625.1550.13625.7170.54525.2430.397nannan25.4550.24625.2730.14325.3950.38125.1740.356nannan0.2376840.0560423False0.3147750.0394289False0.1875860.0941613False0.2902690.106137FalsenannanFalse0.2387810.05410170.2823580.03718870.2523480.08855240.3093140.10142nannan
11125_13494832.859594-5.9970130.9824.1670.07923.9960.0523.9630.09523.3530.06923.8680.27324.1750.0823.9940.0523.9540.09523.3470.06923.8730.2750.7819880.0568987False0.9153770.0421547False0.9436260.0825656False1.655010.105178False1.029910.258963False0.7762480.0571960.9170650.04223240.951480.08325281.664180.1057611.025180.259662
21125_13513632.85888-5.9962380.6126.1960.49125.810.264nannan24.6650.22825.8561.78226.1790.48725.8640.279nannan24.7210.24225.8161.7330.120670.0545704False0.1721870.0418678FalsenannanFalse0.494310.103803False0.1650440.270884False0.1225740.05497990.1638320.0420998nannan0.4694610.1046380.1712380.273322
31125_13524932.858661-5.995810.6427.8922.24925.5180.20427.342.47524.9790.305nannan27.8912.24625.5230.20427.452.73525.0340.32nannan0.02530460.0524161False0.225320.0423356False0.04207260.095907False0.3701690.103986FalsenannanFalse0.02532790.05239440.2242850.04214110.03801890.09577060.3518840.103711nannan
41125_13547032.859722-5.994880.9525.4530.25425.3580.16924.9620.23924.1590.14623.4370.18525.4140.24625.3590.16924.9860.24424.1640.14623.4420.1860.2392220.0559641False0.2610960.0406408False0.3760110.0827701False0.787770.105932False1.531790.261004False0.2479710.05618380.2608550.04060340.367790.08265430.7841520.1054461.524750.261209
51125_13509832.86006-5.9963980.36nannan25.9170.40725.1370.43523.9630.19322.8330.167nannan26.3530.38625.0670.26324.10.14123.1260.141nannanFalse0.1560270.0584885False0.3200370.128223False0.9436260.167739False2.671770.410953Falsenannan0.1044240.03712470.341350.08268590.8317630.1080182.039860.264908
61125_13513032.860673-5.9962760.5928.3244.36526.3590.53524.9880.33724.3940.27223.0120.18427.7051.66826.7140.51124.9620.23124.6650.2423.7660.2540.01699810.0683376False0.1038490.0511717False0.3671130.113948False0.6344540.158944False2.265690.383967False0.03006070.04618190.07488580.03524490.3760110.07999960.494310.1092661.131360.264672
71125_13535132.862758-5.9953760.8626.6640.62625.3920.1524.5510.13524.1640.16125.1440.85126.7760.69925.3950.15124.5530.13624.1610.16125.1150.8340.07841520.0452116False0.2530460.0349596False0.5490350.0682667False0.7841520.116279False0.317980.249233False0.07072950.04553580.2523480.03509560.5480250.06864590.7863220.1166010.3265880.250866
81125_13503132.872115-5.9966390.68nannannannan25.740.41425.310.37724.9160.61nannannannan25.7240.40825.3780.40124.8130.555nannanFalsenannanFalse0.1836540.0700287False0.2728980.0947582False0.3922830.220397Falsenannannannan0.186380.07003830.256330.09467160.431320.22048
91125_13546632.870538-5.9948740.9225.4040.19625.790.2125.3390.33825.020.29224.9760.64925.4150.19725.7760.20625.3170.32925.1220.31924.8720.5860.2502650.0451785False0.1753880.033923False0.2657050.0827164False0.3564510.0958646False0.3711930.221881False0.2477420.04495120.1776640.03370880.2711440.08216210.3244890.09533810.4085070.220482

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_cfhtls-wide_u',
            'merr_ap_cfhtls-wide_g',
            'merr_ap_cfhtls-wide_r',
            'merr_ap_cfhtls-wide_i',
            'merr_ap_cfhtls-wide_z',]
FLAG_NAME = 'cfhtls-wide_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 3565362 sources.
The cleaned catalogue has 3565219 sources (143 removed).
The cleaned catalogue has 143 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.09701123327374717 arcsec
Dec correction: -0.12296987141358073 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-wide_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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