GAMA-09 master catalogue

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

Isaac Newton Telescope / Wide Field Camera (INT/WFC) 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_GAMA-09.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:])))
        
        # 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_uflag_cfhtlens_uf_cfhtlens_gferr_cfhtlens_gflag_cfhtlens_gf_cfhtlens_rferr_cfhtlens_rflag_cfhtlens_rf_cfhtlens_iferr_cfhtlens_iflag_cfhtlens_if_cfhtlens_zferr_cfhtlens_zflag_cfhtlens_z
0W2m0p2_210647133.0356386-1.9556687690.65791326.04540.080425.07730.021425.03850.03824.79630.027524.28670.06830.1386240.0102653False0.3381270.00666454False0.3504290.0122648False0.4380050.011094False0.7003580.0440572False
1W2m0p2_210971133.0336776-1.9550689690.027894723.39760.010722.92970.004322.69040.006221.98140.003221.80270.00911.58840.0156538False2.44410.00967974False3.046770.0173983False5.853830.017253False6.901120.0578411False
2W2m0p2_211087133.0324869-1.9539359940.097675426.41520.113325.39590.027924.9710.036424.0270.014823.7070.04220.09860990.0102903False0.2521390.00647917False0.3729060.0125019False0.889610.0121265False1.194540.0464288False
3W2m0p2_211139133.036176-1.9537742540.012234925.11980.033724.76610.014924.52210.022424.07410.013623.69540.03720.3251470.0100922False0.450360.00618047False0.5638450.0116328False0.8518440.0106702False1.207370.0413674False
4W2m0p2_211150133.0332197-1.953730550.665074nannan25.99880.055525.98580.098625.42310.054nannannannanFalse0.1447040.00739687False0.1464470.0132994False0.2459010.0122301FalsenannanFalse
5W2m0p2_211262133.0320383-1.9533257120.525169nannannannannannan25.27480.0637nannannannanFalsenannanFalsenannanFalse0.281890.0165385FalsenannanFalse
6W2m0p2_211277133.0283815-1.9540717850.01020524.39820.024623.9230.009923.35030.011122.69080.005822.34680.01540.6320050.0143196False0.9790390.00892711False1.659130.0169621False3.045650.0162698False4.1810.0593029False
7W2m0p2_211295133.03748-1.953182530.29763526.97920.1685nannan25.4590.055424.13540.014623.37130.02940.0586570.00910322FalsenannanFalse0.2379030.0121391False0.8050810.010826False1.627350.044066False
8W2m0p2_211296133.0363248-1.9532943250.9793526.59470.116424.9540.016623.81930.012222.52170.004321.83710.00740.08358340.00896084False0.3787910.0057914False1.077160.0121036False3.558940.014095False6.68590.0455688False
9W2m0p2_211484133.0398925-1.952337070.43235725.57060.053925.31120.025625.16910.04224.83230.02924.29420.06840.2146640.0106567False0.2725960.00642741False0.3107130.0120195False0.4237210.0113176False0.6955360.0438179False

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 569071 sources.
The cleaned catalogue has 569066 sources (5 removed).
The cleaned catalogue has 5 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.059877701926325244 arcsec
Dec correction: -0.04593033190820606 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)))
8602 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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