XMM-LSS master catalogue¶

Preparation of Spitzer datafusion SWIRE 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:

We keep:

  • The internal identifier (this one is only in HeDaM data);
  • The position;
  • The fluxes in aperture 2 (1.9 arcsec) for IRAC bands.
  • The Kron flux;
  • The stellarity in each band

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

We do not use the MIPS fluxes as they will be extracted on MIPS maps using XID+.

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 = "swire_ra"
DEC_COL = "swire_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'internal_id': "swire_intid",
        'ra_spitzer': "swire_ra",
        'dec_spitzer': "swire_dec",
        'flux_ap2_36': "f_ap_swire_irac_i1",
        'uncf_ap2_36': "ferr_ap_swire_irac_i1",
        'flux_kr_36': "f_swire_irac_i1",
        'uncf_kr_36': "ferr_swire_irac_i1",
        'stell_36': "swire_stellarity_irac_i1",
        'flux_ap2_45': "f_ap_swire_irac_i2",
        'uncf_ap2_45': "ferr_ap_swire_irac_i2",
        'flux_kr_45': "f_swire_irac_i2",
        'uncf_kr_45': "ferr_swire_irac_i2",
        'stell_45': "swire_stellarity_irac_i2",
        'flux_ap2_58': "f_ap_irac_i3",
        'uncf_ap2_58': "ferr_ap_irac_i3",
        'flux_kr_58': "f_irac_i3",
        'uncf_kr_58': "ferr_irac_i3",
        'stell_58': "swire_stellarity_irac_i3",
        'flux_ap2_80': "f_ap_irac_i4",
        'uncf_ap2_80': "ferr_ap_irac_i4",
        'flux_kr_80': "f_irac_i4",
        'uncf_kr_80': "ferr_irac_i4",
        'stell_80': "swire_stellarity_irac_i4",
    })


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

epoch = 2004

# 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>
idxswire_intidswire_raswire_decf_ap_swire_irac_i1ferr_ap_swire_irac_i1f_swire_irac_i1ferr_swire_irac_i1swire_stellarity_irac_i1f_ap_swire_irac_i2ferr_ap_swire_irac_i2f_swire_irac_i2ferr_swire_irac_i2swire_stellarity_irac_i2f_ap_irac_i3ferr_ap_irac_i3f_irac_i3ferr_irac_i3swire_stellarity_irac_i3f_ap_irac_i4ferr_ap_irac_i4f_irac_i4ferr_irac_i4swire_stellarity_irac_i4m_ap_swire_irac_i1merr_ap_swire_irac_i1m_swire_irac_i1merr_swire_irac_i1flag_swire_irac_i1m_ap_swire_irac_i2merr_ap_swire_irac_i2m_swire_irac_i2merr_swire_irac_i2flag_swire_irac_i2m_ap_irac_i3merr_ap_irac_i3m_irac_i3merr_irac_i3flag_irac_i3m_ap_irac_i4merr_ap_irac_i4m_irac_i4merr_irac_i4flag_irac_i4
degdeguJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJy
0271946734.440117-6.445593nannannannannan23.382.3530.882.970.62nannannannannannannannannannannannannannanFalse20.47788873290.10913088456720.17580677080.104424758035FalsenannannannanFalsenannannannanFalse
1271946834.442707-6.444653nannannannannan15.92.2518.842.340.51nannannannannannannannannannannannannannanFalse20.89650718920.15364191576820.71229775390.134852585941FalsenannannannanFalsenannannannanFalse
2271963434.436877-6.439533nannannannannan96.552.368.451.510.98nannannannannannannannannannannannannannanFalse18.93811930470.025864249310719.31156636880.0239512296448FalsenannannannanFalsenannannannanFalse
3271969934.438797-6.436143nannannannannan19.591.5819.761.650.56nannannannannannannannannannannannannannanFalse20.669913910.08756831054220.66053264940.0906611709439FalsenannannannanFalsenannannannanFalse
4271962634.441717-6.437973nannannannannan115.462.4580.831.730.99nannannannannannannannannannannannannannanFalse18.74392111710.023038746766519.1310685530.0232379516792FalsenannannannanFalsenannannannanFalse
5271967634.440737-6.436373nannannannannan73.722.1352.411.411.0nannannannannannannannannannannannannannanFalse19.23103668360.031370294575919.60146460070.0292098463787FalsenannannannanFalsenannannannanFalse
6271948934.445617-6.442743nannannannannan12.672.1811.11.810.51nannannannannannannannannannannannannannanFalse21.14305846280.18681175425221.2866925530.177043471226FalsenannannannanFalsenannannannanFalse
7271955734.450507-6.438063nannannannannan37.01.8131.821.760.79nannannannannannannannannannannannannannanFalse19.97949568980.053113041367920.14324956170.0600532910237FalsenannannannanFalsenannannannanFalse
8271944734.455027-6.441013nannannannannan36.392.5635.52.70.93nannannannannannannannannannannannannannanFalse19.9975448610.076380452986620.02442911740.0825771197985FalsenannannannanFalsenannannannanFalse
9271942234.460637-6.440053nannannannannan24.032.3923.012.120.65nannannannannannannannannannannannannannanFalse20.4481155730.10798624758120.49520845330.10003306189FalsenannannannanFalsenannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['ferr_ap_swire_irac_i1', 'ferr_ap_swire_irac_i2', 'ferr_ap_irac_i3', 'ferr_ap_irac_i4']
FLAG_NAME = "swire_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 497404 sources.
The cleaned catalogue has 497381 sources (23 removed).
The cleaned catalogue has 23 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.09761311656575344 arcsec
Dec correction: -0.11673921999317827 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 = "swire_flag_gaia"

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

V - Saving to disk¶

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