CDFS SWIRE master catalogue¶

Preparation of PanSTARRS data¶

The catalogue comes from dmu0_PanSTARRS1-3SS.

In the catalogue, we keep:

  • The identifier (it's unique in the catalogue);
  • The position;
  • The stellarity;
  • The aperture magnitude
  • The kron magnitude to be used as total magnitude (no “auto” magnitude is provided).
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 = "ps1_ra"
DEC_COL = "ps1_dec"

I - Column selection¶

In [4]:
imported_columns = OrderedDict({
    'uniquePspsSTid':'ps1_id', 
    'raMean':'ps1_ra', 
    'decMean':'ps1_dec',   
    'gApMag':'m_ap_ps1_g', 
    'gApMagErr':'merr_ap_ps1_g', 
    'gKronMag':'m_ps1_g', 
    'gKronMagErr':'merr_ps1_g', 
    'rApMag':'m_ap_ps1_r', 
    'rApMagErr':'merr_ap_ps1_r', 
    'rKronMag':'m_ps1_r', 
    'rKronMagErr':'merr_ps1_r',
    'iApMag':'m_ap_ps1_i', 
    'iApMagErr':'merr_ap_ps1_i', 
    'iKronMag':'m_ps1_i', 
    'iKronMagErr':'merr_ps1_i',
    'zApMag':'m_ap_ps1_z', 
    'zApMagErr':'merr_ap_ps1_z', 
    'zKronMag':'m_ps1_z', 
    'zKronMagErr':'merr_ps1_z',
    'yApMag':'m_ap_ps1_y', 
    'yApMagErr':'merr_ap_ps1_y', 
    'yKronMag':'m_ps1_y', 
    'yKronMagErr':'merr_ps1_y'
    })


catalogue = Table.read("../../dmu0/dmu0_PanSTARRS1-3SS/data/PanSTARRS1-3SS_CDFS-SWIRE.fits")[list(imported_columns)]
for column in imported_columns:
    catalogue[column].name = imported_columns[column]

epoch = 2009

# 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:])
        
        # -999 is used for missing values
        catalogue[col][catalogue[col] < -900] = np.nan
        catalogue[errcol][catalogue[errcol] < -900] = 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 [6]:
catalogue[:10].show_in_notebook()
Out[6]:
<Table masked=True length=10>
idxps1_idps1_raps1_decm_ap_ps1_gmerr_ap_ps1_gm_ps1_gmerr_ps1_gm_ap_ps1_rmerr_ap_ps1_rm_ps1_rmerr_ps1_rm_ap_ps1_imerr_ap_ps1_im_ps1_imerr_ps1_im_ap_ps1_zmerr_ap_ps1_zm_ps1_zmerr_ps1_zm_ap_ps1_ymerr_ap_ps1_ym_ps1_ymerr_ps1_yf_ap_ps1_gferr_ap_ps1_gf_ps1_gferr_ps1_gflag_ps1_gf_ap_ps1_rferr_ap_ps1_rf_ps1_rferr_ps1_rflag_ps1_rf_ap_ps1_iferr_ap_ps1_if_ps1_iferr_ps1_iflag_ps1_if_ap_ps1_zferr_ap_ps1_zf_ps1_zferr_ps1_zflag_ps1_zf_ap_ps1_yferr_ap_ps1_yf_ps1_yferr_ps1_yflag_ps1_y
0104645000000107954.05465606-30.4271333922.15909957890.0301580000669nannan22.24440002440.0264989994466nannan21.03100013730.0062899999320521.24860000610.099068999290519.57620048520.012005000375219.78980064390.10589899867820.37080001830.0105200000107nannan4.970043254770.138050627908nannanFalse4.594518348350.11213602221nannanFalse14.04752925020.081381607836111.49635053941.04899508595False53.6438335040.59314061603644.06357628574.29781063427False25.8035816830.250018078417nannanFalse
1104645000000114954.07805742-30.4289298122.73859977720.0393819995224nannan20.43099975590.011495999991920.37739944460.10301800072220.00340080260.00391899980605nannan18.57139968870.0075579998083418.6580009460.048842001706419.68779945370.0076810000464319.77330017090.1489170044662.914473354260.105714249688nannanFalse24.41181654980.25847737381225.64721557112.43348693784False36.19425809570.130644340527nannanFalse135.3443480710.942155702554124.9682308315.62171411136False48.4038847830.34243146690344.73834679086.13620560838False
2104645000000115254.08000797-30.430669518.02429962160.0044920002110317.98100090030.017795000225317.57659912110.0030879999976617.41959953310.012110999785417.35619926450.0011579999700217.01530075070.0057000000961116.21890068050.002557999920115.89550018310.0096279997378617.21209907530.0024560000747416.82699966430.0173359997571224.0165741590.926820432058233.1307924353.82096727154False338.3454585750.962306286471390.9850815694.36129901372False414.4959526070.442083720326567.3874163822.97872384999False1181.516328082.783658368921591.4753882514.1127509184False473.3260095561.07069167423674.83893952110.7751842854False
3104645000000104154.04404335-30.4210469922.16150093080.030191000551nannan20.72970008850.013190999627120.6389999390.1100739985720.1250.0041439998894920.16920089720.043173998594319.03000068660.0093350000679519.0538997650.0660350024719.54730033870.0071990001015419.80739974980.1478620022544.959063023710.137896363615nannanFalse18.54043692760.22525443613920.15579926132.0434332109False32.3593656930.12350809272831.06845387741.23542843846False88.71554509790.76276319780886.78408602165.27825019529False55.09089963970.36528153925643.3550907985.904353659False
4104645000000102154.03739504-30.42387156nannannannannannannannannannannannan19.42440032960.011194000020619.17140007020.0929569974542nannannannannannannannanFalsenannannannanFalsenannannannanFalse61.69356517410.63606405202777.88251580926.66803298267FalsenannannannanFalse
5104645000000112054.06711346-30.4241600623.70019912720.0613240003586nannan21.91920089720.0228140000254nannan21.47629928590.007722000125821.73979949950.16543200612120.53240013120.018647000193621.12840080260.42048299312622.90290069580.0337609983981nannan1.202043956020.0678932356377nannanFalse6.198971520580.130255706504nannanFalse9.321381559190.0662957625047.312741137781.11423146006False22.23514405750.38187796789612.84220738574.97351914419False2.505184532850.0778987848336nannanFalse
6104645000000113054.0699512-30.42341408nan0.129620999098nannan21.89529991150.0225639995188nannan20.16900062560.0042289998382320.2420997620.050484001636518.92300033570.008886000141518.9647998810.07199499756119.90600013730.0084929997101420.12840080260.202264994383nannannannanFalse6.336946424320.131695761311nannanFalse31.07418519870.12103559188929.05093369971.35079532027False97.90387147440.80127549579994.20632182496.24680643446False39.59131666510.309696811732.25816648296.00946881376False
7104645000000126354.10597218-30.4197605321.22209930420.019588999450221.23710060120.178812995553nan0.0335969999433nannan21.35639953610.00730699999258nannan18.66390037540.00788700021803nannannannannannan11.78040654480.2125436881611.6187594281.91352666405FalsenannannannanFalse10.40974726520.0700575543638nannanFalse124.2910479790.902874490335nannanFalsenannannannanFalse
8104645000000126454.10597218-30.41976053nan0.0774419978261nannan19.9044990540.009021000005320.01189994810.08340000361219.22500038150.0027379998937219.31609916690.0333469994366nannannannannannannannannannannannanFalse39.64609145130.32940542060335.91203542122.7585557806False74.13099808440.18694289090468.16482643942.09359549669FalsenannannannanFalsenannannannanFalse
9104645000000099754.03174085-30.4200001618.5725994110.0057819997891818.51939964290.02665100060418.07679939270.0038880000356617.86160087590.017317999154317.64979934690.0013259999686917.16629981990.0069639999419516.5517005920.0029819998890216.10820007320.013972000218917.6023998260.0029400000348717.13599967960.0226499997079135.1948771850.719969314788141.9842405513.48521313382False213.4421775310.764332247757260.2313709384.15081181053False316.2862129370.386277538331493.7192629943.16675533501False869.6004647512.388378022221308.33804616.8365938107False330.4000235320.894670433249507.69177572410.5911717059False

II - Removal of duplicated sources¶

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_ps1_g', 
              'merr_ap_ps1_r',
              'merr_ap_ps1_i', 
              'merr_ap_ps1_z', 
              'merr_ap_ps1_y']
FLAG_NAME = 'ps1_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 216352 sources.
The cleaned catalogue has 179224 sources (37128 removed).
The cleaned catalogue has 32982 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.0001800822658992729 arcsec
Dec correction: -0.0003455704778332347 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 = "ps1_flag_gaia"

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

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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