CDFS SWIRE master catalogue¶

Preparation of DES data¶

Blanco DES catalogue: the catalogue comes from dmu0_DES.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The G band stellarity;
  • The magnitude for each band.
  • The auto/kron magnitudes/fluxes to be used as total magnitude.
  • The aperture magnitudes, which are used to compute a corrected 2 arcsec aperture magnitude.

We don't know when the maps have been observed. We will take the final observation date as 2017.

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, \
                                            nb_plot_mag_ap_evol, nb_plot_mag_vs_apcor 
from herschelhelp_internal.utils import astrometric_correction, mag_to_flux, flux_to_mag, aperture_correction
In [3]:
OUT_DIR =  os.environ.get('TMP_DIR', "./data_tmp")
try:
    os.makedirs(OUT_DIR)
except FileExistsError:
    pass

RA_COL = "des_ra"
DEC_COL = "des_dec"
In [4]:
# Pristine HSC catalogue
orig_des = Table.read("../../dmu0/dmu0_DES/data/DES-DR1_CDFS-SWIRE.fits")

1 - Aperture correction¶

To compute aperture correction we need to dertermine two parametres: the target aperture and the range of magnitudes for the stars that will be used to compute the correction.

Target aperture: To determine the target aperture, we simulate a curve of growth using the provided apertures and draw two figures:

The evolution of the magnitudes of the objects by plotting on the same plot aperture number vs the mean magnitude. The mean gain (loss when negative) of magnitude is each aperture compared to the previous (except for the first of course). As target aperture, we should use the smallest (i.e. less noisy) aperture for which most of the flux is captures.

Magnitude range: To know what limits in aperture to use when doing the aperture correction, we plot for each magnitude bin the correction that is computed and its RMS. We should then use the wide limits (to use more stars) where the correction is stable and with few dispersion.

In [5]:
bands = ["g", "r", "i", "z", "y"]
apertures = ["1", "2", "3", "4",  "5", "6", "7", "8", "9", "10", "11"] #Removed "40" and "235" because they lack errors

magnitudes = {}
stellarities = {}

for band in bands:
    magnitudes[band] = np.array(
        [orig_des["MAG_APER_{}_{}".format(aperture, band.upper())] for aperture in apertures]
    )

    stellarities[band] = 1 - np.array(orig_des["CLASS_STAR_{}".format(band.upper())])
    
    # Some sources have an infinite magnitude
    mask = np.isclose(magnitudes[band], 99.)
    magnitudes[band][mask] = np.nan

    
mag_corr = {}

I.a - g band¶

In [6]:
nb_plot_mag_ap_evol(magnitudes['g'], stellarities['g'], labels=apertures)

We will use aperture 10 as target.

In [7]:
nb_plot_mag_vs_apcor(orig_des['MAG_APER_4_G'], orig_des['MAG_APER_10_G'], stellarities['g'])

We will use magnitudes between 18.0 and 21.0

In [8]:
# Aperture correction
mag_corr['g'], num, std = aperture_correction(
    orig_des['MAG_APER_4_G'], orig_des['MAG_APER_10_G'], 
    stellarities['g'],
    mag_min=18.0, mag_max=21.0)
print("Aperture correction for g band:")
print("Correction: {}".format(mag_corr['g']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for g band:
Correction: -1.1639633178710938
Number of source used: 5284
RMS: 0.4047448234496646

I.b - r band¶

In [9]:
nb_plot_mag_ap_evol(magnitudes['r'], stellarities['r'], labels=apertures)

We will use aperture 10 as target.

In [10]:
nb_plot_mag_vs_apcor(orig_des['MAG_APER_4_R'], orig_des['MAG_APER_10_R'], stellarities['r'])

We use magnitudes between 17.0 and 20.0.

In [11]:
# Aperture correction
mag_corr['r'], num, std = aperture_correction(
    orig_des['MAG_APER_4_R'], orig_des['MAG_APER_10_R'], 
    stellarities['r'],
    mag_min=17.0, mag_max=20.0)
print("Aperture correction for r band:")
print("Correction: {}".format(mag_corr['r']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for r band:
Correction: -1.0371665954589844
Number of source used: 5476
RMS: 0.29878870981512956

I.b - i band¶

In [12]:
nb_plot_mag_ap_evol(magnitudes['i'], stellarities['i'], labels=apertures)

We will use aperture 10 as target.

In [13]:
nb_plot_mag_vs_apcor(orig_des['MAG_APER_4_I'], orig_des['MAG_APER_10_I'], stellarities['i'])

We use magnitudes between 17.5 and 20.0.

In [14]:
# Aperture correction
mag_corr['i'], num, std = aperture_correction(
    orig_des['MAG_APER_4_I'], orig_des['MAG_APER_10_I'], 
    stellarities['i'],
    mag_min=17.5, mag_max=20.0)
print("Aperture correction for i band:")
print("Correction: {}".format(mag_corr['i']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for i band:
Correction: -0.8794097900390625
Number of source used: 10281
RMS: 0.2809941852103083

I.b - z band¶

In [15]:
nb_plot_mag_ap_evol(magnitudes['z'], stellarities['z'], labels=apertures)

We will use aperture 57 as target.

In [16]:
nb_plot_mag_vs_apcor(orig_des['MAG_APER_4_Z'], orig_des['MAG_APER_10_Z'], stellarities['z'])

We use magnitudes between 17.5 and 20.0.

In [17]:
# Aperture correction
mag_corr['z'], num, std = aperture_correction(
    orig_des['MAG_APER_4_Z'], orig_des['MAG_APER_10_Z'], 
    stellarities['z'],
    mag_min=17.5, mag_max=20.0)
print("Aperture correction for z band:")
print("Correction: {}".format(mag_corr['z']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for z band:
Correction: -0.8297138214111328
Number of source used: 15326
RMS: 0.27388941891543533

I.b - y band¶

In [18]:
nb_plot_mag_ap_evol(magnitudes['y'], stellarities['y'], labels=apertures)

We will use aperture 10 as target.

In [19]:
nb_plot_mag_vs_apcor(orig_des['MAG_APER_4_Y'], orig_des['MAG_APER_10_Y'], stellarities['y'])

We use magnitudes between 17.0 and 19.0.

In [20]:
# Aperture correction
mag_corr['y'], num, std = aperture_correction(
    orig_des['MAG_APER_4_Y'], orig_des['MAG_APER_10_Y'], 
    stellarities['y'],
    mag_min=17.0, mag_max=19.0)
print("Aperture correction for y band:")
print("Correction: {}".format(mag_corr['y']))
print("Number of source used: {}".format(num))
print("RMS: {}".format(std))
Aperture correction for y band:
Correction: -0.9593305587768555
Number of source used: 4840
RMS: 0.3048783923502631

2 - Column selection¶

In [21]:
imported_columns = OrderedDict({
        'COADD_OBJECT_ID': "des_id",
        'RA': "des_ra",
        'DEC': "des_dec",
        'CLASS_STAR_G':  "des_stellarity",
    
        'MAG_AUTO_G': "m_decam_g", 
        'MAGERR_AUTO_G': "merr_decam_g", 
        'MAG_APER_4_G': "m_ap_decam_g", 
        'MAGERR_APER_4_G': "merr_ap_decam_g",
    
        'MAG_AUTO_R': "m_decam_r", 
        'MAGERR_AUTO_R': "merr_decam_r", 
        'MAG_APER_4_R': "m_ap_decam_r", 
        'MAGERR_APER_4_R': "merr_ap_decam_r",
    
        'MAG_AUTO_I': "m_decam_i", 
        'MAGERR_AUTO_I': "merr_decam_i", 
        'MAG_APER_4_I': "m_ap_decam_i", 
        'MAGERR_APER_4_I': "merr_ap_decam_i",
    
        'MAG_AUTO_Z': "m_decam_z", 
        'MAGERR_AUTO_Z': "merr_decam_z", 
        'MAG_APER_4_Z': "m_ap_decam_z", 
        'MAGERR_APER_4_Z': "merr_ap_decam_z",
    
        'MAG_AUTO_Y': "m_decam_y", 
        'MAGERR_AUTO_Y': "merr_decam_y", 
        'MAG_APER_4_Y': "m_ap_decam_y", 
        'MAGERR_APER_4_Y': "merr_ap_decam_y",

    })


catalogue = Table.read("../../dmu0/dmu0_DES/data/DES-DR1_CDFS-SWIRE.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2017

# Clean table metadata
catalogue.meta = None
In [22]:
# Aperture correction
for band in bands:
    catalogue["m_ap_decam_{}".format(band)] += mag_corr[band]
In [23]:
# Adding flux and band-flag columns
for col in catalogue.colnames:

            
    if col.startswith('m_'):
        
        errcol = "merr{}".format(col[1:])
        
        # Some objects have -99.0 values
        mask = (np.isclose(catalogue[col], 99.) )
        catalogue[col][mask] = np.nan
        catalogue[errcol][mask] = 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)
In [24]:
catalogue[:10].show_in_notebook()
Out[24]:
<Table masked=True length=10>
idxdes_iddes_rades_decdes_stellaritym_decam_gmerr_decam_gm_ap_decam_gmerr_ap_decam_gm_decam_rmerr_decam_rm_ap_decam_rmerr_ap_decam_rm_decam_imerr_decam_im_ap_decam_imerr_ap_decam_im_decam_zmerr_decam_zm_ap_decam_zmerr_ap_decam_zm_decam_ymerr_decam_ym_ap_decam_ymerr_ap_decam_yf_decam_gferr_decam_gflag_decam_gf_ap_decam_gferr_ap_decam_gf_decam_rferr_decam_rflag_decam_rf_ap_decam_rferr_ap_decam_rf_decam_iferr_decam_iflag_decam_if_ap_decam_iferr_ap_decam_if_decam_zferr_decam_zflag_decam_zf_ap_decam_zferr_ap_decam_zf_decam_yferr_decam_yflag_decam_yf_ap_decam_yferr_ap_decam_y
036922313353.848148-28.2745480.0037190672010223.22056961060.15032139420524.67591857910.42792961001422.30410385130.075003854930422.8546428680.083490528166321.69818115230.091801971197121.81905174260.059144571423521.31791687010.11486180871721.33915138240.064230062067521.13454627990.34858974814420.93545627590.1789978593591.869700980390.258862195889False0.4893646208530.1928770639124.348690097620.300412309905False2.619044350610.2013982725877.598494248270.642473509738False6.797970928290.37031377911210.78532538461.14099721079False10.57643846640.62568172284912.7697233344.09988597724False15.33972202152.52895444858
136922787153.957453-28.3702950.50745850801524.2787551880.12342972308423.37114334110.13227871060424.40244483950.16649301350123.46514701840.15425896644624.00140190120.24969798326523.45342445370.28582412004524.05485534670.55192857980723.71622467040.73149520158823.37063789370.94578129053122.27075290680.7007014751430.7055014729350.0802035071301False1.627581195690.1982934169690.6295381655540.0965369910645False1.492592285490.2120641664860.910834012010.209473917229False1.508794938580.3971959153220.8670773893310.440774462507False1.184431998780.7979897141841.628339066871.41844088586False4.484343140622.89406012244
236924867953.903767-28.7186090.36866950988828.629219055212.48894596126.97350883483.7720663547524.46003150940.30858740210524.2440204620.31255105137823.59023857120.27672615647322.98657608030.16956545412522.67734718320.2600429356122.11215591430.15760020911724.02104759222.9206454753921.79901027680.4332457780840.01283253265040.14760934204False0.0589652937010.2048573120180.5970179601370.169684146593False0.7284366948760.2096951854861.330162106460.339024014853False2.319367502820.3622285064973.08362193780.738553340582False5.18964480310.7533037054730.8945012733492.40622085299False6.924619099482.7631592062
336925803453.738793-28.8791590.13259705901123.3976440430.12477058172222.74174308780.11143307387822.89624595640.083662785589722.20200729370.064142175018822.31371498110.096999928355221.71177864070.070127807557622.32022857670.22802805900621.67268753050.14925052225622.06209564210.5906735062621.40974903110.4331947565081.58833601250.182528322609False2.906047876270.2982583119832.520586566980.194227007066False4.777460252710.2822386232794.310364602660.385088989214False7.503926019110.4846793148174.284583089090.899855011901False7.779021786241.069341760135.43452690482.95654786831False9.91061003093.95420570887
436949480454.216639-29.2124470.28272396326123.51348114010.11382210254722.86252021790.084954857826222.55865669250.053679496049921.93612098690.036917854100522.25859832760.076414830982721.6972713470.047570370137722.31390190120.17801457643521.58779907230.09035708010222.44749259950.67150628566721.64409351350.3571505546571.42760330250.149661408343False2.600111145080.203449117473.439832718190.170067541268False6.103115728660.2075218041384.534826427980.319164078264False7.604864163520.3331989865684.309622594880.706594877706False8.411634064450.7000325582023.810684207952.35683252259False7.986612151722.62717863448
536951874554.314548-29.5859710.010623810812823.69813156130.13476841151723.1782379150.097657904028922.8369388580.073013730347222.56723022460.05906347557922.24375724790.071860134601622.04295158390.053614150732822.07174873350.15086518228121.8732604980.1072265654821.66471862790.329666197322.14621448520.493250817061.204335187530.149489663738False1.944038376820.1748589688732.662100560020.179021286749False3.412776991490.1856532642184.597239195940.304271171919False5.531200054210.2731331903095.386423628730.7484541632False6.466894869210.6386661171557.836326974172.37937364809False5.02937716862.28485002788
636996501754.141932-27.1708830.65856868028624.52371025090.2320028841523.63214111330.17595000565124.1198463440.20625640451923.16941452030.13176530599623.07861709590.16983711719522.49802589420.13171111047323.44884490970.44619515538222.54995155330.24608960747724.09547233582.8725416660322.07848262790.6369687914850.5630097289810.120305356269False1.279804269560.2073998891020.8166979442430.155147429753False1.959901259010.237854266982.13085138730.333320059886False3.637388105840.4412530636271.515172349070.622676630621False3.467523225490.785938081220.8352395787582.20980057641False5.353119628413.14051435831
736997332753.40032-27.3002860.22674618661423.63869285580.11442952603122.68392944340.066462881863122.44675445560.052201442420521.79750823970.037827793508822.11872291560.078828983008921.41956329350.044180069118721.96845245360.12201067060221.43859672550.07592213898922.79946327210.93350452184721.42160892490.3000474274161.272104701380.134071552006False3.06498407710.1876217019713.813275804090.183339651426False6.934205435680.2415924699015.158350327310.374517777452False9.821429026640.3996471807245.924054135430.665721392158False9.650755429310.6748471607032.755590578212.36922767597False9.802941931182.70908116969
836995601653.578617-27.0238650.0015958765288823.70188713070.12959107756623.11058235170.085464149713523.13299751280.096073187887722.64925575260.06387328356522.43330192570.11608234792922.05184555050.070311076939122.81999778750.29668664932322.25879478450.146222367883nannan21.91675281520.4742078185081.20017657980.143250428201False2.069031293650.1628646069532.026753794940.179340706601False3.164446072590.1861626796963.860817114470.412782325587False5.486075495770.3552721872832.703963874270.738881118848False4.534005954840.610620778607nannanFalse6.212964525442.71358396373
936922316053.648259-28.274030.66098278760923.82521820070.20960631966623.35563468930.14964105188823.3592548370.15709747374122.691658020.087121143937122.23139762880.12291312962821.80843734740.071128286421322.16091537480.18844084441721.48775482180.082457274198521.90005874630.5373107194921.43202304840.3193994760511.071303983370.20682011359False1.650996392330.2275477558271.645500676530.238090982126False3.043244122970.2441945917544.649871470380.526398817951False6.864755299680.449720916584.961738252210.861161433066False9.223549254820.7004912672666.309232059573.1223219807False9.709363949212.85627921827

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [25]:
SORT_COLS = ['merr_ap_decam_g', 'merr_ap_decam_r','merr_ap_decam_i','merr_ap_decam_z','merr_ap_decam_y']
FLAG_NAME = 'des_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 999553 sources.
The cleaned catalogue has 999544 sources (9 removed).
The cleaned catalogue has 9 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 [26]:
gaia = Table.read("../../dmu0/dmu0_GAIA/data/GAIA_CDFS-SWIRE.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [27]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)
In [28]:
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.15149059884294047 arcsec
Dec correction: -0.057696934679540846 arcsec
In [29]:
catalogue[RA_COL] = catalogue[RA_COL] + delta_ra.to(u.deg)
catalogue[DEC_COL] = catalogue[DEC_COL] + delta_dec.to(u.deg)
In [30]:
catalogue[RA_COL].unit = u.deg
catalogue[DEC_COL].unit = u.deg
In [31]:
nb_astcor_diag_plot(catalogue[RA_COL], catalogue[DEC_COL], 
                    gaia_coords.ra, gaia_coords.dec)

IV - Flagging Gaia objects¶

In [32]:
catalogue.add_column(
    gaia_flag_column(SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]), epoch, gaia)
)
In [33]:
GAIA_FLAG_NAME = "des_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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