XMM-LSS 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_XMM-LSS_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
010443033261394457533.26152675-2.97153751nannannannan22.72929954530.24275100231223.14019966130.277249008417nannan21.92309951782.7823801040622.15609931950.30643600225422.51490020750.32510501146320.61269950870.988973021507nannannannannannanFalse2.939545466460.6572292654482.013353970470.514121560522Falsenannan6.1767524031615.8289581935False4.983796172451.406616605813.581293520721.07235667928False20.650006682518.80963296nannanFalse
110443033304045073633.30401392-2.9747801122.7600994110.21081599593223.15299987790.22805500030521.42490005490.067663997411721.67040061950.10841500014120.59959983830.050643000751720.6404991150.071078002452920.29549980160.076572000980420.41160011290.077592000365319.95120048520.1983170062320.1616992950.2288569957022.857328911720.5548038626591.98975703480.417941337122False9.773271825280.6090785557237.795424186130.778403548239False20.90066309160.97488901265420.12798749751.31768392585False27.65668220341.9504991060524.85192045291.77603934768False37.97692578736.9367404301131.28385627556.59417023197False
210443033233185378733.23318568-2.9722130321.22410011290.08308500051521.21910095210.080470003187720.26149940490.031263999640920.25040054320.03254200145619.61879920960.01363500021419.56730079650.015726000070619.36569976810.020592000335519.33580017090.031794998794819.27619934080.051093999296419.45120048520.069977000355711.75871744990.89982542821811.81298409260.875526544495False28.53646926090.82171356248128.82967739950.864091479865False51.57987866270.64775555380854.08535459710.783382083497False65.12085482211.2350777826866.93910966311.96026336944False70.71641953653.3278660822160.18937115093.87927714668False
310443033204679953533.20464792-2.9674497122.85479927060.36345401406322.99309921260.27669799327922.25029945370.16434200108122.30400085450.12027800083221.87459945680.19843399524722.04540061950.15407900512221.73909950260.21860699355621.99469947810.21229299902922.2772998811.1814500093521.3563003541.035699963572.618667098930.8766080235962.305474457160.587546176553False4.569621388380.6916788072984.349102649510.481794168604False6.458924638171.180461897965.518737690050.783175147966False7.317457335821.473329655635.782560812511.13065878394False4.457383977364.850327656610.41069824039.93092036622False
410443033306181209533.30608019-2.9734659121.9328002930.1849679946921.80909919740.14289000630421.36860084530.085274003446121.61660003660.083926998078821.12669944760.093221999704821.34729957580.092523999512221.27440071110.14968200027921.46220016480.078919000923620.53730010990.17270399630120.6501007080.3216589987286.121810512451.042922773876.860571913720.902896264952False10.29341924890.8084478206228.191434923130.633194822134False12.86234697511.1043692755810.49736189450.894561591065False11.22637940741.547693554149.443216226570.686399870282False22.13502190293.5209351259319.95077251995.91059364557False
510443033215423903733.2154869-2.9678289613.18519973750.0032820000778913.22519969940.0034409998916112.56869983670.016039999201912.61279964450.0188219994307nannan13.88169956210.037151001393812.29150009160.0069300001487112.3510999680.0070580001920512.1795997620.0019549999851712.24890041350.0064159999601519316.1293558.389448333218617.446745759.0038648False34081.6070847503.50071043332725.0366957567.311488145Falsenannan10169.9817872347.989692058False43994.6597618280.80761915841644.7263656270.71814074False48770.824225287.817796090145755.1343178270.383301831False
610443033260629572033.26059711-2.9706515322.77059936520.57261401414922.60939979550.75585198402422.39270019530.15958000719522.25349998470.16625900566621.94750022890.15828199684622.2420997620.19866499304822.25749969480.43650498986222.3516006470.501967012882nannannannan2.829829397451.492443526823.282767172022.28534893576False4.007928099510.5890797342454.556170902020.697687376081False6.039485020590.8804548883914.604262705520.842475192753False4.539417442431.825009017854.162552664311.92446758035FalsenannannannanFalse
710443033271985621033.27198637-2.9700345421.35250091550.51318401098321.68099975590.34239301085522.37339973450.19163200259222.31329917910.22622799873422.20719909670.34823900461222.16900062560.38854798674622.19739913940.31331300735522.28380012510.26248800754522.41419982911.82019996643nannan10.44719338284.937969812747.719694211972.43444893201False4.079811578960.7200850995384.312015649620.89846747916False4.754669796491.525012677974.924926458271.76246334224False4.797780160451.384504748124.430777584711.07118651381False3.929344153416.58741236112nannanFalse
810443033296155736933.29621106-2.9692552721.37590026860.41168698668521.17040061950.43258100748121.45779991150.082341998815521.43889999390.077298998832721.09760093690.075589999556521.17399978640.097878001630320.70879936220.11141800135420.52599906920.087333001196421.49069976810.59078401327121.54290008541.2466499805510.22444851943.8768831535912.35491472494.92246775564False9.481565190830.7190798522629.648060151450.686893728989False13.21172803920.9198132218912.31402654491.11009682182False18.90080298151.9395960850822.36662066921.79909641136False9.198565237425.005235400178.7667771261510.0660754296False
910443033311005492133.31102717-2.9712842622.37899971010.46452501416222.15299987790.57376998662922.08539962770.17047299444722.18149948120.24217599630421.3045997620.10311300307521.52519989010.14405700564421.06620025630.1438169926421.1641006470.1592299938220.8412990570.34356498718321.14119911190.2866120040424.058823030421.736540439044.998043697722.64127460524False5.319124418470.8351633329324.868556422931.08594288107False10.91842751381.036929453848.910868689311.18230658188False13.59940468341.8013818409112.42681237441.82246962835False16.72940045955.2937686237812.69171628663.35035179236False

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 384755 sources.
The cleaned catalogue has 384643 sources (112 removed).
The cleaned catalogue has 112 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_XMM-LSS.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.00022419935987727513 arcsec
Dec correction: -0.0008451836286837988 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)))
42278 sources flagged.

V - Saving to disk¶

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