GAMA-12 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_GAMA-12.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 J113219.46-005835.36173.081088813-0.9764893355140.84540514.35150.00054718nannannannannannan2865.82.37214nannannannannannan6597.893.32515FalsenannanFalsenannanFalsenannanFalse15.25690.000898708nannannannannannan
1KIDS J113215.90-005840.82173.066239115-0.9780050289940.028626719.10190.020634117.59890.0028583116.64650.00122716.24150.002722898.443030.23440250.82140.163794143.3190.183881211.2380.45684883.02841.57793False331.4720.872633False796.8690.900547False1157.182.90207False21.58380.03014319.63490.0034992518.50920.0013930218.08810.00234815
2KIDS J113340.65-005842.45173.419366806-0.978457503390.941812nannannannan22.57970.054131624.69381.10083nannannannan2.61370.1066170.8514410.326595nannanFalsenannanFalse3.373910.168213False0.4813760.488067Falsenannannannan22.85690.04428924.07460.416466
3KIDS J113219.26-005836.01173.080233339-0.9766682539090.99219717.69240.00275188nannannannannannan146.4750.539883nannannannannannan304.1280.770835FalsenannanFalsenannanFalsenannanFalse18.48560.00400183nannannannannannan
4KIDS J113213.85-005807.68173.057689629-0.9687993209730.87037515.13150.000776921nannannannannannan2987.242.16713nannannannannannan3216.62.30171FalsenannanFalsenannanFalsenannanFalse15.21180.000787659nannannannannannan
5KIDS J113209.24-005633.18173.038519648-0.9425505335850.028629617.26370.005459915.45450.000622265nannan14.10120.00057777798.83740.39739518.0160.373521nannan1857.470.857652451.3642.2698False2388.881.36913FalsenannanFalse8308.114.42118False18.91270.0043653617.11410.000782881nannan15.72770.000501319
6KIDS J113344.94-005845.68173.437247571-0.9793544891030.89858116.86350.00211798nannannannannannan609.8170.957935nannannannannannan652.521.27289FalsenannanFalsenannanFalsenannanFalse16.9370.00170554nannannannannannan
7KIDS J113322.42-005849.09173.343410757-0.9803039650740.028645223.76850.61841921.52960.03913519.96380.0096727219.46140.02121390.6677890.2216174.929330.11048321.88070.11901534.89540.3576081.128720.642904False8.875090.319899False37.53940.334435False59.62421.16498False24.33840.36032122.1680.02433520.54990.005905620.04310.0111266
8KIDS J113332.33-005848.01173.384717638-0.9800028839810.90749521.70050.063977918.82660.0027701217.35890.00090585816.45410.0009979436.75480.272323106.7110.227502423.0980.317784962.9240.724237.582020.446777False106.9930.27298False413.4770.344975False951.3780.874449False21.8260.04377218.82950.0023147317.33390.00081548416.4410.000816598
9KIDS J113356.28-005843.52173.484480809-0.9787559933560.94636920.88970.02900118.06690.00155863nannannannan16.64380.244979213.2870.264376nannannannan15.99940.427359False215.3890.309203FalsenannanFalsenannanFalse20.84690.015980918.07760.00134581nannannannan

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 6582267 sources.
The cleaned catalogue has 6582157 sources (110 removed).
The cleaned catalogue has 110 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-12.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.12011726085461305 arcsec
Dec correction: -0.10001507929536801 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)))
196511 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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