COSMOS master catalogue¶

Preparation of UKIRT Infrared Deep Sky Survey / Large Area Survey (UKIDSS/LAS)¶

Information about UKIDSS can be found at http://www.ukidss.org/surveys/surveys.html

The catalogue comes from dmu0_UKIDSS-LAS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The magnitude for each band in aperture 3 (2 arcsec).
  • The hall magnitude is described as the total magnitude.

J band magnitudes are available in two eopchs. We take the first arbitrarily.

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

Band AB offset
Y 0.634
J 0.938
H 1.379
K 1.900

Each source is associated with an epoch. These range between 2005 and 2007. We take 2006 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: 
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 = "las_ra"
DEC_COL = "las_dec"

I - Column selection¶

In [4]:
#Is the following standard (different names for radec vs mag)?
imported_columns = OrderedDict({
        'SOURCEID': 'las_id',
        'RA': 'las_ra',
        'Dec': 'las_dec',
        'YHALLMAG': 'm_ukidss_y',
        'YHALLMAGERR': 'merr_ukidss_y',
        'YAPERMAG3': 'm_ap_ukidss_y',
        'YAPERMAG3ERR': 'merr_ap_ukidss_y',
        'J_1HALLMAG': 'm_ukidss_j',
        'J_1HALLMAGERR': 'merr_ukidss_j',
        'J_1APERMAG3': 'm_ap_ukidss_j',
        'J_1APERMAG3ERR': 'merr_ap_ukidss_j',
        'HAPERMAG3': 'm_ap_ukidss_h',
        'HAPERMAG3ERR': 'merr_ap_ukidss_h',
        'HHALLMAG': 'm_ukidss_h',
        'HHALLMAGERR': 'merr_ukidss_h',
        'KAPERMAG3': 'm_ap_ukidss_k',
        'KAPERMAG3ERR': 'merr_ap_ukidss_k',
        'KHALLMAG': 'm_ukidss_k',
        'KHALLMAGERR': 'merr_ukidss_k',
        'PSTAR': 'las_stellarity'
    })

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

#Epochs between 2005 and 2007. Rough average:
epoch = 2006

# Clean table metadata
catalogue.meta = None
WARNING: UnitsWarning: 'RADIANS' did not parse as fits unit: At col 0, Unit 'RADIANS' 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:])
        
        # LAS 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('y'):
            catalogue[col] += 0.634
        elif 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>
idxlas_idlas_ralas_decm_ukidss_ymerr_ukidss_ym_ap_ukidss_ymerr_ap_ukidss_ym_ukidss_jmerr_ukidss_jm_ap_ukidss_jmerr_ap_ukidss_jm_ap_ukidss_hmerr_ap_ukidss_hm_ukidss_hmerr_ukidss_hm_ap_ukidss_kmerr_ap_ukidss_km_ukidss_kmerr_ukidss_klas_stellarityf_ukidss_yferr_ukidss_yflag_ukidss_yf_ap_ukidss_yferr_ap_ukidss_yf_ukidss_jferr_ukidss_jflag_ukidss_jf_ap_ukidss_jferr_ap_ukidss_jf_ap_ukidss_hferr_ap_ukidss_hf_ukidss_hferr_ukidss_hflag_ukidss_hf_ap_ukidss_kferr_ap_ukidss_kf_ukidss_kferr_ukidss_kflag_ukidss_k
0433845436807149.9430043943.37550061639nannannannan20.58110.18487520.43990.177104nannannannannannannannan0.9nannanFalsenannan21.26053.62015False24.21263.94952nannannannanFalsenannannannanFalse
1433845436166149.9616878163.3694376827517.53410.016330917.45860.012695217.62940.018177117.54230.013878317.68430.022038317.71740.032834918.16840.027624418.24320.03754680.999981351.8565.29238False377.1944.41043322.2865.39563False349.214.46373306.396.21911297.1918.98767False196.174.99115183.1146.33242False
2433845436168149.9882928113.3706025065217.81960.021181717.73840.015470417.74810.021117917.66440.015235917.49640.018635817.48440.028484917.82840.02060417.88120.02800920.999981270.495.277False291.4884.15334288.8965.61913False312.064.37907364.2966.25286368.3219.66309False268.3015.09153255.5676.59298False
3433845436187149.9515514523.3763537751218.85970.12011919.69970.076700118.76630.080187719.36580.066934318.88170.063859918.18880.094715718.66690.042668817.82150.0553459.52581e-06103.78211.4818False47.87443.38201113.18.35307False65.11334.01415101.7035.98188192.5216.7948False123.9464.87099270.03413.7649False
4433845436930149.9880208123.37863159768nannannannannannannannan19.87660.15668719.9520.3043119.47620.087474419.6370.1931980.00306749nannanFalsenannannannanFalsenannan40.67735.870337.947710.636False58.82014.7389650.72339.02579False
5433845436224149.9957152043.385201721219.950.17311819.93440.093393819.60910.11885719.59260.080934219.32930.094881219.66110.21075419.69890.10662219.80910.1441760.99998138.01856.06195False38.56783.3175652.04195.6971False52.83943.9388167.34315.8850349.619.62986False47.91294.7051943.28685.74809False
6433845436237149.9862834863.3871076900418.84180.055611418.82180.036010218.88190.057913718.71280.03706318.64770.051284618.73380.088679618.87280.050800218.98290.07363650.999981105.5065.40401False107.4683.56434101.6775.42348False118.8154.0559126.165.95915116.5469.5191False102.5364.7975592.65026.28369False
7433845436247149.9912415663.38811469317.03810.011158116.98370.0091623417.1390.011743217.04380.0092467617.17680.014122217.21290.021175117.61320.01709517.69930.02396010.999981555.5975.70986False584.1694.9297506.3145.47625False552.7024.70713488.9776.36013472.9689.22428False327.1265.15061302.1866.66867False
8433845436255149.999701283.3886998063415.43370.0040324815.40910.0036663315.5360.0036461215.48430.0031525415.58540.004065615.61990.0053250516.0170.0050514516.08250.006162310.9999812435.079.04398False2490.838.411082216.137.4422False2324.256.748672117.657.929642051.4210.0613False1422.986.620481339.697.60366False
9433845436985149.946689323.3696568889nannannannannannannannannannannannan20.19340.16881919.65780.1928970.05nannanFalsenannannannanFalsenannannannannannanFalse30.38364.7242849.76098.84077False

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_ukidss_j', 'merr_ap_ukidss_k']
FLAG_NAME = 'las_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 78235 sources.
The cleaned catalogue has 78114 sources (121 removed).
The cleaned catalogue has 118 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, 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.084222478335505 arcsec
Dec correction: -0.06767946427048699 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 = "las_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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