EGS master catalogue

Preparation of IRAC-EGS data

IRAC-EGS catalogue: the catalogue comes from dmu0_IRAC-EGS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The total flux (no aperture fluxes given).

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, flux_to_mag
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "irac-egs_ra"
DEC_COL = "irac-egs_dec"

I - Column selection

In [4]:
imported_columns = OrderedDict({
        'no.': "irac-egs_id",
        'ALPHA_GR_DEC_ORDER': "irac-egs_ra",
        'DELTA_GR_DEC_ORDER': "irac-egs_dec",
        'irac36_final': "f_irac-egs_i1", 
        'err_irac36_final': "ferr_irac-egs_i1", 
        'irac45_final': "f_irac-egs_i2", 
        'err_irac45_final': "ferr_irac-egs_i2", 
        'irac58_final': "f_irac-egs_i3", 
        'err_irac58_final': "ferr_irac-egs_i3", 
        'irac80_final': "f_irac-egs_i4", 
        'err_irac80_final': "ferr_irac-egs_i4", 
    })


catalogue = Table.read("../../dmu0/dmu0_IRAC-EGS/data/IRAC_EGS.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2011 # TODO: Check

# 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
        catalogue[col][np.isclose(catalogue[col], -99.) ] = np.nan
        catalogue[errcol][np.isclose(catalogue[errcol], -99.) ] = np.nan  
        
        #fluxes already in uJy
        
        mag, error = flux_to_mag(np.array(catalogue[col])*1.e-6, np.array(catalogue[errcol])*1.e-6)
        
        
        catalogue.add_column(Column(mag , name="m{}".format(col[1:])))
        catalogue.add_column(Column(error , name="m{}".format(errcol[1:])))
        
        # Add empty aperture columns
        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: 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>
idxirac-egs_idirac-egs_rairac-egs_decf_irac-egs_i1ferr_irac-egs_i1f_irac-egs_i2ferr_irac-egs_i2f_irac-egs_i3ferr_irac-egs_i3f_irac-egs_i4ferr_irac-egs_i4m_irac-egs_i1merr_irac-egs_i1m_ap_irac-egs_i1merr_ap_irac-egs_i1f_ap_irac-egs_i1ferr_ap_irac-egs_i1flag_irac-egs_i1m_irac-egs_i2merr_irac-egs_i2m_ap_irac-egs_i2merr_ap_irac-egs_i2f_ap_irac-egs_i2ferr_ap_irac-egs_i2flag_irac-egs_i2m_irac-egs_i3merr_irac-egs_i3m_ap_irac-egs_i3merr_ap_irac-egs_i3f_ap_irac-egs_i3ferr_ap_irac-egs_i3flag_irac-egs_i3m_irac-egs_i4merr_irac-egs_i4m_ap_irac-egs_i4merr_ap_irac-egs_i4f_ap_irac-egs_i4ferr_ap_irac-egs_i4flag_irac-egs_i4
01215.7744853.566512378.3213.781153.635.3276196.995.9567165.596.009417.45535174750.0395499329609nannannannanFalse18.43380992360.0376512933963nannannannanFalse18.16388954950.0328311328031nannannannanFalse18.35241473460.0394022776066nannannannanFalse
12215.8228753.570623434.0615.812206.797.1616252.497.5418125.594.625917.30612558480.0395513543511nannannannanFalse18.1111761670.0376014720441nannannannanFalse17.89438954420.0324306123373nannannannanFalse18.65261234890.0399912979504nannannannanFalse
23215.0520353.1249251629.829.3471163.222.113952.923.7654564.0103.7615.86966421630.0195503131679nannannannanFalse16.23586401620.0206403754263nannannannanFalse16.45238168260.0270778895016nannannannanFalse14.75163591060.0246836083711nannannannanFalse
34214.4471352.695783354.5312.912237.328.1948220.366.4664200.927.241617.52586752330.0395425658642nannannannanFalse17.96166415080.0374911134786nannannannanFalse18.04216809070.0318606126087nannannannanFalse18.14244207630.039132327794nannannannanFalse
45216.0294611153.587263513.67960.254162.40340.242710.996541.26931.28661.882222.48549847450.0749947586154nannannannanFalse22.94793485790.109644268227nannannannanFalse23.90376316131.38290983272nannannannanFalse23.62639113231.58835122384nannannannanFalse
56216.032337753.58461661.98190.118181.13030.08374nan0.0nan0.023.15729565580.0647420680551nannannannanFalse23.7670156810.0804384232385nannannannanFalsenannannannannannanFalsenannannannannannanFalse
67216.03333153.58455210.438740.092721.18040.08753nan0.01.41930.5986124.79448192270.2294512944nannannannanFalse23.71992699790.0805104117269nannannannanFalsenannannannannannanFalse23.51981449310.457924716079nannannannanFalse
78216.033073753.58513480.667470.070510.82560.07656nan0.00.487340.5524124.33892062310.114694682604nannannannanFalse24.10807578930.100683095732nannannannanFalsenannannannannannanFalse24.68041985261.23070451198nannannannanFalse
89216.0112954953.602447112.57110.221212.00070.207330.497951.0242nan1.022.87470257910.09341359957nannannannanFalse23.14704506970.112513463954nannannannanFalse24.65703565822.23317807192nannannannanFalsenannannannannannanFalse
910216.0180146853.5957469151.3481.894634.2031.224528.9491.347117.0821.171919.62369116870.040060680329nannannannanFalse20.0648394990.0388703909811nannannannanFalse20.24591608430.0505231697616nannannannanFalse20.81865320620.0744862579532nannannannanFalse

II - Removal of duplicated sources

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['ferr_irac-egs_i1', 'ferr_irac-egs_i2', 'ferr_irac-egs_i3', 'ferr_irac-egs_i4']
FLAG_NAME = 'wfc_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 117929 sources.
The cleaned catalogue has 117929 sources (0 removed).
The cleaned catalogue has 0 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_EGS.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.10139878082782161 arcsec
Dec correction: -0.05154244758358573 arcsec
In [11]:
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 = "irac-egs_flag_gaia"

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

V - Saving to disk

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