EGS master catalogue

Preparation of AEGIS data

This resource contains the near-infrared catalogue of Extended Groth Strip observations with the WIRC instrument at the Palomar Observatory.: the catalogue comes from dmu0_AEGIS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The magnitude for each band in 2 arcsecond aperture.
  • The auto magnitude to be used as 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: 
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, mag_to_flux
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "aegis_ra"
DEC_COL = "aegis_dec"

I - Column selection

In [4]:
imported_columns = OrderedDict({
        'id': "aegis_id",
        'ra': "aegis_ra",
        'dec': "aegis_dec",
        'kmag_auto': "m_aegis_k", 
        'kerr2_auto': "merr_aegis_k", 
        'kmag_d2': "m_ap_aegis_k", 
        'kerr2_d2': "merr_ap_aegis_k",
        #'jmag_auto': "m_aegis_j", 
        #'jerr2_auto': "merr_aegis_j", 
        'jmag_d2': "m_ap_aegis_j", 
        'jerr2_d2': "merr_ap_aegis_j"
    })


catalogue = Table.read("../../dmu0/dmu0_AEGIS/data/EGS_Palomar_20160804.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2011

# Clean table metadata
catalogue.meta = None
WARNING: UnitsWarning: 'vega' did not parse as fits unit: At col 0, Unit 'vega' not supported by the FITS standard.  [astropy.units.core]
In [5]:
#AB correction
#Values from http://svo2.cab.inta-csic.es/svo/theory/fps/index.php?id=P200/WIRC.Ks&&mode=browse&gname=P200&gname2=WIRC#filter
j_vega_to_ab = -2.5 * np.log10 (1564.9/3631)  # = +0.85 (WIRC.J_ori)
ks_vega_to_ab = -2.5 * np.log10 (676.92/3631) # = +1.82 (WIRC.Ks) #The K band in AEGIS is Ks
In [6]:
# Adding flux and band-flag columns
for col in catalogue.colnames:
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        catalogue[errcol].unit = u.mag
        
        # Some object have a magnitude to 0, we suppose this means missing value
        catalogue[col][catalogue[col] <= 0] = np.nan
        catalogue[errcol][catalogue[errcol] <= 0] = np.nan  
        
        #TODO convert Vega to AB
        if col.endswith('j') :
            catalogue[col] += j_vega_to_ab
            catalogue[col].unit = u.mag
        if col.endswith('k') :
            catalogue[col] += ks_vega_to_ab
            catalogue[col].unit = u.mag

        flux, error = mag_to_flux(np.array(catalogue[col]), np.array(catalogue[errcol]))
        
        # Fluxes are added in µJy
        catalogue.add_column(Column(flux * 1.e6, name="f{}".format(col[1:])))
        catalogue.add_column(Column(error * 1.e6, name="f{}".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:])))

#Add nans for total J which is absent
catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="m_aegis_j"))
catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="merr_aegis_j"))   
catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="f_aegis_j"))
catalogue.add_column(Column(np.full(len(catalogue), np.nan), name="ferr_aegis_j"))  
catalogue.add_column(Column(np.zeros(len(catalogue), dtype=bool), name="flag_aegis_j"))

# TODO: Set to True the flag columns for fluxes that should not be used for SED fitting.
/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)
In [7]:
catalogue[:10].show_in_notebook()
Out[7]:
<Table masked=True length=10>
idxaegis_idaegis_raaegis_decm_aegis_kmerr_aegis_km_ap_aegis_kmerr_ap_aegis_km_ap_aegis_jmerr_ap_aegis_jf_aegis_kferr_aegis_kflag_aegis_kf_ap_aegis_kferr_ap_aegis_kf_ap_aegis_jferr_ap_aegis_jm_aegis_jmerr_aegis_jf_aegis_jferr_aegis_jflag_aegis_j
degdegmagmagmagmagmagmag
013007537215.33192768152.890260516219.03420.0119.090.01nannan88.37120.813928False83.94420.773155nannannannannannanFalse
113007941215.33008816952.890493147417.42220.0117.49190.01nannan390.0423.59242False365.7893.36904nannannannannannanFalse
214032571216.08571866653.578529529820.31260.096428921.360.119386nannan27.22392.41787False10.37511.14083nannannannannannanFalse
314032744216.09018141653.574155605814.37280.0114.75060.01nannan6469.5159.5863False4568.2642.0753nannannannannannanFalse
414032720216.08402035253.572982034819.93680.069761620.70020.0617199nannan38.48322.47265False19.05071.08296nannannannannannanFalse
514032727216.09045127453.563470506920.69860.13085321.03050.0868168nannan19.07882.29938False14.05371.12375nannannannannannanFalse
614032681216.08969004753.569276166722.0270.34435121.91730.214116nannan5.612941.78019False6.20971.2246nannannannannannanFalse
714032829216.08997731753.566925566121.53420.26599421.57490.157nannan8.837122.165False8.511981.23085nannannannannannanFalse
814032725216.08135718953.567702258421.28240.21333521.52950.149057nannan11.14372.18962False8.875471.21848nannannannannannanFalse
914032575216.07991603353.572577379720.93430.15784921.71040.180707nannan15.35572.23248False7.51331.25049nannannannannannanFalse

II - Removal of duplicated sources

We remove duplicated objects from the input catalogues.

In [8]:
SORT_COLS = ['merr_ap_aegis_j', 'merr_ap_aegis_k']
FLAG_NAME = 'aegis_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 45065 sources.
The cleaned catalogue has 45065 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 [9]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_EGS.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.6291472751286165 arcsec
Dec correction: -0.21136460382251698 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 = "aegis_flag_gaia"

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

V - Saving to disk

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