XMM-LSS master catalogue¶

Preparation of VHS data¶

VISTA telescope/VHS catalogue: the catalogue comes from dmu0_VHS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The magnitude for each band.
  • The kron magnitude to be used as total magnitude (no “auto” magnitude is provided). These are Vega magnitudes and must be corrected to AB.

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 = "vhs_ra"
DEC_COL = "vhs_dec"

I - Column selection¶

In [4]:
# Bands: Y,J,H,K
imported_columns = OrderedDict({
        'SOURCEID': "vhs_id",
        'ra': "vhs_ra",
        'dec': "vhs_dec",
        'PSTAR':  "vhs_stellarity",
        'YPETROMAG': "m_vhs_y", 
        'YPETROMAGERR': "merr_vhs_y", 
        'YAPERMAG3': "m_ap_vhs_y", 
        'YAPERMAG3ERR': "merr_ap_vhs_y",
        'JPETROMAG': "m_vhs_j", 
        'JPETROMAGERR': "merr_vhs_j", 
        'JAPERMAG3': "m_ap_vhs_j", 
        'JAPERMAG3ERR': "merr_ap_vhs_j",        
        'HPETROMAG': "m_vhs_h", 
        'HPETROMAGERR': "merr_vhs_h", 
        'HAPERMAG3': "m_ap_vhs_h", 
        'HAPERMAG3ERR': "merr_ap_vhs_h",        
        'KSPETROMAG': "m_vhs_k", 
        'KSPETROMAGERR': "merr_vhs_k", 
        'KSAPERMAG3': "m_ap_vhs_k", 
        'KSAPERMAG3ERR': "merr_ap_vhs_k",
    })


catalogue = Table.read("../../dmu0/dmu0_VISTA-VHS/data/VHS_XMM-LSS.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]:
# Conversion from Vega magnitudes to AB is done using values from 
# http://casu.ast.cam.ac.uk/surveys-projects/vista/technical/filter-set
vega_to_ab = {
    "z": 0.521,
    "y": 0.618,
    "j": 0.937,
    "h": 1.384,
    "k": 1.839
}
In [6]:
# Coverting from Vega to AB and 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>
idxvhs_idvhs_ravhs_decvhs_stellaritym_vhs_ymerr_vhs_ym_ap_vhs_ymerr_ap_vhs_ym_vhs_jmerr_vhs_jm_ap_vhs_jmerr_ap_vhs_jm_vhs_hmerr_vhs_hm_ap_vhs_hmerr_ap_vhs_hm_vhs_kmerr_vhs_km_ap_vhs_kmerr_ap_vhs_kf_vhs_yferr_vhs_yflag_vhs_yf_ap_vhs_yferr_ap_vhs_yf_vhs_jferr_vhs_jflag_vhs_jf_ap_vhs_jferr_ap_vhs_jf_vhs_hferr_vhs_hflag_vhs_hf_ap_vhs_hferr_ap_vhs_hf_vhs_kferr_vhs_kflag_vhs_kf_ap_vhs_kferr_ap_vhs_k
degdeg
047253473083833.7283235404-5.832482775360.9nannannannan20.50140.1993420.41080.119768nannannannannannannannannannanFalsenannan22.87834.20042False24.86962.74338nannanFalsenannannannanFalsenannan
147253473084533.7284935702-5.833156395260.05nannannannan20.57270.27726420.6070.152509nannannannannannannannannannanFalsenannan21.42415.47108False20.75812.9158nannanFalsenannannannanFalsenannan
247253473085233.7467765548-5.833540878670.486486nannannannan22.64391.3899621.31760.270364nannannannan20.80640.41529419.84120.132874nannanFalsenannan3.184.07105False10.78872.68654nannanFalsenannan17.27586.60798False42.02435.14298
347253473086133.6717808673-5.834132174060.9nannannannan21.13370.31014421.29760.287634nannannannannannannannannannanFalsenannan12.77983.65058False10.98952.91135nannanFalsenannannannanFalsenannan
447253473087133.7467840652-5.834226807020.820084nannannannan23.34283.3202320.61780.14627618.88360.11399719.30810.075099119.51040.2243819.11130.0676549nannanFalsenannan1.670575.10867False20.55292.76899101.52310.6594False68.66994.7498156.994111.7785False82.31165.12904
547253473088133.6548506581-5.83425786050.944606nannannannan20.35590.29218420.57660.1414119.13240.1247619.49960.090296319.95420.32215119.19110.0725963nannanFalsenannan26.15917.0397False21.34722.7803380.72899.27645False57.56514.7874637.872911.2373False76.4835.11393
647253473098033.6517906022-5.841698056980.05nannannannan21.11890.34181321.17540.243654nannannannannannannannannannanFalsenannan12.95484.07845False12.29872.75999nannanFalsenannannannanFalsenannan
747253473105933.6354611299-5.846618065860.05nannannannan21.29220.40076421.2760.269902nannannannannannannannannannanFalsenannan11.04414.07655False11.20952.78655nannanFalsenannannannanFalsenannan
847253473109933.6865386606-5.848632167530.05nannannannan20.98970.27172821.19010.25905nannannannannannannannannannanFalsenannan14.59183.6519False12.13272.89479nannanFalsenannannannanFalsenannan
947253473110533.6861099083-5.84907511920.00306749nannannannan20.48470.20906920.98430.214736nannannannan20.83720.48878920.71490.290664nannanFalsenannan23.2334.47373False14.66452.90034nannanFalsenannan16.79287.55995False18.79515.03166

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [8]:
SORT_COLS = ['merr_ap_vhs_y', 'merr_ap_vhs_h', 'merr_ap_vhs_j', 'merr_ap_vhs_k']
FLAG_NAME = 'vhs_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 437968 sources.
The cleaned catalogue has 428066 sources (9902 removed).
The cleaned catalogue has 9901 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_XMM-LSS.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.10875042168549953 arcsec
Dec correction: -0.10968037218450633 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 = "vhs_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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