Lockman SWIRE 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.

Strange magnitudes

The missing values seems to be encoded as -99. but there are also quite some 99. magnitudes.

The “sensible” range of magnitudes seems to go from 14 to 37 (depending on the bands and given that 37 is really faint and may not be reliable). In addition to that there are some very low magnitudes under -40. and very high ones above 90. We don't know the meaning of these extreme values so we are removing all the negative magnitudes and and those above 80.

We are also removing the sources for which we have no magnitude information given the modifications above.

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: 
44f1ae0 (Thu Nov 30 18:27:54 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_Lockman-SWIRE.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:])
        
        # 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
        
        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:])))

        # We add NAN filled aperture columns because no aperture fluxes are present
        # EDIT: Better not add empty columns if we can avoid.
        #nancol = np.zeros(len(catalogue))
        #nancol.fill(np.nan)
        #catalogue.add_column(Column(nancol, 
         #                           name="m_ap{}".format(col[1:])))
        #catalogue.add_column(Column(nancol, 
        #                            name="merr_ap{}".format(col[1:])))
        #catalogue.add_column(Column(nancol, 
        #                           name="f_ap{}".format(col[1:])))
        #catalogue.add_column(Column(nancol, 
        #                           name="ferr_ap{}".format(col[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 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_gflag_rcs_gf_rcs_rferr_rcs_rflag_rcs_rf_rcs_iferr_rcs_iflag_rcs_if_rcs_zferr_rcs_zflag_rcs_zf_rcs_yferr_rcs_yflag_rcs_y
0CDE1040A1_012221164.827463255.93429510.5926.43830.19284424.9540.059156224.31090.046863724.24710.128944nannan0.0965340.017146False0.3787910.0206384False0.684920.0295633False0.7263720.0862653FalsenannanFalse
1CDE1040A1_012351164.859858155.93521140.51nannan24.09580.11124124.32930.179642nannannannannannanFalse0.8349870.08555False0.6734110.11142FalsenannanFalsenannanFalse
2CDE1040A1_012523164.844066355.93669530.0524.95880.089157624.00170.042254323.86140.049457523.34690.096879nannan0.377120.0309681False0.9105840.0354378False1.036190.0472006False1.664330.148506FalsenannanFalse
3CDE1040A1_012541164.85643955.9368530.0524.74290.064180424.01790.036581423.85840.042186823.81930.125855nannan0.4600860.0271968False0.8970980.0302257False1.039060.0403731False1.077160.124861FalsenannanFalse
4CDE1040A1_012593164.84401155.93734690.6925.01230.066751825.010.06701224.9470.0838051nannannannan0.3589880.0220708False0.3597490.0222038False0.3812410.029427FalsenannanFalsenannanFalse
5CDE1040A1_012610164.830926655.93757840.5325.74850.15817525.01310.089412324.62550.085921224.13340.171663nannan0.1822220.0265469False0.3587240.0295415False0.5126250.0405673False0.8065660.127524FalsenannanFalse
6CDE1040A1_012657164.860626755.93801410.725.1640.086305524.58950.055558524.41540.063286224.15650.154603nannan0.3121760.024815False0.5299070.027116False0.6220710.0362597False0.7895870.112433FalsenannanFalse
7CDE1040A1_012667164.843023655.93820880.48nannannannannannannannannannannannanFalsenannanFalsenannanFalsenannanFalsenannanFalse
8CDE1040A1_012677164.829446955.93827290.9nannan24.06910.0291555nannan23.20830.0539764nannannannanFalse0.8557760.0229803FalsenannanFalse1.890950.0940069FalsenannanFalse
9CDE1040A1_012702164.843854355.93844710.5825.26180.10472325.11740.0949201nannannannannannan0.2852850.0275167False0.3258670.0284888FalsenannanFalsenannanFalsenannanFalse

1.1 Remove all nan rows

In [7]:
orig_len = len(catalogue)
mask = ~(np.isnan(catalogue['m_rcs_g']) 
        & np.isnan(catalogue['m_rcs_r'])
        & np.isnan(catalogue['m_rcs_i'])
        & np.isnan(catalogue['m_rcs_z'])
        & np.isnan(catalogue['m_rcs_y'])
        )
catalogue = catalogue[mask]
print(orig_len-len(catalogue), 'out of ', orig_len, ' objects removed due to all nan magnitudes.')
481360 out of  2607590  objects removed due to all nan magnitudes.

II - Removal of duplicated sources

We remove duplicated objects from the input catalogues.

In [8]:
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])))
The initial catalogue had 2126230 sources.
The cleaned catalogue has 2052639 sources (73591 removed).
The cleaned catalogue has 72807 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 [9]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_Lockman-SWIRE.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [10]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec, near_ra0=True)
In [11]:
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.07070391181969171 arcsec
Dec correction: -0.1302633008947396 arcsec
In [12]:
catalogue[RA_COL] +=  delta_ra.to(u.deg)
catalogue[DEC_COL] += delta_dec.to(u.deg)
In [13]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec, near_ra0=True)

IV - Flagging Gaia objects

In [14]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [15]:
GAIA_FLAG_NAME = "rcs_flag_gaia"

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

V - Flagging objects near bright stars

VI - Saving to disk

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