Herschel Stripe 82 master catalogue¶

Preparation of Red Cluster Sequence Lensing Survey (RCSLenS) data¶

This catalogue comes from dmu0_RCSLenS.

In the catalogue, we keep:

  • The id as unique object identifier;
  • The position;
  • The g, r, i, z, y auto magnitudes.
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 = "rcs_ra"
DEC_COL = "rcs_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        "id": "rcs_id",
        "ALPHA_J2000": "rcs_ra",
        "DELTA_J2000": "rcs_dec",
        "CLASS_STAR": "rcs_stellarity",
        "MAG_g": "m_rcs_g",
        "MAGERR_g": "merr_rcs_g",
        "MAG_r": "m_rcs_r",
        "MAGERR_r": "merr_rcs_r",        
        "MAG_i": "m_rcs_i",
        "MAGERR_i": "merr_rcs_i",
        "MAG_z": "m_rcs_z",
        "MAGERR_z": "merr_rcs_z",
        "MAG_y": "m_rcs_y",
        "MAGERR_y": "merr_rcs_y"    
    })


catalogue = Table.read("../../dmu0/dmu0_RCSLenS/data/RCSLenS_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]))
           
        # Remove missing values (-99, 99?) and extreme magnitudes (see above).
        mask = (catalogue[col] < 0.) | (catalogue[col] > 80.)
        catalogue[col][mask] = np.nan
        catalogue[errcol][mask] = np.nan       
        
        # 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.
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:39: RuntimeWarning: overflow encountered in power
  fluxes = 10 ** ((8.9 - magnitudes)/2.5)
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:43: RuntimeWarning: invalid value encountered in multiply
  errors = np.log(10)/2.5 * fluxes * errors_on_magnitudes
/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)
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxrcs_idrcs_rarcs_decrcs_stellaritym_rcs_gmerr_rcs_gm_rcs_rmerr_rcs_rm_rcs_imerr_rcs_im_rcs_zmerr_rcs_zm_rcs_ymerr_rcs_yf_rcs_gferr_rcs_gf_ap_rcs_gferr_ap_rcs_gm_ap_rcs_gmerr_ap_rcs_gflag_rcs_gf_rcs_rferr_rcs_rf_ap_rcs_rferr_ap_rcs_rm_ap_rcs_rmerr_ap_rcs_rflag_rcs_rf_rcs_iferr_rcs_if_ap_rcs_iferr_ap_rcs_im_ap_rcs_imerr_ap_rcs_iflag_rcs_if_rcs_zferr_rcs_zf_ap_rcs_zferr_ap_rcs_zm_ap_rcs_zmerr_ap_rcs_zflag_rcs_zf_rcs_yferr_rcs_yf_ap_rcs_yferr_ap_rcs_ym_ap_rcs_ymerr_ap_rcs_yflag_rcs_y
0CDE0047A3_07798416.13519812.5e-060.5425.27430.10871924.9050.0926732nannannannannannan0.282020.0282398nannannannanFalse0.3962780.0338243nannannannanFalseinf-infnannannannanFalse9.12009e-318.31591e-29nannannannanFalse9.12009e-318.31591e-29nannannannanFalse
1CDE0047A3_07798615.43746165.15e-050.0924.29940.051648923.93910.0437929nannan22.63840.04840123.34060.05277540.6922130.0329288nannannannanFalse0.9646280.038908nannannannanFalseinf-infnannannannanFalse3.196250.142485nannannannanFalse1.674020.0813706nannannannanFalse
2CDE0047A3_07798715.26442077.17e-050.1124.54670.053734824.28360.0486367nannan23.84020.1047224.08940.0818590.5512140.0272804nannannannanFalse0.702360.031463nannannannanFalseinf-infnannannannanFalse1.056620.101912nannannannanFalse0.8399240.063326nannannannanFalse
3CDE0047A3_07798916.10032260.00016710.69nannannannannannannannannannaninfnannannannannanFalseinfnannannannannanFalseinf-infnannannannanFalseinfnannannannannanFalseinfnannannannannanFalse
4CDE0047A3_07799015.97708660.00015180.5225.10280.10238925.46610.149545nannannannannannan0.3302780.0311465nannannannanFalse0.2363520.0325542nannannannanFalseinf-infnannannannanFalse9.12009e-318.31591e-29nannannannanFalse9.12009e-318.31591e-29nannannannanFalse
5CDE0047A3_07799115.93797070.00015360.74nannannannannannannannannannaninfnannannannannanFalseinfnannannannannanFalseinf-infnannannannanFalseinfnannannannannanFalseinfnannannannannanFalse
6CDE0047A3_07799215.87703550.00012740.0923.47060.030172423.18750.0263398nannan22.21640.036663922.32140.02385121.485110.041271nannannannanFalse1.927520.0467614nannannannanFalseinf-infnannannannanFalse4.714550.159204nannannannanFalse4.279960.0940213nannannannanFalse
7CDE0047A3_07799315.44008190.00015820.4424.86370.071944624.11480.0463704nannannannan23.97670.08341880.4116420.0272768nannannannanFalse0.8205030.0350426nannannannanFalseinf-infnannannannanFalse9.12009e-318.31591e-29nannannannanFalse0.9317940.0715912nannannannanFalse
8CDE0047A3_07799415.86483520.00014230.6125.55780.1411324.88760.0947058nannan23.75320.12170124.63120.1584480.217210.0282342nannannannanFalse0.402680.0351247nannannannanFalseinf-infnannannannanFalse1.144770.128319nannannannanFalse0.5099410.0744187nannannannanFalse
9CDE0047A3_07799615.85044840.00012030.5525.42120.13268424.71990.0870816nannan23.81290.132467nannan0.2463320.0301033nannannannanFalse0.4699370.0376914nannannannanFalseinf-infnannannannanFalse1.083530.132197nannannannanFalse9.12009e-318.31591e-29nannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = []
FLAG_NAME = 'rcs_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 13515631 sources.
The cleaned catalogue has 13138199 sources (377432 removed).
The cleaned catalogue has 372333 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.09379497242889556 arcsec
Dec correction: -0.11609776623586754 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 = "rcs_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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