COSMOS 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>ApMag aperture magnitude (see below);
  • The grizy <band>KronMag 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).

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_COSMOS_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
0108951496721639304149.671960590.7988674624.10680007931.5705699920723.61260032650.74821501970322.33289909360.71383398771322.26790046690.30849701166221.975900650.19335800409321.80369949340.10518199950521.28820037840.18250000476821.24920082090.16910800337820.44350051880.316558986902nannan0.8265706272351.195674435251.303046365990.89797029714False4.234872724872.784282288284.496139870361.27751631376False5.883553948151.047798022586.894776657470.667939773761False11.08459547971.8631954235611.48999055341.78961459773False24.13235983897.03606948785nannanFalse
1108991496288003541149.62868440.8276639822.23189926150.11217799782822.34760093690.12951000034821.52829933170.036894999444521.64929962160.038748998194921.21039962770.083599001169221.15719985960.1026569977421.03890037540.12655700743221.12150001530.13187499344320.46929931640.065779000520720.0610008240.2952089905744.647723629340.4802016630834.177915243040.498354758927False8.885467185350.3019419500167.948407992180.283671895246False11.90803627430.91688932731112.50604698981.18245410989False13.94568495371.6255552192112.92409060191.56977759047False23.56569613571.4277205932634.32414045239.33264895362False
2108991496397191671149.639665860.82603161nannannannan23.19779968260.2755109965823.09239959720.2080489993122.16060066220.24144299328322.41830062870.19472800195221.43519973750.16157600283621.65209960940.22136500477821.02960014340.50374400615720.48660087590.267969995737nannannannanFalse1.909326177640.4845010746572.103972994470.403163746548False4.963176674821.103697405793.914531106820.702075529645False9.680997433311.440696977677.92793637781.61638496207False14.0656544086.5259766319323.1931453485.72428830576False
3108991496444301025149.64439250.8255219823.15539932250.2536939978622.91959953310.15624099969921.74970054630.031465999782121.79940032960.03612599894421.20240020750.058127000927921.20330047610.1138070002221.05319976810.15405699610721.23419952390.17670099437220.31180000310.1994650065920.13689994810.4285649955271.985364586570.4639018916092.466949087980.355002062217False7.2463579220.2100085599026.92213186370.230321994701False11.99609556920.64223432471711.98615279361.25638998464False13.76322129311.9528873771411.64984616081.89598485514False27.24457256825.0052110476132.006635259412.6337534262False
4108991496367975688149.636778710.8293745422.08729934690.05778399854921.96980094910.069742001593121.75300025940.064774997532421.5919990540.038768999278521.35910034180.10901600122521.0592994690.13424199819621.2611007690.12302400171821.40999984740.1368629932421.71360015870.52358698844920.8631992340.4811860024935.309825651560.2825943874775.916700966840.38005785056False7.224368598350.4310056679338.379157975470.299199352552False10.38388484571.0426193748513.68611586631.69217120455False11.3647449171.287731211389.908320841431.24899809217False7.491347386723.612638134816.39533543487.26622717638False
5108991496063057127149.606163660.8306820823.24250030520.26686298847223.08580017090.40927600860621.85549926760.057705998420721.9037990570.074941001832521.50600051880.06122300028821.21689987180.10915099829421.2679996490.27305001020421.41220092770.37889900803619.83709907530.16376200318319.69260025020.2252870053051.832313907350.4503642440872.116800510790.79794305493False6.573554878970.3493791086666.287534444010.433985832125False9.06984348120.51143457096511.83695649061.18999036051False11.29276109242.839997890829.888254347853.45079195774False42.1852250066.3628134729648.19032995669.99934889618False
6108991496210977834149.621085860.8310972722.36499977110.097505003213922.51969909670.094539999961921.18199920650.030935000628221.28580093380.034887000918420.48019981380.058100000023820.62520027160.060462001711120.2579002380.038982998579720.45310020450.070638999342919.93129920960.1219279989619.97220039370.1679790019994.111498077780.3692348394863.565499347680.310464279183False12.22363342580.3482780679611.10911919290.356959498807False23.33028663021.2484521081920.41361366611.13678436715False28.63122334391.0279945847423.91993076161.55625276743False38.67945232724.3436961966137.2494481045.76302520824False
7108991496279437194149.627853990.8307055922.5233993530.13296699523922.33329963680.082592003047522.59849929810.10249099880522.51519966130.11083299666621.82559967040.15920400619521.80410003660.1109860017921.29240036010.11964999884421.40760040280.11450400203520.31509971620.24055199325119.73710060120.4316839873793.553368587620.4351708472124.233310709460.322028140431False3.315891265560.3130125036313.58030591080.36548107297False6.757096664690.9908086831326.892233547420.70453710715False11.04179947761.216825310739.930242148311.04726402433False27.16189797076.0178970441546.255114412118.3908320811False
8108991496282748381149.628231830.8315721321.63960075380.033194001764121.41900062560.048918999731520.83790016170.017532000318220.82760047910.032182000577420.22500038150.042537998408120.16399955750.048804998397820.00880050660.028830999508519.93040084840.045942001044819.55290031430.13619099557419.5984001160.1256549954418.019729101340.2451856176219.826520166170.44274431972False16.78185387780.27098614399716.94181005730.50216741291False29.51208189771.1562522160431.21764783161.40326650777False36.01469965830.95634628705938.71146977211.63804281088False54.80748507536.8748614300652.55813590986.08268592243False
9108991496690672394149.668902950.8265782221.03750038150.034880001097920.84399986270.048983998596720.47999954220.022433999925920.46080017090.044399000704320.23999977110.0541860014220.31360054020.049504999071420.19249916080.046675998717520.20509910580.05589900165819.69179916380.14773100614519.92609977720.093084998428813.96367870450.44859250931116.68783722440.752887295827False23.3345904610.48215045089123.75089237190.971245024827False29.10717731671.4526563123727.19942881141.24017942125False30.40887376171.3072830642330.05801920971.5475336074False48.22589924526.5618707256438.86512681373.33208034561False

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 134257 sources.
The cleaned catalogue has 134209 sources (48 removed).
The cleaned catalogue has 48 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_COSMOS.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.001830837663874263 arcsec
Dec correction: -0.00030203157574959505 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)))
10748 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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