SSDF 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.

  • Note: on SSDF, the VHS catalogue does not contain Y data.*
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: 
04829ed (Thu Nov 2 16:57:19 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",
        'JPETROMAG': "m_vista_j", 
        'JPETROMAGERR': "merr_vista_j", 
        'JAPERMAG3': "m_ap_vista_j", 
        'JAPERMAG3ERR': "merr_ap_vista_j",        
        'HPETROMAG': "m_vista_h", 
        'HPETROMAGERR': "merr_vista_h", 
        'HAPERMAG3': "m_ap_vista_h", 
        'HAPERMAG3ERR': "merr_ap_vista_h",        
        'KSPETROMAG': "m_vista_k", 
        'KSPETROMAGERR': "merr_vista_k", 
        'KSAPERMAG3': "m_ap_vista_k", 
        'KSAPERMAG3ERR': "merr_ap_vista_k",
    })


catalogue = Table.read("../../dmu0/dmu0_VISTA-VHS/data/VHS_SSDF.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_vista_jmerr_vista_jm_ap_vista_jmerr_ap_vista_jm_vista_hmerr_vista_hm_ap_vista_hmerr_ap_vista_hm_vista_kmerr_vista_km_ap_vista_kmerr_ap_vista_kf_vista_jferr_vista_jflag_vista_jf_ap_vista_jferr_ap_vista_jf_vista_hferr_vista_hflag_vista_hf_ap_vista_hferr_ap_vista_hf_vista_kferr_vista_kflag_vista_kf_ap_vista_kferr_ap_vista_k
degdeg
0473149851020345.176587133-49.37331363870.921.97010.58698621.55050.22594nannannannannannannannan5.915193.19795False8.705531.8116nannanFalsenannannannanFalsenannan
1473149851025345.177625209-49.37355947660.922.77520.86725122.03810.352302nannannannannannannannan2.817962.2509False5.55591.80279nannanFalsenannannannanFalsenannan
2473149851051345.18201649-49.37453791860.922.12730.49533521.82880.290639nannannannannannannannan5.117772.33483False6.736951.80341nannanFalsenannannannanFalsenannan
3473149851178345.183843776-49.37829709810.922.28390.56248121.93880.320968nannannannannannannannan4.430462.29526False6.08781.79969nannanFalsenannannannanFalsenannan
4473149851185345.174272926-49.37839936750.0522.21130.59877421.68510.255197nannannannannannannannan4.736552.61216False7.690791.80768nannanFalsenannannannanFalsenannan
5473149851349345.153239714-49.38305450260.922.01260.43934822.12720.381721nannannannannannannannan5.688132.30173False5.118181.79944nannanFalsenannannannanFalsenannan
6473149851413345.183949007-49.3851452780.0521.61850.31857622.28460.441249nannannannannannannannan8.177432.39941False4.427381.79931nannanFalsenannannannanFalsenannan
7473149851449345.172040955-49.38582566250.0521.71430.32777321.57970.231364nannannannannannannannan7.486462.26009False8.474561.80588nannanFalsenannannannanFalsenannan
8473149851485345.176770521-49.3871877940.0521.15990.22819221.46150.208073nannannannannannannannan12.47532.62197False9.449681.81096nannanFalsenannannannanFalsenannan
9473149851511345.150835119-49.38773316770.0521.05780.23655221.59420.234787nannannannannannannannan13.70482.98591False8.361951.80824nannanFalsenannannannanFalsenannan

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [8]:
SORT_COLS = ['merr_ap_vista_h', 'merr_ap_vista_j', 'merr_ap_vista_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 2406318 sources.
The cleaned catalogue has 2406063 sources (255 removed).
The cleaned catalogue has 253 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_SSDF.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, near_ra0=True)
In [11]:
delta_ra, delta_dec =  astrometric_correction(
    SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]),
    gaia_coords, near_ra0=True
)

print("RA correction: {}".format(delta_ra))
print("Dec correction: {}".format(delta_dec))
RA correction: 0.21025412717108338 arcsec
Dec correction: -0.09461352436233028 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, near_ra0=True)

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)))
301682 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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