ELAIS-S1 master catalogue¶

Preparation of Spitzer datafusion SERVS data¶

The Spitzer catalogues were produced by the datafusion team are available in dmu0_DataFusion-Spitzer. Lucia told that the magnitudes are aperture corrected.

In the catalouge, we keep:

  • The internal identifier (this one is only in HeDaM data);
  • The position;
  • The fluxes in aperture 2 (1.9 arcsec);
  • The “auto” flux (which seems to be the Kron flux);
  • The stellarity in each band

A query of the position in the Spitzer heritage archive show that the SERVS-ELAIS-N1 images were observed in 2009. Let's take this as epoch.

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 = "servs_ra"
DEC_COL = "servs_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'internal_id': "servs_intid",
        'ra_12': "servs_ra",
        'dec_12': "servs_dec",
        'flux_aper_2_1': "f_ap_servs_irac1",
        'fluxerr_aper_2_1': "ferr_ap_servs_irac1",
        'flux_auto_1': "f_servs_irac1",
        'fluxerr_auto_1': "ferr_servs_irac1",
        'class_star_1': "servs_stellarity_irac1",
        'flux_aper_2_2': "f_ap_servs_irac2",
        'fluxerr_aper_2_2': "ferr_ap_servs_irac2",
        'flux_auto_2': "f_servs_irac2",
        'fluxerr_auto_2': "ferr_servs_irac2",
        'class_star_2': "servs_stellarity_irac2",
    })


catalogue = Table.read("../../dmu0/dmu0_DataFusion-Spitzer/data/DF-SERVS_ELAIS-S1.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2009

# Clean table metadata
catalogue.meta = None
In [5]:
# Adding magnitude and band-flag columns
for col in catalogue.colnames:
    if col.startswith('f_'):
        errcol = "ferr{}".format(col[1:])
        
        magnitude, error = flux_to_mag(
            np.array(catalogue[col])/1.e6, np.array(catalogue[errcol])/1.e6)
        # Note that some fluxes are 0.
        
        catalogue.add_column(Column(magnitude, 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:])))
/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[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxservs_intidservs_raservs_decf_ap_servs_irac1ferr_ap_servs_irac1f_servs_irac1ferr_servs_irac1servs_stellarity_irac1f_ap_servs_irac2ferr_ap_servs_irac2f_servs_irac2ferr_servs_irac2servs_stellarity_irac2m_ap_servs_irac1merr_ap_servs_irac1m_servs_irac1merr_servs_irac1flag_servs_irac1m_ap_servs_irac2merr_ap_servs_irac2m_servs_irac2merr_servs_irac2flag_servs_irac2
degdeguJyuJyuJyuJyuJyuJyuJyuJy
018268888.3872733-44.6890863nannannannannan3.876482779850.9116323042475.135227025521.487421623450.8nannannannanFalse22.42890535230.25533254095522.12360087930.314484150417False
116740658.3768692-44.688598977.13990880578.24720410207353.86443628552.5915117260.83nannannannannan19.18180219720.11607854118917.52790770550.161362664594FalsenannannannanFalse
216697378.3819033-44.688311311.89973925840.88546909623412.73833535931.427437404910.39nannannannannan21.21115638640.080790497598521.13721830430.12166585561FalsenannannannanFalse
316695328.3823787-44.68560943.185623808470.9111280000282.39912978731.185860177350.5nannannannannan22.64201377880.31053404804722.94986564270.536665975783FalsenannannannanFalse
416693658.3853193-44.6862528-0.2415100581840.7210975452810.2977562125920.3244865353870.57nannannannannannan-3.2417768351425.21534792081.18320546987FalsenannannannanFalse
518267998.3870609-44.6865231nannannannannan1.597013534610.8400508506931.11491799370.8817297903930.5nannannannanFalse23.39172850810.57111201794323.78189268850.85865145388False
616692968.38806855-44.685079456.212540150180.6704640505355.721821757780.7648215113890.844.102926144740.8659481693053.481861102521.114180988830.9421.91682697880.11717382520822.00616418790.145127625474False22.36726575130.22915140211922.54547139410.347431044091False
716697058.3776621-44.68446862.227962043481.606478858661.664370082451.009331081680.8nannannannannan23.03023053070.78287341749323.34687524850.658427659523FalsenannannannanFalse
816696798.3799682-44.68448343.719224307270.9715403080584.491353522461.627798051560.08nannannannannan22.47386907110.28361733514722.26905689870.393502597774FalsenannannannanFalse
916696648.3804248-44.68333285.149299216650.84668259849610.4243852152.162551640360.02nannannannannan22.12062967840.178524088921.3548738710.225237322123FalsenannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['ferr_ap_servs_irac1', 'ferr_ap_servs_irac2']
FLAG_NAME = "servs_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 605425 sources.
The cleaned catalogue has 605425 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_ELAIS-S1.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.0358870084561147 arcsec
Dec correction: -0.00565381727994918 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 = "servs_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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