GAMA-12 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-12.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
0601300613633174.4833567971.04283276490.0522.07060.16257222.88320.216216nannannannannannannannannannannannannannannannan5.392070.807379False2.550980.508008nannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannan
1601300613647174.4834893881.109397455240.0522.99760.37965423.06060.254602nannannannannannannannannannannannannannannannan2.295880.80281False2.166440.508024nannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannan
2601300613653174.4833141191.24154960850.0523.00470.31266623.10950.264186nannannannannannannannannannannannannannannannan2.280920.65685False2.071080.503943nannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannan
3601300613660174.4836487561.141366144015.29221e-0722.77690.33471522.95330.22963622.04390.43327421.86710.17173421.12170.27767821.32350.11335820.75420.34587420.89360.14211420.66210.38613220.59470.1258012.813360.867315False2.391480.5058045.526382.20536False6.503591.0286912.92123.30461False10.72971.1202518.12615.77428False15.94312.0868219.73217.01753False20.99482.4326
4601300613665174.4843221620.8471816413290.0522.94730.25908322.51840.153933nannannannannannannannannannannannannannannannan2.40490.573867False3.56990.506131nannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannan
5601300613669174.4833038141.265527189269.52581e-0622.52540.37321322.04840.10168422.47740.61521121.9290.1821222.35920.56999521.67490.15375822.06350.64072221.81890.331753nannannannan3.546941.21923False5.503730.5154493.707142.10058False6.143441.030494.133482.17001False7.763361.099425.427353.20282False6.799212.07754nannanFalsenannan
6601300613672174.4832298651.209790223160.94721521.30210.11133721.26370.051244821.34270.1960321.11190.088190220.94090.17492620.89220.076997121.56590.4496521.08430.16905520.93790.33698921.10380.19975510.94381.12223False11.33720.53509610.5421.90336False13.0391.0591115.26292.45905False15.96261.132028.582783.5545False13.3742.0824115.30534.75043False13.13692.41694
7601300613675174.4841372851.011226008580.0522.89840.28367923.16370.27759nannannannannannannannannannannannannannannannan2.515610.657274False1.970270.50374nannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannan
8601300613677174.4832921481.367005402010.0522.68390.26027322.79590.200309nannannannannannannannannannannannannannannannan3.064930.734725False2.764680.510059nannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannan
9601300613681174.4834007811.302044625455.29221e-0722.46330.34801222.30440.12777821.7520.31626421.87110.17293321.35620.26775321.39240.11916621.11910.36941621.34970.21602620.94020.36158220.81620.1560233.755561.20377False4.34750.5116487.231042.10633False6.479761.0320810.41172.56763False10.07051.105312.95214.40689False10.4742.0839815.27355.08653False17.11992.46019

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 3045586 sources.
The cleaned catalogue has 3045013 sources (573 removed).
The cleaned catalogue has 572 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-12.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.11862931214636774 arcsec
Dec correction: -0.09424492095163606 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)))
145807 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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