XMM-LSS master catalogue¶

Preparation of HST CANDELS-3D data¶

The catalogue comes from dmu0_CANDELS-3D-HST.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The kron magnitude, there doesn't appear to be aperture magnitudes. This may mean the survey is unusable.
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, flux_to_mag
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "candels_ra"
DEC_COL = "candels_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'ID': "candels_id",
        'RAJ2000': "candels_ra",
        'DEJ2000': "candels_dec",
        'S/G':  "candels_stellarity",
        'F140Wap': "f_ap_candels_f140w",
        'e_F140Wap': "ferr_ap_candels_f140w",
        'F140W': "f_candels_f140w",
        'e_F140W': "ferr_candels_f140w",
        'F160Wap': "f_ap_candels_f160w",
        'e_F160Wap': "ferr_ap_candels_f160w",
        'F160W': "f_candels_f160w",
        'e_F160W': "ferr_candels_f160w",
        'F606W': "f_candels_f606w",
        'e_F606W': "ferr_candels_f606w",
        'F814W': "f_candels_f814w",
        'e_F814W': "ferr_candels_f814w",
        'F125W': "f_candels_f125w",
        'e_F125W': "ferr_candels_f125w"

    })


catalogue = Table.read("../../dmu0/dmu0_CANDELS-3D-HST/data/CANDELS-3D-HST_XMM-LSS.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2012 #Year of publication

# Clean table metadata
catalogue.meta = None
WARNING: UnitsWarning: '0.3631uJy' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]
WARNING: UnitsWarning: '[Msun]' did not parse as fits unit: Invalid character at col 0 [astropy.units.core]
In [5]:
# Adding flux and band-flag columns
for col in catalogue.colnames:
    if col.startswith('f_'):
        
        errcol = "ferr{}".format(col[1:])
        
        #Calculate mags, errors including the fact that fluxes are in units of 0.3631 uJy
        mag, error = flux_to_mag(np.array(catalogue[col]) * 0.3631e-6, np.array(catalogue[errcol] * 0.3631e-6))
        
        
        # magnitudes are added
        catalogue.add_column(Column(mag, name="m{}".format(col[1:])))
        catalogue.add_column(Column(error, name="m{}".format(errcol[1:])))
        
        
        #Correct flux units to uJy
        catalogue[col] = catalogue[col] * 0.3631
        catalogue[col].unit = u.microjansky
        catalogue[errcol] = catalogue[errcol] * 0.3631
        catalogue[errcol].unit = u.microjansky        

        if ('125' in col) or ('814' in col) or ('606' in col) :
            # We add nan filled aperture photometry for consistency
            catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="m_ap{}".format(col[1:])))
            catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="merr_ap{}".format(col[1:])))
            catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="f_ap{}".format(col[1:])))
            catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="ferr_ap{}".format(col[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/herschelhelp_internal/herschelhelp_internal/utils.py:76: RuntimeWarning: invalid value encountered in log10
  magnitudes = 2.5 * (23 - np.log10(fluxes)) - 48.6
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxcandels_idcandels_racandels_deccandels_stellarityf_ap_candels_f140wferr_ap_candels_f140wf_candels_f140wferr_candels_f140wf_ap_candels_f160wferr_ap_candels_f160wf_candels_f160wferr_candels_f160wf_candels_f606wferr_candels_f606wf_candels_f814wferr_candels_f814wf_candels_f125wferr_candels_f125wm_ap_candels_f140wmerr_ap_candels_f140wm_candels_f140wmerr_candels_f140wflag_candels_f140wm_ap_candels_f160wmerr_ap_candels_f160wm_candels_f160wmerr_candels_f160wflag_candels_f160wm_candels_f606wmerr_candels_f606wm_ap_candels_f606wmerr_ap_candels_f606wf_ap_candels_f606wferr_ap_candels_f606wflag_candels_f606wm_candels_f814wmerr_candels_f814wm_ap_candels_f814wmerr_ap_candels_f814wf_ap_candels_f814wferr_ap_candels_f814wflag_candels_f814wm_candels_f125wmerr_candels_f125wm_ap_candels_f125wmerr_ap_candels_f125wf_ap_candels_f125wferr_ap_candels_f125wflag_candels_f125w
degdeguJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJy
0134.44606781-5.285457132nannannannan0.1817460.02832180.2609640.0466620.2320610.01869780.2568610.02230850.1845530.0413063nannannannanFalse25.75130.16919225.35860.194137False25.4860.087481nannannannanFalse25.37580.0942969nannannannanFalse25.73470.243007nannannannanFalse
1234.44749069-5.284815790nannannannan5.067060.02723837.603310.08590220.2157320.01939831.00590.02334625.522390.0378386nannannannanFalse22.13810.0058364421.69750.0122666False25.56520.0976274nannannannanFalse23.89360.0251993nannannannanFalse22.04470.00743932nannannannanFalse
2334.43383026-5.285183912nannannannan0.03870280.02452890.04658940.02952620.05065250.01561080.08544470.01858930.1319180.0377769nannannannanFalse27.43060.68811227.22930.68809False27.13850.334617nannannannanFalse26.57080.236212nannannannanFalse26.09920.310919nannannannanFalse
3434.43863678-5.283362870nannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannannannanFalsenannannannannannanFalse
4534.44387817-5.284455780nannannannan0.7373830.02209860.9716190.05072140.1126260.01698440.1656970.02044830.6596440.0285219nannannannanFalse24.23080.032538423.93130.0566787False26.27090.163732nannannannanFalse25.85170.133988nannannannanFalse24.35170.0469454nannannannanFalse
5634.43869019-5.284337040nannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannannannanFalsenannannannannannanFalsenannannannannannanFalse
6734.44271088-5.2843380nannannannan0.4560170.02584070.6299780.0932840.2897540.0178010.2996950.02148930.6240240.0322701nannannannanFalse24.75250.061524524.40170.16077False25.24490.066702nannannannanFalse25.20830.0778516nannannannanFalse24.4120.0561467nannannannanFalse
7834.43680954-5.28429892nannannannan0.0747260.0191510.05512580.05405110.04133890.009579670.05520570.01141660.09537180.0159688nannannannanFalse26.71630.27825527.04661.06457False27.35910.251603nannannannanFalse27.0450.224531nannannannanFalse26.45150.181792nannannannanFalse
8934.43286133-5.284348012nannannannan0.07037970.01974760.1223210.0388590.09109090.02267960.03867740.02670890.147110.0424754nannannannanFalse26.78140.30464226.18130.344917False26.50130.270324nannannannanFalse27.43140.749761nannannannanFalse25.98090.313487nannannannanFalse
91034.43959045-5.282533170nannannannan2.633310.02371379.679880.2288471.90450.04745353.212740.0568768.167210.0795697nannannannanFalse22.84870.0097773621.43530.0256685False23.20060.0270528nannannannanFalse22.63280.019221nannannannanFalse21.61980.0105779nannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_candels_f140w', 
             'merr_candels_f160w', 
             'merr_candels_f606w', 
             'merr_candels_f814w',
             'merr_candels_f125w']
FLAG_NAME = 'candels_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 44102 sources.
The cleaned catalogue has 43863 sources (239 removed).
The cleaned catalogue has 236 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_XMM-LSS.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)
In [10]:
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.09405840634997276 arcsec
Dec correction: -0.10633781055542357 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)

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 = "candels_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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