EGS master catalogue

Preparation of DEEP2 data

DEEP2 catalogue: the catalogue comes from dmu0_DEEP2.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The total magnitude. No aperture magnitudes are 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, mag_to_flux
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "deep2_ra"
DEC_COL = "deep2_dec"

I - Column selection

In [4]:
imported_columns = OrderedDict({
        'objno': "deep2_id",
        'ra': "deep2_ra",
        'dec': "deep2_dec",
       # 'pgal':  "deep2_stellarity", #TODO these numbers seems strange.
        'magb': "m_deep2_b", 
        'magberr': "merr_deep2_b",
        'magr': "m_deep2_r", 
        'magrerr': "merr_deep2_r",
        'magi': "m_deep2_i", 
        'magierr': "merr_deep2_i",
    })


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

epoch = 2011 # TODO : check this

# Clean table metadata
catalogue.meta = None
In [5]:
# Adding flux and band-flag columns
for col in catalogue.colnames:
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        
        # Some object have a magnitude to 0, we suppose this means missing value
        catalogue[col][catalogue[col] < 0.] = np.nan
        catalogue[errcol][np.isclose(catalogue[errcol], 9.99)] = np.nan  
        

        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:])))
        
        #Add empty aperture columns
        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:])))
        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:])))        
        
        # 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/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 [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxdeep2_iddeep2_radeep2_decm_deep2_bmerr_deep2_bm_deep2_rmerr_deep2_rm_deep2_imerr_deep2_if_deep2_bferr_deep2_bf_ap_deep2_bferr_ap_deep2_bm_ap_deep2_bmerr_ap_deep2_bflag_deep2_bf_deep2_rferr_deep2_rf_ap_deep2_rferr_ap_deep2_rm_ap_deep2_rmerr_ap_deep2_rflag_deep2_rf_deep2_iferr_deep2_if_ap_deep2_iferr_ap_deep2_im_ap_deep2_imerr_ap_deep2_iflag_deep2_i
degdegmagmagmagmagmagmag
014025920216.2939758353.528530120825.1572nan24.533nan23.6281nan0.314138nannannannannanFalse0.558212nannannannannanFalse1.28458nannannannannanFalse
114026150216.29216003453.521598815924.63320.28339523.38230.058033623.58030.3916340.5090020.132858nannannannanFalse1.610940.0861063nannannannanFalse1.342390.484213nannannannanFalse
214026187216.29315185553.524566650425.01750.41966122.3170.025511921.3030.04997970.3572730.138094nannannannanFalse4.297340.100976nannannannanFalse10.93450.503349nannannannanFalse
314026147216.2910766653.527362823527.72364.4207622.18670.021205321.06880.03011380.02955010.120318nannannannanFalse4.845290.0946323nannannannanFalse13.56690.376288nannannannanFalse
414026196216.29594421453.515541076725.55452.8232323.03590.1499824.0105nan0.2178710.566528nannannannanFalse2.216360.30616nannannannanFalse0.903234nannannannannanFalse
514025984216.29551696853.511611938525.3563nan24.1624nan24.6074nan0.261505nannannannannanFalse0.785308nannannannannanFalse0.521242nannannannannanFalse
614026202216.29479980553.510673522927.2561nan23.8307nan24.2675nan0.0454527nannannannannanFalse1.06591nannannannannanFalse0.712853nannannannannanFalse
714026017216.29321289153.512302398724.35310.15752224.02360.077492523.91120.3922620.658810.0955821nannannannanFalse0.8924010.0636935nannannannanFalse0.9897380.357579nannannannanFalse
814026199216.28912353553.512474060125.74920.98932122.84010.049757821.36450.05581660.1821040.165933nannannannanFalse2.654360.121646nannannannanFalse10.33240.531176nannannannanFalse
914026120216.29444885353.518169403124.67520.5231824.17710.17720924.1368nan0.4896890.235965nannannannanFalse0.7747470.126451nannannannanFalse0.804044nannannannannanFalse

II - Removal of duplicated sources

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_deep2_b', 'merr_deep2_r', 'merr_deep2_i']
FLAG_NAME = 'deep_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 208517 sources.
The cleaned catalogue has 204382 sources (4135 removed).
The cleaned catalogue has 4134 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.5583843305942082 arcsec
Dec correction: -0.24953763438304577 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 = "deep2_flag_gaia"

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

V - Saving to disk

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