Bootes master catalogue¶

Preparation of NDWFS data¶

The catalogue comes from dmu0_NDWFS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The magnitude for each band in 2 arcsec aperture.
  • The kron magnitude to be used as total magnitude (no “auto” magnitude is provided).

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 = "ndwfs_ra"
DEC_COL = "ndwfs_dec"

I - Column selection¶

1.i - Aperture correction¶

TODO

In [4]:
imported_columns = OrderedDict({
        'ndwfs_name': "ndwfs_id",
        'ra': "ndwfs_ra",
        'dec': "ndwfs_dec",
        'k_class_star':  "ndwfs_stellarity",
            'r_mag_aper_02': "m_ap_mosaic_r", 
        'r_magerr_aper_02': "merr_ap_mosaic_r", 
        'r_mag_auto': "m_mosaic_r", 
        'r_magerr_auto': "merr_mosaic_r",
            'i_mag_aper_02': "m_ap_mosaic_i", 
        'i_magerr_aper_02': "merr_ap_mosaic_i", 
        'i_mag_auto': "m_mosaic_i", 
        'i_magerr_auto': "merr_mosaic_i",
            'b_mag_aper_02': "m_ap_mosaic_b", 
        'b_magerr_aper_02': "merr_ap_mosaic_b", 
        'b_mag_auto': "m_mosaic_b", 
        'b_magerr_auto': "merr_mosaic_b",
            'k_mag_aper_02': "m_ap_mosaic_k", 
        'k_magerr_aper_02': "merr_ap_mosaic_k", 
        'k_mag_auto': "m_mosaic_k", 
        'k_magerr_auto': "merr_mosaic_k"
    })


catalogue = Table.read("../../dmu0/dmu0_NDWFS/data/NDWFS_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
        mask = (catalogue[col] <= 0) | (catalogue[col] > 90.)
        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:])))
        
        # 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.

catalogue["ndwfs_stellarity"][catalogue["ndwfs_stellarity"] < 0.] = np.nan
/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>
idxndwfs_idndwfs_randwfs_decndwfs_stellaritym_ap_mosaic_rmerr_ap_mosaic_rm_mosaic_rmerr_mosaic_rm_ap_mosaic_imerr_ap_mosaic_im_mosaic_imerr_mosaic_im_ap_mosaic_bmerr_ap_mosaic_bm_mosaic_bmerr_mosaic_bm_ap_mosaic_kmerr_ap_mosaic_km_mosaic_kmerr_mosaic_kf_ap_mosaic_rferr_ap_mosaic_rf_mosaic_rferr_mosaic_rflag_mosaic_rf_ap_mosaic_iferr_ap_mosaic_if_mosaic_iferr_mosaic_iflag_mosaic_if_ap_mosaic_bferr_ap_mosaic_bf_mosaic_bferr_mosaic_bflag_mosaic_bf_ap_mosaic_kferr_ap_mosaic_kf_mosaic_kferr_mosaic_kflag_mosaic_k
degdegmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmag
0NDWFS_J142539.6+322451216.41529432.4143894nan22.33960.009721.33570.01521.89760.010920.89770.017123.62950.012822.5290.0186nannannannan4.208816583580.037601694299110.61011277390.146584125049False6.323536067740.063483692296915.88254154420.250144979246False1.282921253710.01512466101393.535086133620.0605603845549FalsenannannannanFalse
1NDWFS_J142540.4+322444216.4184332.4122584nannannannannannannannannan26.73480.216626.58610.2988nannannannannannannannanFalsenannannannanFalse0.07346491830740.01465595531920.08424807764190.0231854897065FalsenannannannanFalse
2NDWFS_J142543.3+322356216.430663232.3991127nannannannannannannannannan27.17260.324326.78440.3222nannannannannannannannanFalsenannannannanFalse0.04908626639480.01466164259980.07018430440710.0208276953286FalsenannannannanFalse
3NDWFS_J142543.4+322400216.430936532.400052nan24.59780.075823.30950.1095nannannannan25.85910.097125.0370.1229nannannannan0.5258719425270.03671342363721.722661707380.173735992345FalsenannannannanFalse0.1645735358410.01471820711160.3509134383590.039721675841FalsenannannannanFalse
4NDWFS_J142543.6+322400216.431950832.4000057nannannannannannannannannan27.09720.301826.85030.2817nannannannannannannannanFalsenannannannanFalse0.05261626304150.01462564121590.0660510916880.017137305035FalsenannannannanFalse
5NDWFS_J142543.6+322404216.43191132.4011937nan18.55330.000518.27020.000817.88660.001217.43670.00121.15050.001720.82160.0029nannannannan137.6195077220.0633761253971178.6158521990.131609023566False254.3079868890.281071574227384.8752641690.354483218375False12.58345788690.019702648133117.03570064690.0455023344155FalsenannannannanFalse
6NDWFS_J142542.3+322417216.426444232.4048224nan25.52780.177825.26290.1886nannannannannannannannannannannannan0.2232955149270.03656684043520.2849968107020.0495059465299FalsenannannannanFalsenannannannanFalsenannannannanFalse
7NDWFS_J142540.8+322442216.420355732.4118799nan24.38220.062123.9690.097224.05340.078823.27650.115325.59780.07625.15960.1155nannannannan0.6413867738180.03668489498610.9384259312370.0840121201785False0.8682404198270.06301470355561.775824322550.188584062586False0.2093533911130.01465444152530.313444028210.0333439974642FalsenannannannanFalse
8NDWFS_J142541.1+322444216.421312232.4124599nan25.15220.126124.75660.197924.49480.118423.86960.169827.00910.278126.79960.415nannannannan0.3155876503820.03665310462960.4543180587630.0828097501355False0.5782025464420.0630532363191.02839510310.160832334541False0.05706370948540.01461627376740.06920858978240.0264535387453FalsenannannannanFalse
9NDWFS_J142543.0+322415216.429229132.4043039nan25.76610.222925.5550.216525.14630.215324.34060.278nannannannannannannannan0.1792916235790.0368082990330.2177709772350.0434243754282False0.3173072535080.06292159309130.6664383799740.170639855999FalsenannannannanFalsenannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_mosaic_b', 'merr_ap_mosaic_i', 'merr_ap_mosaic_r', 'merr_ap_mosaic_k']
FLAG_NAME = 'ndwfs_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 2834130 sources.
The cleaned catalogue has 2834130 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.40784830923712434 arcsec
Dec correction: -0.2130986199659901 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 = "ndwfs_flag_gaia"

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

V - Saving to disk¶

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