AKARI-SEP 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_vista_y",     #All Y fluxes empty on AKARI-SEP
        #'YPETROMAGERR': "merr_vista_y", 
        #'YAPERMAG3': "m_ap_vista_y", 
        #'YAPERMAG3ERR': "merr_ap_vista_y",
        '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_AKARI-SEP.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
047321540775769.806952647-53.29481119370.921.36060.35766321.09750.261915nannannannannannannannan10.36993.41605False13.21263.18732nannanFalsenannannannanFalsenannan
147321541096869.8989119787-53.46750184870.0520.25970.165320.90930.237073nannannannannannannannan28.58424.35184False15.71313.43099nannanFalsenannannannanFalsenannan
247321540577769.8767007631-53.19098270860.921.1670.30841120.53010.168175nannannannannannannannan12.39313.52035False22.28153.4513nannanFalsenannannannanFalsenannan
347321541572169.8310028706-53.71377159260.0520.70590.19307720.45940.147989nannannannannannannannan18.95213.37027False23.78143.24148nannanFalsenannannannanFalsenannan
447321541134269.8717086782-53.48847011940.0520.69140.19168520.50630.161906nannannannannannannannan19.20613.3908False22.77583.39634nannanFalsenannannannanFalsenannan
547321541143369.8619655263-53.49377604070.0521.81820.5484120.51380.159067nannannannannannannannan6.803273.43636False22.61953.31389nannanFalsenannannannanFalsenannan
647321541609169.8673184652-53.73265735990.920.92070.30306920.96970.240281nannannannannannannannan15.55014.34061False14.8633.28929nannanFalsenannannannanFalsenannan
747321541168769.8027676351-53.50859617740.0520.84750.2536720.68340.185638nannannannannannannannan16.63423.8864False19.34743.308nannanFalsenannannannanFalsenannan
847321541171969.90305388-53.51089915270.921.70870.62526420.96690.249831nannannannannannannannan7.525164.33366False14.90133.42884nannanFalsenannannannanFalsenannan
947321541646169.8923657242-53.75160402770.921.48690.5099121.14640.285518nannannannannannannannan9.230684.33514False12.63153.32172nannanFalsenannannannanFalsenannan

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 160013 sources.
The cleaned catalogue has 159999 sources (14 removed).
The cleaned catalogue has 14 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_AKARI-SEP.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.13254794655779278 arcsec
Dec correction: 0.06519666017936743 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)))
30228 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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