Herschel Stripe 82 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_Herschel-Stripe-82_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
096743594852878235359.4853139-9.37670821.43190002440.11144000291821.5366992950.078530997037920.14679908750.026024000719220.26370048520.025979999452819.57990074160.016721000894919.70100021360.023027999326619.27239990230.041205998510119.39789962770.0384909994919.02379989620.078047998249519.13629913330.06220899894839.710464172570.9966823902418.816988655110.637730331662False31.71614283080.7602039245128.47867673620.681450984853False53.46132317110.82333703957747.8189366581.0142191412False70.96431893292.6932468562963.21791219362.24117111997False89.22366148996.4138306756880.44153451654.6090268651False
196743595020681771359.50202269-9.382182124.01119995120.80548501014724.22780036931.2174999713921.93460083010.14146700501422.01169967650.16513100266521.61590003970.0959779992721.57500076290.11534699797621.44770050050.1509020030521.60639953610.19507299363621.31669998170.26139301061622.21780014042.878679990770.9026513157360.6696581554790.7394006913270.82913355619False6.111666784760.7963252877615.69272401240.865813647865False8.196717816180.7245816922478.511374401140.904235744853False9.570173247161.330118960948.268756169091.48563805138False10.79742030722.599499020694.7084714765112.4838635454False
296743595027290782359.50273667-9.3830773523.52020072940.98055201768922.94409942630.88456201553322.29400062560.13511499762522.37980079650.17294999957121.39940071110.084788002073821.46689987180.11924000084421.35359954830.11589899659221.48089981080.17360100150120.3936996460.22052800655420.45179939270.3098219931131.41879519261.281344844812.411905175811.96500742468False4.389345326170.5462343253574.055829422210.646064572367False10.00552117870.7813575219599.402428753731.03261326979False10.4366274421.114077842339.28196818911.48411646076False25.26504881035.1316800758823.94860621176.83389287034False
396743595262620792359.52631104-9.3829990920.22940063480.049074001610320.24909973140.033365998417119.46150016780.020468000322619.43420028690.024592999368919.20949935910.018249999731819.09390068050.02390700019918.88920021060.021556999534418.92919921880.033429998904518.84269905090.063079997897118.83869934080.10560499876729.39271787381.3285163356928.86423870260.887033276262False59.62109291971.1239604461661.13921879731.38486380274False75.19695527241.2639759156483.64495036421.84179162142False100.9996609242.0053210291597.34649350072.99731477759False105.4193610566.12474102326105.80842838210.2915412601False
496743595317835688359.53180398-9.3789139722.59210014340.17897500097822.67620086670.12805600464321.44840049740.056644998490821.46319961550.05390100181120.2546997070.024273000657620.39660072330.027042999863619.82600021360.047141000628520.04420089720.036233998835119.68059921260.079478003084719.85110092160.1110439971093.33549230160.5498294478193.086879334440.364078707749False9.564005143920.4989730052019.434527480430.468373883619False28.71574692460.64197669832625.19763093960.6276105808False42.6186721571.850437373434.8593785971.16335319568False48.72594996833.5668343607941.64468978624.25922318143False
596743595380042987359.53798864-9.381189922.36199951170.20708400011122.9116992950.17565800249621.5646991730.09678100049521.47130012510.15301099419621.0578002930.06420200318121.12260055540.091003000736221.00950050350.17910000681921.01210021970.25458499789220.90390014650.23945799469921.1217994690.4058650135994.122875261380.7863618228282.484965033070.402035035829False8.592515630160.7659247760299.364399863241.31970926901False13.70502660050.81040878764712.91099692921.08215923712False14.32846933542.3635842154214.2942019023.35172516598False15.79210203623.4829317371112.92052653774.82989298502False
696743595384444068359.53845929-9.3802982822.06340026860.14458900690122.35120010380.14603799581521.4080009460.08099400252121.42189979550.064938999712520.90710067750.026402000337820.95389938350.053387999534620.59040069580.12927600741420.69179916380.1348910033720.01819992070.062882997095620.1368007660.06387100368745.42800066980.7228544308124.164088571270.560094751083False9.926579419290.7405052857119.80031605730.586166988664False15.7456186550.38288842835615.08135095980.741582674039False21.07850094872.5097665832419.19907629592.38527798372False35.70425961712.0678971963632.00955920281.8830381311False
796743595451595825359.54517174-9.3788302722.89270019530.057130999863124.47349929814.1404099464424.23620033261.2446700334523.08539962770.34238299727421.82950019840.15794199705121.85840034480.10869099944820.9486007690.10949599742921.10440063480.13404999673420.98390007020.20046399533721.6954002380.1592359989882.528831670540.1330660994730.5896581163472.24863674917False0.7337022771020.8411041593572.117581572060.667771713273False6.73286521850.9794296016166.556013845260.656310155373False15.1551309181.5283879903413.1292448031.62099708496False14.67033299912.708644653327.617981344371.117266666False
896743595457878818359.54573356-9.3762446422.11949920650.17432199418522.21859931950.13622699677921.59009933470.10045100003521.68070030210.14785499870820.8290004730.060862001031620.84709930420.067111000418720.55360031130.10941000282820.57159996030.10298799723420.37789916990.11397700011720.43169975280.09243100136525.154663474860.8276146750524.70500698180.590335818358False8.393831872880.7765871692047.721823651951.05155397884False16.91997865350.94846589231516.64026653541.02856009547False21.80519001142.1973163373921.44667723572.03433423897False25.6354137962.691121055424.39608281122.07688972122False
996743595390387092359.53904034-9.377759323.00040054320.55573701858523.20800018310.8313760161422.91160011290.20158100128222.98999977110.4023529887222.55089950560.24314799904822.60120010380.22052499651922.42989921570.32497000694321.75559997561.13638997078nannannannan2.290022675641.172154312141.891472043841.44834858187False2.485192045290.4614081198272.312065277580.85680699462False3.464497065030.7758657447163.307653124060.671820825788False3.87293594081.159202404837.207091067587.54332955998FalsenannannannanFalse

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 6797876 sources.
The cleaned catalogue has 6795065 sources (2811 removed).
The cleaned catalogue has 2810 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_Herschel-Stripe-82.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, near_ra0=True)
In [10]:
delta_ra, delta_dec =  astrometric_correction(
    SkyCoord(catalogue[RA_COL], catalogue[DEC_COL]),
    gaia_coords, near_ra0=True
)

print("RA correction: {}".format(delta_ra))
print("Dec correction: {}".format(delta_dec))
RA correction: 0.0001763459522408084 arcsec
Dec correction: -0.0009540056027157462 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, near_ra0=True)

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)))
881634 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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