Bootes master catalogue¶

Preparation of zBootes data¶

The catalogue comes from dmu0_zBootes.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The magnitude for each band in 2 arcssec aperture.
  • The auto magnitude.

We don't know when the maps have been observed. We will use the year of the reference paper.

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 = "zbootes_ra"
DEC_COL = "zbootes_dec"

I - Column selection¶

1.i Aperture correction]¶

TODO

In [4]:
imported_columns = OrderedDict({
        'internal_id': "zbootes_id",
        'alpha_j2000': "zbootes_ra",
        'delta_j2000': "zbootes_dec",
        'class_star':  "zbootes_stellarity",
        'mag_aper_02': "m_ap_90prime_z", 
        'magerr_aper_02': "merr_ap_90prime_z", 
        'mag_auto': "m_90prime_z", 
        'magerr_auto': "merr_90prime_z"
    })


catalogue = Table.read("../../dmu0/dmu0_zBootes/data/zBootes_MLselected_20160801.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2011

# 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:])
        
        # Some object have a magnitude to 0, we suppose this means missing value
        catalogue[col][catalogue[col] <= 0] = np.nan
        catalogue[errcol][catalogue[errcol] <= 0] = 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:])))
        
        # 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/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>
idxzbootes_idzbootes_razbootes_deczbootes_stellaritym_ap_90prime_zmerr_ap_90prime_zm_90prime_zmerr_90prime_zf_ap_90prime_zferr_ap_90prime_zf_90prime_zferr_90prime_zflag_90prime_z
degdegmagmagmagmag
018926216.37038961732.64324718530.020914622.27870.10988419.14870.03212944.451640.45053779.52792.35341False
119639216.38208676832.64449962440.31003422.24720.1085720.0630.04714.582680.45825334.2611.48627False
219351216.37717500832.65063069040.49238922.29890.11008220.35490.05128184.369580.44302826.18421.23674False
319784216.38473117732.64254415960.00039309122.20320.10634318.67530.02376064.772210.467417122.9932.69161False
419926216.38705114532.64122807180.309422.2620.10909819.02910.02592434.520640.45424788.78912.12003False
518698216.3666361332.66541649380.16255421.11370.038644620.37730.040270613.01730.46332325.64950.951357False
619079216.37276492132.66318021870.47043522.72640.12841122.24860.1415962.94740.3485924.576780.596879False
719081216.37280764632.66774958220.36678920.6870.029632719.99550.027255619.28410.52631636.45860.915232False
819231216.37529943132.66466631750.1772222.32130.09076621.57160.1006074.280350.3578328.538070.791159False
919823216.38526686232.65357902720.34730522.0030.089204321.08020.09415115.738520.47147813.42521.16418False

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_90prime_z']
FLAG_NAME = 'wfc_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 187628 sources.
The cleaned catalogue has 187628 sources (0 removed).
The cleaned catalogue has 0 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_Bootes.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)
In [10]:
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))
RA correction: -0.10194170581598883 arcsec
Dec correction: -0.06714873594120263 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)

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 = "zbootes_flag_gaia"

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

V - Saving to disk¶

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