Bootes master catalogue¶

Preparation of IBIS data¶

The catalogue comes from dmu0_IBIS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The magnitude for each band in apertude 4 ($1.2 * \sqrt{2}$ arcsec = 1.7 arcsec).
  • 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 = "ibis_ra"
DEC_COL = "ibis_dec"

I - Column selection¶

I.i - Aperture correction¶

In [4]:
#TODO get these (non-zero) values from Catalogue header

j_ap_to_tot = 0.
h_ap_to_tot = 0.
k_ap_to_tot = 0.
newfirm_ap_to_tot = {
    'j': j_ap_to_tot,
    'h': h_ap_to_tot,
    'k': k_ap_to_tot
    
}

1.ii - Vega-like to AB¶

In [5]:
## Vega to AB
# http://svo2.cab.inta-csic.es/svo/theory/fps3/index.php?mode=browse&gname=NOAO
j_vega_to_ab   =  -2.5*np.log10(1559.06 / 3631.) 
h_vega_to_ab   =  -2.5*np.log10(1044.7 / 3631.) 
k_vega_to_ab   =  -2.5*np.log10( 677.1/ 3631.) 

#Vega correction - the magnitudes are nto in true Vega and have to be converted first
#Magnitudes also need a minor correction to turn them into Vega
# http://r2.sdm.noao.edu/nsa/NEWFIRM_NDWFS.html
j_newfirm_to_vega = -0.056
h_newfirm_to_vega = -0.007
k_newfirm_to_vega = 0.

newfirm_to_ab = {
    'j': j_newfirm_to_vega + j_vega_to_ab,
    'h': h_newfirm_to_vega + h_vega_to_ab,
    'k': k_newfirm_to_vega + k_vega_to_ab,
}
In [6]:
imported_columns = OrderedDict({
        'internal_id': "ibis_id",
        'alpha_j2000': "ibis_ra",
        'delta_j2000': "ibis_dec",
        'k_class_star':  "ibis_stellarity",
        'j_mag_auto': "m_newfirm_j", 
        'j_magerr_auto': "merr_newfirm_j", 
        'j_mag_aper_3': "m_ap_newfirm_j", 
        'j_magerr_aper_3': "merr_ap_newfirm_j",
            'h_mag_auto': "m_newfirm_h", 
        'h_magerr_auto': "merr_newfirm_h", 
        'h_mag_aper_3': "m_ap_newfirm_h", 
        'h_magerr_aper_3': "merr_ap_newfirm_h",
            'k_mag_auto': "m_newfirm_k", 
        'k_magerr_auto': "merr_newfirm_k", 
        'k_mag_aper_3': "m_ap_newfirm_k", 
        'k_magerr_aper_3': "merr_ap_newfirm_k"
    })


catalogue = Table.read("../../dmu0/dmu0_IBIS/data/IBIS_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 [7]:
# 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
       
        
        #Vega to AB
        catalogue[col] = catalogue[col] + newfirm_to_ab[col[-1]]
        
        #Aperture correction
        if "ap" in col:
            catalogue[col] = catalogue[col] + newfirm_ap_to_tot[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
        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 [8]:
catalogue[:10].show_in_notebook()
Out[8]:
<Table masked=True length=10>
idxibis_idibis_raibis_decibis_stellaritym_newfirm_jmerr_newfirm_jm_ap_newfirm_jmerr_ap_newfirm_jm_newfirm_hmerr_newfirm_hm_ap_newfirm_hmerr_ap_newfirm_hm_newfirm_kmerr_newfirm_km_ap_newfirm_kmerr_ap_newfirm_kf_newfirm_jferr_newfirm_jflag_newfirm_jf_ap_newfirm_jferr_ap_newfirm_jf_newfirm_hferr_newfirm_hflag_newfirm_hf_ap_newfirm_hferr_ap_newfirm_hf_newfirm_kferr_newfirm_kflag_newfirm_kf_ap_newfirm_kferr_ap_newfirm_k
degdegmagmagmagmagmagmagmagmagmagmagmagmag
0P10_1235216.415231932.41434480.4321.30150.122522.52910.1086999997521.03790.20700000226522.16690.160720.45840.24521.70410.208110.94961.2354027217False3.534730.35388467761413.95872.66128286968False4.934520.73035916034323.80275.37116231499False7.556961.44842058548
1P10_972216.431779832.40110480.9816.94660.004317.87610.0060000000521516.83440.0066999997943617.15980.005417.09940.014817.47210.0088604.4452.39387202892False256.7771.41900383238670.2634.13614299143False496.692.47032959014525.0817.15753866825False372.5173.01928992849
2P10_913216.450583532.39287670.321.70770.171222.70910.13009999692421.48010.29510000348122.03380.142620.89450.358921.98620.27757.532111.18767019521False2.994720.3588471099179.288922.52470131267False5.578090.73262287032815.92895.26545320636False5.827831.48951679535
3P10_887216.446907632.39447840.9717.37140.005518.28870.0073000001721117.26240.0089999996125717.58550.006817.50430.019917.86190.0109408.732.07049764867False175.5971.1806343422451.9033.74596247156False335.5872.10179131245361.6326.62819316203False260.1522.6117336427
4P10_840216.455715732.39012990.1220.49730.081621.95930.071099996566820.4070.15629999339621.68310.10620.83740.476721.26760.141822.96551.72600557853False5.974160.39122073228924.95773.59285745897False7.704870.75222367195216.78917.37135677755False11.29661.47536161676
5P10_764216.468783832.38323230.8220.72980.062721.79280.06219999864720.39730.095399998128420.90920.054720.60640.232120.79140.091918.53861.07058122703False6.964280.39897205729925.18172.21263079536False15.71540.79174952552420.76954.43993928493False17.51571.48257797573
6P10_787216.471151932.38702080.9518.08260.00919.01290.010800000280118.08930.016699999570818.42360.010318.50280.045818.85650.0205212.3031.75984814996False90.12320.896471049025211.0013.24546695438False155.0831.47122291382144.1676.08146254672False104.0851.96524275088
7P10_813216.472810932.3861090.3821.99280.153922.82910.14030000567422.20470.39430001378122.36420.188421.74890.531522.3130.375.792650.821090998124False2.681370.3464898174194.765681.73072224894False4.114580.7139727175857.251483.54981228679False4.313081.46982114984
8P10_988216.456456532.39820950.820.25340.04821.36550.045200001448419.67560.059500001370920.3480.036819.5280.102720.10850.053128.74991.2710224546False10.32280.42974510610448.95142.68261050038False26.35150.89315932127656.07735.30436088738False32.85391.60678031443
9P10_947216.463160432.39534890.4822.02620.179723.00840.16799999773521.69740.27320000529322.41110.195621.89090.661622.4180.39375.617160.92969447237False2.27320.3517401444577.604051.91338004457False3.940620.7099199792726.362493.87702134649False3.915491.41980074568

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [9]:
SORT_COLS = ['merr_ap_newfirm_j', 'merr_ap_newfirm_h', 'merr_ap_newfirm_k']
FLAG_NAME = 'ibis_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 389594 sources.
The cleaned catalogue has 389594 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 [10]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_Bootes.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [11]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)
In [12]:
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.14042821500197533 arcsec
Dec correction: -0.11290194161972522 arcsec
In [13]:
catalogue[RA_COL] +=  delta_ra.to(u.deg)
catalogue[DEC_COL] += delta_dec.to(u.deg)
In [14]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)

IV - Flagging Gaia objects¶

In [15]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [16]:
GAIA_FLAG_NAME = "ibis_flag_gaia"

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

V - Saving to disk¶

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