Herschel Stripe 82 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: 
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 = "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_Herschel-Stripe-82.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>
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
047248949946733.3317792233-1.520175444250.944606nannannannan20.30680.35266920.12330.12527720.20510.33606320.12180.204520.61170.39320920.5320.35181nannanFalsenannan27.36918.89004False32.40953.7395630.05769.30358False32.45586.1130920.66887.48539False22.24247.20719
147248949947633.5224288616-1.5208559510.944606nannannannan18.83840.087563618.72020.0380318.55030.11791518.66580.054451118.96040.21736818.9170.0829968nannanFalsenannan105.8378.53563False118.0074.13342138.014.9873False124.0776.2226494.588418.9369False98.44897.52572
247248949947833.4011536286-1.52093524450.000171409nannannannan17.69920.062584818.20650.023022317.44650.07419517.95610.02889717.28720.084193317.88870.031609nannanFalsenannan302.23117.4214False189.4064.01622381.40126.0635False238.5476.34895441.69434.2511False253.817.38915
347248949948833.3453269641-1.521930501460.999657nannannannan18.4490.059208918.25030.023654718.1570.08497118.25270.037591518.58760.13421318.37450.0494034nannanFalsenannan151.4968.26162False181.9123.96327198.24415.5148False181.526.28476133.33516.4822False162.267.38319
447248949949033.5026975929-1.521889414120.000171409nannannannan19.89970.1952720.54490.1968519.31950.16639919.98920.18128918.52590.15634419.52520.144603nannanFalsenannan39.82337.16222False21.98143.9853567.949310.4139False36.66916.12275141.13320.3229False56.22447.48819
547248949949233.37675186-1.522185985670.000171409nannannannan19.01110.15995119.62170.079560418.97610.18611119.20640.088734618.72420.19851519.05060.0909168nannanFalsenannan90.274513.2992False51.44453.7697493.229315.9809False75.41026.16309117.57621.4976False87.04617.28902
647248949949633.4437163988-1.520989233360.000171409nannannannan15.63910.012429516.62850.0064749615.4320.015890116.37940.0076418215.30.015760716.26160.00804405nannanFalsenannan2015.4523.0728False810.1794.831632438.9435.6948False1019.177.173282754.1939.9803False1135.938.41595
747248949950233.4813581409-1.522029137250.000171409nannannannan16.20290.02224517.49560.013020415.92880.027492817.24470.015609815.88990.032626817.16350.0173545nannanFalsenannan1199.0624.5667False364.5424.371651543.4439.0826False459.3376.603971599.6448.0698False494.9887.91192
847248949950733.4331889026-1.522565667470.000171409nannannannan17.02690.025937917.34950.011276216.78270.032692917.08840.013651716.56750.031349916.89740.0134715nannanFalsenannan561.37913.4112False417.0784.33169702.93921.1664False530.426.66933857.00824.7455False632.4777.84761
947248949950833.5241111643-1.522733850610.000171409nannannannan19.62660.25859719.88010.10753219.83060.27912319.95840.17621619.69660.33118619.64480.160903nannanFalsenannan51.210112.1971False40.54714.0158342.437310.9099False37.72476.1227448.012114.6453False50.35947.46314

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 4723782 sources.
The cleaned catalogue has 4708094 sources (15688 removed).
The cleaned catalogue has 15670 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_Herschel-Stripe-82.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.08399760600354966 arcsec
Dec correction: -0.11251507613907474 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)))
443115 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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