COSMOS master catalogue¶

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

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_ra"
DEC_COL = "cfhtls_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'cfhtls': "cfhtls_id",
        'raj2000': "cfhtls_ra",
        'dej2000': "cfhtls_dec",
        'gcl':  "cfhtls_stellarity",
        'umaga': "m_megacam_u",
        'e_umaga': "merr_megacam_u",
        'gmaga': "m_megacam_g",
        'e_gmaga': "merr_megacam_g",
        'rmaga': "m_megacam_r",
        'e_rmaga': "merr_megacam_r",
        'imaga': "m_megacam_i",
        'e_imaga': "merr_megacam_i",
        'zmaga': "m_megacam_z",
        'e_zmaga': "merr_megacam_z",
        'umag': "m_ap_megacam_u",
        'e_umag': "merr_ap_megacam_u",
        'gmag': "m_ap_megacam_g",
        'e_gmag': "merr_ap_megacam_g",
        'rmag': "m_ap_megacam_r",
        'e_rmag': "merr_ap_megacam_r",
        'imag': "m_ap_megacam_i",
        'e_imag': "merr_ap_megacam_i",
        'zmag': "m_ap_megacam_z",
        'e_zmag': "merr_ap_megacam_z"
        
    })


catalogue = Table.read("../../dmu0/dmu0_CFHTLS/data/CFHTLS-DEEP_COSMOS.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_idcfhtls_racfhtls_deccfhtls_stellaritym_megacam_umerr_megacam_um_megacam_gmerr_megacam_gm_megacam_rmerr_megacam_rm_megacam_imerr_megacam_im_megacam_zmerr_megacam_zm_ap_megacam_umerr_ap_megacam_um_ap_megacam_gmerr_ap_megacam_gm_ap_megacam_rmerr_ap_megacam_rm_ap_megacam_imerr_ap_megacam_im_ap_megacam_zmerr_ap_megacam_zf_megacam_uferr_megacam_uflag_megacam_uf_megacam_gferr_megacam_gflag_megacam_gf_megacam_rferr_megacam_rflag_megacam_rf_megacam_iferr_megacam_iflag_megacam_if_megacam_zferr_megacam_zflag_megacam_zf_ap_megacam_uferr_ap_megacam_uf_ap_megacam_gferr_ap_megacam_gf_ap_megacam_rferr_ap_megacam_rf_ap_megacam_iferr_ap_megacam_if_ap_megacam_zferr_ap_megacam_z
degdegmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmag
00200_0001316149.6173111.7113030.6428.6241.533nannannannannannannannan28.5611.447nannannannannannannannan0.01289440.0182061FalsenannanFalsenannanFalsenannanFalsenannanFalse0.01366470.0182114nannannannannannannannan
10200_0001703149.6172791.7121520.67nannannannannannannannannannannannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalsenannannannannannannannannannan
20200_0001184149.6215361.7110540.63nannannannan25.920.65nannannannannannannannan26.0520.741nannannannannannanFalsenannanFalse0.1555970.0931513FalsenannanFalsenannanFalsenannannannan0.1377840.0940359nannannannan
30200_0001689149.6218421.7120830.57nannan27.8382.14127.5141.967nannan25.6821.95nannan27.7141.91427.3991.772nannan25.9382.466nannanFalse0.0265950.0524436False0.03584260.0649352FalsenannanFalse0.1937310.347945Falsenannan0.02981260.05255540.03984740.0650338nannan0.1530380.347591
40200_0002042149.6209271.7127880.6424.9340.05123.8320.10823.0210.0923.0430.15nannan24.9390.05123.8390.10923.0330.09123.0250.148nannan0.3858340.0181237False1.064630.105901False2.246980.186259False2.201910.304206FalsenannanFalse0.3840610.01804041.057790.1061942.222280.1862592.238720.305167nannan
50200_0000397149.6241881.7092350.43nannannannannannannannan24.7280.29729.9845.233nannannannannannan24.6960.289nannanFalsenannanFalsenannanFalsenannanFalse0.4664440.127594False0.003684690.0177593nannannannannannan0.4803970.127871
60200_0001045149.624341.7107070.5127.1840.41528.3481.56527.4270.8725.4760.21125.6140.68126.9990.32928.2581.35427.1070.6125.470.19725.2930.4770.04857360.0185662False0.01662650.0239657False0.03883290.0311168False0.2342070.0455154False0.2062530.129367False0.0575970.01745310.01806340.02252650.05214350.02929580.2355050.04273090.2772040.121785
70200_0002388149.6250241.7118740.9722.870.0122.5150.00921.8350.00621.3970.00621.3590.01522.9570.00822.5940.00721.9060.00521.4720.00521.4180.0122.582260.0237835False3.580960.0296837False6.698850.0370192False10.02770.055415False10.38490.143472False2.383410.01756173.329660.02146716.27480.02889659.358370.04309699.835590.108707
80200_0001939149.624631.7125430.4726.0570.13826.2510.20526.0950.22625.4930.19327.0982.35926.060.13926.2630.20926.0760.22325.5060.19627.1372.4610.1371510.0174323False0.114710.0216586False0.1324340.0275667False0.2305680.0409857False0.05257750.114236False0.1367730.01751020.1134490.02183840.1347720.02768090.2278240.04112740.05072250.114971
90200_0002102149.6251911.712780.4825.4330.09724.9740.07324.9550.09325.1510.16626.4231.40725.5550.08525.1750.06925.1190.08525.2410.14225.3940.4290.2436690.0217694False0.3718770.0250033False0.3784430.0324159False0.3159370.0483041False0.09790390.126873False0.2177710.01704880.309030.01963930.3253870.02547390.2908040.03803330.2525810.0998005

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_megacam_u',
            'merr_ap_megacam_g',
            'merr_ap_megacam_r',
            'merr_ap_megacam_i',
            'merr_ap_megacam_z',]
FLAG_NAME = 'cfhtls_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 554830 sources.
The cleaned catalogue has 554830 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_COSMOS.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.07301163240072128 arcsec
Dec correction: -0.06591029994105213 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_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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