GAMA-09 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: 
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_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_cfhtls_u",
        'e_umaga': "merr_cfhtls_u",
        'gmaga': "m_cfhtls_g",
        'e_gmaga': "merr_cfhtls_g",
        'rmaga': "m_cfhtls_r",
        'e_rmaga': "merr_cfhtls_r",
        'imaga': "m_cfhtls_i",
        'e_imaga': "merr_cfhtls_i",
        'zmaga': "m_cfhtls_z",
        'e_zmaga': "merr_cfhtls_z",
        'umag': "m_ap_cfhtls_u",
        'e_umag': "merr_ap_cfhtls_u",
        'gmag': "m_ap_cfhtls_g",
        'e_gmag': "merr_ap_cfhtls_g",
        'rmag': "m_ap_cfhtls_r",
        'e_rmag': "merr_ap_cfhtls_r",
        'imag': "m_ap_cfhtls_i",
        'e_imag': "merr_ap_cfhtls_i",
        'zmag': "m_ap_cfhtls_z",
        'e_zmag': "merr_ap_cfhtls_z"
        
    })


catalogue = Table.read("../../dmu0/dmu0_CFHTLS/data/CFHTLS-WIDE_GAMA-09.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_cfhtls_umerr_cfhtls_um_cfhtls_gmerr_cfhtls_gm_cfhtls_rmerr_cfhtls_rm_cfhtls_imerr_cfhtls_im_cfhtls_zmerr_cfhtls_zm_ap_cfhtls_umerr_ap_cfhtls_um_ap_cfhtls_gmerr_ap_cfhtls_gm_ap_cfhtls_rmerr_ap_cfhtls_rm_ap_cfhtls_imerr_ap_cfhtls_im_ap_cfhtls_zmerr_ap_cfhtls_zf_cfhtls_uferr_cfhtls_uflag_cfhtls_uf_cfhtls_gferr_cfhtls_gflag_cfhtls_gf_cfhtls_rferr_cfhtls_rflag_cfhtls_rf_cfhtls_iferr_cfhtls_iflag_cfhtls_if_cfhtls_zferr_cfhtls_zflag_cfhtls_zf_ap_cfhtls_uferr_ap_cfhtls_uf_ap_cfhtls_gferr_ap_cfhtls_gf_ap_cfhtls_rferr_ap_cfhtls_rf_ap_cfhtls_iferr_ap_cfhtls_if_ap_cfhtls_zferr_ap_cfhtls_z
degdegmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmag
01210_186805132.065848-2.1240480.4625.6720.34225.9660.30825.8940.49826.1920.976nannan25.6450.33425.9330.29925.8070.45926.090.887nannan0.1955240.0615888False0.1491420.0423084False0.1593680.073098False0.1211160.108874FalsenannanFalse0.2004470.06166260.1537440.04233960.1726630.07299420.1330450.108692nannan
11210_186722132.067068-2.1244440.7126.720.94925.7190.26125.5560.39nannan25.0951.01626.6180.80925.9570.30425.660.40226.4461.23325.0170.8830.07447320.0650942False0.1872410.0450107False0.217570.078152FalsenannanFalse0.332660.311293False0.08180880.06095710.1503830.04210640.1976970.07319840.09585180.1088530.3574370.290694
21210_186926132.066104-2.1235570.626.81.05626.3350.47525.3730.33824.7960.297nannan26.2990.60726.3060.41925.3610.30425.0720.34726.6734.0650.06918310.0672883False0.106170.0464482False0.2575130.0801664False0.4381270.119848FalsenannanFalse0.1097490.0613570.1090440.04208140.2603750.07290360.3397810.1085940.07776780.291163
31210_186792132.067672-2.1240650.89nannan24.8970.15724.5280.19425.8971.01924.7190.9226.4870.7224.9930.12524.7780.17826.0030.81924.2360.43nannanFalse0.3992090.0577265False0.5607890.100202False0.1589280.149159False0.4703270.398532False0.09229960.0612080.3654260.04207130.4454510.0730290.1441450.1087320.7338370.290632
41210_187561132.064531-2.1209010.9325.430.27624.8440.11624.6090.19824.2420.20923.2770.18825.4730.23724.9890.10724.6460.16924.3240.18423.7380.2310.2443430.0621133False0.4191790.0447851False0.5204750.0949164False0.7297930.140482False1.775010.30735False0.2348550.05126540.3667750.03614590.5030370.07830010.6767060.1146821.160910.246994
51210_187784132.063017-2.12010.8225.7530.35325.6140.18225.5360.40425.4560.47924.5020.51325.760.35725.6050.18125.5520.41125.3950.45424.2940.4250.1814680.0589997False0.2062530.0345738False0.2216150.0824626False0.2385610.105247False0.574380.271389False0.1803020.05928480.207970.034670.2183740.08266420.2523480.1055190.6956640.27231
61210_187747132.065303-2.1204480.0524.8460.22723.9520.06823.720.11523.4140.12623.2020.23925.1350.17524.2780.05323.9390.08423.5350.08223.5760.1960.4184080.0874785False0.9532350.0597014False1.180320.125018False1.564590.181571False1.901950.418672False0.3206270.05167890.7059920.03446290.9647180.07463721.399590.1057041.347720.243294
71210_187559132.066571-2.1209410.5826.5120.63326.6280.49427.6912.60526.9551.93725.2750.97326.6320.70726.6620.5127.3331.8727.3372.74925.351.040.09019870.0525871False0.08105870.036881False0.03045090.0730606False0.05997910.107005False0.2818380.252574False0.08076070.0525890.07855970.03690160.04234480.07293180.04218910.1068190.2630270.251947
81210_188153132.067689-2.1184120.5726.1320.53724.9750.10624.310.10323.2040.06622.6280.09226.1450.50925.0440.10624.2870.09423.2380.06322.6650.0890.1279970.0633067False0.3715350.0362728False0.6854880.0650299False1.898450.115404False3.2270.273441False0.1264740.05929160.3486580.03403930.7001640.06061821.839920.1067623.118890.255661
91210_188297132.068746-2.1177380.9125.5880.31725.3990.14924.8510.17724.4960.20723.0850.1525.5440.30625.3850.14724.8320.17424.4680.20223.0820.150.2112520.0616787False0.251420.0345034False0.4164850.0678967False0.5775630.110115False2.118360.292663False0.2199880.06200070.2546830.0344820.4238380.06792420.5926520.1102622.124220.293472

II - Removal of duplicated sources

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_cfhtls_u',
            'merr_ap_cfhtls_g',
            'merr_ap_cfhtls_r',
            'merr_ap_cfhtls_i',
            'merr_ap_cfhtls_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 1044973 sources.
The cleaned catalogue has 1044965 sources (8 removed).
The cleaned catalogue has 8 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_GAMA-09.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.04861379154590395 arcsec
Dec correction: -0.06012614039372366 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)))
20482 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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