COSMOS 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_COSMOS.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:])
        
        catalogue[col] = catalogue[col] * 0.3631e-6
        catalogue[col].unit = u.microjansky
        catalogue[errcol] = catalogue[errcol] * 0.3631e-6
        catalogue[errcol].unit = u.microjansky
      

        mag, error = flux_to_mag(np.array(catalogue[col]) * 1.e-6 , np.array(catalogue[errcol] ) * 1.e-6)
        
        # Fluxes are added in µJy
        catalogue.add_column(Column(mag, name="m{}".format(col[1:])))
        catalogue.add_column(Column(error, name="m{}".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/herschelhelp_internal/herschelhelp_internal/utils.py:76: RuntimeWarning: divide by zero encountered in log10
  magnitudes = 2.5 * (23 - np.log10(fluxes)) - 48.6
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:80: RuntimeWarning: divide by zero encountered in true_divide
  errors = 2.5 / np.log(10) * errors_on_fluxes / fluxes
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:80: RuntimeWarning: invalid value encountered in true_divide
  errors = 2.5 / np.log(10) * errors_on_fluxes / fluxes
/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['candels_stellarity'] = catalogue['candels_stellarity'].astype(float)
catalogue['candels_stellarity'][np.isclose(catalogue['candels_stellarity'], 1.)] = 0.9
catalogue['candels_stellarity'][np.isclose(catalogue['candels_stellarity'], 0.)] = 0.05
catalogue['candels_stellarity'][np.isclose(catalogue['candels_stellarity'], 2.)] = np.nan
In [7]:
catalogue[:10].show_in_notebook()
Out[7]:
<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_f606wflag_candels_f606wm_candels_f814wmerr_candels_f814wflag_candels_f814wm_candels_f125wmerr_candels_f125wflag_candels_f125w
degdeguJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJy
01150.071441652.169014450.05nannannannan1.81107e-066.55976e-082.5702e-061.19645e-071.4882e-061.21733e-083.05443e-061.49935e-082.55971e-065.8372e-08nannannannanFalse38.25520.039325837.87510.0505419False38.46830.00888118False37.68770.00532962False37.87950.0247593False
12150.071578982.169059510.05nannannannan7.8386e-076.01039e-081.2548e-069.1897e-088.07208e-071.37383e-081.53976e-061.69513e-081.25887e-066.90035e-08nannannannanFalse39.16440.083250838.65360.0795153False39.13250.0184787False38.43140.0119529False38.65010.0595135False
23150.075515752.173113580.05nannannannan6.58554e-061.6699e-082.12399e-051.983e-071.70541e-062.80277e-087.05285e-063.45236e-081.62117e-053.74937e-08nannannannanFalse36.85350.002753135.58210.0101366False38.32040.0178436False36.77910.00531465False35.87540.00251104False
34150.068344122.16974521nannannannannan1.95954e-073.50283e-082.36952e-073.28769e-087.29069e-081.15397e-088.18682e-081.6118e-087.56664e-083.14532e-08nannannannanFalse40.66960.19408340.46330.150645False41.74310.17185False41.61720.213757False41.70270.451321False
45150.071456912.17064571nannannannannan2.64123e-072.48694e-082.99321e-072.954e-081.00927e-079.7968e-091.18643e-071.22463e-083.4976e-072.06677e-08nannannannanFalse40.34550.10223240.20970.107151False41.390.10539False41.21440.112069False40.04060.0641572False
56150.069595342.17076755nannannannannan1.42974e-071.98961e-081.7789e-073.42327e-086.36696e-081.06835e-087.85603e-081.34641e-081.56881e-071.74898e-08nannannannanFalse41.01190.15108940.77460.208936False41.89020.182182False41.6620.18608False40.91110.121043False
67150.068359382.171061990.05nannannannan1.10175e-062.44958e-081.47201e-065.34846e-084.72647e-071.12641e-087.2148e-071.44053e-081.08774e-062.36287e-08nannannannanFalse38.79480.024139738.48020.0394497False39.71370.0258752False39.25440.0216781False38.80870.0235852False
78150.069168092.17103839nannannannannan1.23541e-072.02806e-081.7252e-074.45887e-084.02823e-081.22031e-083.75881e-081.52458e-081.25059e-071.97065e-08nannannannanFalse41.17050.17823540.80790.280615False42.38720.328911False42.46240.440378False41.15720.171088False
89150.079971312.171032190.05nannannannan2.48139e-074.26679e-084.68835e-079.99106e-081.13589e-071.6695e-082.15605e-072.04462e-084.43599e-076.01875e-08nannannannanFalse40.41330.18669439.72250.231375False41.26170.159579False40.56580.102962False39.78250.147312False
910150.0685732.171544790.05nannannannan1.62977e-062.09149e-082.39443e-065.30525e-088.18318e-071.27045e-081.27005e-061.56736e-082.09737e-062.14015e-08nannannannanFalse38.36970.013933337.9520.0240563False39.11770.0168562False38.64040.013399False38.09580.0110788False

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [8]:
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 33879 sources.
The cleaned catalogue has 33869 sources (10 removed).
The cleaned catalogue has 10 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_COSMOS.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.10791846540882943 arcsec
Dec correction: -0.028431532331651965 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 = "candels_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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