ELAIS-N2 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_ELAIS-N2_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
0154982484143831193248.414347539.1504427321.85050010680.088361002504821.89089965820.10478899627921.44109916690.061305001378121.5445003510.071851000189821.28790092470.077719002962121.50519943240.067152999341520.90530014040.11958099901721.08029937740.16573899984420.56089973450.30441400408720.91939926150.3225440084936.603891925110.537447778186.362680806140.614089253355False9.628537656830.5436656820828.753865299840.579306441623False11.08765311130.7936746893239.076537933820.561385669209False15.77175215891.7370719251513.42394762452.04918252102False21.65908502676.0726802412415.56826786594.62492776859False
1154982484155593849248.4155768139.1527202322.72999954220.26703700423222.99040031430.26418998837521.27319908140.065397001802921.21960067750.054916001856320.53730010990.036757998168520.61770057680.04773300141120.09379959110.06043399870420.17340087890.084876000881219.57659912110.10873000323819.82220077510.1292530000212.937650890520.7225157361872.31121248180.562382645086False11.23881098880.67694578045311.80754825170.597219968229False22.13502190290.74938930008920.55510829860.903679005193False33.30275509091.8536902879230.94850312052.41935855746False53.62414139955.3701378313142.76807371295.09138574203False
2154982484724262964248.4724680739.1518934921.3771991730.062001999467621.4475994110.04365399852420.7413997650.058855000883320.83670043950.071883998811220.41419982910.038623999804320.51899909970.037501998245720.2992000580.065886996686520.34329986570.076797999441620.12849998470.11260800063620.30410003660.081151001155410.21222396570.5831787704169.571064337330.384822046666False18.34172146390.9942581155816.80040782471.11231484297False24.79248552590.88196833807522.5112888250.777553802041False27.56258694691.6726126170226.46549697671.87199912201False32.25521983023.3453759755327.43847596362.05082946011False
3154982484950789789248.4951232439.1576626922.51020050050.095362998545222.62070083620.18418300151822.13100051880.12496100366122.18700027470.1430220007921.77000045780.11370699852721.93379974370.12634100019921.54140090940.2074989974521.61219978330.35059699416224.45400047311.784199714720.34849929810.6342369914053.59682907180.3159187324133.248775232040.551118375599False5.100347802490.587016051994.843952660110.638084829577False7.112132137940.7448394877046.116177806790.711705125168False8.778890584321.67776572898.224700395142.65585252088False0.6003434971816.5159176208526.339060555115.386063806False
4154982484459074396248.4457637539.1529976322.14389991760.12454699724922.08069992070.094141997396921.7413997650.1577689945721.92919921880.18065199255921.69319915770.14710299670721.79560089110.11063300073121.62730026250.29567098617621.66360092160.24873200058920.94099998470.32814800739320.68050003050.2411569952965.040110208520.5781612416765.342198631360.463211273091False7.301970835071.061053865556.142148503371.02197141522False7.633440713481.034230966256.946397689410.707815413436False8.111102600942.208840134917.84439819981.79707819368False15.26159787074.612596419819.39992217864.30899045374False
5154982484199681803248.4201221139.1509285520.20240020750.034747000783719.95660018920.029200000688419.89629936220.011667000129819.4834995270.039933998137719.50139999390.028604000806819.31180000310.024547999724719.55750083920.028214000165519.26600074770.026274999603619.47089958190.054639998823419.30540084840.060819000005730.13282969140.96434608361937.78852359831.01629190429False39.94663994550.42925477789958.42519750772.14891215587False57.46984190711.5140578319868.43527216631.54729024872False54.57574392411.4182082547871.38380620251.72750017127False59.10717014052.9745859931568.83980962813.85615618583False
6154982484799019834248.479900439.1576718619.84580039980.0171729996819.94300079350.020721999928418.69969940190.014767999760818.76539993290.019166000187417.79400062560.004091999959217.86529922490.0043390002101717.37509918210.0049370001070217.45039939880.0062270001508317.21059989930.013168999925317.33779907230.010688999667841.84849461810.66191417541238.26482069550.730309635284False120.2597340981.63575251209113.1983318361.99823791422False276.9489671011.04378499778259.3464514461.03644356926False407.3430652681.85224803963380.0495656112.17969032626False473.9800258195.74894978838421.5803607054.15043020188False
7154982485128658777248.5129274939.1568016121.732799530.072696998715421.89109992980.080595999956121.47060012820.079660996794721.49020004270.085386998951421.34480094910.068728998303421.3455009460.066060997545721.09440040590.12325700372521.09070014950.13819800317320.49419975280.20175500214120.59659957890.2504439949997.360040226430.4928018726296.361507273570.472225240068False9.370439235280.6875137133829.202799980780.723748060409False10.52154750470.66603233587510.51476622810.639764929038False13.25073100271.5042746050113.29596735651.69237806648False23.03138731674.2797666477520.95849862434.83444330366False
8154982484231263312248.4231871539.1521488722.33370018010.15469400584722.57939910890.090112000703822.31049919130.56489402055722.21920013430.76449900865622.45420074460.2505260109922.49720001220.34470999240922.08090019230.091585002839623.06319999692.1916999816921.70689964290.718389987946nannan4.231749270190.6029330545283.374740290060.280090686909False4.323150189232.249277201194.70240408813.31110194898False3.787212745370.8738727673533.640155993681.15571180131False5.341213316480.4505468592.161324623034.36291533428False7.537722463444.98742173828nannanFalse
9154982484358937627248.4356408239.1559766321.03499984740.031403001397820.63769912720.048787999898220.7180004120.029400000348719.85869979860.11901299655420.24620056150.054083999246419.76449966430.042493999004420.45199966430.063267000019620.27680015560.076012000441620.24930000310.18933400511719.90749931340.16060599684713.99587519270.40480596144320.17996223330.90679484673False18.74130528830.50748458013741.35424349554.53304625661False28.94141597411.4416646629945.10245005671.76523860898False23.94418913181.3952532923128.13713911051.96987096969False28.85891498375.0325059929539.53668701085.84840866646False

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 231114 sources.
The cleaned catalogue has 231052 sources (62 removed).
The cleaned catalogue has 62 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-N2.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.00037055522170703625 arcsec
Dec correction: -0.0010222747192756287 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)))
48202 sources flagged.

V - Flagging objects near bright stars

VI - Saving to disk

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