CDFS-SWIRE Master List Creation¶

Preparation of VIDEO/VISTA/VIRCAM data¶

The catalogue comes from dmu0_VISTA_VIDEO-private.

There is an old public version of the catalogue but we are using the newer private version in the hope that it will be public by the time we publish the masterlist.

Filters: Z, Y, J, H, Ks

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position (degrees);
  • The stellarity;
  • The magnitude for each band in apertude 3, which is 2 arcsec (rs548 presumes same for private catalogue).
  • The “auto” magnitude is provided, we presume this is standard Sextractor units etc.

Yannick said the dates of observation for VIDEO are from 2009/11 to 2016/12. There is a paper from 2012 (Jarvis et al). So will use 2012.

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]:
import locale
locale.setlocale(locale.LC_ALL, 'en_GB')
Out[3]:
'en_GB'
In [4]:
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
In [5]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "video_ra"
DEC_COL = "video_dec"

I - Column selection¶

In [6]:
# TODO: Check that the aperture magnitudes are aperture corrected.

imported_columns = OrderedDict({
        'ID':              'video_id', 
        'ALPHA_J2000':     'video_ra', 
        'DELTA_J2000':     'video_dec', 
        'J_CLASS_STAR':    'video_stellarity', 
        'Z_MAG_APER_3':    'm_ap_video_z', 
        'Z_MAGERR_APER_3': 'merr_ap_video_z', 
        'Z_MAG_AUTO':      'm_video_z', 
        'Z_MAGERR_AUTO':   'merr_video_z',
        'Z_FLUX_APER_3':   'f_ap_video_z', 
        'Z_FLUXERR_APER_3':'ferr_ap_video_z', 
        'Z_FLUX_AUTO':     'f_video_z', 
        'Z_FLUXERR_AUTO':  'ferr_video_z',
        'Y_MAG_APER_3':    'm_ap_video_y', 
        'Y_MAGERR_APER_3': 'merr_ap_video_y', 
        'Y_MAG_AUTO':      'm_video_y', 
        'Y_MAGERR_AUTO':   'merr_video_y',
        'Y_FLUX_APER_3':   'f_ap_video_y', 
        'Y_FLUXERR_APER_3':'ferr_ap_video_y', 
        'Y_FLUX_AUTO':     'f_video_y', 
        'Y_FLUXERR_AUTO':  'ferr_video_y',
        'J_MAG_APER_3':    'm_ap_video_j', 
        'J_MAGERR_APER_3': 'merr_ap_video_j', 
        'J_MAG_AUTO':      'm_video_j', 
        'J_MAGERR_AUTO':   'merr_video_j',
        'J_FLUX_APER_3':   'f_ap_video_j', 
        'J_FLUXERR_APER_3':'ferr_ap_video_j', 
        'J_FLUX_AUTO':     'f_video_j', 
        'J_FLUXERR_AUTO':  'ferr_video_j',
        'H_MAG_APER_3':    'm_ap_video_h', 
        'H_MAGERR_APER_3': 'merr_ap_video_h', 
        'H_MAG_AUTO':      'm_video_h', 
        'H_MAGERR_AUTO':   'merr_video_h',
        'H_FLUX_APER_3':   'f_ap_video_h', 
        'H_FLUXERR_APER_3':'ferr_ap_video_h', 
        'H_FLUX_AUTO':     'f_video_h', 
        'H_FLUXERR_AUTO':  'ferr_video_h',    
        'K_MAG_APER_3':    'm_ap_video_k', 
        'K_MAGERR_APER_3': 'merr_ap_video_k', 
        'K_MAG_AUTO':      'm_video_k', 
        'K_MAGERR_AUTO':   'merr_video_k',
        'K_FLUX_APER_3':   'f_ap_video_k', 
        'K_FLUXERR_APER_3':'ferr_ap_video_k', 
        'K_FLUX_AUTO':     'f_video_k', 
        'K_FLUXERR_AUTO':  'ferr_video_k'
})


catalogue = Table.read("../../dmu0/dmu0_VISTA-VIDEO-private/data/VIDEO-all_2017-02-12_fullcat_errfix_CDFS-SWIRE.fits"
                      )[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]
    
    
epoch = 2012

# Clean table metadata
catalogue.meta = None
In [7]:
# Correct wrong values.
# The catalogue contains negative fluxes and 99 in the associated magnitude. These
# values may be considered as upper limits but we don't want this information in the
# master list.  Also, some sources may have a very low signal to noise with the error
# on magnitude superior to 99.  In all these cases, we set the magnitude, the flux, and
# the associated errors to NaN.

band_names = [_[8:] for _ in catalogue.colnames if _.startswith("merr_ap_")]

for band in band_names:
    
    # Total fluxes and magnitudes
    mask = catalogue["m_{}".format(band)] > 90.
    mask &= catalogue["merr_{}".format(band)] > 90.
    mask &= catalogue["f_{}".format(band)] < 0.
    catalogue["m_{}".format(band)][mask] = np.nan
    catalogue["merr_{}".format(band)][mask] = np.nan
    catalogue["f_{}".format(band)][mask] = np.nan
    catalogue["ferr_{}".format(band)][mask] = np.nan
    
    # Aperture fluxes and magnitudes
    mask = catalogue["m_ap_{}".format(band)] > 90.
    mask &= catalogue["merr_ap_{}".format(band)] > 90.
    mask &= catalogue["f_ap_{}".format(band)] < 0.
    catalogue["m_ap_{}".format(band)][mask] = np.nan
    catalogue["merr_ap_{}".format(band)][mask] = np.nan
    catalogue["f_ap_{}".format(band)][mask] = np.nan
    catalogue["ferr_ap_{}".format(band)][mask] = np.nan
    
    # Adding the band-flag column
    catalogue.add_column(Column(np.zeros(len(catalogue), dtype=bool), name="flag_{}".format(band)))
In [8]:
catalogue[:10].show_in_notebook()
Out[8]:
<Table length=10>
idxvideo_idvideo_ravideo_decvideo_stellaritym_ap_video_zmerr_ap_video_zm_video_zmerr_video_zf_ap_video_zferr_ap_video_zf_video_zferr_video_zm_ap_video_ymerr_ap_video_ym_video_ymerr_video_yf_ap_video_yferr_ap_video_yf_video_yferr_video_ym_ap_video_jmerr_ap_video_jm_video_jmerr_video_jf_ap_video_jferr_ap_video_jf_video_jferr_video_jm_ap_video_hmerr_ap_video_hm_video_hmerr_video_hf_ap_video_hferr_ap_video_hf_video_hferr_video_hm_ap_video_kmerr_ap_video_km_video_kmerr_video_kf_ap_video_kferr_ap_video_kf_video_kferr_video_kflag_video_zflag_video_yflag_video_jflag_video_hflag_video_k
0100000151.6895144683-29.23400642590.961231nannannannannannannannan19.64890.013881519.54940.015132913817.9176.67215143.6211.07719.62790.025496619.55050.027019214087.4330.8315128.4376.49319.41040.019353719.40940.023427717211.7306.81517227.8371.74919.59180.045299219.43780.045318814563.6607.64316783.9700.587FalseFalseFalseFalseFalse
1100000251.7010484072-29.23411614440.645479nannannannannannannannannannannannannannannannannannan25.52842.53899nannan61.4675143.74622.12380.22316922.7720.2854541414.05290.663778.413204.66221.00940.13760321.88180.1850343946.64500.2011767.11301.166FalseFalseFalseFalseFalse
2100000351.8898615783-29.23611072760.94454327.6575.3490427.02485.951068.6532842.63315.490884.909921.47290.040205521.05610.0466982575.3395.36933780.68162.61421.24030.066078220.9680.07159453190.54194.1834100.25270.38320.47560.035569220.11950.04026266452.73211.4018958.06332.20520.11660.054078119.85080.05527728981.51447.36411473.1584.139FalseFalseFalseFalseFalse
3100000451.853580029-29.23541942930.68954727.50944.6690329.096940.12669.9135542.6332.297484.909923.15460.14341723.98210.364287547.23272.2874255.36485.682823.09540.24996223.34990.29277577.866133.043457.131123.2721.67040.082421322.79690.2782872147.0162.991760.776195.00223.14530.54193922.84990.396679551.948275.511724.471264.698FalseFalseFalseFalseFalse
4100000551.8860150497-29.23561224660.71161427.82796.260527.957614.05077.3934642.6336.56184.909921.8010.039961821.95420.06426441903.7870.07311653.1697.853522.22670.10128122.44220.1560961286.22119.9871054.64151.6321.42820.06230921.52410.09673562683.56154.0112456.73218.89421.52860.11034721.77550.1777462446.55248.6591948.94319.072FalseFalseFalseFalseFalse
5100000651.7777651536-29.23446816820.59109228.11998.192430.2863120.0075.6499542.6330.76817984.909926.27432.462827.1756.6912930.922570.144413.489883.1389nannan25.24681.59335nannan79.669116.92122.92660.25748125.46773.18308675.095160.10364.9986190.56421.65580.13005921.9520.1655332176.1260.6821656.51252.563FalseFalseFalseFalseFalse
6100000751.9136213696-29.2357736920.649357nannannannannannannannan23.15380.31270924.79230.919412547.638157.734121.082102.53721.87620.1615223.89740.547561776.31264.262276.095139.246nannannannannannannannan21.08260.228721.47560.1587543689.34777.1492568.94375.636FalseFalseFalseFalseFalse
7100000851.8318880739-29.23497197010.6430525.85331.0157526.22182.8405745.568942.63332.453684.909923.10530.12802723.17280.187133572.62367.5243538.11292.749823.19450.24249323.25810.304767527.487117.815497.444139.63721.33750.056267521.43610.08529342917.42151.1982664.15209.29821.79180.13787521.79220.1671751919.87243.8071919.13295.506FalseFalseFalseFalseFalse
8100000951.9471404014-29.23603201890.0192727nannannannannannannannan23.83710.8313223.15990.27562291.841223.463544.535138.238nannannannannannannannannannannannannannannannan21.79170.79589321.76030.3403521920.041407.521976.41619.578FalseFalseFalseFalseFalse
9100001051.8122538425-29.2346664740.35318nannannannannannannannan24.67910.5196827.1946.66789134.38764.325813.255781.4109nannannannannannannannan23.39240.362173nannan439.574146.635nannannannan23.25510.531018nannan498.852243.989FalseFalseFalseFalseFalse

II - Correct z band fluxes and magnitudes¶

We discovered that the catalogue contains some wrong z magnitudes in the CDFS-SWIRE field. Strangely, Sextractor affected some magnitudes to sources which are not on the z image. Boris found a way to get rid of these magnitudes: all the wrong sources have a Z_MAGERR_AUTO to 0.

But we have to look at these sources in another catalogue because the VIDEO catalogue we use has been processed to correct for wrong error. We use the video_id column (which is unique within a field) to find the sources identified in the other catalogue and set their flux, magnitudes, and associated errors to NaN.

In [9]:
not_errfix_catalogue = Table.read("../../dmu0/dmu0_VISTA-VIDEO-private/data/VIDEO-cdfs_2017-02-12_fullcat.fits")
In [10]:
# Identifiers of the sources with bad z measurements
bad_z_sources_ids = not_errfix_catalogue['ID'][not_errfix_catalogue['Z_MAGERR_AUTO'] == 0]

# Mask of the bad z sources in our catalogue
bad_z_sources_mask = np.in1d(catalogue['video_id'], bad_z_sources_ids)

# Check that we caught all the bad sources
assert len(bad_z_sources_ids) == np.sum(bad_z_sources_mask)
In [11]:
del not_errfix_catalogue
In [12]:
# Set the z flux, magnitudes, and associated error of the bad z sources to NaN
catalogue['m_video_z'][bad_z_sources_mask] = np.nan
catalogue['merr_video_z'][bad_z_sources_mask] = np.nan
catalogue['f_video_z'][bad_z_sources_mask] = np.nan
catalogue['ferr_video_z'][bad_z_sources_mask] = np.nan
catalogue['m_ap_video_z'][bad_z_sources_mask] = np.nan
catalogue['merr_ap_video_z'][bad_z_sources_mask] = np.nan
catalogue['f_ap_video_z'][bad_z_sources_mask] = np.nan
catalogue['ferr_ap_video_z'][bad_z_sources_mask] = np.nan

III - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [13]:
SORT_COLS = ['merr_ap_video_z', 'merr_ap_video_y', 'merr_ap_video_j', 'merr_ap_video_h', 'merr_ap_video_k']
FLAG_NAME = 'video_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])))
The initial catalogue had 1073655 sources.
The cleaned catalogue has 1071323 sources (2332 removed).
The cleaned catalogue has 2319 sources flagged as having been cleaned

IV - 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 [14]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_CDFS-SWIRE.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [15]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)
In [16]:
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.13464397878237833 arcsec
Dec correction: -0.05622936663485234 arcsec
In [17]:
catalogue[RA_COL] +=  delta_ra.to(u.deg)
catalogue[DEC_COL] += delta_dec.to(u.deg)
In [18]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)

V - Flagging Gaia objects¶

In [19]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [20]:
GAIA_FLAG_NAME = "video_flag_gaia"

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

VI - Saving to disk¶

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