XMM-LSS master catalogue¶

Preparation of Hyper Suprime-Cam Subaru Strategic Program Catalogues (HSC-SSP) wide 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 aperture magnitude in 2” that we aperture correct;
  • The g, r, i, z, y 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-wide_ra"
DEC_COL = "hsc-wide_dec"
In [4]:
# Pritine HSC catalogue
orig_hsc = Table.read("../../dmu0/dmu0_HSC/data/HSC-PDR1_wide_XMM-LSS_v2.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"]
apertures = ["10", "15", "20", "30",  "57", "84", "118", "168"] #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 57 as target.

In [7]:
nb_plot_mag_vs_apcor(orig_hsc['gmag_aperture20'], orig_hsc['gmag_aperture57'], 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 18.5 and 20.8

In [8]:
# Aperture correction
mag_corr['g'], num, std = aperture_correction(
    orig_hsc['gmag_aperture20'], orig_hsc['gmag_aperture57'], 
    stellarities['g'],
    mag_min=18.5, mag_max=20.8)
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.19431591033935547
Number of source used: 5833
RMS: 0.026450276767739297
/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 57 as target.

In [10]:
nb_plot_mag_vs_apcor(orig_hsc['rmag_aperture20'], orig_hsc['rmag_aperture57'], 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.5 and 20.5.

In [11]:
# Aperture correction
mag_corr['r'], num, std = aperture_correction(
    orig_hsc['rmag_aperture20'], orig_hsc['rmag_aperture57'], 
    stellarities['r'],
    mag_min=19.5, 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.2287282943725586
Number of source used: 6824
RMS: 0.030347691570742935
/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 57 as target.

In [13]:
nb_plot_mag_vs_apcor(orig_hsc['imag_aperture20'], orig_hsc['imag_aperture57'], 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_aperture57'], 
    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.10515594482421875
Number of source used: 9726
RMS: 0.014409932108072392
/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 57 as target.

In [16]:
nb_plot_mag_vs_apcor(orig_hsc['zmag_aperture20'], orig_hsc['zmag_aperture57'], 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 17.5 and 18.8.

In [17]:
# Aperture correction
mag_corr['z'], num, std = aperture_correction(
    orig_hsc['zmag_aperture20'], orig_hsc['zmag_aperture57'], 
    stellarities['z'],
    mag_min=17.5, mag_max=18.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.13919830322265625
Number of source used: 5793
RMS: 0.02398529710992674
/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 57 as target.

In [19]:
nb_plot_mag_vs_apcor(orig_hsc['ymag_aperture20'], orig_hsc['ymag_aperture57'], 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 17.6 and 18.7.

In [20]:
# Aperture correction
mag_corr['y'], num, std = aperture_correction(
    orig_hsc['ymag_aperture20'], orig_hsc['ymag_aperture57'], 
    stellarities['y'],
    mag_min=17.6, mag_max=18.7)
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.18083953857421875
Number of source used: 5837
RMS: 0.049393831306902114
/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 [21]:
# 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']
])
In [22]:
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 [23]:
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 [24]:
vis.hist(stellarity, bins='scott');
In [25]:
orig_hsc.add_column(Column(data=stellarity, name="stellarity"))

II - Column selection¶

In [26]:
imported_columns = OrderedDict({
        "object_id": "hsc-wide_id",
        "ra": "hsc-wide_ra",
        "dec": "hsc-wide_dec",
        "gmag_aperture20": "m_ap_hsc-wide_g",
        "gmag_aperture20_err": "merr_ap_hsc-wide_g",
        "gmag_kron": "m_hsc-wide_g",
        "gmag_kron_err": "merr_hsc-wide_g",
        "rmag_aperture20": "m_ap_hsc-wide_r",
        "rmag_aperture20_err": "merr_ap_hsc-wide_r",
        "rmag_kron": "m_hsc-wide_r",
        "rmag_kron_err": "merr_hsc-wide_r",
        "imag_aperture20": "m_ap_hsc-wide_i",
        "imag_aperture20_err": "merr_ap_hsc-wide_i",
        "imag_kron": "m_hsc-wide_i",
        "imag_kron_err": "merr_hsc-wide_i",
        "zmag_aperture20": "m_ap_hsc-wide_z",
        "zmag_aperture20_err": "merr_ap_hsc-wide_z",
        "zmag_kron": "m_hsc-wide_z",
        "zmag_kron_err": "merr_hsc-wide_z",
        "ymag_aperture20": "m_ap_hsc-wide_y",
        "ymag_aperture20_err": "merr_ap_hsc-wide_y",
        "ymag_kron": "m_hsc-wide_y",
        "ymag_kron_err": "merr_hsc-wide_y",
        "stellarity": "hsc-wide_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 [27]:
# Aperture correction
for band in bands:
    catalogue["m_ap_hsc-wide_{}".format(band)] += mag_corr[band]
In [28]:
# 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 [29]:
catalogue[:10].show_in_notebook()
Out[29]:
<Table masked=True length=10>
idxhsc-wide_idhsc-wide_rahsc-wide_decm_ap_hsc-wide_gmerr_ap_hsc-wide_gm_hsc-wide_gmerr_hsc-wide_gm_ap_hsc-wide_rmerr_ap_hsc-wide_rm_hsc-wide_rmerr_hsc-wide_rm_ap_hsc-wide_imerr_ap_hsc-wide_im_hsc-wide_imerr_hsc-wide_im_ap_hsc-wide_zmerr_ap_hsc-wide_zm_hsc-wide_zmerr_hsc-wide_zm_ap_hsc-wide_ymerr_ap_hsc-wide_ym_hsc-wide_ymerr_hsc-wide_yhsc-wide_stellarityf_ap_hsc-wide_gferr_ap_hsc-wide_gf_hsc-wide_gferr_hsc-wide_gflag_hsc-wide_gf_ap_hsc-wide_rferr_ap_hsc-wide_rf_hsc-wide_rferr_hsc-wide_rflag_hsc-wide_rf_ap_hsc-wide_iferr_ap_hsc-wide_if_hsc-wide_iferr_hsc-wide_iflag_hsc-wide_if_ap_hsc-wide_zferr_ap_hsc-wide_zf_hsc-wide_zferr_hsc-wide_zflag_hsc-wide_zf_ap_hsc-wide_yferr_ap_hsc-wide_yf_hsc-wide_yferr_hsc-wide_yflag_hsc-wide_y
03642025322322347833.5713246615-6.2266729265826.14030.20851626.32750.48323225.72340.25857926.43660.97082525.06580.13361924.39430.15602625.73820.559784nannan25.7741.15875nannan0.00.1270250.02439520.1069050.0475805False0.1864810.04441240.09668310.0864505False0.3417220.04205490.6342640.0911472False0.1839660.0948492nannanFalse0.1779910.18996nannanFalse
13642025322322348133.5869057493-6.2265080793824.93250.082090524.95670.084140223.28650.032368423.40250.035298121.68180.006021521.6940.0067874720.99980.0073014921.0460.0082266620.78770.012443920.86320.01375351.00.3863660.02921240.3778390.029281False1.759490.05245471.581250.0514077False7.714220.04278317.627660.0476843False14.45770.097226913.85470.104977False17.57570.20143916.39530.207686False
23642025322322349133.568789666-6.2264890832326.12320.20468625.49140.2464926.03160.34807325.37370.40597825.42170.18884824.73470.23837324.64930.21478524.20050.32661625.90371.30841nannan0.0530.1290430.02432750.2309010.0524205False0.1403970.04500950.2573530.0962292False0.2462230.0428270.463580.101779False0.5015330.09921540.7582040.228086False0.157950.190343nannanFalse
33642025322322349433.5777361537-6.2263797419325.2920.10993824.96510.35519524.53940.091714423.80640.22184824.25540.064483626.50832.6344524.00960.11516nannan23.94710.218734nannan0.00.2774530.02809390.374940.12266False0.5549190.04687521.090.22272False0.7208710.04281370.09050740.219609False0.9039570.095879nannanFalse0.9575720.192914nannanFalse
43642025322322349533.5697238605-6.2263086616125.13990.08413524.65130.13593625.03870.1438125.41380.50842125.05650.13182424.06930.1552225.43220.42493926.91724.7490625.92831.39167nannan0.00.3191950.02473480.5005810.0626734False0.3503510.04640550.2480260.116144False0.3446730.04184810.8556290.122323False0.2438380.09543410.06210240.271639False0.1544170.197927nannanFalse
53642025322322349833.5807262602-6.226270944324.86290.071899925.04540.070141824.59250.10728824.86340.11119724.06170.052454124.12780.051447823.83610.093368223.98040.094935223.96170.22777824.12870.2252660.00.4119280.02727880.3482040.022495False0.5284310.05221720.4117450.0421694False0.8615940.04162530.8107650.0384182False1.06060.09120660.9286340.0811984False0.9447930.198210.8100950.168077False
63642025322322350033.5820170351-6.2263191957925.18040.097360124.95620.11828725.32510.19981625.03640.22781125.40990.18374225.76030.42726325.92210.664965nannannannannannan0.00.3074960.02757380.3780340.0411855False0.2691210.04952840.3511160.0736719False0.2489180.04212490.1802540.0709343False0.1552990.0951135nannanFalsenannannannanFalse
73642025322322350333.5382549884-6.2263129417726.17710.209432nannan25.9660.324779nannan25.49530.194861nannan26.71521.39332nannannannannannan0.00.1227920.0236857nannanFalse0.149140.0446128nannanFalse0.2300740.0412923nannanFalse0.07480170.0959929nannanFalsenannannannanFalse
83642025322322351333.5623193446-6.2258955119125.0580.077010125.25140.080419524.82080.11400324.89240.10494224.1940.060392224.24350.061726123.77180.093092123.85720.095082924.21160.28781924.44690.3209390.00.3441860.02441270.288020.0213334False0.4282170.04496320.4009020.0387494False0.7628090.04242990.7288050.0414339False1.125380.09649111.040250.0910994False0.7505420.1989620.6042870.178625False
93642025322322351433.5790485015-6.2259930285226.96330.49884426.88070.38038726.02070.4112726.37860.4595325.77560.24894826.50360.445338nannannannan24.98610.55457625.10910.5270861.00.05952010.02734660.06422460.022501False0.1418090.05371640.1019910.0431669False0.1777340.04075270.09089570.0372829FalsenannannannanFalse0.3677540.1878420.3283770.159415False

III - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [30]:
SORT_COLS = [
        'merr_ap_hsc-wide_i', 'merr_ap_hsc-wide_r', 'merr_ap_hsc-wide_z',
        'merr_ap_hsc-wide_y', 'merr_ap_hsc-wide_g']
FLAG_NAME = 'hsc-wide_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 4421152 sources.
The cleaned catalogue has 4421020 sources (132 removed).
The cleaned catalogue has 132 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 [31]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_XMM-LSS.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [32]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)
In [33]:
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.1269925983379494 arcsec
Dec correction: -0.09919436644878488 arcsec
In [34]:
catalogue[RA_COL] +=  delta_ra.to(u.deg)
catalogue[DEC_COL] += delta_dec.to(u.deg)
In [35]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)

IV - Flagging Gaia objects¶

In [36]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [37]:
GAIA_FLAG_NAME = "hsc-wide_flag_gaia"

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

V - Saving to disk¶

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