XMM-LSS master catalogue¶

Preparation of UKIRT Infrared Deep Sky Survey / Ultra Deep Survey (UKIDSS/DXS)¶

The catalogue comes from dmu0_UKIDSS-UDS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The magnitude for each band in apertude 3 (2 arcsec).
  • The kron magnitude to be used as total magnitude (no “auto” magnitude is provided).

The magnitudes are “Vega like”. The AB offsets are given by Hewett et al. (2016):

Band AB offset
J 0.938
H 1.379
K 1.900

A query to the UKIDSS database with 242.9+55.071 position returns a list of images taken between 2007 and 2009. Let's take 2008 for the epoch. TODO: Update for UDS.

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

RA_COL = "uds_ra"
DEC_COL = "uds_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'sourceid': 'uds_id',
        'RA': 'uds_ra',
        'Dec': 'uds_dec',
        'JAPERMAG3': 'm_ap_uds_j',
        'JAPERMAG3ERR': 'merr_ap_uds_j',
        'JKRONMAG': 'm_uds_j',
        'JKRONMAGERR': 'merr_uds_j',
        'HAPERMAG3': 'm_ap_uds_h',
        'HAPERMAG3ERR': 'merr_ap_uds_h',
        'HKRONMAG': 'm_uds_h',
        'HKRONMAGERR': 'merr_uds_h',
        'KAPERMAG3': 'm_ap_uds_k',
        'KAPERMAG3ERR': 'merr_ap_uds_k',
        'KKRONMAG': 'm_uds_k',
         'KKRONMAGERR': 'merr_uds_k',
         'PSTAR': 'uds_stellarity'
    })

catalogue = Table.read(
    "../../dmu0/dmu0_UKIDSS-UDS/data/UKIDSS-UDS_XMM-LSS.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2008

# Clean table metadata
catalogue.meta = None
WARNING: UnitsWarning: 'degrees' did not parse as fits unit: At col 0, Unit 'degrees' not supported by the FITS standard.  [astropy.units.core]
In [5]:
# Adding flux and band-flag columns
for col in catalogue.colnames:
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        
        # DXS uses a huge negative number for missing values
        catalogue[col][catalogue[col] < -100] = np.nan
        catalogue[errcol][catalogue[errcol] < -100] = np.nan
        
        # Vega to AB correction
        if col.endswith('j'):
            catalogue[col] += 0.938
        elif col.endswith('h'):
            catalogue[col] += 1.379
        elif col.endswith('k'):
            catalogue[col] += 1.900
        else:
            print("{} column has wrong band...".format(col))

        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)
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxuds_iduds_rauds_decm_ap_uds_jmerr_ap_uds_jm_uds_jmerr_uds_jm_ap_uds_hmerr_ap_uds_hm_uds_hmerr_uds_hm_ap_uds_kmerr_ap_uds_km_uds_kmerr_uds_kuds_stellarityf_ap_uds_jferr_ap_uds_jf_uds_jferr_uds_jflag_uds_jf_ap_uds_hferr_ap_uds_hf_uds_hferr_uds_hflag_uds_hf_ap_uds_kferr_ap_uds_kf_uds_kferr_uds_kflag_uds_k
degreesdegrees
045097156608134.367870813-5.56541071827nannannannannannannannan20.06440.047561418.19740.0255590.00703433nannannannanFalsenannannannanFalse34.21811.49895191.0054.4964False
145097156608234.7445474465-5.56147712705nannannannannannannannan13.80050.0027698613.68020.002592860.695518nannannannanFalsenannannannanFalse10960.127.960612243.629.2391False
245097156608334.3047073198-5.5622364215319.02750.089717517.29390.0397843nannannannan18.63030.021448916.9770.01122910.0011008488.92297.34795438.9916.0858FalsenannannannanFalse128.1952.53251587.7446.07865False
345097156608434.3003289695-5.56557280323nannannannannannannannan21.79370.13744621.54410.1342290.00703433nannannannanFalsenannannannanFalse6.958740.8809268.756811.0826False
445097156608534.3562070077-5.56551766795nannannannannannannannan22.85240.32959522.80940.3103510.00703433nannannannanFalsenannannannanFalse2.624470.7967052.730540.780508False
545097156608634.2901770877-5.56547068484nannannannannannannannan24.71111.7435724.36291.221330.26296nannannannanFalsenannannannanFalse0.4737510.7607890.6529080.734446False
645097156608734.3925766316-5.56549696485nannannannannannannannan23.32210.49314123.3910.5215360.00703433nannannannanFalsenannannannanFalse1.702730.7733791.598080.767642False
745097156608834.367499354-5.56542091583nannannannannannannannan20.39230.056956619.04280.03310510.00703433nannannannanFalsenannannannanFalse25.2981.3271187.6722.6732False
845097156608934.0377303354-5.56527529519nannannannannannannannan21.17060.21645421.02240.2010290.00703433nannannannanFalsenannannannanFalse12.35222.4625614.15952.62169False
945097156609034.3685481147-5.565392882nannannannannannannannan20.41930.058085518.70350.02769270.00703433nannannannanFalsenannannannanFalse24.67531.3201119.8413.05666False

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_uds_j', 'merr_ap_uds_h', 'merr_ap_uds_k']
FLAG_NAME = 'uds_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 296026 sources.
The cleaned catalogue has 296026 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_XMM-LSS.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.12895760060445127 arcsec
Dec correction: -0.15744215684776464 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 = "uds_flag_gaia"

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

V - Saving to disk¶

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