XMM-LSS 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: 
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 = "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_irac_i1",
        'fluxerr_aper_2_1': "ferr_ap_servs_irac_i1",
        'flux_auto_1': "f_servs_irac_i1",
        'fluxerr_auto_1': "ferr_servs_irac_i1",
        'class_star_1': "servs_stellarity_irac_i1",
        'flux_aper_2_2': "f_ap_servs_irac_i2",
        'fluxerr_aper_2_2': "ferr_ap_servs_irac_i2",
        'flux_auto_2': "f_servs_irac_i2",
        'fluxerr_auto_2': "ferr_servs_irac_i2",
        'class_star_2': "servs_stellarity_irac_i2",
    })


catalogue = Table.read("../../dmu0/dmu0_DataFusion-Spitzer/data/DF-SERVS_XMM-LSS.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_irac_i1ferr_ap_servs_irac_i1f_servs_irac_i1ferr_servs_irac_i1servs_stellarity_irac_i1f_ap_servs_irac_i2ferr_ap_servs_irac_i2f_servs_irac_i2ferr_servs_irac_i2servs_stellarity_irac_i2m_ap_servs_irac_i1merr_ap_servs_irac_i1m_servs_irac_i1merr_servs_irac_i1flag_servs_irac_i1m_ap_servs_irac_i2merr_ap_servs_irac_i2m_servs_irac_i2merr_servs_irac_i2flag_servs_irac_i2
degdeguJyuJyuJyuJyuJyuJyuJyuJy
0278096736.8696323-5.75561827.497471510236.843891259919.485173722916.429302651980.97nannannannannan21.71271293960.99108886404821.45738677630.735940834035FalsenannannannanFalse
1278101136.8640942-5.74611792.412743855674.335622428569.855494072473.358175973940.9nannannannannan22.94372195421.9510327338721.41580399730.369955398486FalsenannannannanFalse
2278100236.8689484-5.74748331.309930072790.9559646519160.9649024478230.7019559733750.5nannannannannan23.60687971850.79235178626123.93879147960.789861209451FalsenannannannanFalse
3278102136.8672617-5.74413062.183033873240.8061837931241.123122292831.200337804480.03nannannannannan23.05234881370.40095710039823.77393238091.16038139443FalsenannannannanFalse
4278100436.8694334-5.74644031.457302567110.8109062837731.435908939490.5537425612840.58nannannannannan23.49112567520.6041506622123.50718275180.418702280044FalsenannannannanFalse
5278108836.8608685-5.739956514.5165766916.8144282764546.116204148120.25617718830.02nannannannannan20.9953394680.50967054092319.74036611740.476901023178FalsenannannannanFalse
6278115736.8574418-5.73457513.513279233623.95431450366.787305223074.23626934720.89nannannannannan22.53571832831.2220327893321.82075655070.677657899888FalsenannannannanFalse
7278103736.8630737-5.744186612.81118062172.886808359237.781635296452.72114692250.03nannannannannan21.13102711440.24465445022919.95679812131.51505506633FalsenannannannanFalse
8278104736.8656367-5.74141740.9012333471320.8275067960610.7655683092340.4632197322980.52nannannannannan24.01290686760.99691616053324.19004013130.656942598129FalsenannannannanFalse
9278103536.8683861-5.74359765.630190012490.7161676456717.110832197671.40875257510.02nannannannannan22.02369236990.13810708694721.77019892440.215099109614FalsenannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['ferr_ap_servs_irac_i1', 'ferr_ap_servs_irac_i2']
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 958421 sources.
The cleaned catalogue has 958421 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_XMM-LSS.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.12892081194593175 arcsec
Dec correction: -0.10182401164797739 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)))
11230 sources flagged.

V - Saving to disk¶

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