Bootes master catalogue¶

Preparation of UKIRT Hemisphere Survey (UHS) data¶

The catalogue comes from dmu0_UHS. This is a J band only survey documented in https://arxiv.org/pdf/1707.09975.pdf

In the catalogue, we keep:

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

We don't know when the maps have been observed. We will use the year of the reference paper.

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 = "uhs_ra"
DEC_COL = "uhs_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'SOURCEID': "uhs_id",
        'RA': "uhs_ra",
        'DEC': "uhs_dec",
        'PSTAR':  "uhs_stellarity",
        'JPETROMAG': "m_wfcam_j", 
        'JPETROMAGERR': "merr_wfcam_j", 
        'JAPERMAG4': "m_ap_wfcam_j", 
        'JAPERMAG4ERR': "merr_ap_wfcam_j", 

    })


catalogue = Table.read("../../dmu0/dmu0_UHS/data/UHS-DR1_Bootes.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2011

# Clean table metadata
catalogue.meta = None
In [5]:
#Vega to AB
#Vega ZPT (1548.66 Jy) from http://svo2.cab.inta-csic.es/svo/theory/fps3/index.php?id=UKIRT/WFCAM.J

vega_to_ab = {
    "j": -2.5*np.log10(1548.66 / 3631)
}
print(vega_to_ab["j"])
0.925175419285
In [6]:
# Adding flux and band-flag columns
for col in catalogue.colnames:
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        
        # Some object have a magnitude to 0, we suppose this means missing value
        catalogue[col][catalogue[col] <= 0] = np.nan
        catalogue[errcol][catalogue[errcol] <= 0] = np.nan  
        
        # Convert magnitude from Vega to AB
        catalogue[col] += vega_to_ab[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:])))
        
# 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 [7]:
catalogue[:10].show_in_notebook()
Out[7]:
<Table masked=True length=10>
idxuhs_iduhs_rauhs_decuhs_stellaritym_wfcam_jmerr_wfcam_jm_ap_wfcam_jmerr_ap_wfcam_jf_wfcam_jferr_wfcam_jflag_wfcam_jf_ap_wfcam_jferr_ap_wfcam_j
degdeg
0459582192227218.54499988633.69883216830.99386519.02180.11237818.92520.061826389.38579.25179False97.70155.56352
1459582192228218.54449667233.78121271140.0030674916.07620.0078953216.04310.006201431347.459.7985False1389.227.93483
2459582192229218.54399326433.87290494270.0030674919.79160.2432820.06810.16451743.98899.85656False34.10195.16731
3459582192230218.54352192633.85221287950.0030674919.57030.18440420.03680.16018253.93629.16063False35.09735.17801
4459582192231218.54364957433.90409680260.99386520.50950.39972120.19430.18540722.70878.36036False30.35745.184
5459582192232218.54309066233.68768299060.0030674918.08530.083088818.85930.0584668211.78616.2075False103.8195.59064
6459582192233218.54301211933.76805723870.0030674918.80090.11338919.07860.0695208109.55911.4418False84.83135.43184
7459582192234218.54208291233.78979794970.0030674920.11040.30776120.35540.21767732.79729.29661False26.17265.24729
8459582192235218.54164107433.83766685670.0030674919.27770.14969619.36170.087376970.61669.73628False65.35955.25994
9459582192236218.5413319333.70713556510.0030674919.70290.19988720.08870.17480847.73438.78801False33.45945.3871

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [8]:
SORT_COLS = ['merr_ap_wfcam_j']
FLAG_NAME = 'uhs_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 110730 sources.
The cleaned catalogue has 102722 sources (8008 removed).
The cleaned catalogue has 7642 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 [9]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_Bootes.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [10]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)
In [11]:
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.10771486696512511 arcsec
Dec correction: -0.08473485251698776 arcsec
In [12]:
catalogue[RA_COL] +=  delta_ra.to(u.deg)
catalogue[DEC_COL] += delta_dec.to(u.deg)
In [13]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)

IV - Flagging Gaia objects¶

In [14]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [15]:
GAIA_FLAG_NAME = "uhs_flag_gaia"

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

V - Saving to disk¶

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