ELAIS-S1 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: 
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 = "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_irac1",
        'uncf_ap2_36': "ferr_ap_swire_irac1",
        'flux_kr_36': "f_swire_irac1",
        'uncf_kr_36': "ferr_swire_irac1",
        'stell_36': "swire_stellarity_irac1",
        'flux_ap2_45': "f_ap_swire_irac2",
        'uncf_ap2_45': "ferr_ap_swire_irac2",
        'flux_kr_45': "f_swire_irac2",
        'uncf_kr_45': "ferr_swire_irac2",
        'stell_45': "swire_stellarity_irac2",
        'flux_ap2_58': "f_ap_irac3",
        'uncf_ap2_58': "ferr_ap_irac3",
        'flux_kr_58': "f_irac3",
        'uncf_kr_58': "ferr_irac3",
        'stell_58': "swire_stellarity_irac3",
        'flux_ap2_80': "f_ap_irac4",
        'uncf_ap2_80': "ferr_ap_irac4",
        'flux_kr_80': "f_irac4",
        'uncf_kr_80': "ferr_irac4",
        'stell_80': "swire_stellarity_irac4",
    })


catalogue = Table.read("../../dmu0/dmu0_DataFusion-Spitzer/data/DF-SWIRE_ELAIS-S1.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: divide by zero encountered in log10
  magnitudes = 2.5 * (23 - np.log10(fluxes)) - 48.6
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:80: RuntimeWarning: divide by zero encountered in true_divide
  errors = 2.5 / np.log(10) * errors_on_fluxes / fluxes
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxswire_intidswire_raswire_decf_ap_swire_irac1ferr_ap_swire_irac1f_swire_irac1ferr_swire_irac1swire_stellarity_irac1f_ap_swire_irac2ferr_ap_swire_irac2f_swire_irac2ferr_swire_irac2swire_stellarity_irac2f_ap_irac3ferr_ap_irac3f_irac3ferr_irac3swire_stellarity_irac3f_ap_irac4ferr_ap_irac4f_irac4ferr_irac4swire_stellarity_irac4m_ap_swire_irac1merr_ap_swire_irac1m_swire_irac1merr_swire_irac1flag_swire_irac1m_ap_swire_irac2merr_ap_swire_irac2m_swire_irac2merr_swire_irac2flag_swire_irac2m_ap_irac3merr_ap_irac3m_irac3merr_irac3flag_irac3m_ap_irac4merr_ap_irac4m_irac4merr_irac4flag_irac4
degdeguJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJy
016505177.122051-43.93917430.170.9229.410.960.2220.691.117.171.040.31nannannannannannannannannannan20.20106172460.033108296598520.22876243870.0354405561567False20.61059877330.057724012819420.81307426210.065763870294FalsenannannannanFalsenannannannanFalse
116504807.124631-43.9392346.660.615.840.610.55nannannannannannannannannannannannannannannan21.84131442710.099444307042421.98396788220.113407377552FalsenannannannanFalsenannannannanFalsenannannannanFalse
216505097.123371-43.93894414.110.7214.260.770.6419.811.121.921.180.53nannannannannannannannannannan21.02618246560.055402556160621.01470118620.0586267095136False20.65778881120.060288229441420.54789862550.0584474781758FalsenannannannanFalsenannannannanFalse
316506857.119691-43.93444425.350.8520.940.750.9622.561.1427.371.860.43nannannannannannannannannannan20.39005509080.036405355978120.59755830660.0388873998839False20.51665226170.054864329495820.30681300650.0737840460669FalsenannannannanFalsenannannannanFalse
416506377.122621-43.93518427.870.9431.541.10.1723.321.1421.961.40.09nannannannannannannannannannan20.28715757820.036619735646720.15284577750.0378665131653False20.48067863480.053076298174320.54591916060.0692181551303FalsenannannannanFalsenannannannanFalse
516506167.123811-43.93535412.170.710.940.790.7616.381.0715.621.30.09nannannannannannannannannannan21.18677355440.062449904957321.3024566950.0784032542741False20.86421525640.070924159895720.91579742610.0903621681297FalsenannannannanFalsenannannannanFalse
616509627.117501-43.92510452.71.0250.230.990.1750.341.1347.91.290.41nannannannannannannannannannan19.5954734620.021014249124419.64759205460.0213991408065False19.6452169720.024371909244719.69916121650.0292400773306FalsenannannannanFalsenannannannanFalse
716509247.120101-43.9258446.620.655.030.50.08.570.826.290.70.47nannannannannannannannannannan21.84785502640.10660551859422.14608003740.107926064091False21.56754794520.10388607793521.90337338640.120829148383FalsenannannannanFalsenannannannanFalse
816510137.119051-43.92300444.030.8747.530.970.5634.561.0131.71.160.77nannannannannannannannannannan19.79062828640.021453338590519.70758046430.0221578817298False20.05356566550.031730137928420.14735184450.0397304100164FalsenannannannanFalsenannannannanFalse
916510227.122591-43.9213245.420.514.190.450.478.420.7514.361.310.14nannannannannannannannannannan22.06500178370.1021633698222.34446494260.116606513638False21.58671977130.09671046954521.00711390020.0990469657544FalsenannannannanFalsenannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['ferr_ap_swire_irac1', 'ferr_ap_swire_irac2', 'ferr_ap_irac3', 'ferr_ap_irac4']
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 368900 sources.
The cleaned catalogue has 368884 sources (16 removed).
The cleaned catalogue has 16 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.13695796841588503 arcsec
Dec correction: -0.06500249892269494 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)))
17650 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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