Bootes 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).

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_Bootes_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
0146702167456644408216.7456439332.2531923122.17530059810.17141799628722.48850059510.22719499468821.61899948120.22060100734221.8412990570.17434300482321.56279945370.10169699788121.56170082090.081116996705521.50510025020.101635001621.52930068970.09157399833220.75449943540.14254300296321.31760025020.2932739853864.896432374240.7730576017183.669439756110.767846132647False8.173352085261.660670147576.660094281991.06945024439False8.607563167540.8062394248018.616277381310.643735136482False9.07736711450.8497259437068.877276031620.748734045111False18.12175379982.3791499208210.78847103482.91413133572False
1146702166930813304216.6930880332.2522454422.23380088810.36299100518222.41720008850.46714299917222.24600028990.22467400133622.22570037840.3406339883821.95890045170.17274400591921.9867000580.17067599296622.15279960630.62856501340922.44529914860.506998002529nannan21.13459968571.096029996874.639590438811.55114068193.918501024041.6859531004False4.587751480430.9493544359374.674335155711.46650486567False5.976402232870.9508641769185.825322542170.915731376437False4.998965706732.894050076543.818390497571.78304485626Falsenannan12.769095225612.8901581607False
2146702166930832785216.6931102832.2517965822.00060081480.2371769994521.91069984440.12180300056921.55970001220.069706000387721.86540031430.22995600104321.85199928280.13341400027321.8638992310.08455400168921.75769996640.23647299408922.28700065610.24666999280523.163400652.1236200332625.013200759945.02109909065.751215937111.256342132816.24769848510.700896238702False8.632170207930.5541991297926.513881809221.37962260589False6.594779615550.8103588381536.522893797550.50798414086False7.19316485051.566668976984.417735779191.0036718386False1.970787232053.854714643340.35869035266114.8734414853False
3146702167448086199216.744777932.2544629422.8904991150.20548599958422.99259948730.19443899393121.82159996030.12264399975521.9633007050.21321800351121.88240051270.11582600325322.14130020140.08888600021622.74360084530.35471400618622.04269981380.18738199770520.49710083010.3005790114420.09480094910.3384230136872.533963494890.4795769169122.30653582840.413065810991False6.782034830730.766093895075.952230186271.16890514583False6.412683340760.6841030797685.052192844680.413608031413False2.901079711560.9477933979185.532482826050.954824643101False22.96992980266.3590757705833.272054624510.3708699666False
4146702166823058922216.6823081832.2569923222.89940071110.61941099166922.73609924320.90815502405230.2315998077211.66700744622.18029975891.2759599685723.81739997860.477008998394nannan21.61949920650.36306500434921.50069999690.35648900270519.94980049130.37887200713219.82959938050.6437630057332.51327328891.433818908672.92119334612.44340789398False0.00293332427910.5718589555234.873939078395.72786568782False1.07904612270.474069767551nannanFalse8.169591050742.731872251639.114230363062.99255277508False38.025926416613.269299670942.477627076725.1861591825False
5146702167588178685216.7587798432.2567048121.74950027470.15734300017421.66099929810.083494000136920.142200470.044969998300120.24699974060.033700000494719.29100036620.014973999932419.38649940490.013185000047118.90999984740.020503999665419.02009963990.01513299997918.64669990540.039724998176118.79590034480.04757200181487.247694686481.050323293377.863217357980.604687831433False31.85076090891.3192234519328.92012087160.897647221682False69.75893690410.96208481573163.88519695450.775811215617False99.08320841431.8711746585189.52826001441.24784561017False126.2757736124.62018753216110.0626238634.82244150946False
6146702168662162795216.8663886732.2517593322.47229957580.28752100467722.17399978640.22835400700622.07519912720.28283300995822.30520057680.36927801370621.28709983830.097829997539521.2686996460.09171099960820.95949935910.076302997767921.17910003660.11653099954120.45170021060.16956600546820.47680091860.2878049910073.72460455180.9863372318834.902302265911.03106110036False5.369333121991.398704990874.344299610171.47757284316False11.09583690940.99978769501511.28548275850.953272903954False15.00376510561.0544294740712.25631700661.31545845594False23.95079401963.7405407058323.40343648926.20374064969False
7146702167029127789216.7028549732.2560343222.70439910890.20634099841122.93289947510.22118599712821.83429908750.079608000814921.93880081180.17797799408421.79470062260.067399002611621.84700012210.20329099893622.67910003660.61840599775322.26880073550.28945699334121.05209922790.58481401205121.63909912110.365148007873.007740449470.5716122982592.436914039230.496447718442False6.703172025880.4914878234336.08807053310.997979598153False6.952159878030.4315676678396.625214614151.24049146668False3.078647638911.75351448774.492413315381.1976762361False13.77717924827.420851801358.023435238952.69839154385False
8146702169338237034216.9339238632.2553875523.43250083920.63061398267723.62360000611.0704400539423.41690063480.65522497892423.27700042720.47883799672121.02650070190.083829000592221.25650024410.080206997692620.18110084530.059200998395720.33810043330.094112999737319.70789909360.06556899845619.88120079040.05833800137041.538153451370.8933855845331.289911746231.27173911413False1.560413669290.9416854748791.775006015020.78282396836False14.1058648741.0891048393611.41300223580.843116992857False30.7297949151.6755769324926.59254033612.30507533109False47.51605348922.8695552604940.50603035572.17644105819False
9146702167600223181216.7600094232.2521336618.78260040280.0087750004604518.85230064390.0085990000516218.51469993590.0095250001177218.59000015260.00701100006718.40340042110.0040449998341518.49869918820.0084480000659818.40690040590.012064999900818.51140022280.021880999207518.34280014040.039636999368718.38559913640.0241299998015111.4191494610.900497822157104.4912061810.827567399346False142.6001642131.25100975262133.04542310.859123483382False157.993722460.588618651886144.7172578271.12602987569False157.4852331191.75001930822143.0342064582.88258910815False167.0628722696.09896854654160.6054747323.5693845857False

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 230699 sources.
The cleaned catalogue has 230626 sources (73 removed).
The cleaned catalogue has 73 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_Bootes.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.00015850442878218018 arcsec
Dec correction: -0.0003453544650255935 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)))
34850 sources flagged.

V - Flagging objects near bright stars¶

VI - Saving to disk¶

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