CDFS-SWIRE master catalogue¶

Preparation of CANDELS-GOODS-S data¶

CANDELS-GOODS-N catalogue: the catalogue comes from dmu0_CANDELS-GOODS-S.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The total magnitude.

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: 
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",
        'RA': "candels_ra",
        'DEC': "candels_dec",
        'CLASS_STAR':  "candels_stellarity",
    #HST data
        'ACS_F435W_FLUX': "f_acs_f435w", 
        'ACS_F435W_FLUXERR': "ferr_acs_f435w", 
        'ACS_F606W_FLUX': "f_acs_f606w", 
        'ACS_F606W_FLUXERR': "ferr_acs_f606w", 
        'ACS_F775W_FLUX': "f_acs_f775w", 
        'ACS_F775W_FLUXERR': "ferr_acs_f775w", 
        'ACS_F814W_FLUX': "f_acs_f814w", 
        'ACS_F814W_FLUXERR': "ferr_acs_f814w", 
        'ACS_F850LP_FLUX': "f_acs_f850lp", 
        'ACS_F850LP_FLUXERR': "ferr_acs_f850lp", 
    
        'WFC3_F098M_FLUX': "f_wfc3_f098m", 
        'WFC3_F098M_FLUXERR': "ferr_wfc3_f098m", 
        'WFC3_F105W_FLUX': "f_wfc3_f105w", 
        'WFC3_F105W_FLUXERR': "ferr_wfc3_f105w", 
        'WFC3_F125W_FLUX': "f_wfc3_f125w", 
        'WFC3_F125W_FLUXERR': "ferr_wfc3_f125w", 
        'WFC3_F160W_FLUX': "f_wfc3_f160w", 
        'WFC3_F160W_FLUXERR': "ferr_wfc3_f160w", 
    #ISAAC?
        'ISAAC_KS_FLUX':"f_isaac_k",
        'ISAAC_KS_FLUXERR':"ferr_isaac_k",
    #HAWKI WIRCAM
        'HAWKI_KS_FLUX': "f_hawki_k",# 33 WIRCAM_K_FLUX Flux density (in μJy) in the Ks-band (CFHT/WIRCam) (3)
        'HAWKI_KS_FLUXERR': "ferr_hawki_k",# 34 WIRCAM_K_FLUXERR 
    #Spitzer/IRAC
        'IRAC_CH1_FLUX': "f_candels-irac_i1",# 47 IRAC_CH1_FLUX Flux density (in μJy) in the 3.6μm-band (Spitzer/IRAC) (3)
        'IRAC_CH1_FLUXERR': "ferr_candels-irac_i1",# 48 IRAC_CH1_FLUXERR Flux uncertainty (in μJy) in the 3.6μm-band (Spitzer/IRAC) (3)
        'IRAC_CH2_FLUX': "f_candels-irac_i2",# 49 IRAC_CH2_FLUX Flux density (in μJy) in the 4.5μm-band (Spitzer/IRAC) (3)
        'IRAC_CH2_FLUXERR': "ferr_candels-irac_i2",# 50 IRAC_CH2_FLUXERR Flux uncertainty (in μJy) in the 4.5μm-band (Spitzer/IRAC) (3)
        'IRAC_CH3_FLUX': "f_candels-irac_i3",# 51 IRAC_CH3_FLUX Flux density (in μJy) in the 5.8μm-band (Spitzer/IRAC) (3)
        'IRAC_CH3_FLUXERR': "ferr_candels-irac_i3",# 52 IRAC_CH3_FLUXERR Flux uncertainty (in μJy) in the 5.8μm-band (Spitzer/IRAC) (3)
        'IRAC_CH4_FLUX': "f_candels-irac_i4",# 53 IRAC_CH4_FLUX Flux density (in μJy) in the 8.0μm-band (Spitzer/IRAC) (3)
        'IRAC_CH4_FLUXERR': "ferr_candels-irac_i4"# 54 IRAC_CH4_FLUXERR
    
    
    })


catalogue = Table.read("../../dmu0/dmu0_CANDELS-GOODS-S/data/hlsp_candels_hst_wfc3_goodss-tot-multiband_f160w_v1_cat.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]:
# Adding flux and band-flag columns
for col in catalogue.colnames:
    if col.startswith('f_'):
        
        errcol = "ferr{}".format(col[1:])
        
        # Some object have a magnitude to 0, we suppose this means missing value
        mask = np.isclose(catalogue[col], -99.) 
        catalogue[col][mask] = np.nan
        catalogue[errcol][mask] = np.nan  
        

        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:])))
        
catalogue['candels_stellarity'] = catalogue['candels_stellarity'].astype(float)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:76: RuntimeWarning: invalid value encountered in log10
  magnitudes = 2.5 * (23 - np.log10(fluxes)) - 48.6
/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
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table length=10>
idxcandels_idcandels_racandels_deccandels_stellarityf_acs_f435wferr_acs_f435wf_acs_f606wferr_acs_f606wf_acs_f775wferr_acs_f775wf_acs_f814wferr_acs_f814wf_acs_f850lpferr_acs_f850lpf_wfc3_f098mferr_wfc3_f098mf_wfc3_f105wferr_wfc3_f105wf_wfc3_f125wferr_wfc3_f125wf_wfc3_f160wferr_wfc3_f160wf_isaac_kferr_isaac_kf_hawki_kferr_hawki_kf_candels-irac_i1ferr_candels-irac_i1f_candels-irac_i2ferr_candels-irac_i2f_candels-irac_i3ferr_candels-irac_i3f_candels-irac_i4ferr_candels-irac_i4m_acs_f435wmerr_acs_f435wflag_acs_f435wm_acs_f606wmerr_acs_f606wflag_acs_f606wm_acs_f775wmerr_acs_f775wflag_acs_f775wm_acs_f814wmerr_acs_f814wflag_acs_f814wm_acs_f850lpmerr_acs_f850lpflag_acs_f850lpm_wfc3_f098mmerr_wfc3_f098mflag_wfc3_f098mm_wfc3_f105wmerr_wfc3_f105wflag_wfc3_f105wm_wfc3_f125wmerr_wfc3_f125wflag_wfc3_f125wm_wfc3_f160wmerr_wfc3_f160wflag_wfc3_f160wm_isaac_kmerr_isaac_kflag_isaac_km_hawki_kmerr_hawki_kflag_hawki_km_candels-irac_i1merr_candels-irac_i1flag_candels-irac_i1m_candels-irac_i2merr_candels-irac_i2flag_candels-irac_i2m_candels-irac_i3merr_candels-irac_i3flag_candels-irac_i3m_candels-irac_i4merr_candels-irac_i4flag_candels-irac_i4
0153.0929957-27.95453750.02999999932941.572470.05620026.561540.056783915.67080.13134217.66840.18093623.16310.165851nannannannan37.90730.095899554.83620.116206nannannannan76.36190.13900858.92980.082203749.55860.59155435.96970.52303623.40850.0388043False21.85750.00939602False20.91230.0090999False20.7820.0111187False20.4880.00777402FalsenannanFalsenannanFalse19.95320.00274674False19.55230.00230084FalsenannanFalsenannanFalse19.19280.00197646False19.47420.00151454False19.66220.0129598False20.01020.0157877False
1253.1028883-27.95966220.509999990463nannan0.1227520.0268322nannan0.1203980.03534730.2042520.0639968nannannannan0.4890160.05832470.3760550.101423nannannannan4.323430.1258554.173590.07177041.935590.7063971.406680.541094nannanFalse26.17740.23733FalsenannanFalse26.19840.318758False25.62460.340186FalsenannanFalsenannanFalse24.67670.129495False24.96190.292826FalsenannanFalsenannanFalse22.31040.0316058False22.34870.0186707False23.1830.396241False23.52950.41764False
2353.1016865-27.95847860.0299999993294nannan3.347790.0594275nannan5.479880.09569896.132150.155562nannannannan8.466960.077748110.55020.110988nannannannan7.492080.1353646.482260.08098013.458650.7215657.874050.57855nannanFalse22.58810.0192732FalsenannanFalse22.05310.018961False21.9310.0275432FalsenannanFalsenannanFalse21.58070.0099698False21.34190.0114219FalsenannanFalsenannanFalse21.71350.0196167False21.87070.0135636False22.55270.226513False21.65950.079775False
3453.1022798-27.95865090.00999999977648nannan0.282940.0769396nannan0.5726610.1228730.6202820.190909nannannannan0.7063610.1069920.8811690.214985nannannannan1.711410.1299011.372160.07707051.783490.699897-0.3259730.557147nannanFalse25.27080.295243FalsenannanFalse24.50530.232961False24.41850.334165FalsenannanFalsenannanFalse24.27740.164456False24.03740.264895FalsenannanFalsenannanFalse23.31660.0824105False23.55650.0609828False23.27180.426077Falsenan-1.85572False
4553.0905594-27.95849950.00.06166290.01011970.1174890.01311630.1303160.02213470.1143630.02340910.1110820.0262729nannannannan0.1658810.02568180.3085740.0219707nannannannan2.826230.1335842.121980.06714094.579580.6067222.526120.52771726.92490.178184False26.2250.12121False26.11250.184417False26.25430.222241False26.28590.256796FalsenannanFalsenannanFalse25.85050.168094False25.17660.0773052FalsenannanFalsenannanFalse22.7720.0513182False23.08320.0343534False22.24790.143843False22.89390.226815False
5653.0999405-27.95827970.0nannan1.012990.0415012nannan1.19130.05876541.142860.0900046nannannannan1.382840.03632051.374060.063972nannannannan1.834820.1249171.753060.07264562.20020.6457250.4794550.521698nannanFalse23.8860.0444815FalsenannanFalse23.70990.0535581False23.7550.0855059FalsenannanFalsenannanFalse23.54810.028517False23.5550.0505485FalsenannanFalsenannanFalse23.2410.0739184False23.29050.0449922False23.04380.318647False24.69811.1814False
6753.0961485-27.95759240.00.7508370.03357191.758130.03268853.875520.07721684.051890.09575585.050380.0863977nannannannan7.307260.07045249.554740.136626nannannannan18.53870.16215113.75080.091658912.36780.75840210.76630.65881124.21110.0485461False23.28740.0201868False22.42920.0216325False22.38090.0256585False22.14170.0185739FalsenannanFalsenannanFalse21.74060.010468False21.44950.0155253FalsenannanFalsenannanFalse20.72980.00949652False21.05420.00723721False21.16930.0665781False21.31980.0664383False
7853.091539-27.95836310.3600000143050.05521730.01231910.0702710.01161160.08060830.02104330.1017590.02731730.1064260.027046nannannannan0.1377550.02817350.1461310.0232199nannannannan1.809130.1839081.053410.09035561.443880.7258993.633580.64944727.04480.24223False26.78310.179407False26.63410.283438False26.38110.291467False26.33240.275918FalsenannanFalsenannanFalse26.05220.222054False25.98820.172521FalsenannanFalsenannanFalse23.25630.110371False23.84350.0931283False23.50120.545845False22.49920.194059False
8953.0895949-27.95802950.00.1165140.01821760.2077750.025970.4413550.04462170.4128820.0384710.4396510.0527499nannannannan0.4757930.04563590.5452270.0355639nannannannan1.639950.1303411.384030.06970791.591810.6110550.2590890.5263826.23410.169761False25.6060.135707False24.7880.10977False24.86040.101165False24.79220.130268FalsenannanFalsenannanFalse24.70650.104139False24.55860.0708201FalsenannanFalsenannanFalse23.36290.0862928False23.54710.0546841False23.39530.416786False25.36642.20584False
91053.0909628-27.95783330.00.221390.02169180.3579640.02538680.5841020.04593670.5849980.05232990.6160880.0576579nannannannan0.7030040.05299710.7557780.045867nannannannan2.974970.1388391.97970.07110563.014860.6067224.981120.52102925.53710.10638False25.01540.0770004False24.48380.0853877False24.48210.0971225False24.42590.101611FalsenannanFalsenannanFalse24.28260.08185False24.2040.0658917FalsenannanFalsenannanFalse22.71630.0506703False23.15850.0389968False22.70180.218498False22.15670.113569False

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ["ferr_acs_f435w","ferr_acs_f606w","ferr_acs_f775w","ferr_acs_f814w","ferr_acs_f850lp",    
             "ferr_wfc3_f098m","ferr_wfc3_f105w","ferr_wfc3_f125w","ferr_wfc3_f160w",    
             "ferr_isaac_k","ferr_hawki_k",    
             "ferr_candels-irac_i1","ferr_candels-irac_i2","ferr_candels-irac_i3","ferr_candels-irac_i4"]
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])))
The initial catalogue had 34930 sources.
The cleaned catalogue has 34926 sources (4 removed).
The cleaned catalogue has 4 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_CDFS-SWIRE.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.11352528611894286 arcsec
Dec correction: -0.2639050027212875 arcsec
In [11]:
catalogue[RA_COL].unit = u.deg
catalogue[DEC_COL].unit = u.deg
catalogue[RA_COL] = catalogue[RA_COL] +  delta_ra.to(u.deg)
catalogue[DEC_COL] = 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)))
123 sources flagged.

V - Saving to disk¶

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