EGS 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: 
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
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_EGS.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="ferr{}".format(col[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="ferr_ap{}".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_uferr_ap_cfhtlens_uflag_cfhtlens_uf_cfhtlens_gferr_cfhtlens_gm_ap_cfhtlens_gmerr_ap_cfhtlens_gf_ap_cfhtlens_gferr_ap_cfhtlens_gflag_cfhtlens_gf_cfhtlens_rferr_cfhtlens_rm_ap_cfhtlens_rmerr_ap_cfhtlens_rf_ap_cfhtlens_rferr_ap_cfhtlens_rflag_cfhtlens_rf_cfhtlens_iferr_cfhtlens_im_ap_cfhtlens_imerr_ap_cfhtlens_if_ap_cfhtlens_iferr_ap_cfhtlens_iflag_cfhtlens_if_cfhtlens_zferr_cfhtlens_zm_ap_cfhtlens_zmerr_ap_cfhtlens_zf_ap_cfhtlens_zferr_ap_cfhtlens_zflag_cfhtlens_z
0W3m0m1_8272214.516695553.103323220.0378624.58460.037123.94120.015223.86260.0159nannan23.74390.03120.5323040.018189nannannannanFalse0.9627630.0134784nannannannanFalse1.035050.0151577nannannannanFalsenannannannannannanFalse1.154620.0331795nannannannanFalse
1W3m0m1_8280214.461126853.103377580.573496nannannannan25.21490.0685nannan24.41720.0711nannannannannannanFalsenannannannannannanFalse0.2978790.0187934nannannannanFalsenannannannannannanFalse0.6210410.0406692nannannannanFalse
2W3m0m1_8305214.513860853.103450540.483708nannannannannannannannannannannannannannannannanFalsenannannannannannanFalsenannannannannannanFalsenannannannannannanFalsenannannannannannanFalse
3W3m0m1_8306214.543344653.103449270.653694nannannannan25.91220.0744nannan25.24560.0875nannannannannannanFalsenannannannannannanFalse0.1567180.0107391nannannannanFalsenannannannannannanFalse0.2895740.0233369nannannannanFalse
4W3m0m1_8307214.497340153.103476520.628447nannan25.30220.052224.96210.0438nannan24.28210.0499nannannannannannanFalse0.2748650.013215nannannannanFalse0.3759760.0151674nannannannanFalsenannannannannannanFalse0.703330.0323248nannannannanFalse
5W3m0m1_8309214.362101353.103438310.557704nannan25.32080.059125.2160.0609nannannannannannannannannannanFalse0.2701960.0147076nannannannanFalse0.2975770.0166914nannannannanFalsenannannannannannanFalsenannannannannannanFalse
6W3m0m1_8312214.589941453.103412240.0295821nannan24.95930.028123.60150.0113nannan22.74740.0103nannannannannannanFalse0.3769470.00975578nannannannanFalse1.316440.0137011nannannannanFalsenannannannannannanFalse2.890940.0274254nannannannanFalse
7W3m0m1_8315214.661784853.103374010.007821524.72520.034524.51060.020623.69430.0119nannan23.27660.01710.4676480.0148598nannannannanFalse0.569850.0108119nannannannanFalse1.208590.0132466nannannannanFalsenannannannannannanFalse1.775660.0279661nannannannanFalse
8W3m0m1_8320214.623072753.10344850.0871178nannannannannannannannannannannannannannannannanFalsenannannannannannanFalsenannannannannannanFalsenannannannannannanFalsenannannannannannanFalse
9W3m0m1_8329214.364807553.103502950.0139106nannannannan25.8570.0724nannan25.03350.0766nannannannannannanFalsenannannannannannanFalse0.1648920.0109955nannannannanFalsenannannannannannanFalse0.3520460.0248373nannannannanFalse

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 466735 sources.
The cleaned catalogue has 466731 sources (4 removed).
The cleaned catalogue has 4 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_EGS.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.054139660204555184 arcsec
Dec correction: -0.043344491388097595 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)))
5159 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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