CDFS SWIRE master catalogue¶

Preparation of Spitzer datafusion SERVS data¶

The data is in 'dmu0_DataFusion-Spitzer'

The Spitzer catalogues were produced by the datafusion team are available in the HELP virtual observatory server. They are described there: https://herschel-vos.phys.sussex.ac.uk/browse/df_spitzer/q.

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: 
04829ed (Thu Nov 2 16:57:19 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, 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_CDFS-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
        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/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_irac1flag_ap_servs_irac1m_servs_irac1merr_servs_irac1flag_servs_irac1m_ap_servs_irac2merr_ap_servs_irac2flag_ap_servs_irac2m_servs_irac2merr_servs_irac2flag_servs_irac2
degdeguJyuJyuJyuJyuJyuJyuJyuJy
080789851.6954516-29.1215403nannannannannan15.85205951512.325504680758.172126844273.06124330130.77nannanFalsenannanFalse20.89978576450.159278018339False19.48821264391.36362965083False
180650351.7039523-29.1228421nannannannannan10.912977082.2587725325625.60162432475.563674959780.03nannanFalsenannanFalse21.30514189230.224726131003False20.37933119870.235949221765False
280642651.7063866-29.1210209nannannannannan8.263511519411.1612837535710.59116372758.990010233490.99nannanFalsenannanFalse21.60708840790.152580148559False21.33764079550.921596516001False
380646551.7070847-29.1200175nannannannannan9.156974320661.042137409928.002969825181.157802214080.89nannanFalsenannanFalse21.49562000930.123565522482False21.64187205150.157075162False
480710151.6983532-29.1138065nannannannannan11.80548107921.4640890391611.59502301771.543945593850.98nannanFalsenannanFalse21.21979077630.134650546313False21.23932096220.144572169185False
580768351.6973431-29.1082011nannannannannan5.976899915839.314252138158.505348109242.487154484090.45nannanFalsenannanFalse21.95881004111.69198429103False21.57576976690.317493609376False
680694651.6994919-29.1159869nannannannannan5.257858690611.223467089534.025552699580.9413550802220.86nannanFalsenannanFalse22.09797772530.252643251293False22.38793620880.253893904367False
780651051.7064869-29.1169483nannannannannan2.884902885810.8107788356262.058260721490.8032401387150.58nannanFalsenannanFalse22.74967200470.30513745895False23.11624903420.423710607025False
880674951.7032145-29.1148313nannannannannan3.796321649050.7910007951093.73147663610.9710334782710.64nannanFalsenannanFalse22.45159249610.226223771491False22.47029818320.28253860501False
980645551.7062952-29.1162974nannannannannan2.894029829880.7405751384493.692213109090.9748157586130.52nannanFalsenannanFalse22.74624249190.277837233002False22.48178310020.286655382781False

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 829191 sources.
The cleaned catalogue has 829191 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_CDFS-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.09465175745901888 arcsec
Dec correction: -0.023302447203832344 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)))
13977 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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