This notebook presents the merge of the various pristine catalogues to produce HELP mater catalogue on ELAIS-S1.
from herschelhelp_internal import git_version
print("This notebook was run with herschelhelp_internal version: \n{}".format(git_version()))
%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
from herschelhelp_internal.utils import coords_to_hpidx, ebv, gen_help_id, inMoc
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
video = Table.read("{}/VISTA-VIDEO.fits".format(TMP_DIR))
vhs = Table.read("{}/VISTA-VHS.fits".format(TMP_DIR))
voice = Table.read("{}/ESIS-VOICE.fits".format(TMP_DIR))
servs = Table.read("{}/SERVS.fits".format(TMP_DIR))
swire= Table.read("{}/SWIRE.fits".format(TMP_DIR))
des = Table.read("{}/DES.fits".format(TMP_DIR))
We merge in order of increasing wavelength: VIDEO, VHS, VOICE, 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.
master_catalogue = video
master_catalogue['video_ra'].name = 'ra'
master_catalogue['video_dec'].name = 'dec'
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(vhs['vhs_ra'], vhs['vhs_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, vhs, "vhs_ra", "vhs_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(voice['voice_ra'], voice['voice_dec'])
)
# Given the graph above, we use 0.8 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, voice, "voice_ra", "voice_dec", radius=0.8*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(servs['servs_ra'], servs['servs_dec'])
)
# Given the graph above, we use 1 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, servs, "servs_ra", "servs_dec", radius=1.*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(swire['swire_ra'], swire['swire_dec'])
)
# Given the graph above, we use 1 arc-second radius
master_catalogue = merge_catalogues(master_catalogue, swire, "swire_ra", "swire_dec", radius=1.*u.arcsec)
nb_merge_dist_plot(
SkyCoord(master_catalogue['ra'], master_catalogue['dec']),
SkyCoord(des['des_ra'], des['des_dec'])
)
# 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)
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.
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()
master_catalogue[:10].show_in_notebook()
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.
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.
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.
stellarity_columns = [column for column in master_catalogue.colnames
if 'stellarity' in column]
master_catalogue.add_column(Column(
data=np.nanmax([master_catalogue[column] for column in stellarity_columns], axis=0),
name="stellarity"
))
master_catalogue.remove_columns(stellarity_columns)
master_catalogue.add_column(
ebv(master_catalogue['ra'], master_catalogue['dec'])
)
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), "ELAIS-S1", dtype='<U18'),
name="field"))
# 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!")
Both SERVS and SWIRE provide IRAC1 and IRAC2 fluxes. SERVS is deeper but tends to under-estimate flux of bright sources (Mattia said over 2000 µJy) as illustrated by this comparison of SWIRE, SERVS, and Spitzer-EIP fluxes.
seip = Table.read("../../dmu0/dmu0_SEIP/data/SEIP_ELAIS-S1.fits")
seip_coords = SkyCoord(seip['ra'], seip['dec'])
idx, d2d, _ = seip_coords.match_to_catalog_sky(SkyCoord(master_catalogue['ra'], master_catalogue['dec']))
mask = d2d <= 2 * u.arcsec
fig, ax = plt.subplots()
ax.scatter(seip['i1_f_ap1'][mask], master_catalogue[idx[mask]]['f_ap_servs_irac1'], label="SERVS", s=2.)
ax.scatter(seip['i1_f_ap1'][mask], master_catalogue[idx[mask]]['f_ap_swire_irac1'], label="SWIRE", s=2.)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel("SEIP flux [μJy]")
ax.set_ylabel("SERVS/SWIRE flux [μJy]")
ax.set_title("IRAC 1")
ax.legend()
ax.axvline(2000, color="black", linestyle="--", linewidth=1.)
ax.plot(seip['i1_f_ap1'][mask], seip['i1_f_ap1'][mask], linewidth=.1, color="black", alpha=.5);
fig, ax = plt.subplots()
ax.scatter(seip['i2_f_ap1'][mask], master_catalogue[idx[mask]]['f_ap_servs_irac2'], label="SERVS", s=2.)
ax.scatter(seip['i2_f_ap1'][mask], master_catalogue[idx[mask]]['f_ap_swire_irac2'], label="SWIRE", s=2.)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel("SEIP flux [μJy]")
ax.set_ylabel("SERVS/SWIRE flux [μJy]")
ax.set_title("IRAC 2")
ax.legend()
ax.axvline(2000, color="black", linestyle="--", linewidth=1.)
ax.plot(seip['i1_f_ap2'][mask], seip['i1_f_ap2'][mask], linewidth=.1, color="black", alpha=.5);
When both SWIRE and SERVS fluxes are provided, we use the SERVS flux below 2000 μJy and the SWIRE flux over.
We create a table indicating for each source the origin on the IRAC1 and IRAC2 fluxes that will be saved separately.
irac_origin = Table()
irac_origin.add_column(master_catalogue['help_id'])
# IRAC1 aperture flux and magnitudes
has_servs = ~np.isnan(master_catalogue['f_ap_servs_irac1'])
has_swire = ~np.isnan(master_catalogue['f_ap_swire_irac1'])
has_both = has_servs & has_swire
print("{} sources with SERVS flux".format(np.sum(has_servs)))
print("{} sources with SWIRE flux".format(np.sum(has_swire)))
print("{} sources with SERVS and SWIRE flux".format(np.sum(has_both)))
has_servs_above_limit = has_servs.copy()
has_servs_above_limit[has_servs] = master_catalogue['f_ap_servs_irac1'][has_servs] > 2000
use_swire = (has_swire & ~has_servs) | (has_both & has_servs_above_limit)
use_servs = (has_servs & ~(has_both & has_servs_above_limit))
print("{} sources for which we use SERVS".format(np.sum(use_servs)))
print("{} sources for which we use SWIRE".format(np.sum(use_swire)))
f_ap_irac = np.full(len(master_catalogue), np.nan)
f_ap_irac[use_servs] = master_catalogue['f_ap_servs_irac1'][use_servs]
f_ap_irac[use_swire] = master_catalogue['f_ap_swire_irac1'][use_swire]
ferr_ap_irac = np.full(len(master_catalogue), np.nan)
ferr_ap_irac[use_servs] = master_catalogue['ferr_ap_servs_irac1'][use_servs]
ferr_ap_irac[use_swire] = master_catalogue['ferr_ap_swire_irac1'][use_swire]
m_ap_irac = np.full(len(master_catalogue), np.nan)
m_ap_irac[use_servs] = master_catalogue['m_ap_servs_irac1'][use_servs]
m_ap_irac[use_swire] = master_catalogue['m_ap_swire_irac1'][use_swire]
merr_ap_irac = np.full(len(master_catalogue), np.nan)
merr_ap_irac[use_servs] = master_catalogue['merr_ap_servs_irac1'][use_servs]
merr_ap_irac[use_swire] = master_catalogue['merr_ap_swire_irac1'][use_swire]
master_catalogue.add_column(Column(data=f_ap_irac, name="f_ap_irac1"))
master_catalogue.add_column(Column(data=ferr_ap_irac, name="ferr_ap_irac1"))
master_catalogue.add_column(Column(data=m_ap_irac, name="m_ap_irac1"))
master_catalogue.add_column(Column(data=merr_ap_irac, name="merr_ap_irac1"))
master_catalogue.remove_columns(['f_ap_servs_irac1', 'f_ap_swire_irac1', 'ferr_ap_servs_irac1',
'ferr_ap_swire_irac1', 'm_ap_servs_irac1', 'm_ap_swire_irac1',
'merr_ap_servs_irac1', 'merr_ap_swire_irac1'])
origin = np.full(len(master_catalogue), ' ', dtype='<U5')
origin[use_servs] = "SERVS"
origin[use_swire] = "SWIRE"
irac_origin.add_column(Column(data=origin, name="IRAC1_app"))
# IRAC1 total flux and magnitudes
has_servs = ~np.isnan(master_catalogue['f_servs_irac1'])
has_swire = ~np.isnan(master_catalogue['f_swire_irac1'])
has_both = has_servs & has_swire
print("{} sources with SERVS flux".format(np.sum(has_servs)))
print("{} sources with SWIRE flux".format(np.sum(has_swire)))
print("{} sources with SERVS and SWIRE flux".format(np.sum(has_both)))
has_servs_above_limit = has_servs.copy()
has_servs_above_limit[has_servs] = master_catalogue['f_servs_irac1'][has_servs] > 2000
use_swire = (has_swire & ~has_servs) | (has_both & has_servs_above_limit)
use_servs = (has_servs & ~(has_both & has_servs_above_limit))
print("{} sources for which we use SERVS".format(np.sum(use_servs)))
print("{} sources for which we use SWIRE".format(np.sum(use_swire)))
f_ap_irac = np.full(len(master_catalogue), np.nan)
f_ap_irac[use_servs] = master_catalogue['f_servs_irac1'][use_servs]
f_ap_irac[use_swire] = master_catalogue['f_swire_irac1'][use_swire]
ferr_ap_irac = np.full(len(master_catalogue), np.nan)
ferr_ap_irac[use_servs] = master_catalogue['ferr_servs_irac1'][use_servs]
ferr_ap_irac[use_swire] = master_catalogue['ferr_swire_irac1'][use_swire]
flag_irac = np.full(len(master_catalogue), False, dtype=bool)
flag_irac[use_servs] = master_catalogue['flag_servs_irac1'][use_servs]
flag_irac[use_swire] = master_catalogue['flag_swire_irac1'][use_swire]
m_ap_irac = np.full(len(master_catalogue), np.nan)
m_ap_irac[use_servs] = master_catalogue['m_servs_irac1'][use_servs]
m_ap_irac[use_swire] = master_catalogue['m_swire_irac1'][use_swire]
merr_ap_irac = np.full(len(master_catalogue), np.nan)
merr_ap_irac[use_servs] = master_catalogue['merr_servs_irac1'][use_servs]
merr_ap_irac[use_swire] = master_catalogue['merr_swire_irac1'][use_swire]
master_catalogue.add_column(Column(data=f_ap_irac, name="f_irac1"))
master_catalogue.add_column(Column(data=ferr_ap_irac, name="ferr_irac1"))
master_catalogue.add_column(Column(data=m_ap_irac, name="m_irac1"))
master_catalogue.add_column(Column(data=merr_ap_irac, name="merr_irac1"))
master_catalogue.add_column(Column(data=flag_irac, name="flag_irac1"))
master_catalogue.remove_columns(['f_servs_irac1', 'f_swire_irac1', 'ferr_servs_irac1',
'ferr_swire_irac1', 'm_servs_irac1', 'flag_servs_irac1', 'm_swire_irac1',
'merr_servs_irac1', 'merr_swire_irac1', 'flag_swire_irac1'])
origin = np.full(len(master_catalogue), ' ', dtype='<U5')
origin[use_servs] = "SERVS"
origin[use_swire] = "SWIRE"
irac_origin.add_column(Column(data=origin, name="IRAC1_total"))
# IRAC2 aperture flux and magnitudes
has_servs = ~np.isnan(master_catalogue['f_ap_servs_irac2'])
has_swire = ~np.isnan(master_catalogue['f_ap_swire_irac2'])
has_both = has_servs & has_swire
print("{} sources with SERVS flux".format(np.sum(has_servs)))
print("{} sources with SWIRE flux".format(np.sum(has_swire)))
print("{} sources with SERVS and SWIRE flux".format(np.sum(has_both)))
has_servs_above_limit = has_servs.copy()
has_servs_above_limit[has_servs] = master_catalogue['f_ap_servs_irac2'][has_servs] > 2000
use_swire = (has_swire & ~has_servs) | (has_both & has_servs_above_limit)
use_servs = (has_servs & ~(has_both & has_servs_above_limit))
print("{} sources for which we use SERVS".format(np.sum(use_servs)))
print("{} sources for which we use SWIRE".format(np.sum(use_swire)))
f_ap_irac = np.full(len(master_catalogue), np.nan)
f_ap_irac[use_servs] = master_catalogue['f_ap_servs_irac2'][use_servs]
f_ap_irac[use_swire] = master_catalogue['f_ap_swire_irac2'][use_swire]
ferr_ap_irac = np.full(len(master_catalogue), np.nan)
ferr_ap_irac[use_servs] = master_catalogue['ferr_ap_servs_irac2'][use_servs]
ferr_ap_irac[use_swire] = master_catalogue['ferr_ap_swire_irac2'][use_swire]
m_ap_irac = np.full(len(master_catalogue), np.nan)
m_ap_irac[use_servs] = master_catalogue['m_ap_servs_irac2'][use_servs]
m_ap_irac[use_swire] = master_catalogue['m_ap_swire_irac2'][use_swire]
merr_ap_irac = np.full(len(master_catalogue), np.nan)
merr_ap_irac[use_servs] = master_catalogue['merr_ap_servs_irac2'][use_servs]
merr_ap_irac[use_swire] = master_catalogue['merr_ap_swire_irac2'][use_swire]
master_catalogue.add_column(Column(data=f_ap_irac, name="f_ap_irac2"))
master_catalogue.add_column(Column(data=ferr_ap_irac, name="ferr_ap_irac2"))
master_catalogue.add_column(Column(data=m_ap_irac, name="m_ap_irac2"))
master_catalogue.add_column(Column(data=merr_ap_irac, name="merr_ap_irac2"))
master_catalogue.remove_columns(['f_ap_servs_irac2', 'f_ap_swire_irac2', 'ferr_ap_servs_irac2',
'ferr_ap_swire_irac2', 'm_ap_servs_irac2', 'm_ap_swire_irac2',
'merr_ap_servs_irac2', 'merr_ap_swire_irac2'])
origin = np.full(len(master_catalogue), ' ', dtype='<U5')
origin[use_servs] = "SERVS"
origin[use_swire] = "SWIRE"
irac_origin.add_column(Column(data=origin, name="IRAC2_app"))
# IRAC2 total flux and magnitudes
has_servs = ~np.isnan(master_catalogue['f_servs_irac2'])
has_swire = ~np.isnan(master_catalogue['f_swire_irac2'])
has_both = has_servs & has_swire
print("{} sources with SERVS flux".format(np.sum(has_servs)))
print("{} sources with SWIRE flux".format(np.sum(has_swire)))
print("{} sources with SERVS and SWIRE flux".format(np.sum(has_both)))
has_servs_above_limit = has_servs.copy()
has_servs_above_limit[has_servs] = master_catalogue['f_servs_irac2'][has_servs] > 2000
use_swire = (has_swire & ~has_servs) | (has_both & has_servs_above_limit)
use_servs = (has_servs & ~(has_both & has_servs_above_limit))
print("{} sources for which we use SERVS".format(np.sum(use_servs)))
print("{} sources for which we use SWIRE".format(np.sum(use_swire)))
f_ap_irac = np.full(len(master_catalogue), np.nan)
f_ap_irac[use_servs] = master_catalogue['f_servs_irac2'][use_servs]
f_ap_irac[use_swire] = master_catalogue['f_swire_irac2'][use_swire]
ferr_ap_irac = np.full(len(master_catalogue), np.nan)
ferr_ap_irac[use_servs] = master_catalogue['ferr_servs_irac2'][use_servs]
ferr_ap_irac[use_swire] = master_catalogue['ferr_swire_irac2'][use_swire]
flag_irac = np.full(len(master_catalogue), False, dtype=bool)
flag_irac[use_servs] = master_catalogue['flag_servs_irac2'][use_servs]
flag_irac[use_swire] = master_catalogue['flag_swire_irac2'][use_swire]
m_ap_irac = np.full(len(master_catalogue), np.nan)
m_ap_irac[use_servs] = master_catalogue['m_servs_irac2'][use_servs]
m_ap_irac[use_swire] = master_catalogue['m_swire_irac2'][use_swire]
merr_ap_irac = np.full(len(master_catalogue), np.nan)
merr_ap_irac[use_servs] = master_catalogue['merr_servs_irac2'][use_servs]
merr_ap_irac[use_swire] = master_catalogue['merr_swire_irac2'][use_swire]
master_catalogue.add_column(Column(data=f_ap_irac, name="f_irac2"))
master_catalogue.add_column(Column(data=ferr_ap_irac, name="ferr_irac2"))
master_catalogue.add_column(Column(data=m_ap_irac, name="m_irac2"))
master_catalogue.add_column(Column(data=merr_ap_irac, name="merr_irac2"))
master_catalogue.add_column(Column(data=flag_irac, name="flag_irac2"))
master_catalogue.remove_columns(['f_servs_irac2', 'f_swire_irac2', 'ferr_servs_irac2',
'ferr_swire_irac2', 'm_servs_irac2', 'flag_servs_irac2', 'm_swire_irac2',
'merr_servs_irac2', 'merr_swire_irac2', 'flag_swire_irac2'])
origin = np.full(len(master_catalogue), ' ', dtype='<U5')
origin[use_servs] = "SERVS"
origin[use_swire] = "SWIRE"
irac_origin.add_column(Column(data=origin, name="IRAC2_total"))
irac_origin.write("{}/elais-s1_irac_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX))
According to Mattia Vacari VIDEO is deeper than VHS so we take the VIDEO flux if both are available
vista_origin = Table()
vista_origin.add_column(master_catalogue['help_id'])
vista_stats = Table()
vista_stats.add_column(Column(data=['y','j','h','k','z'], name="Band"))
vista_stats.add_column(Column(data=np.full(5, 0, dtype=int), name="VIDEO"))
vista_stats.add_column(Column(data=np.full(5, 0, dtype=int), name="VHS"))
vista_stats.add_column(Column(data=np.full(5, 0, dtype=int), name="use VIDEO"))
vista_stats.add_column(Column(data=np.full(5, 0, dtype=int), name="use VHS"))
vista_stats.add_column(Column(data=np.full(5, 0, dtype=int), name="VIDEO ap"))
vista_stats.add_column(Column(data=np.full(5, 0, dtype=int), name="VHS ap"))
vista_stats.add_column(Column(data=np.full(5, 0, dtype=int), name="use VIDEO ap"))
vista_stats.add_column(Column(data=np.full(5, 0, dtype=int), name="use VHS ap"))
vista_bands = ['y','j','h','k','z'] # Lowercase naming convention (k is Ks)
for band in vista_bands:
#print('For VISTA band ' + band + ':')
# VISTA total flux
has_video = ~np.isnan(master_catalogue['f_video_' + band])
if band == 'z':
has_vhs = np.full(len(master_catalogue), False, dtype=bool)
else:
has_vhs = ~np.isnan(master_catalogue['f_vhs_' + band])
use_video = has_video
use_vhs = has_vhs & ~has_video
f_vista = np.full(len(master_catalogue), np.nan)
f_vista[use_video] = master_catalogue['f_video_' + band][use_video]
if not (band == 'z'):
f_vista[use_vhs] = master_catalogue['f_vhs_' + band][use_vhs]
ferr_vista = np.full(len(master_catalogue), np.nan)
ferr_vista[use_video] = master_catalogue['ferr_video_' + band][use_video]
if not (band == 'z'):
ferr_vista[use_vhs] = master_catalogue['ferr_vhs_' + band][use_vhs]
m_vista = np.full(len(master_catalogue), np.nan)
m_vista[use_video] = master_catalogue['m_video_' + band][use_video]
if not (band == 'z'):
m_vista[use_vhs] = master_catalogue['m_vhs_' + band][use_vhs]
merr_vista = np.full(len(master_catalogue), np.nan)
merr_vista[use_video] = master_catalogue['merr_video_' + band][use_video]
if not (band == 'z'):
merr_vista[use_vhs] = master_catalogue['merr_vhs_' + band][use_vhs]
flag_vista = np.full(len(master_catalogue), False, dtype=bool)
flag_vista[use_video] = master_catalogue['flag_video_' + band][use_video]
if not (band == 'z'):
flag_vista[use_vhs] = master_catalogue['flag_vhs_' + band][use_vhs]
master_catalogue.add_column(Column(data=f_vista, name="f_vista_" + band))
master_catalogue.add_column(Column(data=ferr_vista, name="ferr_vista_" + band))
master_catalogue.add_column(Column(data=m_vista, name="m_vista_" + band))
master_catalogue.add_column(Column(data=merr_vista, name="merr_vista_" + band))
master_catalogue.add_column(Column(data=flag_vista, name="flag_vista_" + band))
old_video_columns = ['f_video_' + band,
'ferr_video_' + band,
'm_video_' + band,
'merr_video_' + band,
'flag_video_' + band]
old_vhs_columns = ['f_vhs_' + band,
'ferr_vhs_' + band,
'm_vhs_' + band,
'merr_vhs_' + band,
'flag_vhs_' + band]
if not (band == 'z'):
old_columns = old_video_columns + old_vhs_columns
else:
old_columns = old_video_columns
master_catalogue.remove_columns(old_columns)
origin = np.full(len(master_catalogue), ' ', dtype='<U5')
origin[use_video] = "VIDEO"
origin[use_vhs] = "VHS"
vista_origin.add_column(Column(data=origin, name= 'f_vista_' + band ))
# VISTA Aperture flux
has_ap_video = ~np.isnan(master_catalogue['f_ap_video_' + band])
if (band == 'z'):
has_ap_vhs = np.full(len(master_catalogue), False, dtype=bool)
else:
has_ap_vhs = ~np.isnan(master_catalogue['f_ap_vhs_' + band])
use_ap_video = has_ap_video
use_ap_vhs = has_ap_vhs & ~has_ap_video
f_ap_vista = np.full(len(master_catalogue), np.nan)
f_ap_vista[use_ap_video] = master_catalogue['f_ap_video_' + band][use_ap_video]
if not (band == 'z'):
f_ap_vista[use_ap_vhs] = master_catalogue['f_ap_vhs_' + band][use_ap_vhs]
ferr_ap_vista = np.full(len(master_catalogue), np.nan)
ferr_ap_vista[use_ap_video] = master_catalogue['ferr_ap_video_' + band][use_ap_video]
if not (band == 'z'):
ferr_ap_vista[use_ap_vhs] = master_catalogue['ferr_ap_vhs_' + band][use_ap_vhs]
m_ap_vista = np.full(len(master_catalogue), np.nan)
m_ap_vista[use_ap_video] = master_catalogue['m_ap_video_' + band][use_ap_video]
if not (band == 'z'):
m_ap_vista[use_ap_vhs] = master_catalogue['m_ap_vhs_' + band][use_ap_vhs]
merr_ap_vista = np.full(len(master_catalogue), np.nan)
merr_ap_vista[use_ap_video] = master_catalogue['merr_ap_video_' + band][use_ap_video]
if not (band == 'z'):
merr_ap_vista[use_ap_vhs] = master_catalogue['merr_ap_vhs_' + band][use_ap_vhs]
master_catalogue.add_column(Column(data=f_ap_vista, name="f_ap_vista_" + band))
master_catalogue.add_column(Column(data=ferr_ap_vista, name="ferr_ap_vista_" + band))
master_catalogue.add_column(Column(data=m_ap_vista, name="m_ap_vista_" + band))
master_catalogue.add_column(Column(data=merr_vista, name="merr_ap_vista_" + band))
ap_old_video_columns = ['f_ap_video_' + band,
'ferr_ap_video_' + band,
'm_ap_video_' + band,
'merr_ap_video_' + band]
ap_old_vhs_columns = ['f_ap_vhs_' + band,
'ferr_ap_vhs_' + band,
'm_ap_vhs_' + band,
'merr_ap_vhs_' + band]
if not (band == 'z'):
ap_old_columns = ap_old_video_columns + ap_old_vhs_columns
else:
ap_old_columns = ap_old_video_columns
master_catalogue.remove_columns(ap_old_columns)
origin_ap = np.full(len(master_catalogue), ' ', dtype='<U5')
origin_ap[use_ap_video] = "VIDEO"
origin_ap[use_ap_vhs] = "VHS"
vista_origin.add_column(Column(data=origin_ap, name= 'f_ap_vista_' + band ))
vista_stats['VIDEO'][vista_stats['Band'] == band] = np.sum(has_video)
vista_stats['VHS'][vista_stats['Band'] == band] = np.sum(has_vhs)
vista_stats['use VIDEO'][vista_stats['Band'] == band] = np.sum(use_video)
vista_stats['use VHS'][vista_stats['Band'] == band] = np.sum(use_vhs)
vista_stats['VIDEO ap'][vista_stats['Band'] == band] = np.sum(has_ap_video)
vista_stats['VHS ap'][vista_stats['Band'] == band] = np.sum(has_ap_vhs)
vista_stats['use VIDEO ap'][vista_stats['Band'] == band] = np.sum(use_ap_video)
vista_stats['use VHS ap'][vista_stats['Band'] == band] = np.sum(use_ap_vhs)
For each band show how many objects have fluxes from each survey for both total and aperture photometries.
vista_stats.show_in_notebook()
vista_origin.write("{}/elais-s1_vista_fluxes_origins{}.fits".format(OUT_DIR, SUFFIX))
We add a binary flag_optnir_obs
indicating that a source was observed in a given wavelength domain:
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.
video_moc = MOC(filename="../../dmu0/dmu0_VISTA-VIDEO-private/data/VIDEO-all_2017-02-12_fullcat_errfix_ELAIS-S1_MOC.fits")
vhs_moc = MOC(filename="../../dmu0/dmu0_VISTA-VHS/data/VHS_ELAIS-S1_MOC.fits")
voice_moc = MOC(filename="../../dmu0/dmu0_ESIS-VOICE/data/esis_b2vr_cat_03_HELP-coverage_MOC.fits")
servs_moc = MOC(filename="../../dmu0/dmu0_DataFusion-Spitzer/data/DF-SERVS_ELAIS-S1_MOC.fits")
swire_moc = MOC(filename="../../dmu0/dmu0_DataFusion-Spitzer/data/DF-SWIRE_ELAIS-S1_MOC.fits")
des_moc = MOC(filename="../../dmu0/dmu0_DES/data/DES-DR1_ELAIS-S1_MOC.fits")
was_observed_optical = inMoc(
master_catalogue['ra'], master_catalogue['dec'],
voice_moc + des_moc)
was_observed_nir = inMoc(
master_catalogue['ra'], master_catalogue['dec'],
video_moc + vhs_moc + voice_moc
)
was_observed_mir = inMoc(
master_catalogue['ra'], master_catalogue['dec'],
servs_moc + swire_moc
)
master_catalogue.add_column(
Column(
1 * was_observed_optical + 2 * was_observed_nir + 4 * was_observed_mir,
name="flag_optnir_obs")
)
We add a binary flag_optnir_det
indicating that a source was detected in a given wavelength domain:
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.
# 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_voice_r']) +
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_k']) +
1 * ~np.isnan(master_catalogue['f_vista_k'])
)
nb_mir_flux = (
1 * ~np.isnan(master_catalogue['f_irac1']) +
1 * ~np.isnan(master_catalogue['f_irac2']) +
1 * ~np.isnan(master_catalogue['f_irac3']) +
1 * ~np.isnan(master_catalogue['f_irac4'])
)
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")
)
We are producing a table associating to each HELP identifier, the identifiers of the sources in the pristine catalogue. This can be used to easily get additional information from them.
master_catalogue['help_id',
'video_id',
'vhs_id',
'voice_id',
'servs_intid',
'swire_intid',
'des_id'].write(
"{}/master_list_cross_ident_elais-s1{}.fits".format(OUT_DIR, SUFFIX))
master_catalogue.remove_columns([
'video_id',
'vhs_id',
'voice_id',
'servs_intid',
'swire_intid',
'des_id'])
We are adding a column with a HEALPix index at order 13 associated with each source.
master_catalogue.add_column(Column(
data=coords_to_hpidx(master_catalogue['ra'], master_catalogue['dec'], order=13),
name="hp_idx"
))
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", "flag_cleaned", "flag_merged", "flag_gaia", "flag_optnir_obs", "flag_optnir_det", "ebv"]
# 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)))
master_catalogue[columns].write("{}/master_catalogue_elais-s1{}.fits".format(OUT_DIR, SUFFIX))