AKARI-NEP master catalogue

Preparation of Spitzer datafusion SERVS data

The Spitzer catalogues are available in dmu0_NEP-Spitzer.

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); CHECK!
  • The “auto” flux (which seems to be the Kron flux);
  • The stellarity in each band
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, mag_to_flux
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "nep_ra"
DEC_COL = "nep_dec"

I - Column selection

In [4]:
imported_columns = OrderedDict({
        'nep_id': "nep_id",
        'ra': "nep_ra",
        'dec': "nep_dec",
        'm_irac_i1': "m_irac_i1",
        'merr_irac_i1': "merr_irac_i1",
        'm_ap2_irac_i1': "m_ap_irac_i1",
        'merr_ap2_irac_i1': "merr_ap_irac_i1",
        'm_irac_i2': "m_irac_i2",
        'merr_irac_i2': "merr_irac_i2",
        'm_ap2_irac_i2': "m_ap_irac_i2",
        'merr_ap2_irac_i2': "merr_ap_irac_i2",
        'irac_stellarity': "irac_stellarity",
    })


catalogue = Table.read("../../dmu0/dmu0_NEP-Spitzer/data/NEP-Spitzer-APJ.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2017 #Paper year

# Clean table metadata
catalogue.meta = None
In [5]:
# Adding magnitude and band-flag columns
for col in catalogue.colnames:
    if col.startswith('m_'):
        errcol = "merr{}".format(col[1:])
        
        catalogue[col][catalogue[col] > 90.] = np.nan
        catalogue[errcol][catalogue[errcol] > 90.] = np.nan
        
        flux, error = mag_to_flux(
            np.array(catalogue[col]), np.array(catalogue[errcol]))
        # Note that some fluxes are 0.
        
        catalogue.add_column(Column(flux*1.e6, name="f{}".format(col[1:])))
        catalogue.add_column(Column(error*1.e6, name="f{}".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:])))
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table length=10>
idxnep_idnep_ranep_decm_irac_i1merr_irac_i1m_ap_irac_i1merr_ap_irac_i1m_irac_i2merr_irac_i2m_ap_irac_i2merr_ap_irac_i2irac_stellarityf_irac_i1ferr_irac_i1flag_irac_i1f_ap_irac_i1ferr_ap_irac_i1f_irac_i2ferr_irac_i2flag_irac_i2f_ap_irac_i2ferr_ap_irac_i2
01273.719550867.602094420.09040.111920.6860.074nannannannan0.8733.40723.44306False19.30191.31555nannanFalsenannan
12273.707923867.593606221.40440.148121.36770.1263nannannannan0.179.959561.35853False10.3021.19839nannanFalsenannan
23273.708078767.600174720.5770.12120.86220.0846nannannannan0.1521.34032.37827False16.41041.27869nannanFalsenannan
34273.710356167.604104320.2390.105421.08160.1006nannannannan0.2129.1342.82824False13.40791.24232nannanFalsenannan
45273.711878367.600818420.19820.096920.7880.0799nannannannan0.0330.24962.69972False17.57111.29307nannanFalsenannan
56273.715103867.570169821.14380.115721.32540.122nannannannan0.6812.66131.34924False10.71121.20358nannanFalsenannan
67273.714414667.571695321.34670.178820.79150.0802nannannannan0.9310.50311.72967False17.51461.29375nannanFalsenannan
78273.705825467.594943321.88410.27821.5970.1528nannannannan0.156.402651.63938False8.340651.17381nannanFalsenannan
89273.70380967.596083721.1180.183821.00880.0948nannannannan0.1312.96582.19493False14.33771.25188nannanFalsenannan
910273.702740967.602753220.56990.107620.76010.0781nannannannan0.1721.48032.12877False18.02851.29684nannanFalsenannan

II - Removal of duplicated sources

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['ferr_ap_irac_i1', 'ferr_ap_irac_i2']
FLAG_NAME = "nep_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])))
The initial catalogue had 380858 sources.
The cleaned catalogue has 380858 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_AKARI-NEP.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.17224358761041003 arcsec
Dec correction: 0.017100100612310598 arcsec
In [11]:
catalogue[RA_COL] = catalogue[RA_COL] + delta_ra.to(u.deg)
catalogue[DEC_COL] = 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 = "nep_flag_gaia"

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

V - Saving to disk

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