AKARI-SEP master catalogue¶

This notebook presents the merge of the various pristine catalogues to produce HELP mater catalogue on AKARI-SEP.

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))

import os
import time

from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.table import Column, Table
import numpy as np
from pymoc import MOC

from herschelhelp_internal.masterlist import merge_catalogues, nb_merge_dist_plot, specz_merge
from herschelhelp_internal.utils import coords_to_hpidx, ebv, gen_help_id, inMoc
In [3]:
TMP_DIR = os.environ.get('TMP_DIR', "./data_tmp")
OUT_DIR = os.environ.get('OUT_DIR', "./data")
SUFFIX = os.environ.get('SUFFIX', time.strftime("_%Y%m%d"))

try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

I - Reading the prepared pristine catalogues¶

In [4]:
vhs = Table.read("{}/VISTA-VHS.fits".format(TMP_DIR))
simes = Table.read("{}/SIMES.fits".format(TMP_DIR))
des = Table.read("{}/DES.fits".format(TMP_DIR))

II - Merging tables¶

We first merge the optical catalogues and then add the infrared ones: WFC, DXS, SpARCS, HSC, PS1, SERVS, SWIRE.

At every step, we look at the distribution of the distances separating the sources from one catalogue to the other (within a maximum radius) to determine the best cross-matching radius.

WFC¶

In [5]:
master_catalogue = vhs
master_catalogue['vhs_ra'].name = 'ra'
master_catalogue['vhs_dec'].name = 'dec'

Add SIMES¶

In [6]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(simes['simes_ra'], simes['simes_dec'])
)
In [7]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, simes, "simes_ra", "simes_dec", radius=0.8*u.arcsec)

Add DES¶

In [8]:
nb_merge_dist_plot(
    SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
    SkyCoord(des['des_ra'], des['des_dec'])
)
In [9]:
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, des, "des_ra", "des_dec", radius=0.8*u.arcsec)

Cleaning¶

When we merge the catalogues, astropy masks the non-existent values (e.g. when a row comes only from a catalogue and has no counterparts in the other, the columns from the latest are masked for that row). We indicate to use NaN for masked values for floats columns, False for flag columns and -1 for ID columns.

In [10]:
for col in master_catalogue.colnames:
    if "m_" in col or "merr_" in col or "f_" in col or "ferr_" in col or "stellarity" in col:
        master_catalogue[col].fill_value = np.nan
    elif "flag" in col:
        master_catalogue[col].fill_value = 0
    elif "id" in col:
        master_catalogue[col].fill_value = -1
        
master_catalogue = master_catalogue.filled()
In [11]:
master_catalogue[:10].show_in_notebook()
Out[11]:
<Table length=10>
idxvhs_idradecvhs_stellaritym_vista_jmerr_vista_jm_ap_vista_jmerr_ap_vista_jm_vista_hmerr_vista_hm_ap_vista_hmerr_ap_vista_hm_vista_kmerr_vista_km_ap_vista_kmerr_ap_vista_kf_vista_jferr_vista_jflag_vista_jf_ap_vista_jferr_ap_vista_jf_vista_hferr_vista_hflag_vista_hf_ap_vista_hferr_ap_vista_hf_vista_kferr_vista_kflag_vista_kf_ap_vista_kferr_ap_vista_kvhs_flag_cleanedvhs_flag_gaiaflag_mergedsimes_idf_irac_i1ferr_irac_i1f_ap_irac_i1ferr_ap_irac_i1simes_stellarityf_irac_i2ferr_irac_i2f_ap_irac_i2ferr_ap_irac_i2m_irac_i1merr_irac_i1flag_irac_i1m_ap_irac_i1merr_ap_irac_i1m_irac_i2merr_irac_i2flag_irac_i2m_ap_irac_i2merr_ap_irac_i2servs_flag_cleanedservs_flag_gaiades_iddes_stellaritym_decam_gmerr_decam_gm_ap_decam_gmerr_ap_decam_gm_decam_rmerr_decam_rm_ap_decam_rmerr_ap_decam_rm_decam_imerr_decam_im_ap_decam_imerr_ap_decam_im_decam_zmerr_decam_zm_ap_decam_zmerr_ap_decam_zm_decam_ymerr_decam_ym_ap_decam_ymerr_ap_decam_yf_decam_gferr_decam_gflag_decam_gf_ap_decam_gferr_ap_decam_gf_decam_rferr_decam_rflag_decam_rf_ap_decam_rferr_ap_decam_rf_decam_iferr_decam_iflag_decam_if_ap_decam_iferr_ap_decam_if_decam_zferr_decam_zflag_decam_zf_ap_decam_zferr_ap_decam_zf_decam_yferr_decam_yflag_decam_yf_ap_decam_yferr_ap_decam_ydes_flag_cleaneddes_flag_gaia
degdeg
047324026806874.0205586698-52.54682677370.9nannannannan10.52280.00033477212.08460.000542435nannannannannannanFalsenannan224332.069.1696False53230.426.594nannanFalsenannanFalse0False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
147324107315572.5319041476-54.19919244010.993865nannannannan12.42340.00078128412.27970.00054654710.71570.00028347412.11130.000581437nannanFalsenannan38960.228.0353False44477.022.3892187819.049.0375False51937.127.8135False0False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
247324026807574.0224515147-52.54760322090.993865nannannannan11.25010.00045223212.14020.00055731712.06470.00069449611.97620.00057904nannanFalsenannan114801.047.8169False50571.625.958854215.634.6793False58817.631.3684False0False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
347324026807474.0222147308-52.54675144490.9nannannannan10.68360.00031099212.15970.00056267nannannannannannanFalsenannan193452.055.4113False49671.125.7414nannanFalsenannanFalse0False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
447324107315672.5325882644-54.19966538060.993865nannannannan14.32910.0032427812.36840.0005702211.50110.00042104912.23850.000617738nannanFalsenannan6735.1920.1161False40986.821.525991112.035.3332False46193.926.2824False0False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
547326160659369.8075179383-54.17589064080.993865nannannannan12.50020.0013082412.02440.00057471912.00120.0005851611.93610.000579327nannanFalsenannan36300.243.7394False56263.829.782457480.430.9792False61033.932.5665False0False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
647319363110374.0790931604-52.37970588280.9nannannannan11.96290.0005574812.180.000584537nannannannannannanFalsenannan59542.130.5724False48753.426.2478nannanFalsenannanFalse2False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
747319362681372.5373778649-52.4134958390.99386511.23080.00031751811.930.00052669810.61990.00026546512.17890.000585264nannannannan116862.034.1757False61376.429.7741205136.050.1564False48802.426.3069nannanFalsenannanFalse0False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
847326160660169.8080872881-54.17648649780.9nannannannan11.05840.00031887812.0670.00058775nannannannannannanFalsenannan136980.040.2308False54098.129.2853nannanFalsenannanFalse0False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0
947326160659869.8096965887-54.17591484970.9nannannannan11.52380.00063982912.09720.000596377nannannannannannanFalsenannan89221.352.5785False52616.228.9012nannanFalsenannanFalse0False-1nannannannannannannannannannannanFalsenannannannanFalsenannanFalse0-1nannannannannannannannannannannannannannannannannannannannannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannanFalse0

III - Merging flags and stellarity¶

Each pristine catalogue contains a flag indicating if the source was associated to a another nearby source that was removed during the cleaning process. We merge these flags in a single one.

In [12]:
flag_cleaned_columns = [column for column in master_catalogue.colnames
                        if 'flag_cleaned' in column]

flag_column = np.zeros(len(master_catalogue), dtype=bool)
for column in flag_cleaned_columns:
    flag_column |= master_catalogue[column]
    
master_catalogue.add_column(Column(data=flag_column, name="flag_cleaned"))
master_catalogue.remove_columns(flag_cleaned_columns)

Each pristine catalogue contains a flag indicating the probability of a source being a Gaia object (0: not a Gaia object, 1: possibly, 2: probably, 3: definitely). We merge these flags taking the highest value.

In [13]:
flag_gaia_columns = [column for column in master_catalogue.colnames
                     if 'flag_gaia' in column]

master_catalogue.add_column(Column(
    data=np.max([master_catalogue[column] for column in flag_gaia_columns], axis=0),
    name="flag_gaia"
))
master_catalogue.remove_columns(flag_gaia_columns)

Each prisitine catalogue may contain one or several stellarity columns indicating the probability (0 to 1) of each source being a star. We merge these columns taking the highest value. We keep trace of the origin of the stellarity.

In [14]:
stellarity_columns = [column for column in master_catalogue.colnames
                      if 'stellarity' in column]

print(", ".join(stellarity_columns))
vhs_stellarity, simes_stellarity, des_stellarity
In [15]:
# We create an masked array with all the stellarities and get the maximum value, as well as its
# origin.  Some sources may not have an associated stellarity.
stellarity_array = np.array([master_catalogue[column] for column in stellarity_columns])
stellarity_array = np.ma.masked_array(stellarity_array, np.isnan(stellarity_array))

max_stellarity = np.max(stellarity_array, axis=0)
max_stellarity.fill_value = np.nan

no_stellarity_mask = max_stellarity.mask

master_catalogue.add_column(Column(data=max_stellarity.filled(), name="stellarity"))

stellarity_origin = np.full(len(master_catalogue), "NO_INFORMATION", dtype="S20")
stellarity_origin[~no_stellarity_mask] = np.array(stellarity_columns)[np.argmax(stellarity_array, axis=0)[~no_stellarity_mask]]

master_catalogue.add_column(Column(data=stellarity_origin, name="stellarity_origin"))

master_catalogue.remove_columns(stellarity_columns)

IV - Adding E(B-V) column¶

In [16]:
master_catalogue.add_column(
    ebv(master_catalogue['ra'], master_catalogue['dec'])
)

V - Adding HELP unique identifiers and field columns¶

In [17]:
master_catalogue.add_column(Column(gen_help_id(master_catalogue['ra'], master_catalogue['dec']),
                                   name="help_id"))
master_catalogue.add_column(Column(np.full(len(master_catalogue), "AKARI-SEP", dtype='<U18'),
                                   name="field"))
In [18]:
# Check that the HELP Ids are unique
if len(master_catalogue) != len(np.unique(master_catalogue['help_id'])):
    print("The HELP IDs are not unique!!!")
else:
    print("OK!")
OK!

VI.a Wavelength domain coverage¶

We add a binary flag_optnir_obs indicating that a source was observed in a given wavelength domain:

  • 1 for observation in optical;
  • 2 for observation in near-infrared;
  • 4 for observation in mid-infrared (IRAC).

It's an integer binary flag, so a source observed both in optical and near-infrared by not in mid-infrared would have this flag at 1 + 2 = 3.

Note 1: The observation flag is based on the creation of multi-order coverage maps from the catalogues, this may not be accurate, especially on the edges of the coverage.

Note 2: Being on the observation coverage does not mean having fluxes in that wavelength domain. For sources observed in one domain but having no flux in it, one must take into consideration de different depths in the catalogue we are using.

In [19]:
simes_moc = MOC(filename="../../dmu0/dmu0_SIMES/data/SEP_catalog7.2_mJy_HELP-coverage_MOC.fits")
vhs_moc = MOC(filename="../../dmu0/dmu0_VISTA-VHS/data/VHS_AKARI-SEP_MOC.fits")
des_moc = MOC(filename="../../dmu0/dmu0_DES/data/DES-DR1_AKARI-SEP.fits")
In [20]:
was_observed_optical =inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    des_moc
)

was_observed_nir = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    vhs_moc
)

was_observed_mir = inMoc(
    master_catalogue['ra'], master_catalogue['dec'],
    simes_moc
)
In [21]:
master_catalogue.add_column(
    Column(
        1 * was_observed_optical + 2 * was_observed_nir + 4 * was_observed_mir,
        name="flag_optnir_obs")
)

VIII.b Wavelength domain detection¶

We add a binary flag_optnir_det indicating that a source was detected in a given wavelength domain:

  • 1 for detection in optical;
  • 2 for detection in near-infrared;
  • 4 for detection in mid-infrared (IRAC).

It's an integer binary flag, so a source detected both in optical and near-infrared by not in mid-infrared would have this flag at 1 + 2 = 3.

Note 1: We use the total flux columns to know if the source has flux, in some catalogues, we may have aperture flux and no total flux.

To get rid of artefacts (chip edges, star flares, etc.) we consider that a source is detected in one wavelength domain when it has a flux value in at least two bands. That means that good sources will be excluded from this flag when they are on the coverage of only one band.

In [22]:
# SpARCS is a catalogue of sources detected in r (with fluxes measured at 
# this prior position in the other bands).  Thus, we are only using the r
# CFHT band.
# Check to use catalogue flags from HSC and PanSTARRS.
nb_optical_flux = (
    1 * ~np.isnan(master_catalogue['f_decam_g']) +
    1 * ~np.isnan(master_catalogue['f_decam_r']) +    
    1 * ~np.isnan(master_catalogue['f_decam_i']) +
    1 * ~np.isnan(master_catalogue['f_decam_z']) +
    1 * ~np.isnan(master_catalogue['f_decam_y']) 
)

nb_nir_flux = (
    1 * ~np.isnan(master_catalogue['f_vista_j']) +
    1 * ~np.isnan(master_catalogue['f_vista_h']) +
    1 * ~np.isnan(master_catalogue['f_vista_k'])
)

nb_mir_flux = (
    1 * ~np.isnan(master_catalogue['f_irac_i1']) +
    1 * ~np.isnan(master_catalogue['f_irac_i2']) 
)
In [23]:
has_optical_flux = nb_optical_flux >= 2
has_nir_flux = nb_nir_flux >= 2
has_mir_flux = nb_mir_flux >= 2

master_catalogue.add_column(
    Column(
        1 * has_optical_flux + 2 * has_nir_flux + 4 * has_mir_flux,
        name="flag_optnir_det")
)

IX - Cross-identification table¶

We are producing a table associating to each HELP identifier, the identifiers of the sources in the pristine catalogues. This can be used to easily get additional information from them.

In [24]:
master_catalogue['help_id', 'vhs_id', 'simes_id', 'des_id'].write(
    "{}/master_list_cross_ident_akari-sep{}.fits".format(OUT_DIR, SUFFIX))
master_catalogue.remove_columns(['vhs_id', 'simes_id', 'des_id'])

X - Adding HEALPix index¶

We are adding a column with a HEALPix index at order 13 associated with each source.

In [25]:
master_catalogue.add_column(Column(
    data=coords_to_hpidx(master_catalogue['ra'], master_catalogue['dec'], order=13),
    name="hp_idx"
))

XI - Saving the catalogue¶

In [26]:
columns = ["help_id", "field", "ra", "dec", "hp_idx"]

bands = [column[5:] for column in master_catalogue.colnames if 'f_ap' in column]
for band in bands:
    columns += ["f_ap_{}".format(band), "ferr_ap_{}".format(band),
                "m_ap_{}".format(band), "merr_ap_{}".format(band),
                "f_{}".format(band), "ferr_{}".format(band),
                "m_{}".format(band), "merr_{}".format(band),
                "flag_{}".format(band)]    
    
columns += ["stellarity", "stellarity_origin", "flag_cleaned", "flag_merged", "flag_gaia", "flag_optnir_obs", 
            "flag_optnir_det", "ebv"]
In [27]:
# We check for columns in the master catalogue that we will not save to disk.
print("Missing columns: {}".format(set(master_catalogue.colnames) - set(columns)))
Missing columns: set()
In [28]:
master_catalogue[columns].write("{}/master_catalogue_akari-sep{}.fits".format(OUT_DIR, SUFFIX))