Bootes master catalogue¶

Preparation of Spitzer datafusion data¶

The Spitzer catalogues were produced by the datafusion team are available in dmu0_DataFusion-Spitzer. Lucia told that the magnitudes are aperture corrected.

In the catalouge, we keep:

  • The internal identifier (this one is only in HeDaM data);
  • The position;
  • The fluxes in aperture 2 (1.9 arcsec);
  • The “auto” flux (which seems to be the Kron flux);
  • The stellarity in each band

A query of the position in the Spitzer heritage archive show that the SERVS-ELAIS-N1 images were observed in 2009. Let's take this as epoch.

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, flux_to_mag
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "datafusion_ra"
DEC_COL = "datafusion_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'internal_id': "datafusion_intid",
        'ra_spitzer': "datafusion_ra",
        'dec_spitzer': "datafusion_dec",
        'class_star_1': "datafusion_stellarity",
        'flux_aper_2_1': "f_ap_irac_i1",
        'fluxerr_aper_2_1': "ferr_ap_irac_i1",
        'flux_auto_1': "f_irac_i1",
        'fluxerr_auto_1': "ferr_irac_i1",
        'flux_aper_2_2': "f_ap_irac_i2",
        'fluxerr_aper_2_2': "ferr_ap_irac_i2",
        'flux_auto_2': "f_irac_i2",
        'fluxerr_auto_2': "ferr_irac_i2",
            'flux_aper_2_3': "f_ap_irac_i3",
        'fluxerr_aper_2_3': "ferr_ap_irac_i3",
        'flux_auto_3': "f_irac_i3",
        'fluxerr_auto_3': "ferr_irac_i3",
            'flux_aper_2_4': "f_ap_irac_i4",
        'fluxerr_aper_2_4': "ferr_ap_irac_i4",
        'flux_auto_4': "f_irac_i4",
        'fluxerr_auto_4': "ferr_irac_i4"
    })


catalogue = Table.read("../../dmu0/dmu0_DataFusion-Spitzer/data/Datafusion-Bootes.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2009

# Clean table metadata
catalogue.meta = None
In [5]:
# Adding magnitude and band-flag columns
for col in catalogue.colnames:
    if col.startswith('f_'):
        errcol = "ferr{}".format(col[1:])
        
        magnitude, error = flux_to_mag(
            np.array(catalogue[col])/1.e6, np.array(catalogue[errcol])/1.e6)
        # Note that some fluxes are 0.
        
        catalogue.add_column(Column(magnitude, name="m{}".format(col[1:])))
        catalogue.add_column(Column(error, name="m{}".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:])))
/opt/herschelhelp_internal/herschelhelp_internal/utils.py:76: RuntimeWarning: invalid value encountered in log10
  magnitudes = 2.5 * (23 - np.log10(fluxes)) - 48.6
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxdatafusion_intiddatafusion_radatafusion_decdatafusion_stellarityf_ap_irac_i1ferr_ap_irac_i1f_irac_i1ferr_irac_i1f_ap_irac_i2ferr_ap_irac_i2f_irac_i2ferr_irac_i2f_ap_irac_i3ferr_ap_irac_i3f_irac_i3ferr_irac_i3f_ap_irac_i4ferr_ap_irac_i4f_irac_i4ferr_irac_i4m_ap_irac_i1merr_ap_irac_i1m_irac_i1merr_irac_i1flag_irac_i1m_ap_irac_i2merr_ap_irac_i2m_irac_i2merr_irac_i2flag_irac_i2m_ap_irac_i3merr_ap_irac_i3m_irac_i3merr_irac_i3flag_irac_i3m_ap_irac_i4merr_ap_irac_i4m_irac_i4merr_irac_i4flag_irac_i4
degdeguJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJy
09628216.41528732.4142710.014.650850505550.7424655468713.564782942610.9313154476523.427557023861.124399837932.857053279491.61363990303nannannannannannannannan22.231169050.17332780833522.51991727230.283653427388False22.56253827790.35617251709222.76020415160.613214768078FalsenannannannanFalsenannannannanFalse
19209216.43174732.4010770.98235.2789198971.67713839944250.1706489071.9299961385165.3282571361.81758822614168.8566352412.55610698248109.2268066965.68480526773100.6344460757.7867490171569.04699114156.3650936281465.30027041687.3916179328717.97104245560.0077394518874117.90440911240.00837614920762False18.35413228120.011936382664718.33120467260.0164355868524False18.80417690750.056508096161518.89313334890.0840105516059False19.30213810480.10008854092719.36271255060.122899141921False
2873519216.42654832.405033nannannannannan2.472284870061.108042181941.99908340921.12646709176nannannannannannannannannannannannanFalse22.91725372230.48661120241623.14792271280.611803439197FalsenannannannanFalsenannannannanFalse
38715216.43269232.4050280.02.973145719310.7671848587723.221994123821.22074992299nannannannannannannannannannannannan22.71695951180.28016130238822.62968813990.411363999254FalsenannannannanFalsenannannannanFalsenannannannanFalse
49156216.43107932.4096140.038.234106765450.7780548560227.602911368421.050403054267.835497852281.057730505277.054306712171.36356103997nannannannannannannannan21.61095876530.10259307421421.69755018080.150003146207False21.66483351020.14656583743621.77886415420.209867198705FalsenannannannanFalsenannannannanFalse
58863216.43627432.4071250.133.632691104630.7587518836332.908561128270.8728569075963.935099831311.100757545292.901183493771.00768335191nannannannannannannannan22.49942882390.2267752381822.74080451090.325828581335False22.41261061340.30371080043922.74356200530.377114477746FalsenannannannanFalsenannannannanFalse
66590216.45398232.38650.131.855308618380.6119712558561.734601470520.812366562827nannannannannannannannannannannannan23.2289595950.35812874589723.30200072440.508483247469FalsenannannannanFalsenannannannanFalsenannannannanFalse
7872933216.45506832.387238nannannannannan3.867823040951.069947154633.971707116531.329944128697.396644673994.961096208878.344412309915.09535874721nannannannannannannannanFalse22.43133350950.3003447548322.40255696240.363563688976False21.72741310950.72822773117721.59651061230.662984433488FalsenannannannanFalse
86843216.45519732.3875170.091.979004142050.6135518482161.898654403470.705613026038nannannannan7.396644673994.961096208878.344412309915.09535874721nannannannan23.1588832420.33661145065323.20388519790.403501346805FalsenannannannanFalse21.72741310950.72822773117721.59651061230.662984433488FalsenannannannanFalse
97134216.45220532.3891130.047.264031194880.6532404940387.184301883680.967443953265.69531656661.089536330216.76290927151.83077182191nannannannannannannannan21.74705574860.097638189562321.75903856740.146206123175False22.01120532810.20770558164421.82466609710.293917184144FalsenannannannanFalsenannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['ferr_ap_irac_i1', 'ferr_ap_irac_i2']
FLAG_NAME = "datafusion_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 1142840 sources.
The cleaned catalogue has 1142840 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.0809307827921657 arcsec
Dec correction: -0.08064486934244997 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 = "datafusion_flag_gaia"

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

V - Saving to disk¶

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