Lockman SWIRE 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_Lockman-SWIRE.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
02445195161.966130559.86832130.4846801358321.144844687720.6994423818010.4648815209350.58nannannannannan24.68636194772.5645765823524.28812013930.721630131851FalsenannannannanFalse
12444777161.969945859.86758042.450212539185.913874393541.878696639874.424454968950.52nannannannannan22.92699060482.6205512529223.21535835352.55698064507FalsenannannannanFalse
22444665161.973356859.866104312.75546894841.1890816944912.114459346822.94135567480.22nannannannannan21.13575892540.10121376574621.19173990782.05607693496FalsenannannannanFalse
32441508161.9989359.8613874.064478652444.921170562883.385923978944.381165106060.73nannannannannan22.37748788281.314582633322.57580699231.40487193577FalsenannannannanFalse
42441122162.005345859.85927877.438785310846.597594200258.438029937137.553104781740.57nannannannannan21.7212449380.96295921823121.58439734530.97187132316FalsenannannannanFalse
52441299161.999027359.8594861.719272899641.02597482851.335105741320.6799673191820.17nannannannannan23.3116379560.64791227542223.58621084130.552963794284FalsenannannannanFalse
62440958162.001561259.85885892.531038643261.123786077151.63773940870.7621760936670.52nannannannannan22.89175306020.48206898524223.36438800120.505283181744FalsenannannannanFalse
72441119162.000266259.85899652.779228148520.9727792123322.297972245161.171250384840.59nannannannannan22.79018950070.38002695483322.99663805250.553387426825FalsenannannannanFalse
82442120161.994356559.86276685.4771389455325.52038586876.5038102851226.04087101440.63nannannannannan22.05361560415.0589198434921.86708033884.34722343124FalsenannannannanFalse
92444458161.976311359.863890226.30258841341.0572188711731.10044743931.937233503230.47nannannannannan20.35000377720.043640602466220.16808340690.0676300415173FalsenannannannanFalse

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 951102 sources.
The cleaned catalogue has 951102 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_Lockman-SWIRE.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.16942944777724733 arcsec
Dec correction: -0.10899877246544065 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)))
14350 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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