AKARI-SEP 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_AKARI-SEP.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.2089509963989258
Number of source used: 3515
RMS: 0.5478532537600257

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.0310955047607422
Number of source used: 3578
RMS: 0.32081918827582895

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.9188127517700195
Number of source used: 6539
RMS: 0.2783461474496473

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.8532180786132812
Number of source used: 10553
RMS: 0.2608421567648423

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: -1.0451526641845703
Number of source used: 2981
RMS: 0.5928656140070293

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_AKARI-SEP.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
046992529967.599876-54.2752410.010361419059321.92349624630.036887094378521.64164257050.027699138969221.40210723880.024808062240521.35619544980.0193430595121.24900817870.042069677263521.27006816860.029850577935621.19106101990.083898834884221.14539527890.054948776960421.78280258180.42856431007420.85603523250.1484114825736.174495827250.209773984989False8.004661509990.2042137220769.980610435780.228047663699False10.41170417380.18549092546811.49202940370.445288612463False11.27126686590.30988542938712.12203663080.936714411187False12.6427598460.6398462056397.028764092782.77441004628False16.5038742912.25594802953
146989664167.438557-54.0459590.028609210625320.22436523440.0080133918672819.91989803310.0065343705937319.69060134890.0053908089175819.63519668580.0046033193357319.44347763060.008024510927519.38479137420.005701616872119.38473701480.014479788020319.4010086060.010003865696519.41582489010.05193287506719.26797866820.037684876471829.5293512830.217944526838False39.08776033180.23524490623748.27913278260.239711615397False50.80673956260.21541111513960.61902512340.448025982173False63.98577732740.33601383649763.98898097650.853381213698False63.03714822460.58081803108862.18276709072.97432273188False71.2538824082.47315484637
246990171867.168381-54.0834760.357549190521nannan26.22022724151.8825299739824.60104370120.29556503891923.83823394780.20064069330723.79438209530.26826745271722.97109889980.15511523187223.04393577580.24376808106922.93017196660.24893197417322.70198631290.59150964021723.44865036011.6290217638nannanFalse0.1180073623730.2046099189150.5243032134770.142728684019False1.05853792130.1956145346271.102166386350.272327078751False2.352666887470.3361170680012.200015242070.493944561794False2.443043575590.5601283788783.014431884921.6422640342False1.515443872232.27374848408
346992445167.687042-54.2683970.63259440660525.32822418210.60815966129323.68732929230.1960925906924.24748992920.23583303391923.07641983030.099598273634922.98984718320.14356024563322.36981487270.0905827805422.78979873660.23590835928922.25557708740.151399180293nannan22.36001777650.6557424068450.2683553927810.150315448692False1.216377233690.2196873991720.7261126924990.157719120435False2.135168077990.1958662275022.312390234920.305753191862False4.093304481030.3415036726822.780228592270.604087035853False4.547462904560.634115499829nannanFalse4.130407393212.49460529492
446990611467.770659-54.1178460.4808869659924.16484069820.14022760093223.81675243380.19550581276424.29846572880.17897602915823.5644474030.14581884443823.85743141170.22529165446823.36053180690.20926548540623.57302856450.3327603936223.25478363040.33755198121124.93456459053.7752804756223.15281867981.206218719480.7835445978310.101198227245False1.079689869480.1944170642370.692809299440.11420477353False1.362137780650.1829407145761.039985861860.215798399662False1.643566486950.3167820481441.351414499510.41418644679False1.811701099310.5632521903160.3856329759011.34090825957False1.990089132342.21092633215
546991232467.840913-54.172720.003028393955923.67855644230.2098078429723.00745296480.1058719530722.48348236080.080502748489422.18949890140.050372831523422.27289962770.1231247708222.0260496140.069724164903222.17664718630.23913796246121.84102630620.12546589970625.538791656515.462607383723.34663009641.576076388361.226245489980.236959880381False2.275195992480.2218581661793.686439031360.273333865871False4.832817990920.2242190371594.47548544350.50752946906False5.61797955550.3607772599224.890363321181.07712307575False6.661767593230.7698229653330.2210463445713.14805090291False1.664745928582.41657848302
646992174167.511801-54.2476780.59027183055924.98257064820.42306101322224.117140770.26109427213723.31159591670.097430124878922.87609672550.076179489493423.11656188960.15521834790722.74332141880.11523742973822.85851860050.24315553903622.43191719060.16189953684823.63722991941.7239868640921.65685081480.3401936590670.3689535902040.143764092069False0.8187356327320.1968868525921.719339470520.154287439792False2.567800681680.1801669173362.057667717990.294167019878False2.901826433540.3079928791932.609711863410.584456788026False3.86574429630.5764403990591.273819908642.02263568266False7.893319352012.47321327296
746990830867.448437-54.1359790.49389201402724.1429996490.21118806302523.723774910.23072832822823.4630985260.11594050377623.4380855560.15430647134823.44112968440.22611133754323.20934772490.2239673584723.69793128970.58328169584322.97709274290.34639632701923.66307067871.7865360975325.77377128617.17009544370.7994662609390.155505297108False1.176223998350.249957766511.495411064310.159687695214False1.530261942760.2174831414761.52597748620.317794330661False1.889125933820.3896918453681.204557356030.647115067442False2.339714695530.7464691453141.243860648712.04672363275False0.1780293005622.81539850014
846990559367.955672-54.1139650.54069751501124.60349082950.27556020021423.79893207550.22961725294623.93294906620.1490768194223.38823318480.1338009983323.59720802310.21461114287423.04213237760.17173595726523.28254699710.30505198240322.64894485470.213620886207nannan97.954847335899.00.5231228232510.132768741873False1.097557216980.2321172233270.9701086422580.133200597204False1.602163103510.197443008531.32165100570.261243045567False2.203672484210.3485651504621.76596137780.496170263812False3.165352333490.622789741812nannanFalse2.38814705406e-302.1775690754e-28
946991204467.540125-54.169720.40526384115224.76932716370.35997796058724.80574131010.6201238632224.22965240480.22692100703723.64705467220.1877325326223.19510078430.17329494655122.86270809170.16288191080123.65256118770.58317214250622.64960098270.28511938452722.40715980530.53779876232121.90066337590.4829404056070.4490235659410.148874640833False0.4342136540770.2480033800560.7381405057920.15427282076False1.262345194480.2182696490751.914078240980.305507069777False2.599661265450.3900006212341.255959180870.674602544521False3.163440037810.8307340886463.954905200571.95898701051False6.305719525012.80481274522

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 729517 sources.
The cleaned catalogue has 729508 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_AKARI-SEP.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.1438491276047671 arcsec
Dec correction: 0.07049437199100339 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)))
39225 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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