Lockman SWIRE 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_Lockman-SWIRE_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
0174791587823544922158.7824641655.6618408820.93639945980.059937000274721.03730010990.05455200001619.81819915770.053096000105119.70289993290.027139000594619.24020004270.016550999134819.13960075380.01955199986719.10519981380.012900999747218.91979980470.030458999797718.75769996640.046358000487118.75090026860.039078999310715.32640212270.84607896854813.96625463980.701723973095False42.92599166582.0992193573547.73534072931.19318986947False73.10043863251.1143455392480.19729101341.44419741771False82.77898071060.98360136149398.1928980972.75468152408False114.0039800384.8676617202114.7201992384.12913428448False
1174791586597581621158.6598070755.6590698419.00609970090.01169800013319.07469940190.015336000360518.08370018010.00262399995718.16530036930.0037130001001117.66250038150.0037930000107717.73180007930.0041240002028617.50769996640.0047909999266317.58519935610.0079260002821717.39139938350.012304999865617.51849937440.013276999816390.69014987780.97711891773285.13737178591.20256353125False212.0898710130.512577373748196.7341948650.672791495784False312.6078268791.09208985159293.278325691.11397213185False360.5122392451.59082298647335.6759738652.45047356062False401.2732843454.54776002522356.9441348734.36491589059False
2174791585782383763158.5782110255.6608482221.04940032960.092826999723921.12789916990.087335996329819.83460044860.023367999121519.94160079960.019466999918218.42650032040.011431000195418.47999954220.010440000332917.82080078120.0090669998899117.91749954220.0076210000552217.53569984440.020609999075517.70000076290.022032000124513.81146884691.1808367531812.84814212331.03349716847False42.28241851210.91003276331638.3141927880.686964646295False154.6677870621.62839508933147.2313123181.415716767False270.1964803572.25641499925247.1725187131.73495345417False351.333904556.66919958665301.994959836.12814877445False
3174791586080155691158.6082007655.6624899421.88990020750.19913099706222.31739997860.464352995157nannannannan24.82620048522.2153000831623.00110054020.66777402162622.26289939880.61390900611921.50639915470.588376998901nannan20.75769996640.5711249709136.36854052921.168031258284.295759988061.83723174026FalsenannannannanFalse0.426108115710.8694168436422.288546725741.40755373545False4.516897552652.553994308329.066514034124.91328215317Falsenannan18.06841318769.50444676246False
4174791586394167110158.6389621655.663477722.61380004880.24004200100922.84959983830.15394699573524.4647998811.2826900482223.49519920350.68012297153521.83480072020.16640900075421.88599967960.091338999569422.12339973450.41700300574322.61560058591.2169899940521.29310035710.3975259959722.22649955752.633470058443.269489752270.722841201182.631237588940.373084290739False0.5944017065190.7022268855491.451845218470.909459664204False6.700075736431.02690957846.391460778180.537690122801False5.136178472091.972672414823.264072267743.65866337724False11.03468289184.040183322194.6708957785111.3293303888False
5174791587096447727158.7096967755.6641479620.02280044560.037273999303620.11899948120.033562000840918.98509979250.015739999711519.05410003660.019847000017818.49080085750.010247999802218.56380081180.011123999953318.28089904790.0090629998594518.37840080260.010385000146918.09219932560.041788000613518.30489921570.0472560003435.55329216781.2205666364432.5387007261.00582802373False92.46131867351.3404187157786.76807956871.58609989166False145.7738610751.37592399786136.2949219551.39642087905False176.8643819781.47634560033161.6738122141.54640008894False210.4361122748.09930105512172.9976938217.52961819103False
6174791588777865495158.8778177855.6623601222.88839912410.20173799991622.53680038450.16212700307422.22879981990.12796999514122.17399978640.11680699884920.68740081790.037280000746320.84580039980.038584999740120.05879974370.042169000953420.17469978330.040173999965220.1030998230.15111300349220.15929985050.1612959951162.538869336260.4717411280033.509779606550.524096043372False4.661010400610.5493686916814.902302265910.527405471625False19.27701000860.66189829938116.66018578430.592071316534False34.39379532971.3358235469130.91150047561.14377563683False33.01870763474.5955509821331.35306911444.65778377896False
7174791586897306712158.6897913155.6633174919.70870018010.033263999968819.76499938960.029684999957718.90209960940.0064300000667618.95999908450.008728000335418.56489944460.0069169998168918.62599945070.010575000196718.42320060730.010060000233418.50090026860.014508999884118.22909927370.020787000656118.31649971010.043354000896247.48100775131.45468874845.0816957971.23257392722False99.8068056910.59108074727994.62379592630.76066038782False136.1570778460.867428458588128.7064227431.25359220763False155.1385603881.43745225301144.4241740671.92998107241False185.5069950513.55163069164171.1591479966.83447215181False
8174791587360317921158.73599755.6643494722.96229934690.50630998611523.12919998170.31177499890321.89669990540.13046899437922.07250022890.29609701037421.35750007630.10639800131321.44659996030.099091999232821.48900032040.1563609987521.55450057980.16095900535621.02930068970.22784100472921.69079971310.3624700009822.371811995731.106044077162.033855093060.584032444187False6.328780565090.7605066795735.382696690451.46794441487False10.39920092751.019081973229.579878827350.874327798271False9.212974557651.326795493218.67360755191.28585123926False14.06953435012.952482222077.650329043912.5540409944False
9174791588244583776158.8245429855.6608780428.533100128251.100498199524.62470054631.3729799985922.38990020750.26251301169422.33799934390.168209999820.37129974370.029842000454720.46640014650.034279998391919.55750083920.042224999517219.67860031130.049346998333919.46570014950.17224100232119.54619979860.1300230026250.01402038529710.6598736143180.5130028543020.64872356203False4.018277420520.9715528531334.215026044420.653021909908False25.79170795470.7088979414523.62870615130.746030210025False54.57574392412.1224867981348.81573980912.21868831533False59.39090459919.4217627560855.14677001226.60413513946False

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 435078 sources.
The cleaned catalogue has 434925 sources (153 removed).
The cleaned catalogue has 153 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_Lockman-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.0006137910020242998 arcsec
Dec correction: -0.00026867304541156045 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)))
55984 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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