XMM-LSS master catalogue¶

Preparation of VIKING data¶

VISTA telescope/VIKING catalogue: the catalogue comes from dmu0_VIKING.

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.

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 = "viking_ra"
DEC_COL = "viking_dec"

I - Column selection¶

In [4]:
# Bands: Z,Y,J,H,K
imported_columns = OrderedDict({
        'SOURCEID': "viking_id",
        'ra': "viking_ra",
        'dec': "viking_dec",
        'PSTAR':  "viking_stellarity",
        'ZPETROMAG': "m_viking_z", 
        'ZPETROMAGERR': "merr_viking_z", 
        'ZAPERMAG3': "m_ap_viking_z", 
        'ZAPERMAG3ERR': "merr_ap_viking_z",
        'YPETROMAG': "m_viking_y", 
        'YPETROMAGERR': "merr_viking_y", 
        'YAPERMAG3': "m_ap_viking_y", 
        'YAPERMAG3ERR': "merr_ap_viking_y",
        'JPETROMAG': "m_viking_j", 
        'JPETROMAGERR': "merr_viking_j", 
        'JAPERMAG3': "m_ap_viking_j", 
        'JAPERMAG3ERR': "merr_ap_viking_j",        
        'HPETROMAG': "m_viking_h", 
        'HPETROMAGERR': "merr_viking_h", 
        'HAPERMAG3': "m_ap_viking_h", 
        'HAPERMAG3ERR': "merr_ap_viking_h",        
        'KSPETROMAG': "m_viking_k", 
        'KSPETROMAGERR': "merr_viking_k", 
        'KSAPERMAG3': "m_ap_viking_k", 
        'KSAPERMAG3ERR': "merr_ap_viking_k",
    })


catalogue = Table.read("../../dmu0/dmu0_VISTA-VIKING/data/VIKING_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>
idxviking_idviking_raviking_decviking_stellaritym_viking_zmerr_viking_zm_ap_viking_zmerr_ap_viking_zm_viking_ymerr_viking_ym_ap_viking_ymerr_ap_viking_ym_viking_jmerr_viking_jm_ap_viking_jmerr_ap_viking_jm_viking_hmerr_viking_hm_ap_viking_hmerr_ap_viking_hm_viking_kmerr_viking_km_ap_viking_kmerr_ap_viking_kf_viking_zferr_viking_zflag_viking_zf_ap_viking_zferr_ap_viking_zf_viking_yferr_viking_yflag_viking_yf_ap_viking_yferr_ap_viking_yf_viking_jferr_viking_jflag_viking_jf_ap_viking_jferr_ap_viking_jf_viking_hferr_viking_hflag_viking_hf_ap_viking_hferr_ap_viking_hf_viking_kferr_viking_kflag_viking_kf_ap_viking_kferr_ap_viking_k
degdeg
060131773806936.3759743225-3.51860087130.000171409nannannannannannannannan20.25820.28437220.17080.081313319.84820.17699219.87140.067118919.16920.14075219.60680.0564076nannanFalsenannannannanFalsenannan28.62357.49697False31.0222.3233141.75646.80694False40.87252.5266978.038210.1167False52.15122.70943
160131773807036.3755938453-3.171177223430.000171409nannannannannannannannan19.01560.085431919.42610.040743218.75310.077571119.0980.034354818.52660.062038718.80530.0273085nannanFalsenannannannanFalsenannan89.90417.07417False61.59832.31153114.4918.17986False83.33162.63678141.0468.05936False109.1092.74431
260131773807236.3758481013-3.524297043610.000171409nannannannannannannannan18.89540.08618419.04530.029694218.40140.064413218.78120.02568818.26540.058383418.53940.0223735nannanFalsenannannannanFalsenannan100.4257.9716False87.47662.39243158.2829.39037False111.5632.63954179.4059.64714False139.3892.87236
360131773807536.3756953985-2.855621183280.000171409nannannannannannannannan19.4890.098323119.49840.043546919.46690.11553419.56070.050887519.61060.12390119.67990.0582781nannanFalsenannannannanFalsenannan58.12785.26399False57.62742.3113359.32576.31288False54.41462.5503651.97155.93086False48.75572.61702
460131773807636.3761078049-3.413663420510.0524781nannannannannannannannan20.5220.28118920.49940.10908220.13350.19530120.22490.093741321.00770.42689220.45720.119486nannanFalsenannannannanFalsenannan22.44995.81419False22.92122.3028532.10735.77543False29.51392.548214.35225.64305False23.82932.62243
560131773807736.3758712698-2.898747733340.000171409nannannannannannannannan19.95240.1637919.90720.062833319.52410.13320219.48070.047392119.03380.10097319.20460.0383525nannanFalsenannannannanFalsenannan37.93355.72248False39.54842.2887356.28316.90499False58.57772.556988.40488.22157False75.53462.66818
660131773807836.3758594452-2.792455244050.999657nannannannannannannannan19.50870.094201419.45230.042098519.41820.097256219.36650.0423319.66920.13461219.62630.0558244nannanFalsenannannannanFalsenannan57.08334.9527False60.12822.3314262.04585.55783False65.07212.5369949.24066.10498False51.2252.63379
760131773807936.3756718776-2.558816066920.999657nannannannannannannannan18.77980.051763818.80870.023628518.65750.049525318.68230.023054318.7460.060407818.94760.0311236nannanFalsenannannannanFalsenannan111.7115.32593False108.7762.36725125.0265.703False122.22.59477115.2366.41149False95.70932.7436
860131773808036.3762899555-3.347826691580.000171409nannannannannannannannan20.27250.21900920.73390.13564819.52330.16757319.98350.07464319.71840.15846119.72490.0610043nannanFalsenannannannanFalsenannan28.24995.69842False18.46962.3075256.32148.69269False36.86342.5343147.05966.86825False46.77822.62833
960131773808136.3761706285-3.106890647220.000171409nannannannannannannannan20.1390.20005220.71710.13085920.060.24452420.320.1017219.38820.17210119.840.0675382nannanFalsenannannannanFalsenannan31.94455.88591False18.75672.2606634.35647.73758False27.03922.5332463.787210.111False42.0742.61721

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [8]:
SORT_COLS = ['merr_ap_viking_y', 'merr_ap_viking_h', 'merr_ap_viking_j', 'merr_ap_viking_k']
FLAG_NAME = 'viking_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 325881 sources.
The cleaned catalogue has 325849 sources (32 removed).
The cleaned catalogue has 32 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.10746290045346996 arcsec
Dec correction: -0.0979660293879192 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 = "viking_flag_gaia"

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

V - Saving to disk¶

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