Herschel Stripe 82 master catalogue¶

Preparation of VISTA/CFHT Telescope / VIRCAM/WIRCAM Camera data¶

VISTA/CFHT Telescope / VIRCAM/WIRCAM Camera VICS82 catalogue: the catalogue comes from dmu0_VICS82.

The catalogue is described here: https://arxiv.org/pdf/1705.05451.pdf

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The magnitude for each band.
  • The auto magnitude to be used as total magnitude .
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 = "vics82_ra"
DEC_COL = "vics82_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'VICS82ID': "vics82_id",
        'ALPHA_J2000': "vics82_ra",
        'DELTA_J2000': "vics82_dec",
        'CLASS_STAR':  "vics82_stellarity",
        'MAG_AUTO': "m_vics82_k", 
        'MAG_APER': "m_ap_vics82_k", 
        'JMAG_AUTO': "m_vics82_j", 
        'JMAG_APER': "m_ap_vics82_j", 
})

#No error column?

catalogue = Table.read("../../dmu0/dmu0_VICS82/data/VICS82_FULL_SDSS_FEB2017_K22_HELP-coverage_intIDs.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2011

# Clean table metadata
catalogue.meta = None

#replace list of aperture magnitudes with appropriate choice from list
# Apertures (1", 1.5", 2", 2.5" and 3"
catalogue["m_ap_vics82_j"] = catalogue["m_ap_vics82_j"][:, 2]
catalogue["m_ap_vics82_k"] = catalogue["m_ap_vics82_k"][:, 2]
#catalogue["m_ap_vics82_j"]  = [el[0] for el in catalogue["m_ap_vics82_j"] ]
#catalogue["m_ap_vics82_j"]  = [el[0] for el in catalogue["m_ap_vics82_j"] ]
In [5]:
# Adding flux and band-flag columns
for col in catalogue.colnames:
    if col.startswith('m_'):
        
        # Add err col with all nan values because errors absent
        errcol = "merr{}".format(col[1:])
        nan_values = np.empty(len(catalogue))
        nan_values[:] = np.NAN
        catalogue.add_column(Column(nan_values, name=errcol))
        
        # Some object have a magnitude to 0 or 99., we suppose this means missing value
        mask = ((catalogue[col] <= 0) |
                (catalogue[errcol] <= 0) |
                (catalogue[col] > 50.))
        catalogue[col][mask] = np.nan
        catalogue[errcol][mask] = np.nan  
        

        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)
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/ipykernel/__main__.py:13: RuntimeWarning: invalid value encountered in less_equal
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxvics82_idvics82_ravics82_decvics82_stellaritym_vics82_km_ap_vics82_km_vics82_jm_ap_vics82_jmerr_vics82_kf_vics82_kferr_vics82_kflag_vics82_kmerr_ap_vics82_kf_ap_vics82_kferr_ap_vics82_kmerr_vics82_jf_vics82_jferr_vics82_jflag_vics82_jmerr_ap_vics82_jf_ap_vics82_jferr_ap_vics82_j
0VICS82J000000.00-002426.24.38503205524e-07-0.407277972260.43904849886923.114229202324.527nannannan2.06209333761nanFalsenan0.56129nannannannanFalsenannannan
1VICS82J000000.00+001719.71.11189935936e-060.288796458150.39384222030623.035121917799.0nannannan2.21794735168nanFalsenan9.12009e-31nannannannanFalsenannannan
2VICS82J000000.00-000635.73.23150055392e-06-0.1099135933160.034445151686723.537975311325.5243nannannan1.39575719568nanFalsenan0.224024nannannannanFalsenannannan
3VICS82J000000.00-000912.83.38169190306e-06-0.1535417272760.03789557889122.976335525523.4395nannannan2.34134703553nanFalsenan1.52826nannannannanFalsenannannan
4VICS82J000000.00-001700.93.49929820231e-06-0.2835916311260.35829970240621.376319885321.2107nannannan10.2204977251nanFalsenan11.9053nannannannanFalsenannannan
5VICS82J000000.00-003721.04.28460541424e-06-0.6224911028490.36098235845622.055337905923.0176nannannan5.46845745532nanFalsenan2.2541nannannannanFalsenannannan
6VICS82J000000.00-001634.95.29322761622e-06-0.2763613837840.81699758768118.510280609118.829319.57691574119.9758nan143.181779734nanFalsenan106.733nannan53.6085059317nanFalsenan37.1262nan
7VICS82J000000.00-001758.25.90097545228e-06-0.2995030461880.49883356690421.377437591621.2169nannannan10.2099816931nanFalsenan11.8375nannannannanFalsenannannan
8VICS82J000000.00-010228.56.69776278472e-06-1.041251787180.97637504339217.708951950117.803617.699819564817.8732nan299.515443323nanFalsenan274.512nannan302.045363865nanFalsenan257.464nan
9VICS82J000000.00-003838.18.21837221565e-06-0.6439219123280.44881469011322.386650085422.206nannannan4.03032404732nanFalsenan4.75971nannannannanFalsenannannan

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['m_ap_vics82_j', 'm_ap_vics82_k']
FLAG_NAME = 'vics82_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 15318703 sources.
The cleaned catalogue has 13914785 sources (1403918 removed).
The cleaned catalogue has 1239758 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 [8]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_Herschel-Stripe-82.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [9]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec, near_ra0=True)
In [10]:
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.09985838245256673 arcsec
Dec correction: -0.13517424260163224 arcsec
In [11]:
catalogue[RA_COL] +=  delta_ra.to(u.deg)
catalogue[DEC_COL] += delta_dec.to(u.deg)
In [12]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec, near_ra0=True)

IV - Flagging Gaia objects¶

In [13]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [14]:
GAIA_FLAG_NAME = "vics82_flag_gaia"

catalogue['flag_gaia'].name = GAIA_FLAG_NAME
print("{} sources flagged.".format(np.sum(catalogue[GAIA_FLAG_NAME] > 0)))
194610 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

In [15]:
catalogue.write("{}/VICS82.fits".format(OUT_DIR), overwrite=True)