xFLS master catalogue

Preparation of DataFusion-Spitzer data

The catalogue comes from dmu0_DataFusion-Spitzer.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The aperture magnitude.
  • The total 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: 
255270d (Fri Nov 24 10:35:51 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 = "spitzer_ra"
DEC_COL = "spitzer_dec"

I - Column selection

In [4]:
imported_columns = OrderedDict({
        'internal_id': "spitzer_intid",
        'ra_spitzer': "spitzer_ra",
        'dec_spitzer': "spitzer_dec",
        'class_star_1':  "spitzer_stellarity", #Take IRAC1 stellarity
        'flux_auto_1': "f_irac_i1", 
        'fluxerr_auto_1': "ferr_irac_i1", 
        'flux_aper_2_1': "f_ap_irac_i1", #Is this 2 arcsec aperture
        'fluxerr_aper_2_1': "ferr_ap_irac_i1",
            'flux_auto_2': "f_irac_i2", 
        'fluxerr_auto_2': "ferr_irac_i2", 
        'flux_aper_2_2': "f_ap_irac_i2", 
        'fluxerr_aper_2_2': "ferr_ap_irac_i2",
            'flux_auto_3': "f_irac_i3", 
        'fluxerr_auto_3': "ferr_irac_i3", 
        'flux_aper_2_3': "f_ap_irac_i3", 
        'fluxerr_aper_2_3': "ferr_ap_irac_i3",
            'flux_auto_4': "f_irac_i4", 
        'fluxerr_auto_4': "ferr_irac_i4", 
        'flux_aper_2_4': "f_ap_irac_i4", 
        'fluxerr_aper_2_4': "ferr_ap_irac_i4",
    })


catalogue = Table.read("../../dmu0/dmu0_DataFusion-Spitzer/data/Datafusion-xFLS.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('f_'):
        
        errcol = "ferr{}".format(col[1:])
        
       

        mag, error = flux_to_mag(np.array(catalogue[col]) * 1.e-6, np.array(catalogue[errcol]) * 1.e-6)
        
        # Fluxes are added in µJy
        catalogue.add_column(Column(mag , 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:])))
        
# TODO: Set to True the flag columns for fluxes that should not be used for SED fitting.
/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>
idxspitzer_intidspitzer_raspitzer_decspitzer_stellarityf_irac_i1ferr_irac_i1f_ap_irac_i1ferr_ap_irac_i1f_irac_i2ferr_irac_i2f_ap_irac_i2ferr_ap_irac_i2f_irac_i3ferr_irac_i3f_ap_irac_i3ferr_ap_irac_i3f_irac_i4ferr_irac_i4f_ap_irac_i4ferr_ap_irac_i4m_irac_i1merr_irac_i1flag_irac_i1m_ap_irac_i1merr_ap_irac_i1m_irac_i2merr_irac_i2flag_irac_i2m_ap_irac_i2merr_ap_irac_i2m_irac_i3merr_irac_i3flag_irac_i3m_ap_irac_i3merr_ap_irac_i3m_irac_i4merr_irac_i4flag_irac_i4m_ap_irac_i4merr_ap_irac_i4
degdeguJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJyuJy
01173051261.16196458.6221960.1531.86590746218.654033362437.738731469615.9301441451nannannannannannannannannannannannan20.14168427340.63558081346False19.95803175520.458307250187nannanFalsenannannannanFalsenannannannanFalsenannan
11175336261.16893758.6445170.0389.53238380219.041949137662.945512377712.5770632326nannannannan77.18509223438.993428294895.650471544645.2330454733nannannannan19.02004963060.230916822606False19.40258806730.216939578142nannanFalsenannan19.18116643130.548507174403False18.94828221150.513443941559nannanFalsenannan
21174134261.15881658.6374040.318.11273089989.173024150414.67795711116.84769880707nannannannannannannannannannannannan20.75504016280.549861005627False20.98333596410.506527881081nannanFalsenannannannanFalsenannannannanFalsenannan
31174464261.16098658.6409260.9690.9392943311.177363962893.495114317911.1235154918nannannannannannannannannannannannan19.00312105040.133448019556False18.97302770760.129174701607nannanFalsenannannannanFalsenannannannanFalsenannan
41175556261.16985458.6532661.030.462662455810.597818904838.82891296910.3048837614nannannannannannannannannannannannan20.19058035430.37772258722False19.92711191880.28814572776nannanFalsenannannannanFalsenannannannanFalsenannan
51176502261.18259158.661721.029.89976962989.833799608436.793517538610.3573174696nannannannannannannannannannannannan20.21083039450.357090117997False19.98557172680.305633038458nannanFalsenannannannanFalsenannannannanFalsenannan
61176634261.18370758.6637120.9817.13199566549.525225626422.63984692398.98122280484nannannannannannannannannannannannan20.81548011040.603658938693False20.51281628470.430711338066nannanFalsenannannannanFalsenannannannanFalsenannan
71176773261.17281258.6628090.023.885616351610.836534742815.77631039625.9890432619nannannannannannannannannannannannan20.45465886890.492581724967False20.90498639410.412169952163nannanFalsenannannannanFalsenannannannanFalsenannan
81175478261.17030558.6503750.1632.879317624813.239160744833.377881308410.4644842065nannannannannannannannannannannannan20.10769301090.437181705085False20.09135308510.340395163556nannanFalsenannannannanFalsenannannannanFalsenannan
91175619261.16772958.6516690.0670.46513816413.89307223463.212279559811.834805737nannannannannannannannannannannannan19.28006423050.214066301618False19.39799636970.203275014829nannanFalsenannannannanFalsenannannannanFalsenannan

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', 'ferr_ap_irac_i3', 'ferr_ap_irac_i4']
FLAG_NAME = 'spitzer_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 228354 sources.
The cleaned catalogue has 228354 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_xFLS.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [9]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], #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.07282967051196465 arcsec
Dec correction: -0.06646679910460307 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 = "spitzer_flag_gaia"

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

V - Saving to disk

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