EGS master catalogue

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

CFHTLS has both a wide area across EGS 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: 
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 = "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_EGS.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
01330_132328217.28897453.6580610.528.3134.60926.0710.34425.5790.41424.080.146nannan26.6190.70925.8760.2126.2880.5824.6460.179nannan0.01717120.0728924False0.1353940.0428978False0.213010.0812224False0.8472270.113927FalsenannanFalse0.08173350.05337310.1620320.03133970.1108660.05922480.5030370.0829333nannan
11330_132406217.28674353.6583620.01nannan24.990.2324.0970.1923.7440.19322.4050.20425.4570.24624.980.09324.7240.13724.6580.17524.0060.361nannanFalse0.3664380.0776254False0.8340650.145958False1.154520.205226False3.962780.74457False0.2383410.05400210.3698280.03167810.4681660.05907390.4975070.08018870.9069840.301566
21330_132843217.28560253.6602060.3526.6330.714nannannannan27.2522.039nannan26.5710.677nannan29.3439.90726.9941.609nannan0.08068640.0530608FalsenannanFalsenannanFalse0.04562470.0856826FalsenannanFalse0.0854280.0532678nannan0.006649660.06067610.05786290.0857496nannan
31330_132939217.28375353.6606070.46nannannannannannannannan26.3444.104nannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalse0.1052930.398Falsenannannannannannannannannannan
41330_132793217.28348853.6599690.02nannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannan
51330_133082217.28362453.6612010.45nannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannan
61330_133430217.28182353.6628070.6926.5520.87525.840.26725.8170.49826.170.9325.6272.12226.5920.68825.6770.17425.7050.33925.5160.38625.6741.6760.08693610.0700622False0.1674940.0411895False0.171080.0784703False0.1235950.105867False0.2037980.398309False0.08379150.05309630.1946260.03119070.1896710.05922090.2257350.08025320.1951640.301266
71330_133019217.28246553.660960.37nannannannannannannannan23.6140.476nannannannannannannannan23.8290.307nannanFalsenannanFalsenannanFalsenannanFalse1.301370.570535Falsenannannannannannannannan1.067580.301866
81330_132820217.28220553.6601110.0227.9533.428nannannannannannannannan26.8750.909nannannannannannan25.6411.6290.02392220.0755295FalsenannanFalsenannanFalsenannanFalsenannanFalse0.06456540.0540554nannannannannannan0.2011870.301853
91330_133111217.28152653.6613650.35nannannannannannannannan25.9353.338nannannannannannan27.031.57324.7730.731nannanFalsenannanFalsenannanFalsenannanFalse0.1534620.471804Falsenannannannannannan0.05597570.08109690.4475070.301296

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 780583 sources.
The cleaned catalogue has 780559 sources (24 removed).
The cleaned catalogue has 24 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.14894731443746423 arcsec
Dec correction: -0.04603114763597205 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)))
9254 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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