COSMOS master catalogue¶

Preparation of KIDS/VST data¶

Kilo Degree Survey/VLT Survey Telescope catalogue: the catalogue comes from dmu0_KIDS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The aperture corrected aperture magnitude in each band (10 pixels = 2")
  • The Petrosian magnitude to be used as total magnitude (no “auto” magnitude is provided).

We take 2014 as the observation year from a typical image header.

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, flux_to_mag
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL  = "kids_ra"
DEC_COL = "kids_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'ID': "kids_id",
        'RAJ2000': "kids_ra",
        'DECJ2000': "kids_dec",
        'CLASS_STAR':  "kids_stellarity",
        'MAG_AUTO_U': "m_kids_u", 
        'MAGERR_AUTO_U': "merr_kids_u", 
        'MAG_AUTO_G': "m_kids_g", 
        'MAGERR_AUTO_G': "merr_kids_g", 
        'MAG_AUTO_R': "m_kids_r", 
        'MAGERR_AUTO_R': "merr_kids_r", 
        'MAG_AUTO_I': "m_kids_i", 
        'MAGERR_AUTO_I': "merr_kids_i", 
        'FLUX_APERCOR_10_U': "f_ap_kids_u",
        'FLUXERR_APERCOR_10_U': "ferr_ap_kids_u",
        'FLUX_APERCOR_10_G': "f_ap_kids_g",
        'FLUXERR_APERCOR_10_G': "ferr_ap_kids_g",
        'FLUX_APERCOR_10_R': "f_ap_kids_r",
        'FLUXERR_APERCOR_10_R': "ferr_ap_kids_r",
        'FLUX_APERCOR_10_I': "f_ap_kids_i",
        'FLUXERR_APERCOR_10_I': "ferr_ap_kids_i"

    })


catalogue = Table.read("../../dmu0/dmu0_KIDS/data/KIDS-DR3_COSMOS.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2014 #A range of observation dates from 2011 to 2015.

# 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:])

        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:])))
    if col.startswith('f_'):
        
        errcol = "ferr{}".format(col[1:])
        
        #Convert fluxes in maggies to uJy
        catalogue[col] *= 3631. * 1.e6
        catalogue[col].unit = 'uJy'
        catalogue[errcol] *= 3631. * 1.e6
        catalogue[errcol].unit = 'uJy'

        mag, mag_error = flux_to_mag(np.array(catalogue[col]) * 1.e-6, 
                                     np.array(catalogue[errcol]) * 1.e-6)
        
        # Magnitudes are added
        catalogue.add_column(Column(mag, name="m{}".format(col[1:])))
        catalogue.add_column(Column(mag_error, name="m{}".format(errcol[1:])))
        
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:76: RuntimeWarning: invalid value encountered in log10
  magnitudes = 2.5 * (23 - np.log10(fluxes)) - 48.6
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxkids_idkids_rakids_deckids_stellaritym_kids_umerr_kids_um_kids_gmerr_kids_gm_kids_rmerr_kids_rm_kids_imerr_kids_if_ap_kids_uferr_ap_kids_uf_ap_kids_gferr_ap_kids_gf_ap_kids_rferr_ap_kids_rf_ap_kids_iferr_ap_kids_if_kids_uferr_kids_uflag_kids_uf_kids_gferr_kids_gflag_kids_gf_kids_rferr_kids_rflag_kids_rf_kids_iferr_kids_iflag_kids_im_ap_kids_umerr_ap_kids_um_ap_kids_gmerr_ap_kids_gm_ap_kids_rmerr_ap_kids_rm_ap_kids_imerr_ap_kids_i
degdegmagmagmagmagmagmagmagmaguJyuJyuJyuJyuJyuJyuJyuJy
0KIDS J095828.65+014133.82149.6193919211.692727314320.000349136nannan18.08890.015277317.95430.012965917.6710.0365009nannan4.960960.1593385.682870.1284686.064260.482844nannanFalse211.0682.96993False238.9442.85348False310.1710.4274Falsenannan22.16110.03487222.01360.024544321.94310.0864476
1KIDS J095935.70+014121.64149.8987704371.689343294450.87534516.57020.00339415nannannannannannan803.851.90665nannannannannannan854.9012.67253FalsenannanFalsenannanFalsenannanFalse16.63710.00257526nannannannannannan
2KIDS J095820.45+014108.43149.5851935251.685674297010.98097316.1140.00224911nannannannannannan1128.782.2189nannannannannannan1301.322.6957FalsenannanFalsenannanFalsenannanFalse16.26850.00213428nannannannannannan
3KIDS J100142.36+014057.92150.4264952821.682756825410.0286447nannan19.18480.01267717.86170.0037853517.36990.00856885nannan23.49130.19430880.9520.200246134.9520.598942nannanFalse76.92530.898176False260.2070.907195False409.3033.2303Falsenannan20.47270.0089806819.12940.0026857218.57460.0048187
4KIDS J095951.40+014049.31149.9641746281.680363089210.028619119.63910.072532519.7290.02727517.88240.0048203717.29520.01038671.317460.3814089.746050.17277954.01470.176987103.0950.58042550.62483.38199False46.60081.17067False255.31.13346False438.474.19464False23.60070.31432421.42790.019248119.56870.0035575718.86690.00611267
5KIDS J095905.47+014050.37149.7727976611.680657138140.91646421.6850.083321518.79320.0031491617.44890.0010664116.87720.001685168.295110.356619112.0420.313766381.8240.352298673.2270.8552367.691450.590257False110.3320.320016False380.5660.373794False644.3591.00011False21.60290.046677418.77660.0030405417.44530.0010017816.82960.00137927
6KIDS J100104.26+014048.69150.2677357421.680190391360.028674321.81210.17023719.9480.012516218.52620.0034389118.02410.007643912.723890.33289717.52970.18395169.49750.188674115.9230.5930946.841341.07268False38.08740.439068False141.0980.446907False224.0611.57746False22.8120.13269220.79060.011393419.29510.0029475918.73960.00555492
7KIDS J100009.85+014044.87150.0410473721.679130822460.0286546nannan19.42470.015227118.13790.004483917.64990.0113336nannan17.94270.19103764.94870.186073105.4710.582475nannanFalse61.67570.86498False201.7550.833211False316.2673.30139Falsenannan20.76530.011559919.36860.0031105518.84220.0059961
8KIDS J100119.37+014053.55150.3307107921.681541935830.998776nannan15.97780.00107028nannannannannannan1265.081.34586nannannannannannanFalse1475.241.45424FalsenannanFalsenannanFalsenannan16.14470.00115506nannannannan
9KIDS J095913.79+014045.00149.8074534671.679165634140.88105nannan19.97350.0073495418.52290.0020572217.04240.00174402nannan38.6440.225327144.9490.236308596.060.823679nannanFalse37.20520.251848False141.530.268167False553.4250.888967Falsenannan19.93230.0063307518.4970.0017700616.96180.00150035

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_kids_u', 
             'merr_ap_kids_g', 
             'merr_ap_kids_r', 
             'merr_ap_kids_i']
FLAG_NAME = 'kids_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 152946 sources.
The cleaned catalogue has 152946 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.06793673346123796 arcsec
Dec correction: -0.05321466159404764 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 = "kids_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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