Herschel Stripe 82 master catalogue¶

Preparation of Hyper Suprime-Cam Subaru Strategic Program Catalogues (HSC-SSP) data¶

This catalogue comes from dmu0_HSC.

In the catalogue, we keep:

  • The object_id as unique object identifier;
  • The position;
  • The g, r, i, z, y, N816, N921 aperture magnitude (for now in 3”);
  • The g, r, i, z, y, N816, N921 kron fluxes and magnitudes.

TODO: Check that the aperture magnitudes are aperture corrected and that all the magnitudes are AB.

TODO: Check for stellarity.

We don't know when the maps have been observed. We will use the year of the reference paper.

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 = "hsc_ra"
DEC_COL = "hsc_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        "object_id": "hsc_id",
        "ra": "hsc_ra",
        "dec": "hsc_dec",
        "gmag_aperture30": "m_ap_suprime_g",
        "gmag_aperture30_err": "merr_ap_suprime_g",
        "gmag_kron": "m_suprime_g",
        "gmag_kron_err": "merr_suprime_g",
        "rmag_aperture30": "m_ap_suprime_r",
        "rmag_aperture30_err": "merr_ap_suprime_r",
        "rmag_kron": "m_suprime_r",
        "rmag_kron_err": "merr_suprime_r",
        "imag_aperture30": "m_ap_suprime_i",
        "imag_aperture30_err": "merr_ap_suprime_i",
        "imag_kron": "m_suprime_i",
        "imag_kron_err": "merr_suprime_i",
        "zmag_aperture30": "m_ap_suprime_z",
        "zmag_aperture30_err": "merr_ap_suprime_z",
        "zmag_kron": "m_suprime_z",
        "zmag_kron_err": "merr_suprime_z",
        "ymag_aperture30": "m_ap_suprime_y",
        "ymag_aperture30_err": "merr_ap_suprime_y",
        "ymag_kron": "m_suprime_y",
        "ymag_kron_err": "merr_suprime_y",
        "n816mag_aperture30": "m_ap_suprime_n816",
        "n816mag_aperture30_err": "merr_ap_suprime_n816",
        "n816mag_kron": "m_suprime_n816",
        "n816mag_kron_err": "merr_suprime_n816",
        "n921mag_aperture30": "m_ap_suprime_n921",
        "n921mag_aperture30_err": "merr_ap_suprime_n921",
        "n921mag_kron": "m_suprime_n921",
        "n921mag_kron_err": "merr_suprime_n921",
    })


catalogue = Table.read("../../dmu0/dmu0_HSC/data/HSC-PDR1_deep_Herschel-Stripe-82.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2017

# Clean table metadata
catalogue.meta = None
In [5]:
# Adding flux and band-flag columns
for col in catalogue.colnames:
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        flux, error = mag_to_flux(np.array(catalogue[col]), np.array(catalogue[errcol]))
        
        # Fluxes are added in µJy
        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:])))
        
# TODO: Set to True the flag columns for fluxes that should not be used for SED fitting.
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxhsc_idhsc_rahsc_decm_ap_suprime_gmerr_ap_suprime_gm_suprime_gmerr_suprime_gm_ap_suprime_rmerr_ap_suprime_rm_suprime_rmerr_suprime_rm_ap_suprime_imerr_ap_suprime_im_suprime_imerr_suprime_im_ap_suprime_zmerr_ap_suprime_zm_suprime_zmerr_suprime_zm_ap_suprime_ymerr_ap_suprime_ym_suprime_ymerr_suprime_ym_ap_suprime_n816merr_ap_suprime_n816m_suprime_n816merr_suprime_n816m_ap_suprime_n921merr_ap_suprime_n921m_suprime_n921merr_suprime_n921f_ap_suprime_gferr_ap_suprime_gf_suprime_gferr_suprime_gflag_suprime_gf_ap_suprime_rferr_ap_suprime_rf_suprime_rferr_suprime_rflag_suprime_rf_ap_suprime_iferr_ap_suprime_if_suprime_iferr_suprime_iflag_suprime_if_ap_suprime_zferr_ap_suprime_zf_suprime_zferr_suprime_zflag_suprime_zf_ap_suprime_yferr_ap_suprime_yf_suprime_yferr_suprime_yflag_suprime_yf_ap_suprime_n816ferr_ap_suprime_n816f_suprime_n816ferr_suprime_n816flag_suprime_n816f_ap_suprime_n921ferr_ap_suprime_n921f_suprime_n921ferr_suprime_n921flag_suprime_n921
040550156336103690351.541886707-1.6008127550823.00650.035167422.8480.04258121.7390.013542921.57450.0161641nannannannan20.55140.016487620.40720.021137120.23770.017356920.09410.0224672nannannannannannannannan2.27720.07375932.635030.103342False7.318460.09128668.515650.126778FalsenannannannanFalse21.850.33180524.95260.485777False29.1680.46628933.2930.688936FalsenannannannanFalsenannannannanFalse
140550160631070739351.561521863-1.4949171352124.45110.11563824.4490.11234423.79790.080625323.80830.078780923.92340.11240723.96680.11725722.9650.097523522.84330.08664722.61960.1137622.69410.12066826.36170.68820526.51230.73673622.60760.083380722.56610.08128090.6019630.06411330.6031030.0624047False1.098580.08157921.088170.0789575False0.9787070.1013260.9403190.101553False2.365930.2125142.646450.2112False3.251980.3407313.036520.337477False0.103590.06566180.09017180.0611869False3.288150.2525183.416340.255756False
240550160631070743351.57416619-1.4940536308724.78540.15483524.87940.10244124.30780.12873624.32890.082401623.58320.096366623.64550.064980823.50650.16153523.35260.089971823.05650.17340723.14850.11634226.36170.68871927.47211.1393423.3990.18918823.35880.1161480.4424110.06309150.405750.0382833False0.6868680.08144230.6736720.0511281False1.338770.1188251.264170.0756597False1.436830.2137721.655570.137192False2.174650.3473211.997950.21409False0.1035910.06571120.03725290.0390921False1.586410.276431.646230.176108False
340550160631070748351.543182052-1.4937091376725.36650.19461824.67920.55051625.03530.19103223.65670.30321223.8790.12177521.63470.080091924.64710.329169nannan26.5784.23811nannan26.36170.68809822.92370.14288723.99170.31767320.61150.07374230.2590680.04643790.4878970.247385False0.3514590.0618381.251220.349427False1.019520.1143498.056320.594294False0.5025210.152352nannanFalse0.08487870.331319nannanFalse0.103590.06565162.457590.323429False0.918970.26887920.67341.40412False
440550160631070750351.55173188-1.4932824042624.80690.11708324.47090.17052224.72460.14556624.52490.25095824.49020.21423524.00940.28613824.77570.41493725.04731.0964524.22520.48463923.69880.63370726.36170.68817724.92580.35925525.73581.58243nannan0.4337360.04677280.5910520.0928286False0.4679040.06273270.5623960.129992False0.5806640.1145750.9041490.238282False0.44640.1706010.3476160.351047False0.7411460.3308241.203550.702471False0.103590.06565910.3887690.128638False0.1843720.268717nannanFalse
540550160631070751351.564763353-1.4932473438725.61690.246711nannan24.99590.189929nannan25.52390.574722nannan24.6880.394989nannannannannannan26.36170.688348nannan23.99890.322774nannan0.2056940.0467396nannanFalse0.364460.0637554nannanFalse0.2241040.118627nannanFalse0.4839620.176065nannanFalsenannannannanFalse0.103590.0656755nannanFalse0.9129450.271405nannanFalse
640550160631070753351.559050391-1.4930269710923.12080.025211423.09650.023305423.16830.035065223.11720.032072822.85210.048264722.85340.046534722.77080.066367222.71690.060519123.17640.18441223.04060.15781326.36170.68846626.55620.75214622.86410.11403322.69850.09501842.049630.04759372.095950.0449897False1.961950.06336372.056540.0607507False2.625090.1166942.622110.112384False2.829420.1729522.973440.16574False1.947260.3307412.206720.32075False0.1035910.0656870.08659660.05999False2.596450.2727013.023990.264645False
740550160631070755351.542590217-1.4924551653822.23830.011315422.25370.0099857821.67590.0091075421.64330.0078199421.39930.01277621.37890.011236921.37320.016345221.33410.013968721.21640.030972321.17740.027103826.36170.68822726.74050.81780921.28260.02653521.25070.02316154.620550.04815454.555440.0418975False7.755760.06505817.992210.0575634False10.00650.11774710.19620.105526False10.24970.15430310.62580.136707False11.8420.33781212.2760.306453False0.103590.06566380.07308220.0550476False11.1420.27230611.47420.244775False
840550160631070764351.548508359-1.49095170627nannannannan28.08293.20895nannan24.95110.325438nannannannannannannannannannan26.36170.688121nannan24.64530.579076nannannannannannanFalse0.02122560.0627332nannanFalse0.3797880.113838nannanFalsenannannannanFalsenannannannanFalse0.103590.0656537nannanFalse0.5033440.268458nannanFalse
940550160631070765351.55136997-1.4905354933224.54280.09214924.60620.060778923.93450.069986324.08360.051064324.05910.14592623.94140.079992523.85560.16004723.92760.10618823.57430.26599623.48670.15531426.36170.6883727.45881.1325223.66740.23390623.54940.1392010.5531910.04695060.521810.0292106False0.9687680.06244650.8444320.0397153False0.8637230.1160870.9625690.070918False1.041730.153560.9749180.0953495False1.349880.3307081.463290.209322False0.103590.06567770.03771250.0393375False1.238920.2669071.381190.17708False

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = [
        'merr_ap_suprime_i', 'merr_ap_suprime_r', 'merr_ap_suprime_z',
        'merr_ap_suprime_y', 'merr_ap_suprime_g']
FLAG_NAME = 'hsc_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 2868474 sources.
The cleaned catalogue has 2868272 sources (202 removed).
The cleaned catalogue has 168 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.109708158538524 arcsec
Dec correction: -0.10202967583285982 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 = "hsc_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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