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))
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
OUT_DIR = os.environ.get('TMP_DIR', "./data_tmp")
try:
os.makedirs(OUT_DIR)
except FileExistsError:
pass
RA_COL = "fireworks_ra"
DEC_COL = "fireworks_dec"
imported_columns = OrderedDict({
'Seq':'fireworks_id',
'RAJ2000':'fireworks_ra',
'DEJ2000':'fireworks_dec',
'FU38':'m_fireworks_fu38',
'e_FU38':'merr_fireworks_fu38',
'FB435':'m_fireworks_fb435',
'e_FB435':'merr_fireworks_fb435',
'FB':'m_fireworks_fb',
'e_FB':'merr_fireworks_fb',
'FV':'m_fireworks_fv',
'e_FV':'merr_fireworks_fv',
'FV606':'m_fireworks_fv606',
'e_FV606':'merr_fireworks_fv606',
'FRc':'m_fireworks_frc',
'e_FRc':'merr_fireworks_frc',
'Fi775':'m_fireworks_fi775',
'e_Fi775':'merr_fireworks_fi775',
'FI':'m_fireworks_fi',
'e_FI':'merr_fireworks_fi',
'Fz850':'m_fireworks_fz850',
'e_Fz850':'merr_fireworks_fz850',
'FJ':'m_fireworks_fj',
'e_FJ':'merr_fireworks_fj',
'FH':'m_fireworks_fh',
'e_FH':'merr_fireworks_fh',
'FKs':'m_fireworks_fks',
'e_FKs':'merr_fireworks_fks',
#'F3.6':'m_fireworks_f3.6',
#'e_F3.6':'merr_fireworks_F3.6',
#'F4.5':'m_fireworks_F4.5',
#'e_F4.5':'merr_fireworks_F4.5',
#'F5.8':'m_fireworks_F5.8',
#'e_F5.8':'merr_fireworks_F5.8',
#'F8.0':'m_fireworks_F8.0',
#'e_F8.0':'merr_fireworks_F8.0',
'FKs.t':'m_fireworks_fkst',
'e_FKs.t':'merr_fireworks_fkst',
'F24.t':'m_fireworks_f24t',
'e_F24.t':'merr_fireworks_f24t'
})
catalogue = Table.read("../../dmu0/dmu0_Fireworks/data/fireworks.fits")[list(imported_columns)]
for column in imported_columns:
catalogue[column].name = imported_columns[column]
epoch = 2008
# Clean table metadata
catalogue.meta = None
# Add 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
catalogue.add_column(Column(np.zeros(len(catalogue), dtype=bool), name="flag{}".format(col[1:])))
catalogue[:10].show_in_notebook()
We remove duplicated objects from the input catalogues.
SORT_COLS = ['merr_fireworks_fu38',
'merr_fireworks_fb435',
'merr_fireworks_fb',
'merr_fireworks_fv',
'merr_fireworks_fv606',
'merr_fireworks_frc',
'merr_fireworks_fi775',
'merr_fireworks_fi',
'merr_fireworks_fz850',
'merr_fireworks_fj',
'merr_fireworks_fh',
'merr_fireworks_fks',
#'merr_fireworks_F3.6',
#'merr_fireworks_F4.5',
#'merr_fireworks_F5.8',
#'merr_fireworks_F8.0',
'merr_fireworks_fkst',
'merr_fireworks_f24t']
FLAG_NAME = 'fireworks_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])))
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.
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_CDFS-SWIRE.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL],
gaia_coords.ra, gaia_coords.dec)
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))
catalogue[RA_COL] += delta_ra.to(u.deg)
catalogue[DEC_COL] += delta_dec.to(u.deg)
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL],
gaia_coords.ra, gaia_coords.dec)
catalogue.add_column(
gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
GAIA_FLAG_NAME = "fireworks_flag_gaia"
catalogue['flag_gaia'].name = GAIA_FLAG_NAME
print("{} sources flagged.".format(np.sum(catalogue[GAIA_FLAG_NAME] > 0)))
catalogue.write("{}/Fireworks.fits".format(OUT_DIR), overwrite=True)