EGS master catalogue

Preparation of Pan-STARRS1 - 3pi Steradian Survey (3SS) data

This catalogue comes from dmu0_PanSTARRS1-3SS.

In the catalogue, we keep:

  • The uniquePspsSTid as unique object identifier;
  • The r-band position which is given for all the sources;
  • The grizy <band>FApMag aperture magnitude (see below);
  • The grizy <band>FKronMag as total magnitude.

The Pan-STARRS1-3SS catalogue provides for each band an aperture magnitude defined as “In PS1, an 'optimal' aperture radius is determined based on the local PSF. The wings of the same analytic PSF are then used to extrapolate the flux measured inside this aperture to a 'total' flux.”

The observations used for the catalogue where done between 2010 and 2015 (ref).

TODO: Check if the detection flag can be used to know in which bands an object was detected to construct the coverage maps.

TODO: Check for stellarity.

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: 
44f1ae0 (Thu Nov 30 18:27:54 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({
        "objID": "ps1_id",
        "raMean": "ps1_ra",
        "decMean": "ps1_dec",
        "gFApMag": "m_ap_gpc1_g",
        "gFApMagErr": "merr_ap_gpc1_g",
        "gFKronMag": "m_gpc1_g",
        "gFKronMagErr": "merr_gpc1_g",
        "rFApMag": "m_ap_gpc1_r",
        "rFApMagErr": "merr_ap_gpc1_r",
        "rFKronMag": "m_gpc1_r",
        "rFKronMagErr": "merr_gpc1_r",
        "iFApMag": "m_ap_gpc1_i",
        "iFApMagErr": "merr_ap_gpc1_i",
        "iFKronMag": "m_gpc1_i",
        "iFKronMagErr": "merr_gpc1_i",
        "zFApMag": "m_ap_gpc1_z",
        "zFApMagErr": "merr_ap_gpc1_z",
        "zFKronMag": "m_gpc1_z",
        "zFKronMagErr": "merr_gpc1_z",
        "yFApMag": "m_ap_gpc1_y",
        "yFApMagErr": "merr_ap_gpc1_y",
        "yFKronMag": "m_gpc1_y",
        "yFKronMagErr": "merr_gpc1_y"
    })


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

epoch = 2012

# 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_gpc1_gmerr_ap_gpc1_gm_gpc1_gmerr_gpc1_gm_ap_gpc1_rmerr_ap_gpc1_rm_gpc1_rmerr_gpc1_rm_ap_gpc1_imerr_ap_gpc1_im_gpc1_imerr_gpc1_im_ap_gpc1_zmerr_ap_gpc1_zm_gpc1_zmerr_gpc1_zm_ap_gpc1_ymerr_ap_gpc1_ym_gpc1_ymerr_gpc1_yf_ap_gpc1_gferr_ap_gpc1_gf_gpc1_gferr_gpc1_gflag_gpc1_gf_ap_gpc1_rferr_ap_gpc1_rf_gpc1_rferr_gpc1_rflag_gpc1_rf_ap_gpc1_iferr_ap_gpc1_if_gpc1_iferr_gpc1_iflag_gpc1_if_ap_gpc1_zferr_ap_gpc1_zf_gpc1_zferr_gpc1_zflag_gpc1_zf_ap_gpc1_yferr_ap_gpc1_yf_gpc1_yferr_gpc1_yflag_gpc1_y
0169402138268177708213.8266875651.172474619.82150077820.015176000073619.69400024410.06072000041619.45059967040.050204001367119.92880058290.0900539979339nannannannan23.76889991760.500658988953nannan22.45960044861.5753899812721.69350051881.6122299432842.79565607930.59818110233548.12823136462.69158034491False60.22268741462.7846726194138.76856863723.21557352942FalsenannannannanFalse1.128340126450.520304678456nannanFalse3.768424516555.467937978427.6313222405611.3318927462False
1169412138221890846213.8221855851.1751386321.54439926150.11867100000421.61039924620.099498003721221.52960014340.093456000089621.46019935610.16760799288721.33200073240.064373001456321.52700042720.10876099765321.14179992680.12065900117221.15150070190.14905099570820.26149940490.22575299441820.07570075990.1796170026068.75468038260.9568868304888.23835119190.754971137516False8.874827953630.7639110848439.460634351771.4604633503False10.64632468870.6312176674998.89610354340.891145650633False12.68469500311.4096634362312.57186530211.7258787475False28.53646926095.933479382533.86255286495.60199634085False
2169412138169467958213.8172650951.1807980822.80660057070.0038330000825222.5251007080.22516299784222.2632999420.30306500196522.3390998840.32080799341222.74970054630.24714699387621.94779968260.19020000100121.10230064390.12836000323321.15390014650.11102700233520.67659950260.56239998340620.31019973750.913825988772.737535575450.009664386285213.547804798650.735753639532False4.515231513541.260350941164.210755711361.24417338631False2.884827049150.6566754704536.037819517541.05770929739False13.15466347711.555196040312.5441125331.28275653459False19.469742107410.085122509627.284757923722.9646214049False
3169412138162257920213.8161823151.1810109122.74200057980.53819400072122.93199920650.62860399484622.05330085750.1577879935521.9321002960.19194400310521.24489974980.062849000096321.28779983520.079636998474620.76930046080.12398499995520.74620056150.095854997634922.204700470.84311300516120.86409950260.470109999182.905358762711.440171792352.438935512651.41205994578False5.478726955960.7962130486236.125758644921.08295424912False11.53559765560.66775039368811.08868549580.813337186365False17.87638978612.0413836962518.26079896851.61216770176False4.765624414563.7006778479216.38174641837.09308832248False
4169412138470435786213.8468934651.1792883723.1023998260.43695199489623.47159957890.64467400312422.20660018920.27843099832522.11860084530.28560900688221.78019905090.18346300721221.86129951480.2288970053221.15040016170.11869999766321.3462009430.11938799917722.29039955141.1294499635721.65579986571.511350035672.084683214640.8389758814071.483748074810.881000197674False4.757293263211.219981342435.158930317951.35708559614False7.045638875561.190541579236.538531104921.37846576594False12.58461504481.3758349126410.50798932221.15546282334False4.403927689544.581238008577.9009634675410.9981792687False
5169422138554567649213.8554757351.1891434922.0219001770.38896200060822.17140007020.65674400329622.58020019530.27693998813622.30520057680.19544999301421.59329986570.065674997866221.79800033570.1084539964821.18199920650.12979300320121.14620018010.093593999743520.40880012510.18014900386320.48430061340.1297670006755.639491276482.02033219464.914054535642.97243090357False3.372251230990.8601640175684.344299610170.782043856269False8.369124985480.5062392348666.931063308520.692342681737False12.22363342581.4612592685212.63339071891.08903945776False24.91609338614.1341620404723.24233489852.77791978866False
6169422139576049608213.9575604651.1907757523.3444995880.66203498840323.44190025330.61333698034322.22069931030.35529801249522.37199974060.45092898607320.41830062870.033620998263420.53540039060.051481999456919.795299530.022980000823719.93300056460.042876999825219.33600044250.10854499787119.43709945680.09940599650141.668015818021.017083917711.524894853480.861419560918False4.695915526181.536698735834.085075652621.69661747853False24.69902152040.76483196931822.17378558791.05140715819False43.84097337740.92791011288938.61888886331.52510534676False66.92676341686.6909119920160.97618053775.58275386106False
7169422138450237224213.8448184451.1888680622.48530006410.30744799971622.35359954830.31122899055521.83769989010.11450900137422.36210060120.30296099185921.96579933170.093154996633522.07939910890.12988099455821.25110054020.18240000307621.39959907530.18066400289520.90180015560.21602000296120.0258007050.3068749904633.680272481761.042143025144.154896221071.19101136268False6.682208830240.7047504327214.122491411331.15032922494False5.938547948090.5095210159595.348602912030.639825643345False11.4699040251.9269050071910.00369333471.66459152201False15.82267609453.1481077280135.455181915310.021134567False
8169422138764680110213.8764361751.182842614.79049968720.0017979999538514.84759998320.0053190002217914.47459983830.0048659997992214.54629993440.0081449998542714.35890007020.0018870000494614.43920040130.0060169999487714.3484001160.0029130000621114.41969966890.0020099999383114.33469963070.0043810000643114.39550018310.002510000020274403.52154077.292316026924177.9189127920.467542232False5890.6072109526.40023735065514.1684143841.3663104672False6552.997042111.38905167616085.8303188833.7268302894False6616.6772893417.75236127376196.1244558211.4707511082False6700.6995884227.03765905496335.7776382114.6470219291False
9169422139790088710213.9791119251.1900574422.47719955440.25445699691822.70569992070.10991399735221.26289939880.16230799257821.12980079650.23836399614820.92309951780.060786999762120.9428997040.1075809970520.61949920650.14237099885920.54859924320.181642994285nannan22.09210014341.605270028113.707833109620.8689809495263.004139057790.304122613758False11.3459336751.6961170776512.82565877532.81576248956False15.51530055230.86865351532615.2349179081.50956342004False20.52108491132.6908998186721.90585974583.66483676162Falsenannan5.286399042317.81598504506False

II - Removal of duplicated sources

We remove duplicated objects from the input catalogues.

In [7]:
SORT_COLS = ['merr_ap_gpc1_r', 'merr_ap_gpc1_g', 'merr_ap_gpc1_i', 'merr_ap_gpc1_z', 'merr_ap_gpc1_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 59217 sources.
The cleaned catalogue has 59207 sources (10 removed).
The cleaned catalogue has 10 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_EGS.fits")
gaia_coords = SkyCoord(gaia['ra'], gaia['dec'])
In [9]:
catalogue[RA_COL].unit = u.deg
catalogue[DEC_COL].unit = u.deg
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.0004886441843154898 arcsec
Dec correction: -0.000554433862021142 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)))
9109 sources flagged.

V - Saving to disk

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