XMM-LSS master catalogue¶

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

This catalogue comes from dmu0_HSC. We only have n921 and n816 photometry on the ultradeep field.

In the catalogue, we keep:

  • The object_id as unique object identifier;
  • The position;
  • The g, r, i, z, y, n921, n816 aperture magnitude in 2” that we aperture correct;
  • The g, r, i, z, y, n921, n816 kron fluxes and magnitudes.
  • The extended flag that we convert to a stellariy.

TODO: Check that the magnitudes are AB.

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))
plt.style.use('ggplot')

from collections import OrderedDict
import os

from astropy import units as u
from astropy import visualization as vis
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, nb_plot_mag_ap_evol, \
    nb_plot_mag_vs_apcor, remove_duplicates
from herschelhelp_internal.utils import astrometric_correction, mag_to_flux, aperture_correction
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "hsc-udeep_ra"
DEC_COL = "hsc-udeep_dec"
In [4]:
# Pritine HSC catalogue
orig_hsc = Table.read("../../dmu0/dmu0_HSC/data/HSC-PDR1_uDeep_XMM-LSS.fits")

I - Aperture correction¶

To compute aperture correction we need to dertermine two parametres: the target aperture and the range of magnitudes for the stars that will be used to compute the correction.

Target aperture: To determine the target aperture, we simulate a curve of growth using the provided apertures and draw two figures:

  • The evolution of the magnitudes of the objects by plotting on the same plot aperture number vs the mean magnitude.
  • The mean gain (loss when negative) of magnitude is each aperture compared to the previous (except for the first of course).

As target aperture, we should use the smallest (i.e. less noisy) aperture for which most of the flux is captures.

Magnitude range: To know what limits in aperture to use when doing the aperture correction, we plot for each magnitude bin the correction that is computed and its RMS. We should then use the wide limits (to use more stars) where the correction is stable and with few dispersion.

In [5]:
bands = ["g", "r", "i", "z", "y", "n921", "n816"]
apertures = ["10", "15", "20", "30", "40", "57", "84", "118", "168", "235"] #Removed "40" and "235" because they lack errors

magnitudes = {}
magnitude_errors ={}
stellarities = {}

for band in bands:
    magnitudes[band] = np.array(
        [orig_hsc["{}mag_aperture{}".format(band, aperture)] for aperture in apertures]
    )
    magnitude_errors[band] = np.array(
        [orig_hsc["{}mag_aperture{}_err".format(band, aperture)] for aperture in apertures]
    )
    stellarities[band] = 1 - np.array(orig_hsc["{}classification_extendedness".format(band)])
    
    # Some sources have an infinite magnitude
    mask = np.isinf(magnitudes[band])
    magnitudes[band][mask] = np.nan
    magnitude_errors[band][mask] = np.nan
    
mag_corr = {}

I.a - g band¶

In [6]:
nb_plot_mag_ap_evol(magnitudes['g'], stellarities['g'], labels=apertures)
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:850: RuntimeWarning: invalid value encountered in greater
  mags = magnitudes[:, stellarity > stel_threshold].copy()

We will use aperture 40 as target.

In [7]:
nb_plot_mag_vs_apcor(orig_hsc['gmag_aperture20'], orig_hsc['gmag_aperture40'], stellarities['g'])
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:903: RuntimeWarning: invalid value encountered in greater
  mask = stellarity > .9
/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)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

We will use magnitudes between 20.0 and 21.5

In [8]:
# Aperture correction
mag_corr['g'], num, std = aperture_correction(
    orig_hsc['gmag_aperture20'], orig_hsc['gmag_aperture40'], 
    stellarities['g'],
    mag_min=20.0, mag_max=21.5)
print("Aperture correction for g band:")
print("Correction: {}".format(mag_corr['g']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for g band:
Correction: -0.11709976196289062
Number of source used: 1468
RMS: 0.010006448273662748
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

I.b - r band¶

In [9]:
nb_plot_mag_ap_evol(magnitudes['r'], stellarities['r'], labels=apertures)
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:850: RuntimeWarning: invalid value encountered in greater
  mags = magnitudes[:, stellarity > stel_threshold].copy()

We will use aperture 40 as target.

In [10]:
nb_plot_mag_vs_apcor(orig_hsc['rmag_aperture20'], orig_hsc['rmag_aperture40'], stellarities['r'])
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:903: RuntimeWarning: invalid value encountered in greater
  mask = stellarity > .9
/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)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

We use magnitudes between 19.0 and 20.5.

In [11]:
# Aperture correction
mag_corr['r'], num, std = aperture_correction(
    orig_hsc['rmag_aperture20'], orig_hsc['rmag_aperture40'], 
    stellarities['r'],
    mag_min=19.0, mag_max=20.5)
print("Aperture correction for r band:")
print("Correction: {}".format(mag_corr['r']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for r band:
Correction: -0.1352062225341797
Number of source used: 1132
RMS: 0.03414906800433681
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

I.c - i band¶

In [12]:
nb_plot_mag_ap_evol(magnitudes['i'], stellarities['i'], labels=apertures)
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:850: RuntimeWarning: invalid value encountered in greater
  mags = magnitudes[:, stellarity > stel_threshold].copy()

We will use aperture 40 as target.

In [13]:
nb_plot_mag_vs_apcor(orig_hsc['imag_aperture20'], orig_hsc['imag_aperture40'], stellarities['i'])
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:903: RuntimeWarning: invalid value encountered in greater
  mask = stellarity > .9
/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)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

We use magnitudes between 18.5 and 19.8.

In [14]:
# Aperture correction
mag_corr['i'], num, std = aperture_correction(
    orig_hsc['imag_aperture20'], orig_hsc['imag_aperture40'], 
    stellarities['i'],
    mag_min=18.5, mag_max=19.8)
print("Aperture correction for i band:")
print("Correction: {}".format(mag_corr['i']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for i band:
Correction: -0.08892059326171875
Number of source used: 1474
RMS: 0.005790887515601094
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

I.d - z band¶

In [15]:
nb_plot_mag_ap_evol(magnitudes['z'], stellarities['z'], labels=apertures)
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:850: RuntimeWarning: invalid value encountered in greater
  mags = magnitudes[:, stellarity > stel_threshold].copy()

We will use aperture 40 as target.

In [16]:
nb_plot_mag_vs_apcor(orig_hsc['zmag_aperture20'], orig_hsc['zmag_aperture40'], stellarities['z'])
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:903: RuntimeWarning: invalid value encountered in greater
  mask = stellarity > .9
/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)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

We use magnitudes between 18.5 and 19.8.

In [17]:
# Aperture correction
mag_corr['z'], num, std = aperture_correction(
    orig_hsc['zmag_aperture20'], orig_hsc['zmag_aperture40'], 
    stellarities['z'],
    mag_min=18.5, mag_max=19.8)
print("Aperture correction for z band:")
print("Correction: {}".format(mag_corr['z']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for z band:
Correction: -0.14960098266601562
Number of source used: 1770
RMS: 0.013925026504311305
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

I.e - y band¶

In [18]:
nb_plot_mag_ap_evol(magnitudes['y'], stellarities['y'], labels=apertures)
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:850: RuntimeWarning: invalid value encountered in greater
  mags = magnitudes[:, stellarity > stel_threshold].copy()

We will use aperture 40 as target.

In [19]:
nb_plot_mag_vs_apcor(orig_hsc['ymag_aperture20'], orig_hsc['ymag_aperture40'], stellarities['y'])
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:903: RuntimeWarning: invalid value encountered in greater
  mask = stellarity > .9
/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)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

We use magnitudes between 18.0 and 19.5.

In [20]:
# Aperture correction
mag_corr['y'], num, std = aperture_correction(
    orig_hsc['ymag_aperture20'], orig_hsc['ymag_aperture40'], 
    stellarities['y'],
    mag_min=18.0, mag_max=19.5)
print("Aperture correction for y band:")
print("Correction: {}".format(mag_corr['y']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for y band:
Correction: -0.11351203918457031
Number of source used: 1913
RMS: 0.010453534442076362
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

I.f - n921 band¶

In [21]:
nb_plot_mag_ap_evol(magnitudes['n921'], stellarities['n921'], labels=apertures)
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:850: RuntimeWarning: invalid value encountered in greater
  mags = magnitudes[:, stellarity > stel_threshold].copy()

We will use aperture 40 as target.

In [22]:
nb_plot_mag_vs_apcor(orig_hsc['n921mag_aperture20'], orig_hsc['n921mag_aperture40'], stellarities['n921'])
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:903: RuntimeWarning: invalid value encountered in greater
  mask = stellarity > .9
/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)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

We use magnitudes between 18.0 and 19.5.

In [23]:
# Aperture correction
mag_corr['n921'], num, std = aperture_correction(
    orig_hsc['n921mag_aperture20'], orig_hsc['n921mag_aperture40'], 
    stellarities['n921'],
    mag_min=18.0, mag_max=19.5)
print("Aperture correction for n921 band:")
print("Correction: {}".format(mag_corr['n921']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for n921 band:
Correction: -0.23302078247070312
Number of source used: 1549
RMS: 0.014689342783144942
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

I.g - n816 band¶

In [24]:
nb_plot_mag_ap_evol(magnitudes['n816'], stellarities['n816'], labels=apertures)
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:850: RuntimeWarning: invalid value encountered in greater
  mags = magnitudes[:, stellarity > stel_threshold].copy()

We will use aperture 40 as target.

In [25]:
nb_plot_mag_vs_apcor(orig_hsc['n816mag_aperture20'], orig_hsc['n816mag_aperture40'], stellarities['n816'])
/opt/herschelhelp_internal/herschelhelp_internal/masterlist.py:903: RuntimeWarning: invalid value encountered in greater
  mask = stellarity > .9
/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)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

We use magnitudes between 18.0 and 19.5.

In [26]:
# Aperture correction
mag_corr['n816'], num, std = aperture_correction(
    orig_hsc['n816mag_aperture20'], orig_hsc['n816mag_aperture40'], 
    stellarities['n816'],
    mag_min=18.0, mag_max=19.5)
print("Aperture correction for n816 band:")
print("Correction: {}".format(mag_corr['y']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for n816 band:
Correction: -0.11351203918457031
Number of source used: 1199
RMS: 0.007980501010658921
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:129: RuntimeWarning: invalid value encountered in greater
  mask &= (stellarity > 0.9)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:131: RuntimeWarning: invalid value encountered in greater_equal
  mask &= (mag >= mag_min)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:133: RuntimeWarning: invalid value encountered in less_equal
  mask &= (mag <= mag_max)

II - Stellarity¶

HSC does not provide a 0 to 1 stellarity value but a 0/1 extended flag in each band. We are using the same method as UKIDSS (cf this page) to compute a stellarity based on the class in each band:

\begin{equation*} P(star) = \frac{ \prod_{i} P(star)_i }{ \prod_{i} P(star)_i + \prod_{i} P(galaxy)_i } \end{equation*}

where $i$ is the band, and with using the same probabilities as UKDISS:

HSC flag UKIDSS flag Meaning P(star) P(galaxy) P(noise) P(saturated)
-9 Saturated 0.0 0.0 5.0 95.0
-3 Probable galaxy 25.0 70.0 5.0 0.0
-2 Probable star 70.0 25.0 5.0 0.0
0 -1 Star 90.0 5.0 5.0 0.0
0 Noise 5.0 5.0 90.0 0.0
1 +1 Galaxy 5.0 90.0 5.0 0.0
In [27]:
# We are creating an array containing the extended flag in all band.
# Some sources have no flag in some band, there will be NaN in the array.
hsc_ext_flag = np.array([
    orig_hsc[colname] for colname in 
    ['gclassification_extendedness',
     'rclassification_extendedness',
     'iclassification_extendedness',
     'zclassification_extendedness',
     'yclassification_extendedness',
     'n921classification_extendedness',
     'n816classification_extendedness']
])
In [28]:
hsc_pstar = 0.9 * (hsc_ext_flag == 0) + 0.05 * (hsc_ext_flag == 1)
hsc_pgal = 0.05 * (hsc_ext_flag == 0) + 0.9 * (hsc_ext_flag == 1)

# We put back the NaN values
hsc_pstar[np.isnan(hsc_ext_flag)] = np.nan
hsc_pgal[np.isnan(hsc_ext_flag)] = np.nan
In [29]:
stellarity = np.nanprod(hsc_pstar, axis=0) / np.nansum(
    [np.nanprod(hsc_pgal, axis=0), np.nanprod(hsc_pstar, axis=0)], axis=0)

stellarity = np.round(stellarity, 3)
In [30]:
vis.hist(stellarity, bins='scott');
In [31]:
orig_hsc.add_column(Column(data=stellarity, name="stellarity"))

II - Column selection¶

In [32]:
imported_columns = OrderedDict({
        "object_id": "hsc-udeep_id",
        "ra": "hsc-udeep_ra",
        "dec": "hsc-udeep_dec",
        "gmag_aperture20": "m_ap_hsc-udeep_g",
        "gmag_aperture20_err": "merr_ap_hsc-udeep_g",
        "gmag_kron": "m_hsc-udeep_g",
        "gmag_kron_err": "merr_hsc-udeep_g",
        "rmag_aperture20": "m_ap_hsc-udeep_r",
        "rmag_aperture20_err": "merr_ap_hsc-udeep_r",
        "rmag_kron": "m_hsc-udeep_r",
        "rmag_kron_err": "merr_hsc-udeep_r",
        "imag_aperture20": "m_ap_hsc-udeep_i",
        "imag_aperture20_err": "merr_ap_hsc-udeep_i",
        "imag_kron": "m_hsc-udeep_i",
        "imag_kron_err": "merr_hsc-udeep_i",
        "zmag_aperture20": "m_ap_hsc-udeep_z",
        "zmag_aperture20_err": "merr_ap_hsc-udeep_z",
        "zmag_kron": "m_hsc-udeep_z",
        "zmag_kron_err": "merr_hsc-udeep_z",
        "ymag_aperture20": "m_ap_hsc-udeep_y",
        "ymag_aperture20_err": "merr_ap_hsc-udeep_y",
        "ymag_kron": "m_hsc-udeep_y",
        "ymag_kron_err": "merr_hsc-udeep_y",
        "n921mag_aperture20": "m_ap_hsc-udeep_n921",
        "n921mag_aperture20_err": "merr_ap_hsc-udeep_n921",
        "n921mag_kron": "m_hsc-udeep_n921",
        "n921mag_kron_err": "merr_hsc-udeep_n921",
        "n816mag_aperture20": "m_ap_hsc-udeep_n816",
        "n816mag_aperture20_err": "merr_ap_hsc-udeep_n816",
        "n816mag_kron": "m_hsc-udeep_n816",
        "n816mag_kron_err": "merr_hsc-udeep_n816",
        "stellarity": "hsc-udeep_stellarity"
    })


catalogue = orig_hsc[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2017

# Clean table metadata
catalogue.meta = None
In [33]:
# Aperture correction
for band in bands:
    catalogue["m_ap_hsc-udeep_{}".format(band)] += mag_corr[band]
In [34]:
# 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 [35]:
catalogue[:10].show_in_notebook()
Out[35]:
<Table masked=True length=10>
idxhsc-udeep_idhsc-udeep_rahsc-udeep_decm_ap_hsc-udeep_gmerr_ap_hsc-udeep_gm_hsc-udeep_gmerr_hsc-udeep_gm_ap_hsc-udeep_rmerr_ap_hsc-udeep_rm_hsc-udeep_rmerr_hsc-udeep_rm_ap_hsc-udeep_imerr_ap_hsc-udeep_im_hsc-udeep_imerr_hsc-udeep_im_ap_hsc-udeep_zmerr_ap_hsc-udeep_zm_hsc-udeep_zmerr_hsc-udeep_zm_ap_hsc-udeep_ymerr_ap_hsc-udeep_ym_hsc-udeep_ymerr_hsc-udeep_ym_ap_hsc-udeep_n921merr_ap_hsc-udeep_n921m_hsc-udeep_n921merr_hsc-udeep_n921m_ap_hsc-udeep_n816merr_ap_hsc-udeep_n816m_hsc-udeep_n816merr_hsc-udeep_n816hsc-udeep_stellarityf_ap_hsc-udeep_gferr_ap_hsc-udeep_gf_hsc-udeep_gferr_hsc-udeep_gflag_hsc-udeep_gf_ap_hsc-udeep_rferr_ap_hsc-udeep_rf_hsc-udeep_rferr_hsc-udeep_rflag_hsc-udeep_rf_ap_hsc-udeep_iferr_ap_hsc-udeep_if_hsc-udeep_iferr_hsc-udeep_iflag_hsc-udeep_if_ap_hsc-udeep_zferr_ap_hsc-udeep_zf_hsc-udeep_zferr_hsc-udeep_zflag_hsc-udeep_zf_ap_hsc-udeep_yferr_ap_hsc-udeep_yf_hsc-udeep_yferr_hsc-udeep_yflag_hsc-udeep_yf_ap_hsc-udeep_n921ferr_ap_hsc-udeep_n921f_hsc-udeep_n921ferr_hsc-udeep_n921flag_hsc-udeep_n921f_ap_hsc-udeep_n816ferr_ap_hsc-udeep_n816f_hsc-udeep_n816ferr_hsc-udeep_n816flag_hsc-udeep_n816
03748455900407399134.8714549822-5.6651220962128.19161.923727.90781.6042327.40331.2924827.13771.0778423.88280.10789223.86920.12636523.39890.11205823.50580.13646423.26660.17854323.25240.19969826.30230.77209326.13440.64387227.04861.0722926.72860.8942190.00.01920350.03402460.02493880.0368485False0.03968890.04724630.05069010.0503213False1.015970.1009591.028810.11974False1.586490.163741.437780.180713False1.792150.2947081.815630.333946False0.109420.07781130.127710.0757357False0.05502370.05434250.07388850.0608551False
13748455900407399634.8829039964-5.6627463852228.19521.9306727.52331.3457927.43831.3350926.78490.93095524.24240.15202323.67810.12557323.4240.10913223.33370.1336322.83970.12297222.60260.13216226.31910.78430525.76340.54689727.0671.0908726.35750.7594640.00.01913830.0340320.03553620.0440478False0.03843030.04725650.07015380.0601528False0.7295240.1021461.226750.141882False1.550290.1558261.684730.207352False2.655380.3007523.303470.402116False0.107740.07782820.1797320.0905327False0.05409870.05435430.1039960.0727447False
23748455900407399734.8809825858-5.6626046463328.19251.9253126.80350.96928527.43131.326126.06050.6677224.00780.12136223.6020.16256423.38660.10820523.17220.16283123.7410.27932625.5682.8152126.31510.78121825.04210.39335527.06241.0858825.63660.5464790.00.0191860.0340220.06896120.0615648False0.03867980.04724270.1367080.0840745False0.9054830.1012131.315790.19701False1.60460.1599141.95480.293168False1.157690.2978370.2151860.557958False0.1081340.07780530.3492620.126536False0.05433130.05433830.2020040.101674False
33748455900407400134.8715190736-5.6614566579328.17451.893529.0812.7198127.39391.2811228.3171.837724.57540.19461924.69310.1455725.48620.74024725.43560.4485424.84750.77742125.70711.1280926.29210.76479427.31321.0972927.03461.0583927.9081.524840.00.0195070.03401980.008464620.0212042False0.04003510.04723960.01710820.0289571False0.536830.09622730.4816970.0645835False0.2320150.1581860.2430810.100422False0.4178480.2991920.1892990.196683False0.1104490.07780020.04312270.0435816False0.05573870.05433490.02493440.0350187False
43748455900407400334.8829262475-5.6607330379428.18741.9148427.90631.594627.4341.3284527.17141.1067324.09480.12560624.0240.14009624.07220.19904224.12150.22919624.16860.4183424.58510.69464526.31480.78041626.150.6501527.06111.0838326.74250.9015650.00.01927660.03399680.02497390.0366788False0.03858250.04720760.04913950.0500896False0.8357910.09669030.8920570.115105False0.8533150.1564340.8154350.172136False0.7808260.3008570.5320810.340421False0.1081650.07774770.1258950.0753871False0.05439370.0542980.0729490.0605748False
53748455900407400434.881142836-5.6605103250428.18491.9111628.29181.9005927.42771.3212527.55261.3138624.74490.22721824.70060.22192425.14290.52091524.92510.39734825.38931.2790824.89990.76931726.31130.77817926.5340.7738327.0571.0801127.12771.074280.00.01932110.03400990.01750980.030651False0.03880770.04722590.034590.0418577False0.4592260.09610480.4783860.0977817False0.3182970.1527120.3890120.142367False0.2536780.2988510.3981290.282101False0.1085170.07777770.08839030.0629978False0.05460210.0543190.05115960.0506199False
63748455900407400534.8890740619-5.660410786128.1931.92659nannan27.45471.35541nannan25.52940.473055nannan24.43850.272794nannan24.08380.383556nannan26.32580.789146nannan27.07361.09749nannan0.00.01917830.0340311nannanFalse0.03785320.0472552nannanFalse0.2229770.097151nannanFalse0.6089820.153008nannanFalse0.8442490.298246nannanFalse0.1070760.0778259nannanFalse0.05377070.0543529nannanFalse
73748455900407400634.877236788-5.660360036828.17991.90192nannan27.4141.30432nannan26.11370.79398nannan25.1860.564613nannan24.67590.638943nannan26.30350.772453nannan27.04791.07088nannan0.00.01941040.034002nannanFalse0.03930230.0472148nannanFalse0.1301760.0951955nannanFalse0.3059120.159083nannanFalse0.4893520.287978nannanFalse0.1092960.0777595nannanFalse0.05505980.0543063nannanFalse
83748455900407400734.876108297-5.6603016865828.17861.90141nannan27.41021.301nannan24.49910.183588nannan24.18870.221133nannan23.7630.277792nannan26.30140.771697nannan27.04551.06948nannan0.00.01943370.0340336nannanFalse0.03943910.0472587nannanFalse0.5758930.0973783nannanFalse0.7664950.156113nannanFalse1.134520.290272nannanFalse0.1095050.0778317nannanFalse0.05518320.0543568nannanFalse
93748455900407400934.8825222407-5.659535599228.18271.9097226.79570.97021427.43041.3262526.06150.67379524.35390.16661523.97060.22821324.06480.20649424.50410.56239425.1330.98236824.96551.6227926.31190.77959625.04080.39606927.05711.0816125.63380.5495050.00.019360.03405260.06945710.0620669False0.038710.04728520.136580.0847602False0.6583250.1010250.9370040.196951False0.8591660.1634030.573260.296939False0.3212240.2906410.3747920.560181False0.1084560.07787530.3496990.127568False0.05459450.05438730.202530.102503False

III - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [36]:
SORT_COLS = [
        'merr_ap_hsc-udeep_i', 'merr_ap_hsc-udeep_r', 'merr_ap_hsc-udeep_z',
        'merr_ap_hsc-udeep_y', 'merr_ap_hsc-udeep_g']
FLAG_NAME = 'hsc-udeep_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 1128935 sources.
The cleaned catalogue has 1128841 sources (94 removed).
The cleaned catalogue has 79 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 [37]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_XMM-LSS.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [38]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)
In [39]:
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.11995867840823848 arcsec
Dec correction: -0.08751257112411537 arcsec
In [40]:
catalogue[RA_COL] +=  delta_ra.to(u.deg)
catalogue[DEC_COL] += delta_dec.to(u.deg)
In [41]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)

IV - Flagging Gaia objects¶

In [42]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [43]:
GAIA_FLAG_NAME = "hsc-udeep_flag_gaia"

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

V - Saving to disk¶

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