ELAIS-N1 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).

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: 
284b2ef (Mon Aug 14 20:02:12 2017 +0100)
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",
        "gApMag": "m_ap_gpc1_g",
        "gApMagErr": "merr_ap_gpc1_g",
        "gKronMag": "m_gpc1_g",
        "gKronMagErr": "merr_gpc1_g",
        "rApMag": "m_ap_gpc1_r",
        "rApMagErr": "merr_ap_gpc1_r",
        "rKronMag": "m_gpc1_r",
        "rKronMagErr": "merr_gpc1_r",
        "iApMag": "m_ap_gpc1_i",
        "iApMagErr": "merr_ap_gpc1_i",
        "iKronMag": "m_gpc1_i",
        "iKronMagErr": "merr_gpc1_i",
        "zApMag": "m_ap_gpc1_z",
        "zApMagErr": "merr_ap_gpc1_z",
        "zKronMag": "m_gpc1_z",
        "zKronMagErr": "merr_gpc1_z",
        "yApMag": "m_ap_gpc1_y",
        "yApMagErr": "merr_ap_gpc1_y",
        "yKronMag": "m_gpc1_y",
        "yKronMagErr": "merr_gpc1_y"
    })


catalogue = Table.read("../../dmu0/dmu0_PanSTARRS1-3SS/data/PanSTARRS1-3SS_ELAIS-N1.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
0171032431403638729243.1404199852.5317707822.84250068660.0150380004197nannan21.28280067440.0067590000107921.50009918210.051993999630220.49150085450.00306700007059nannan20.038400650.0048110000789220.44129943850.056797999888719.7205009460.003861000062920.10079956050.07282199710612.648498463630.0366830550858nannanFalse11.13985993180.06934862544819.119275308650.436706075516False23.08870942990.0652212509271nannanFalse35.04610356320.15529260815824.18133226891.26499540266False46.96773549420.16702255013933.08873588492.21931240599False
1171032431416139697243.141635352.5323757421.61300086980.0085370000451822.29879951480.09728199988620.97080039980.0058539998717621.54479980470.062203999608821.03879928590.0039459997788121.24399948120.037386000156421.39660072330.00899199955165nannan20.3782005310.00522699998692nannan8.218634220180.06462203286724.36998749380.391551024099False14.84840620980.08005864377278.751451254710.501388153069False13.94698345290.050688918154411.54516668590.397543714239False10.0313575580.0830790778357nannanFalse25.62829932020.123380909308nannanFalse
2171032432095675207243.2096057452.528798721.40940093990.0077720000408621.48320007320.054747000336620.71649932860.0052069998346320.75830078120.033707000315220.56159973140.0031669999007120.56489944460.030656000599320.27890014650.0053739999420920.35650062560.072623997926720.21649932860.0048520001582820.35040092470.122250996539.913787919280.07096563582959.262324042130.467042045048False18.76723397860.09000435261818.05841741950.560628888475False21.64512545990.063136984731621.57944257830.609300308595False28.08276989230.13899951306226.14566845671.74886216696False29.74406137410.13292196563326.29296904562.960518083False
3171032431054219294243.105412652.5322234223.86429977420.024072999134723.50720024110.27637600898722.70009994510.012981000356422.73780059810.14421500265622.13439941410.0065350001677922.21019935610.0949679985642nan0.0294850002974nannan22.29999923710.0126660000533nannan1.033427681290.02291321185411.435885809710.365507190152False3.019673738160.03610304759052.916619403690.387405590056False5.084406138430.03060282490554.741549159120.414737421265FalsenannannannanFalse4.365161389770.0509231746654nannanFalse
4171032431384026127243.1384276952.529576423.45509910580.019938999787nannan23.52249908450.0189580004662nannan22.57439994810.0080030001699922.82509994510.14618399739322.27479934690.0134739996865nannan21.53170013430.00889199972153nannan1.50646954960.0276655562345nannanFalse1.41579497380.0247211446535nannanFalse3.390314762890.02499013066422.691287051990.362356065559False4.467661506210.0554437343715nannanFalse8.857679178970.0725429256643nannanFalse
5171032432016167931243.2016479352.5311042222.28070068360.011610000394322.25760078430.10004299879121.25939941410.0066860001534221.37829971310.053869999945221.01749992370.0039070001803321.09189987180.033923998475121.03210067750.0076029999181621.07620048520.11365199834120.03980064390.0044729998335220.14439964290.09523300081494.443444157220.04751466165654.538994811250.418236630982False11.38256749920.070094234411910.20187774320.506177422339False14.22328887070.051182222660713.28128362530.414975795664False14.03329739780.098269873012613.47472175131.4104982844False35.00094276670.14419636232331.78631206652.78806755238False
6171032432248128083243.224828252.53094605nan0.0197960007936nannan22.97839927670.014755999669423.41220092770.292517006397nan0.012037999928nannan23.4626007080.0232849996537nannannan0.0109459999949nannannannannannanFalse2.336900864870.0317603007421.567182700120.422227415746FalsenannannannanFalse1.496096878440.0320857084287nannanFalsenannannannanFalse
7171082430858384660243.0859331152.5700686nan0.0434119999409nannannan0.0622599981725nannan21.4055004120.0046720001846621.47940063480.044018000364320.38030052190.0056309998035420.49869918820.068862996995419.93300056460.0042579998262220.08029937740.0865150019526nannannannanFalsenannannannanFalse9.949467442140.04281326672469.29479351040.376830230339False25.57877791740.13266030256422.93613967621.45472842361False38.61888886330.15145412057633.71943189522.68687431023False
8171082430918177630243.0919454252.5724957523.60810089110.0213939994574nannan23.9820003510.0234260000288nannan22.0154991150.0061869998462522.15620040890.077928997576221.24419975280.0083830002695321.50709915160.1684850007323.149099350.0187270008028nannan1.308457568290.025782635214nannanFalse0.9272564428550.0200066179629nannanFalse5.672837640370.0323263104384.983332168490.357679958335False11.54303729580.08912412088519.06067054591.40603866468False1.996918130260.0344432535863nannanFalse
9171082431213695601243.1213956652.5707396123.30279922490.0185889992863nannan22.65749931340.012729000300222.42280006410.14431700110421.00699996950.0038880000356621.04249954220.037347998470120.5287990570.0060299998149320.60289955140.10053899884220.19269943240.0047989999875420.48649978640.1650290042161.733326233670.0296764536168nannanFalse3.140510680010.03681885269493.898342335980.518171055493False14.36150693270.051428274402113.89953217240.478126918891False22.309014060.12390058474920.83723930681.92952502584False30.40326515040.13438371902723.19530488923.52562441189False

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 388700 sources.
The cleaned catalogue has 311453 sources (77247 removed).
The cleaned catalogue has 68405 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_ELAIS-N1.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.0001799550204850675 arcsec
Dec correction: -0.0005682078040081251 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)))
53200 sources flagged.

V - Saving to disk

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