CDFS SWIRE master catalogue¶

Preparation of ATLAS/VST data¶

ATLAS/VST catalogue: the catalogue comes from dmu0_ATLAS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The aperture corrected aperture magnitude in each band (2")
  • The Petrosian 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: 
04829ed (Thu Nov 2 16:57:19 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 = "atlas_ra"
DEC_COL = "atlas_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
        'sourceID': "atlas_id",
        'ra': "atlas_ra",
        'dec': "atlas_dec",
        'pStar':  "atlas_stellarity",
        'uAperMag3': "m_ap_atlas_u", 
        'uAperMag3Err': "merr_ap_atlas_u", 
        'uPetroMag': "m_atlas_u", 
        'uPetroMagErr': "merr_atlas_u",  
        'ulAperMag3': "m_ap_atlas_ul", 
        'ulAperMag3Err': "merr_ap_atlas_ul", 
        'ulPetroMag': "m_atlas_ul", 
        'ulPetroMagErr': "merr_atlas_ul", 
        'gAperMag3': "m_ap_atlas_g", 
        'gAperMag3Err': "merr_ap_atlas_g", 
        'gPetroMag': "m_atlas_g", 
        'gPetroMagErr': "merr_atlas_g",     
        'rAperMag3': "m_ap_atlas_r", 
        'rAperMag3Err': "merr_ap_atlas_r", 
        'rPetroMag': "m_atlas_r", 
        'rPetroMagErr': "merr_atlas_r",     
        'iAperMag3': "m_ap_atlas_i", 
        'iAperMag3Err': "merr_ap_atlas_i", 
        'iPetroMag': "m_atlas_i", 
        'iPetroMagErr': "merr_atlas_i",    
        'zAperMag3': "m_ap_atlas_z", 
        'zAperMag3Err': "merr_ap_atlas_z", 
        'zPetroMag': "m_atlas_z", 
        'zPetroMagErr': "merr_atlas_z", 

    })


catalogue = Table.read("../../dmu0/dmu0_ATLAS/data/ATLAS_CDFS-SWIRE.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:])
        
        # Large negative numbers are used for missing values.
        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.
In [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table length=10>
idxatlas_idatlas_raatlas_decatlas_stellaritym_ap_atlas_umerr_ap_atlas_um_atlas_umerr_atlas_um_ap_atlas_ulmerr_ap_atlas_ulm_atlas_ulmerr_atlas_ulm_ap_atlas_gmerr_ap_atlas_gm_atlas_gmerr_atlas_gm_ap_atlas_rmerr_ap_atlas_rm_atlas_rmerr_atlas_rm_ap_atlas_imerr_ap_atlas_im_atlas_imerr_atlas_im_ap_atlas_zmerr_ap_atlas_zm_atlas_zmerr_atlas_zf_ap_atlas_uferr_ap_atlas_uf_atlas_uferr_atlas_uflag_atlas_uf_ap_atlas_ulferr_ap_atlas_ulf_atlas_ulferr_atlas_ulflag_atlas_ulf_ap_atlas_gferr_ap_atlas_gf_atlas_gferr_atlas_gflag_atlas_gf_ap_atlas_rferr_ap_atlas_rf_atlas_rferr_atlas_rflag_atlas_rf_ap_atlas_iferr_ap_atlas_if_atlas_iferr_atlas_iflag_atlas_if_ap_atlas_zferr_ap_atlas_zf_atlas_zferr_atlas_zflag_atlas_z
073016536208151.416438263-28.56750239610.050000000745119.48331069950.0303370878119.89030838010.0423593558371nannannannannannannannannannannannannannannannannannannannan58.43535950121.6327710401740.16767069751.56711791388FalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalse
173016536208251.4341608062-28.56506748720.050000000745119.40041160580.028450943529619.75593757630.0377803966403nannannannannannannannannannannannannannannannannannannannan63.07181920031.6527520759845.459532951.58185678842FalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalsenannannannanFalse
273016536208351.4410104768-28.55788993935.29221040324e-0721.39948081970.14461241662521.67231369020.16668000817321.50336074830.17877113819121.61940002440.39269343018520.96799659730.029026431962820.36285209660.055309820920220.35303115840.024393530562520.00978088380.051589258015219.94063186650.043050508946219.48734664920.081962823867819.56477737430.075586073100619.16595649720.09714471548810.00478297071.332566637157.781700717631.1946308261False9.091921988411.497024079238.170337377922.95508042989False14.88680025030.39798865757225.99316486551.32414972215False26.22935050260.58930195043435.98219447511.70971061533False38.34840041561.5205518135358.21854406124.3949499444False54.21120368443.7740401274378.2739771447.00345369938False
373016536208551.43345417-28.55530831370.052623040974121.35320663450.13870441913621.57844543460.13818304240721.45120429990.17051741480820.71364593510.2365208715220.77412223820.024906110018520.74910926820.052632216364120.27145195010.022882802411920.26375007630.042740769684320.18140411380.053094167262320.32330322270.12401350587619.98031616210.11063805222519.99465942380.13601978123210.44040500531.333777307478.484413497071.07982221181False9.539338943361.4981755314718.8166204994.09908360796False17.79717638710.40825610417318.21194343390.882843312238False28.27608118850.59594215978328.47737600071.12103194452False30.72121265051.5023144625926.95744395263.07909703975False36.97205029483.767504126236.4868381714.57102906223False
473016536208751.5065358537-28.54859726990.33333334326718.06686210630.011697715148318.07021141050.017678001895518.84624671940.020403955131818.08610916140.026091830804919.30050277710.0084014637395718.90818786620.0135871795937nannannannan15.15059947970.0017333803698415.05353641510.00165672285948nannannannan215.4046912522.32076880999214.7412297273.49642560461False105.075462981.97465555878211.6198174675.08553408104False69.15106755810.53509331649599.24870608111.24202360395FalsenannannannanFalse3160.532118375.045796859523456.093107965.27364605818FalsenannannannanFalse
573016536208851.437546604-28.53821019425.29221040324e-0721.34043693540.13736519217521.19154357910.15726555883921.37290954590.15933336317521.63992881770.59323883056620.88265991210.027338854968520.44173622130.064419135451320.53493499760.028246926143819.89184188840.06121902167820.29752922060.058578740805419.77628898620.10024848580420.17308044430.12889173626919.67666435240.12156780809210.56392297171.3365265916112.11665014681.75505960679False10.25265117441.504591433848.017306241474.38060125299False16.10408429520.40550109963924.17160627221.43415497402False22.183292260.57712897050740.11097739022.26164954582False27.60503561371.4893748767544.61536039784.11943739544False30.95763833573.6750950538348.90286002235.47555978724False
673016536208951.4267302675-28.535560640.99999898672121.60129165650.17336869239821.63148498540.17579758167321.59610748290.19502975046622.13725662230.80525654554419.50756454470.0099153770133919.54409790040.016748130321518.38924789430.0060272305272518.41043663020.0087580587714917.92513084410.0087074739858517.93188095090.016136148944517.57345199580.014114254154317.60602951050.02720303833488.307748437111.326568532038.079900373021.30826156437False8.347511130971.499455397875.07104367613.76103430559False57.14446645080.52186610947155.25363314080.852320337595False160.0666450260.888575479998156.9731407821.26621916677False245.4413111911.96840984291243.9201169753.62512673043False339.3276126784.41116004597329.2973196958.25051939134False
773016536209251.4723752174-28.53155027330.99999898672115.8353929520.0036271242424815.84125900270.0035700295120515.84835338590.0036773618776416.08835411070.0044602248817714.65421104430.00077834195690214.73877716060.00076228310354114.09274959560.00068071024725214.07037830350.00064808171009613.89292812350.00095010595396213.85963249210.00079760252265313.70243358610.0013893609866513.69048309330.001423848094421682.065174275.61928334371673.001764185.50102837655False1662.10572595.629511299551332.472809985.47382352666False4992.471361333.579000048194618.374384823.24250839563False8373.367679315.249744052328547.688335245.10216058873False10065.34697568.8079830517910378.79665477.62446196195False11995.72678115.350316884512128.490788515.9054551388False
873016536209351.4169423276-28.53069712455.29221040324e-0721.28442955020.13124570250520.90972518920.13737593591221.25927925110.14461128413721.03671836850.38168025016819.72983360290.011571016162619.16872787480.021499648690218.74279022220.0075538200326318.23872947690.013093485496918.29226875310.011371611617517.84005546570.021476743742817.92475128170.018699645996117.40205955510.037479642778611.12315988731.3445871355215.70760329311.98745026082False11.38382732521.516233759813.9737398144.91233550528False46.565745350.4962651053878.07443500651.54602279722False115.5803249490.804129925992183.8688709252.21737507163False175.0219421711.83311705199265.446995285.25075710836False245.5271299874.22871632453397.35270878113.7166261169False
973016536209651.4204295545-28.517799050.0030763975810321.30303382870.13379655778421.29393577580.18806427717221.34107589720.15586377680321.47332763670.49849864840521.27333641050.037961311638421.15318679810.10088782012521.06181526180.044220298528720.80067634580.10216154903220.77589988710.089698359370221.04371643070.182684645057nannannannan10.9341862811.3474327190711.02619553111.90988702728False10.55770787331.515620660269.346929033254.29149499611False11.23738954020.39290026846912.55235695071.16637901972False13.65444005780.55612349754217.36718624511.63415260663False17.76806135331.4679126896513.8839623642.33609851576FalsenannannannanFalse

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_atlas_g', 
             'merr_ap_atlas_r', 
             'merr_ap_atlas_i', 
             'merr_ap_atlas_u', 
             'merr_ap_atlas_ul', 
             'merr_ap_atlas_z']
FLAG_NAME = 'atlas_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])))
The initial catalogue had 316547 sources.
The cleaned catalogue has 301248 sources (15299 removed).
The cleaned catalogue has 14639 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_CDFS-SWIRE.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.13242675666447212 arcsec
Dec correction: -0.0507013146410884 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 = "atlas_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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