GAMA-15 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).

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: 
44f1ae0 (Thu Nov 30 18:27:54 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_GAMA-15.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]:
# 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
0601296107568211.8511367212.078997270490.99965722.17150.32843421.74530.10318522.66170.79087421.89520.2184923.67721.8613422.14760.314501nannannannannannannannan4.913771.48641False7.275580.691453.12842.2788False6.337721.275381.227822.10493False5.022871.45495nannanFalsenannannannanFalsenannan
1601296107579211.8511562392.161708587260.99981921.3780.15061121.26870.066358820.72990.16090321.0080.097128721.22690.27411720.78790.091243421.08890.50554420.68110.18899721.42790.45599221.01360.24055210.2051.41561False11.28540.68974918.53752.74721False14.34881.2836211.7282.96098False17.57331.4768313.31836.20129False19.38923.375149.746264.09328False14.27393.16247
2601296107580211.8511859682.220392798670.0030674922.72040.38924622.64390.219982nannannannan22.54340.7223821.86370.239096nannannannannannannannan2.963841.06256False3.180150.644334nannanFalsenannan3.488352.32093False6.524251.43674nannanFalsenannannannanFalsenannan
3601296107598211.8512290732.263561722670.0030674923.39460.98477422.38680.174264nannannannan21.87770.39171321.74730.215011nannannannannannannannan1.592791.44468False4.029810.646796nannanFalsenannan6.440232.32351False7.262311.43817nannanFalsenannannannanFalsenannan
4601296107603211.8515658012.082890727270.99998121.9970.24731721.47020.080634121.520.31217921.30560.12876421.590.34356221.00310.11099421.34410.46379421.1510.292735nannannannan5.770591.31447False9.373650.6961518.953252.5743False10.90811.293668.394552.65631False14.41331.4734610.52884.49757False12.57763.39115nannanFalsenannan
5601296107607211.8515530582.124244816349.52581e-0622.39180.54242121.79870.1063821.42440.28381321.69250.1788121.51740.30374821.66590.202271nannannannan21.04010.35680520.80270.1986964.01132.004False6.926380.6786419.77792.55596False7.638571.2588.974762.5108False7.82791.45833nannanFalsenannan13.93034.5779False17.33493.17238
6601296107610211.8512195862.447640448330.0030674921.62640.17857922.21670.15240522.30680.49486321.93110.221559nannannannannannannannannannannannan8.11791.33521False4.713050.661574.337781.9771False6.131131.25114nannanFalsenannannannanFalsenannannannanFalsenannan
7601296107612211.8513238442.18633995340.0519.43330.059404321.95070.120522nannannannannannannannannannannannannannannannan61.1923.34803False6.02180.668449nannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannan
8601296107613211.8521754481.97540980860.0522.27630.25899722.62550.222289nannannannannannannannannannannannannannannannan4.461691.06431False3.234570.662231nannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannan
9601296107614211.8518651082.158932861790.923.64120.76720623.2280.387767nannannannannannannannannannannannannannannannan1.269220.896861False1.85690.663186nannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannan

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 3349591 sources.
The cleaned catalogue has 3348955 sources (636 removed).
The cleaned catalogue has 632 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_GAMA-15.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.09687912408935517 arcsec
Dec correction: -0.08577507370057802 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)))
178880 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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