Herschel Stripe 82 master catalogue¶

Preparation of Spitzer SHELA data¶

The Spitzer/HETDEX Exploratory Large-Area (SHELA) survey covers ~24 sq. deg at 3.6 and 4.5 microns. The Spitzer/SHELA catalogues are available in dmu0_SHELA.

In the catalouge, we keep:

  • The internal identifier;
  • The position;
  • The fluxes in 4 arcsecond apertures;
  • The “auto” flux;
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 = "shela_ra"
DEC_COL = "shela_dec"

I - Column selection¶

In [4]:
#IRAC1 = 3.6 um
#IRAC2 = 4.5 um
#No stelarity 

imported_columns = OrderedDict({
        'ID': "shela_intid",
        'RA': "shela_ra",
        'DEC': "shela_dec",
        'F3P6_AUTO': "f_shela_irac1",
        'F3P6ERR_AUTO': "ferr_shela_irac1",
        'F3P6_4ARCS': "f_ap_shela_irac1",
        'F3P6ERR_4ARCS': "ferr_ap_shela_irac1",
        'F4P5_AUTO': "f_shela_irac2",
        'F4P5ERR_AUTO': "ferr_shela_irac2",
        'F4P5_4ARCS': "f_ap_shela_irac2",
        'F4P5ERR_4ARCS': "ferr_ap_shela_irac2"
    })


catalogue = Table.read("../../dmu0/dmu0_SHELA/data/shela_irac_v1.3_flux_cat.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:])
        
        # Note that some fluxes are 0.
        catalogue[col][np.isclose(catalogue[col], 0.)] = np.nan
        catalogue[errcol][np.isclose(catalogue[errcol], 0.)] = np.nan
        
        magnitude, error = flux_to_mag(
            np.array(catalogue[col])/1.e6, np.array(catalogue[errcol])/1.e6)
        
        
        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 length=10>
idxshela_intidshela_rashela_decf_shela_irac1ferr_shela_irac1f_ap_shela_irac1ferr_ap_shela_irac1f_shela_irac2ferr_shela_irac2f_ap_shela_irac2ferr_ap_shela_irac2m_shela_irac1merr_shela_irac1flag_shela_irac1m_ap_shela_irac1merr_ap_shela_irac1m_shela_irac2merr_shela_irac2flag_shela_irac2m_ap_shela_irac2merr_ap_shela_irac2
0115.4756838087-1.36443322375nannannannan11.10520.45228914.04162.15102nannanFalsenannan21.28620.0442196False21.03150.166323
1215.4740823478-1.36373876082nannannannan9.966810.4284813.60841.69246nannanFalsenannan21.40360.0466766False21.06550.135032
2315.4764671284-1.36319564707nannannannan9.224560.41221712.23941.66885nannanFalsenannan21.48760.0485182False21.18060.148041
3414.6648752838-1.36060981938nannannannan-0.0952322nan-1.228054.53532nannanFalsenannannannanFalsenan-4.00973
4514.669433439-1.36236619592nannannannan31.9990.76775222.27851.71998nannanFalsenannan20.13720.0260501False20.53030.0838229
5615.4684264607-1.36181616808nannannannan6.05040.33384510.99471.65931nannanFalsenannan21.94550.0599081False21.2970.163858
6714.677735725-1.36068860967nannannannan28.20570.72081135.49732.39602nannanFalsenannan20.27420.0277465False20.02450.0732857
7816.2727708794-1.36338582978nannannannan24.07890.66599629.45162.37547nannanFalsenannan20.44590.0300302False20.22720.087572
8916.2775800352-1.36178700509nannannannan29.44160.73643328.06382.37078nannanFalsenannan20.22760.0271579False20.27960.0917209
91014.6715473473-1.36114361198nannannannan68.99061.1273261.22761.91793nannanFalsenannan19.3030.0177412False19.43260.0340102

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['ferr_ap_shela_irac1', 'ferr_ap_shela_irac2']
FLAG_NAME = "shela_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 2294786 sources.
The cleaned catalogue has 2294786 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.07131256496677452 arcsec
Dec correction: -0.08313942358052495 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, 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 = "shela_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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