Herschel Stripe 82 master catalogue¶

Preparation of Spitzer SpIES data¶

The Spitzer catalogues are available in dmu0_SpIES. 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

TODO: 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: 
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 = "spies_ra"
DEC_COL = "spies_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'internal_id': "spies_intid",
        'ra': "spies_ra",
        'dec': "spies_dec",
        'FLUX_APER_2_ch1': "f_ap_spies_irac1",
        'FLUXERR_APER_2_ch1': "ferr_ap_spies_irac1",
        'FLUX_AUTO_ch1': "f_spies_irac1",
        'FLUXERR_AUTO_ch1': "ferr_spies_irac1",
        'CLASS_STAR_ch1': "spies_stellarity_irac1",
        'FLUX_APER_2_ch2': "f_ap_spies_irac2",
        'FLUXERR_APER_2_ch2': "ferr_ap_spies_irac2",
        'FLUX_AUTO_ch2': "f_spies_irac2",
        'FLUXERR_AUTO_ch2': "ferr_spies_irac2",
        'CLASS_STAR_ch2': "spies_stellarity_irac2",
    })


catalogue = Table.read("../../dmu0/dmu0_SpIES/data/SpIES_ch1andch2_HELP-coverage.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>
idxspies_intidspies_raspies_decf_ap_spies_irac1ferr_ap_spies_irac1f_spies_irac1ferr_spies_irac1spies_stellarity_irac1f_ap_spies_irac2ferr_ap_spies_irac2f_spies_irac2ferr_spies_irac2spies_stellarity_irac2m_ap_spies_irac1merr_ap_spies_irac1m_spies_irac1merr_spies_irac1flag_spies_irac1m_ap_spies_irac2merr_ap_spies_irac2m_spies_irac2merr_spies_irac2flag_spies_irac2
0ch1ch2_16.49499250309e-05-0.58666150229728.16002774811.7651487606332.39409099923.088273200310.009925881400720.54223559111.8154391976622.74078065222.779921205280.00048909417819220.2759173040.068056961212720.12383550540.103508075712False20.61838073580.095952948046520.5079865770.132724603659False
1ch1ch2_27.35155179947e-05-0.62135286083416.29515374432.188970666314.81080019392.170283920340.17941741645313.01230446492.0487249376313.90098138982.454772325730.65083611011520.86985384410.14584978705120.97355369230.159097131557False21.11411445890.17094395880221.04238634520.191730001914False
2ch1ch2_37.37219688014e-050.2932855154017.00012467412.1589035988810.47478915883.633455517450.01985229179266.614205544832.412357295146.512749773823.36877137480.0077720690169421.78723556250.33485115037521.34963677490.376616096408False21.84880578240.39599368909821.86558901880.561605646494False
3ch1ch2_48.01140426867e-05-0.1693561669066.421102896262.0615834436.364950009493.056702632760.054256081581110.68255309951.7725496105412.34899142412.294884686430.000623958068921.88097592650.34859054890621.89051250740.52141379125False21.32831234940.18015555541521.17092127740.201768654964False
4ch1ch2_58.64262992602e-05-0.6811478719837.74598085281.4576755575247.63797785924.688514617550.0029218194540634.88367515421.7137285998941.86074934612.84728198770.0078058294020619.95782321180.041928997255819.70511670440.106857811678False20.04344441610.053338909326819.84548250410.0738495413362False
5ch1ch2_68.72926807298e-05-0.29950745538211.29002827461.4280311074610.43164299381.860839880680.0001788545050667.714372690861.392246270036.156222089651.173276429730.39177498221421.26826242610.13733048644221.3541182110.19367814168False21.68174845920.1959475179521.92671430280.206923772306False
6ch1ch2_79.41826855459e-050.4754369974132.63144098131.9855777742634.85935759512.891932125410.013447853736629.84514003872.0561089311233.57793243423.080245959920.0049886242486520.11590936910.066065537164520.04420155130.0900726699193False20.21281594750.074799176835720.08486512280.0995991806461False
7ch1ch2_80.000105106695157-0.69344337261510.7003834451.697848130959.156672508932.089715210590.03688540682211.59051673891.9700549460716.54764566374.009295643360.00035567488521321.32650164810.17227561941421.49565579550.247784275299False21.23974300370.18454397060220.85315946820.263060831978False
8ch1ch2_90.0001342346271590.5566546305668.627303638571.373797682399.232410803072.216048420180.0006748224841439.352503380031.832403018618.877369329631.990637472920.007886120118221.56031229170.17289085260921.48671219870.260608420987False21.47268031540.21272446725421.52928927890.243462572599False
9ch1ch2_100.000163163807299-0.57012409590612.88645220191.670944449611.80407010821.923035989290.0054255751892915.09958355721.7092884775413.7012576372.041286353860.0090277586132321.12466658190.14078389122521.21992054940.176880497784False20.95258757570.12290646145421.05809891790.161758763858False

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['ferr_ap_spies_irac1', 'ferr_ap_spies_irac2']
FLAG_NAME = "spies_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 3365594 sources.
The cleaned catalogue has 3365594 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_Herschel-Stripe-82.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, near_ra0=True)
In [10]:
delta_ra, delta_dec =  astrometric_correction(
    SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]),
    gaia_coords, near_ra0=True
)

print("RA correction: {}".format(delta_ra))
print("Dec correction: {}".format(delta_dec))
RA correction: 0.007062192162266001 arcsec
Dec correction: -0.10853834623070213 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, near_ra0=True)

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 = "spies_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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