HDF-N 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: 
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
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_HDF-N_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
0182121890719878577189.0720555761.7731423422.39030075070.19185699522522.56529998780.41733399033521.75830078120.17195500433421.55570030210.13121399283421.0391006470.062327999621621.11540031430.092278003692620.5851001740.14167900383520.57209968570.17454800009720.16200065610.181741997620.24049949650.1455509960654.01679529540.7097951347963.418849669991.31413336765False7.189185463541.13859739798.664028638361.04706998503False13.94311281220.80042124990712.99690289811.10462214336False21.1816569662.7640195153921.43680837253.44628097828False31.2751742145.2351691064729.0937834123.90023758659False
1182121892482139671189.2482750161.7740692822.0046997070.22557799518122.11989974980.26258298754721.41480064390.076321996748421.44549942020.059103000909120.67250061040.035119000822320.72500038150.051205001771520.41580009460.14327000081520.47349929810.16232299804719.87899971010.19176900386820.04619979860.1251839995385.729544768491.190398935315.152762198421.24618455777False9.864605967170.6934340231569.589594250440.522017959075False19.54338357130.63214628074918.62086482420.878188838258False24.75597082243.266712433823.47471242933.50958702778False40.58823030427.1689278298934.79525956354.01184904588False
2182121893935411750189.3935045461.7675219222.24069976810.19547300040722.09639930730.2105520069623.58189964291.1002000570323.11910057071.6684099435821.64249992370.22279199957821.72830009460.18701599538322.02449989320.42038398981121.83399963380.17365300655421.25769996640.37172600626921.07789993290.3649089932444.610203464680.8300085230465.265508001971.02111661435False1.340417665531.358274307882.052862075873.1545558536False7.998343112111.641252126857.390604500771.27301756277False5.626004079272.178321061026.705021063181.07240327947False11.40039800383.9031805343413.4536469534.52168468137False
3182121895032868523189.5034728161.7731811623.23979949950.43513599038123.13260078430.4731239974521.58489990230.16059200465721.6030998230.19801700115221.97730064390.35545200109522.23010063170.28604099154521.60289955140.44638499617621.72069931030.12544399499921.41290092470.60069197416320.11079978940.455390989781.836877524110.7361746961752.027494507040.883507708204False8.434125112041.247497369378.293924369351.5126492275False5.875972335481.923695752134.655429425671.22648912613False8.295454382583.410558067997.442524549810.859895809234False9.881881237125.4672274192932.785369619413.7511873104False
4182121890317965793189.0315140761.7707944621.99699974060.32621601223922.16970062260.61343801021622.48550033570.25305500626622.67379951480.33939599990820.86949920650.12845000624720.9561996460.20558099448720.56800079350.19889700412820.90629959110.28903698921220.32099914550.1468989998120.38529968260.2206490039835.770322731951.73372837964.921752278022.78077668496False3.679593692470.8576112694993.093714224050.967080426996False16.30047715221.9284577440215.04943313072.84956641946False21.51788997813.9418818613915.75724049814.19478076895False27.01471199063.655062946425.46127378885.17437355133False
5182121890162173457189.0160671661.7689505723.53429985051.2240500450122.45359992980.30525699257921.80270004270.27560600638421.91609954830.36827600002321.18400001530.12525500357221.32250022890.083377003669720.94910049440.083543002605421.19529914860.13457599282320.88489913940.59113097190919.96940040590.2442670017481.40049015371.57890105183.789309058651.06537212458False6.901126415231.751799269956.216703873342.10867319867False12.20112829881.4075724489510.73989185940.824749141685False15.1481571611.1655893278912.07481096831.49666158969False16.07090538438.7498324893637.34563408498.4019543848False
6182121895065164294189.5063616361.7696769521.89319992070.21702100336622.26679992680.32731398940121.57509994510.080858998000622.56040000920.37351599335721.16349983220.097291998565221.1537990570.12252999842220.33869934080.082046002149620.57220077510.068604998290519.74869918820.070481002330819.83449935910.09849700331696.349214972781.269104776964.500699625431.35681387711False8.51059692160.6338172536323.434313968911.18147593124False12.43369091371.1141736208412.54528053021.41578884155False26.57787555922.0084145906721.43481255171.35441304437False45.76361514682.9707634798342.28635547823.83617979905False
7182121890003063437189.0003385161.768966621.23030090330.10693799704321.27289962770.091660000383920.3455009460.053743999451420.39249992370.057440999895319.95289993290.031014999374720.01370048520.027703000232619.86529922490.063551999628520.00300025940.057220999151519.86860084530.09809900075220.08149909970.095280997455111.6917531831.1515621030511.241911160.94906440139False26.4118986191.3073903759225.29298174181.3381281339False37.91752893551.0831472056235.85252983740.914791860189False41.10364253862.4059423125936.20761312511.9082312912False40.97884012523.7025414190333.68219300462.95584961788False
8182121890210536771189.0210635461.7717289620.2970008850.023760000243820.33559989930.058485999703419.34830093380.020012000575719.27459907530.045000001788118.97890090940.02237699925918.91320037840.026179000735318.75399971010.03790599852818.70750045780.026737000793218.60490036010.028023999184418.5219001770.033987998962427.61847190830.60439625794726.65385558331.43577913577False66.17281751191.2196797494170.82072524542.93527354869False92.99072554361.9165368046798.79156120112.3820374986False114.39317553.99377631795119.3987601062.94027658806False131.232032743.38723749135141.657616184.43446473521False
9182121894277446259189.4276767561.7712767920.09499931340.029790999367820.17110061650.04520199820418.96050071720.01733000017719.00930023190.018821999430718.26420021060.0081489998847218.34259986880.0081690000370117.96789932250.015168000012618.0876007080.011739999987217.77169990540.019480999559217.89730072020.030194999650133.26597636760.91276930491431.01414074461.29119866142False94.58008786391.5096419666690.42320727571.56754978641False179.6056174421.34803108657167.0936910221.25720074744False235.9610233413.29643313849211.3293011192.28509096552False282.6962436755.07232362177251.8139073327.00310149966False

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 10100 sources.
The cleaned catalogue has 10097 sources (3 removed).
The cleaned catalogue has 3 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_HDF-N.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.0009251711844626698 arcsec
Dec correction: -0.000312677103408987 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)))
1548 sources flagged.

V - Saving to disk

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