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

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 = "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_GAMA-09.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
0472459129425135.971788641-0.1227341117540.993865nannannannan19.21780.11425819.19630.0545987nannannannan20.36190.60234119.86110.185373nannanFalsenannan74.62657.85335False76.11473.8276nannanFalsenannan26.01714.4337False41.26367.04514
1472459129426135.981416066-0.1228752912380.05nannannannan21.07140.471420.87820.25277nannannannannannannannannannanFalsenannan13.53395.87607False16.17113.76479nannanFalsenannannannanFalsenannan
2472459129438136.039605281-0.1231125597530.00306749nannannannan19.32360.18226619.45450.0699765nannannannan18.51890.14876518.68190.0645196nannanFalsenannan67.695511.3643False60.00583.86741nannanFalsenannan142.04619.4629False122.2517.26475
3472459129446135.991356476-0.1234768789520.993865nannannannan19.40920.13763519.48910.0721627nannannannan19.46870.29642119.5880.147284nannanFalsenannan62.56227.93078False58.12253.86307nannanFalsenannan59.226416.1696False53.06547.1985
4472459129447135.926057091-0.1237516743370.00306749nannannannan20.05150.23816720.53470.180361nannannannan19.33890.2838819.5140.133932nannanFalsenannan34.62677.59571False22.1883.68584nannanFalsenannan66.747917.4521False56.80627.0074
5472459129451135.940822088-0.1238013016670.486486nannannannan20.3790.32244720.22710.136581nannannannan20.24750.42315920.22030.255736nannanFalsenannan25.60977.6057False29.45483.70529nannanFalsenannan28.905511.2658False29.63986.9814
6472459129458135.918291871-0.1243736531550.486486nannannannan20.40920.32635420.16760.12945nannannannan20.23660.45879920.16150.242343nannanFalsenannan24.90727.48669False31.11413.70966nannanFalsenannan29.199312.3387False31.29066.98425
7472459129462135.991821296-0.1246213225370.05nannannannan20.01970.25323220.4810.176119nannannannannannannannannannanFalsenannan35.65658.31634False23.31343.78171nannanFalsenannannannanFalsenannan
8472459129474136.010345889-0.1251210227140.486486nannannannan20.11720.27695420.30420.150036nannannannan20.36110.51448919.94050.203425nannanFalsenannan32.59348.31408False27.43673.79143nannanFalsenannan26.035812.3374False38.35417.18605
9472459129475135.934952323-0.1247868330380.00306749nannannannan18.37720.12663319.26850.0579215nannannannan18.13210.18482418.73810.0660653nannanFalsenannan161.8518.8771False71.22173.79951nannanFalsenannan202.84434.53False116.087.06325

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 532739 sources.
The cleaned catalogue has 532707 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_GAMA-09.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.053860528453242296 arcsec
Dec correction: -0.055894050792959504 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)))
97043 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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