Bootes master catalogue¶

Preparation of SDWFS data¶

The catalogue comes from dmu0_SDWFS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • There is no stellarity;
  • The magnitude for each band in 2 arcsec 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 = "sdwfs_ra"
DEC_COL = "sdwfs_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'internal_id': "sdwfs_id",
        'ra': "sdwfs_ra",
        'dec': "sdwfs_dec",
        #'pstar':  "sdwfs_stellarity", #No stellarity
        'ch1_4': "m_ap_sdwfs-irac_i1", 
        'err1_4': "merr_ap_sdwfs-irac_i1", 
        'ch1_ma': "m_sdwfs-irac_i1", 
        'err1_ma': "merr_sdwfs-irac_i1",
            'ch2_4': "m_ap_sdwfs-irac_i2", 
        'err2_4': "merr_ap_sdwfs-irac_i2", 
        'ch2_ma': "m_sdwfs-irac_i2", 
        'err2_ma': "merr_sdwfs-irac_i2",
            'ch3_4': "m_ap_sdwfs-irac_i3", 
        'err3_4': "merr_ap_sdwfs-irac_i3", 
        'ch3_ma': "m_sdwfs-irac_i3", 
        'err3_ma': "merr_sdwfs-irac_i3",
            'ch4_4': "m_ap_sdwfs-irac_i4", 
        'err4_4': "merr_ap_sdwfs-irac_i4", 
        'ch4_ma': "m_sdwfs-irac_i4", 
        'err4_ma': "merr_sdwfs-irac_i4",

    })


catalogue = Table.read("../../dmu0/dmu0_SDWFS/data/SDWFS_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
WARNING: UnitsWarning: 'vega' did not parse as fits unit: At col 0, Unit 'vega' not supported by the FITS standard.  [astropy.units.core]
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)
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/ipykernel/__main__.py:8: RuntimeWarning: invalid value encountered in less_equal
/opt/anaconda3/envs/herschelhelp_internal/lib/python3.6/site-packages/ipykernel/__main__.py:9: RuntimeWarning: invalid value encountered in less_equal
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxsdwfs_idsdwfs_rasdwfs_decm_ap_sdwfs-irac_i1merr_ap_sdwfs-irac_i1m_sdwfs-irac_i1merr_sdwfs-irac_i1m_ap_sdwfs-irac_i2merr_ap_sdwfs-irac_i2m_sdwfs-irac_i2merr_sdwfs-irac_i2m_ap_sdwfs-irac_i3merr_ap_sdwfs-irac_i3m_sdwfs-irac_i3merr_sdwfs-irac_i3m_ap_sdwfs-irac_i4merr_ap_sdwfs-irac_i4m_sdwfs-irac_i4merr_sdwfs-irac_i4f_ap_sdwfs-irac_i1ferr_ap_sdwfs-irac_i1f_sdwfs-irac_i1ferr_sdwfs-irac_i1flag_sdwfs-irac_i1f_ap_sdwfs-irac_i2ferr_ap_sdwfs-irac_i2f_sdwfs-irac_i2ferr_sdwfs-irac_i2flag_sdwfs-irac_i2f_ap_sdwfs-irac_i3ferr_ap_sdwfs-irac_i3f_sdwfs-irac_i3ferr_sdwfs-irac_i3flag_sdwfs-irac_i3f_ap_sdwfs-irac_i4ferr_ap_sdwfs-irac_i4f_sdwfs-irac_i4ferr_sdwfs-irac_i4flag_sdwfs-irac_i4
degdegvegavegavegavegavegavegavegavegavegavegavegavegavegavegavegavega
0SDWFS1_J142539.66+322451.39216.415249932.414275319.28120.151519.51550.202619.1340.328219.24220.3724nannannannannannan17.33420.990470.39146436579.8221895932756.728330163110.5855912704False80.612056386424.367684148472.965909466225.026801691FalsenannannannanFalsenannan422.980162774385.839167356False
1SDWFS1_J142543.62+322403.85216.431738232.401068515.07990.00315.10690.006615.01650.006815.06450.014414.99360.053415.2350.113914.80960.093515.00870.1733373.183753999.320451153433290.3341122620.0013640936False3576.0205018122.39672887923421.3696613545.377249932False3652.2458141179.6292005542924.15237784306.760476787False4326.73204375372.6038095793601.8033693573.907345227False
2SDWFS1_J142543.48+322434.48216.431151132.409576518.70880.09218.87040.133118.40720.157218.68440.2615nannannannan17.20220.9279nannan119.2559345210.1051672845102.76376326812.5977717525False157.44178320922.7954527187121.96634236429.3756424336FalsenannannannanFalse477.661238103408.222421702nannanFalse
3SDWFS1_J142544.71+322425.88216.436276832.407188819.6270.193119.88690.236919.35250.329319.98980.6671nannannannannannannannan51.19175289.1045388579240.29396454878.79185953251False65.917389524419.992514088836.650508116122.5188713954FalsenannannannanFalsenannannannanFalse
4SDWFS1_J142548.52+322321.00216.452155632.389167718.87890.103318.99930.154218.860.263518.8050.3018nannannannannannannannan101.9623884079.7009887634591.259902406212.9610460528False103.75284158225.1800332687109.14403364530.3385566491FalsenannannannanFalsenannannannanFalse
5SDWFS1_J142548.14+322334.53216.450563432.392925618.73850.086818.98020.13718.71590.204318.94260.311217.3240.684517.10690.391116.70490.612217.17750.9336116.0379372619.2767404367292.879528060811.7196933183False118.4786235422.293797225596.152371469827.5597496614False426.972594048269.183931921521.482813545187.846667988False755.161777433425.803282711488.652359343420.181109079False
6SDWFS1_J142547.25+322340.16216.446889632.394489715.31970.003815.42460.007615.26850.008415.38280.016815.23190.066115.32510.107615.05960.116915.34850.20662704.705598649.466278484412455.6134304817.1889469927False2835.3064117621.93587517342551.9960626639.4879839733False2932.51336433178.5324395862691.28691583266.715313419False3436.84542644370.0412941832633.90435275501.194154614False
7SDWFS1_J142549.36+322324.66216.455654532.390184217.15640.021217.16320.035616.92980.04116.8830.063316.65530.238216.36850.269415.4450.173615.78610.2947498.2416165929.72862673775495.13086521216.2347527183False613.87507471823.1813933745640.91435664537.3662392373False790.460185601173.4193033121029.43753666255.43080461False2409.90542869385.3234151971760.19182649477.766633363False
8SDWFS1_J142546.77+322405.38216.444894332.401494719.39740.168319.45420.193718.90780.240919.37020.4299nannannannannannan17.30530.96663.24701013439.8039208409560.02331815110.7084176386False99.284167822322.028883188764.851496167425.6781141498FalsenannannannanFalsenannan434.390181145386.485145422False
9SDWFS1_J142547.55+322347.96216.448112432.396654319.31650.145419.43940.27518.77720.224719.03550.4519nannan17.12280.5317nannannannan68.13966592839.1251515631160.847116197615.4116228979False111.97472383223.173879930388.267332072136.7382124577Falsenannan513.901635694251.664721597FalsenannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_sdwfs-irac_i1', 'merr_ap_sdwfs-irac_i2', 'merr_ap_sdwfs-irac_i3', 'merr_ap_sdwfs-irac_i4']
FLAG_NAME = 'sdwfs_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 614263 sources.
The cleaned catalogue has 614263 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.03827762104720023 arcsec
Dec correction: -0.10533761135036457 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 = "sdwfs_flag_gaia"

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

V - Saving to disk¶

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