HATLAS-SGP 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: 
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, 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_HATLAS-SGP.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: divide by zero encountered in log10
  magnitudes = 2.5 * (23 - np.log10(fluxes)) - 48.6
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:76: RuntimeWarning: invalid value encountered in log10
  magnitudes = 2.5 * (23 - np.log10(fluxes)) - 48.6
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:80: RuntimeWarning: invalid value encountered in true_divide
  errors = 2.5 / np.log(10) * errors_on_fluxes / fluxes
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 J000026.12-313822.170.108820584302-31.63949142140.014022816.93870.020597217.73370.015706817.72460.014937316.79010.01485864.11350.27499312.09030.12272224.48220.10513836.13720.220867608.86211.5506False292.7654.23528False295.2414.06186False698.1689.5546False22.36450.07258321.19390.011020820.42790.0046626620.00510.00663591
1KIDS J235812.48-313717.43359.552019286-31.62150716060.84471615.37140.00122288nannannannannannan221.2650.832352nannannannannannan2578.922.90468FalsenannanFalsenannanFalsenannanFalse18.03770.0040843nannannannannannan
2KIDS J235812.76-313720.51359.553169232-31.62236412190.98399915.42550.00107514nannannannannannan116.1520.6041nannannannannannan2453.672.42973FalsenannanFalsenannanFalsenannanFalse18.73740.00564687nannannannannannan
3KIDS J235805.17-313749.95359.521537496-31.63054091420.02862818.54810.015695616.79690.0013623516.02320.00069755215.69310.0011118231.21950.321258177.7950.247222373.8950.268671517.690.471311138.2821.99902False693.8090.87057False1414.880.909016False1917.671.96373False20.16390.011172518.27520.001509717.46810.00078018217.11480.000988467
4KIDS J235957.31-313822.63359.988804035-31.63961903490.97924315.76230.00154891nannannannannannan1686.592.03184nannannannannannan1799.222.56676FalsenannanFalsenannanFalsenannanFalse15.83250.00130799nannannannannannan
5KIDS J000053.94-313756.930.22475244384-31.6324799290.028744420.44220.044052319.14670.0050709818.49620.0028005318.13040.0045843810.36380.29812130.1630.1284654.45990.12794879.80370.25900524.16210.980344False79.67140.372109False145.0570.374158False203.1690.857856False21.36120.031231820.20130.0046240219.55980.0025508219.14490.00352378
6KIDS J235907.14-313821.45359.779740448-31.63929178520.97740316.79230.00249413nannannannannannan624.7591.06752nannannannannannan696.7351.60053FalsenannanFalsenannanFalsenannanFalse16.91070.00185519nannannannannannan
7KIDS J000212.69-313817.320.552891244908-31.63814382360.94489518.27880.0040340417.18810.000936475nannan16.59850.000837783170.7990.573301481.7320.41674nannan828.4860.545636177.2060.658408False483.8950.417372FalsenannanFalse832.9210.642704False18.31880.0036443617.1930.000939258nannan16.60430.00071506
8KIDS J235934.61-313806.83359.894189366-31.6352306180.000323485nannan22.34880.15116720.68920.032845319.45910.0245017nannan0.6547720.1000042.962840.1201846.458090.258299nannanFalse4.17340.581063False19.24570.582216False59.75171.34841Falsenannan24.35980.16582522.72070.044041821.87470.0434252
9KIDS J235757.92-313819.86359.491339438-31.63884899540.02862320.50570.047226318.92950.0052997218.21120.0024753117.83930.003888076.9760.25838827.56690.14433351.89360.12953571.90180.24948222.78920.991261False97.31660.475024False188.5880.429951False265.640.951266False21.7910.040215320.2990.0056846219.61220.0027101719.25820.00376725

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 9667089 sources.
The cleaned catalogue has 9666966 sources (123 removed).
The cleaned catalogue has 123 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_SGP.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, near_ra0=True)
In [10]:
delta_ra, delta_dec =  astrometric_correction(
    SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]),
    gaia_coords, near_ra0=True
)

print("RA correction: {}".format(delta_ra))
print("Dec correction: {}".format(delta_dec))
RA correction: 0.11440588580171607 arcsec
Dec correction: -0.12961663829287318 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, near_ra0=True)

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)))
240146 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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