XMM-LSS master catalogue¶

Preparation of Canada France Hawaii Telescope Lensing Survey (CFHTLenS) data¶

CFHTLenS catalogue: the catalogue comes from dmu0_CFHTLenS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The kron magnitude, there doesn't appear to be aperture magnitudes. This may mean the survey is unusable.

We use the publication year 2012 for the epoch.

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 = "cfhtlens_ra"
DEC_COL = "cfhtlens_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'id': "cfhtlens_id",
        'ALPHA_J2000': "cfhtlens_ra",
        'DELTA_J2000': "cfhtlens_dec",
        'CLASS_STAR':  "cfhtlens_stellarity",
        'MAG_u': "m_cfhtlens_u",
        'MAGERR_u': "merr_cfhtlens_u",
        'MAG_g': "m_cfhtlens_g",
        'MAGERR_g': "merr_cfhtlens_g",
        'MAG_r': "m_cfhtlens_r",
        'MAGERR_r': "merr_cfhtlens_r",
        'MAG_i': "m_cfhtlens_i",
        'MAGERR_i': "merr_cfhtlens_i",
        'MAG_z': "m_cfhtlens_z",
        'MAGERR_z': "merr_cfhtlens_z",

    })


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

epoch = 2012 #Year of publication

# 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  
        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:])))
        
        # We add nan filled aperture photometry for consistency
        catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="m_ap{}".format(col[1:])))
        catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="merr_ap{}".format(col[1:])))
        catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="f_ap{}".format(col[1:])))
        catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="f_err{}".format(col[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.
/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:10: RuntimeWarning: invalid value encountered in greater
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/ipykernel/__main__.py:11: RuntimeWarning: invalid value encountered in greater
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxcfhtlens_idcfhtlens_racfhtlens_deccfhtlens_stellaritym_cfhtlens_umerr_cfhtlens_um_cfhtlens_gmerr_cfhtlens_gm_cfhtlens_rmerr_cfhtlens_rm_cfhtlens_imerr_cfhtlens_im_cfhtlens_zmerr_cfhtlens_zf_cfhtlens_uferr_cfhtlens_um_ap_cfhtlens_umerr_ap_cfhtlens_uf_ap_cfhtlens_uf_err_cfhtlens_uflag_cfhtlens_uf_cfhtlens_gferr_cfhtlens_gm_ap_cfhtlens_gmerr_ap_cfhtlens_gf_ap_cfhtlens_gf_err_cfhtlens_gflag_cfhtlens_gf_cfhtlens_rferr_cfhtlens_rm_ap_cfhtlens_rmerr_ap_cfhtlens_rf_ap_cfhtlens_rf_err_cfhtlens_rflag_cfhtlens_rf_cfhtlens_iferr_cfhtlens_im_ap_cfhtlens_imerr_ap_cfhtlens_if_ap_cfhtlens_if_err_cfhtlens_iflag_cfhtlens_if_cfhtlens_zferr_cfhtlens_zm_ap_cfhtlens_zmerr_ap_cfhtlens_zf_ap_cfhtlens_zf_err_cfhtlens_zflag_cfhtlens_z
0W1m0m0_5820034.97608891-7.1481800020.12523824.70010.024424.51220.015324.23110.016423.66670.01323.23280.03890.4785860.0107554nannannannanFalse0.569010.00801839nannannannanFalse0.7371570.0111347nannannannanFalse1.239710.0148436nannannannanFalse1.848760.0662377nannannannanFalse
1W1m0m0_5830734.97553765-7.1475944030.034840925.27010.04224.92680.023524.21570.017723.93230.018723.80530.07230.2831130.0109518nannannannanFalse0.3884010.00840666nannannannanFalse0.7476870.012189nannannannanFalse0.9706880.0167185nannannannanFalse1.091140.0726598nannannannanFalse
2W1m0m0_5833834.97477759-7.1473107940.1028325.76560.054625.42480.030725.08540.030924.19910.019323.98880.07140.1793740.00902045nannannannanFalse0.2455160.00694214nannannannanFalse0.3356140.00955155nannannannanFalse0.7592060.0134956nannannannanFalse0.9214670.0605974nannannannanFalse
3W1m0m0_5842534.97648555-7.1470484350.033452125.03260.031824.13220.011523.41310.009323.1160.008422.92890.03070.3523380.0103196nannannannanFalse0.8074580.0085525nannannannanFalse1.565890.0134128nannannannanFalse2.058730.0159278nannannannanFalse2.445910.0691599nannannannanFalse
4W1m0m0_5909234.97096718-7.1427277380.18594425.3510.041425.48730.033825.20470.035824.87080.03624.64080.13310.2627850.0100202nannannannanFalse0.2317820.00721559nannannannanFalse0.3006910.00991468nannannannanFalse0.4089590.01356nannannannanFalse0.5054520.0619631nannannannanFalse
5W1m0m0_5909434.97634122-7.1427344190.662571nannannannan26.35570.118825.34820.070424.37780.1312nannannannannannanFalsenannannannannannanFalse0.1041650.0113976nannannannanFalse0.2634630.0170832nannannannanFalse0.6439910.0778197nannannannanFalse
6W1m0m0_5910934.97395827-7.1428471320.026334523.46660.011623.05770.006122.35610.005321.74350.003521.59230.0131.49060.0159255nannannannanFalse2.17230.0122047nannannannanFalse4.145340.0202354nannannannanFalse7.287860.0234933nannannannanFalse8.376830.100299nannannannanFalse
7W1m0m0_5931434.96874302-7.14148730.502324nannan26.73270.132126.06020.116825.01290.0558nannannannannannannannanFalse0.07360710.00895567nannannannanFalse0.1367480.0147109nannannannanFalse0.358790.0184395nannannannanFalsenannannannannannanFalse
8W1m0m0_5939734.96990438-7.1410682910.78629126.85780.148125.53320.03624.75940.025724.54310.027824.73510.150.06559640.00894769nannannannanFalse0.2221880.00736713nannannannanFalse0.4531480.0107263nannannannanFalse0.5530440.0141606nannannannanFalse0.4634040.0640216nannannannanFalse
9W1m0m0_5940934.96991906-7.1421052690.98246223.98370.018121.73630.002520.57760.001719.85050.00119.49750.00230.9258060.0154338nannannannanFalse7.336350.0168926nannannannanFalse21.32850.0333952nannannannanFalse41.66770.0383774nannannannanFalse57.67670.122181nannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_cfhtlens_u', 
             'merr_cfhtlens_g', 
             'merr_cfhtlens_r', 
             'merr_cfhtlens_i',
             'merr_cfhtlens_z']
FLAG_NAME = 'cfhtlens_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 2317959 sources.
The cleaned catalogue has 2317937 sources (22 removed).
The cleaned catalogue has 22 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.08798053969201192 arcsec
Dec correction: -0.11095108088596817 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 = "cfhtlens_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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