In [1]:
% matplotlib inline
from __future__ import (division, 
                        print_function)

import os
import sys
import copy
import glob
import fnmatch
import warnings
import collections

import numpy as np
import scipy
try:
    from scipy.stats import scoreatpercentile
except:
    scoreatpercentile = False
from scipy.interpolate import interp1d
from scipy.ndimage import gaussian_filter
import cPickle as pickle

# Astropy
from astropy.io import fits
from astropy    import units as u
from astropy.stats import sigma_clip
from astropy.table import Table, Column, join
from astropy.utils.console import ProgressBar
from astropy.convolution import convolve, Box1DKernel

# AstroML
from astroML.plotting import hist
from astroML.density_estimation import KNeighborsDensity
try:
    from sklearn.neighbors import KernelDensity
    use_sklearn_KDE = True
except:
    import warnings
    warnings.warn("KDE will be removed in astroML version 0.3.  Please "
                  "upgrade to scikit-learn 0.14+ and use "
                  "sklearn.neighbors.KernelDensity.", DeprecationWarning)
    from astroML.density_estimation import KDE
    use_sklearn_KDE = False
from sklearn.neighbors import KDTree
from sklearn.neighbors import BallTree

# Matplotlib related
import matplotlib as mpl
mpl.style.use('classic')
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.patches import Ellipse
from matplotlib.ticker import NullFormatter, MaxNLocator, FormatStrFormatter
from matplotlib.collections import PatchCollection

# Personal
import hscUtils as hUtil

# Cosmology
import cosmology
c=cosmology.Cosmo(H0=70.0, omega_m=0.3, omega_l=0.7, flat=1)

import emcee
import corner

# Color map 
from palettable.colorbrewer.sequential import Greys_9, OrRd_9, Blues_9, Purples_9, YlGn_9
BLK = Greys_9.mpl_colormap
ORG = OrRd_9.mpl_colormap
BLU = Blues_9.mpl_colormap
GRN = YlGn_9.mpl_colormap
PUR = Purples_9.mpl_colormap

# Personal tools
from hscUtils import songPlotSetup, removeIsNullCol
from hscUtils import confidence_interval, ma_confidence_interval_1d, confidence_interval_1d

## Constants
# SDSS pivot wavelength 
sdss_u_pivot = 3551.0
sdss_g_pivot = 4686.0
sdss_r_pivot = 6165.0
sdss_i_pivot = 7481.0
sdss_z_pivot = 8931.0

# HSC pivot wavelength 
hsc_g_pivot = 4782.2
hsc_r_pivot = 6101.7 
hsc_i_pivot = 7648.0 
hsc_z_pivot = 8883.0
hsc_y_pivot = 9750.8

hscFiltWave = np.asarray([hsc_g_pivot, hsc_r_pivot, hsc_i_pivot, hsc_z_pivot, hsc_y_pivot])

"""
Absolute magnitude of the Sun in HSC filters
Right now, just use the DES filters
"""
SUN_G = 5.08
SUN_R = 4.62
SUN_I = 4.52
SUN_Z = 4.52
SUN_Y = 4.51

# Solar stellar metallicity 
Z_SUN = 0.02

# definitions for the axes
left, width    = 0.15, 0.64
right          = left + width 
bottom, height = 0.13, 0.86
bottom_h = left_h = left + width + 0.02
recScat = [0.16, 0.11, 0.59, 0.88]
recHist = [0.75, 0.11, 0.24, 0.88]
SBP1 = [0.124, 0.085, 0.865, 0.33]
SBP2 = [0.124, 0.41, 0.865, 0.55]
EC1 = [0.19, 0.14, 0.65, 0.65]
EC2 = [0.19, 0.79, 0.65, 0.18]
EC3 = [0.84, 0.14, 0.157, 0.65]
REC = [0.12, 0.11, 0.87, 0.87]
COG1 = [0.143, 0.10, 0.850, 0.43]
COG2 = [0.143, 0.53, 0.850, 0.43]

# Universal RSMA array
RSMA_COMMON = np.arange(0.4, 4.2, 0.01)
RR50_COMMON = np.arange(0.0, 9.0, 0.01)
EMPTY = (RSMA_COMMON * np.nan)

# Color 
BLUE0 = "#92c5de"
BLUE1 = "#0571b0"
RED0 = "#f4a582"
RED1 = "#ca0020"
PURPLE0 = '#af8dc3'
PURPLE1 = '#762a83'
BROWN0 = '#bf812d'
BROWN1 = '#543005'
GREEN0 = '#7fbf7b'
GREEN1 = '#1b7837'

# Color maps for different filters
from palettable.colorbrewer.sequential import Blues_9, Greens_9, Reds_9, Purples_9, Greys_9
GCMAP = Blues_9.mpl_colormap
RCMAP = Greens_9.mpl_colormap
ICMAP = Reds_9.mpl_colormap
ZCMAP = Purples_9.mpl_colormap
YCMAP = Greys_9.mpl_colormap

# 3-sigma
SIGMA1 = 0.3173
SIGMA2 = 0.0455
SIGMA3 = 0.0027

#import seaborn as sns
#sns.set(color_codes=False)

Location and Files


In [2]:
# Location of the data
homeDir = os.getenv('HOME')
synpipeDir = os.path.join(homeDir, 'astro4/synpipe/')
sampleDir = os.path.join(synpipeDir, 'sample/cosmos')

# Samples
#cosPhoFile = os.path.join(sampleDir, 'cosmos_mag25.2_shuang_photo.fits')
#cosHscFile = os.path.join(sampleDir, 'cosmos_mag25.2_shuang_photo_hscmatch.fits')

#cosPho = Table.read(cosPhoFile, format='fits')
#cosHsc = Table.read(cosHscFile, format='fits')

# Outputs 
figDir = os.path.join(synpipeDir, 'figure')
outDir = os.path.join(synpipeDir, 'outputs')
inDir = os.path.join(synpipeDir, 'inputs')

starDir = os.path.join(outDir, 'star')
galaxyDir = os.path.join(outDir, 'galaxy')

Test outputs for stars


In [3]:
glob.glob(inDir + '/*star*')


Out[3]:
['/Users/song/astro4/synpipe/inputs/cosmos_mag25.2_star_xdgmm.fits',
 '/Users/song/astro4/synpipe/inputs/dr1_s16a_star_vvds_i26.5_input.fits',
 '/Users/song/astro4/synpipe/inputs/dr1_s16a_star_vvds_i26.5_use.fits',
 '/Users/song/astro4/synpipe/inputs/star_8764_HSC-G.fits',
 '/Users/song/astro4/synpipe/inputs/star_8764_HSC-I.fits',
 '/Users/song/astro4/synpipe/inputs/star_8764_HSC-R.fits',
 '/Users/song/astro4/synpipe/inputs/star_8764_HSC-Y.fits',
 '/Users/song/astro4/synpipe/inputs/star_8764_HSC-Z.fits',
 '/Users/song/astro4/synpipe/inputs/star_9699_HSC-G.fits',
 '/Users/song/astro4/synpipe/inputs/star_9699_HSC-I.fits',
 '/Users/song/astro4/synpipe/inputs/star_9699_HSC-R.fits',
 '/Users/song/astro4/synpipe/inputs/star_9699_HSC-Y.fits',
 '/Users/song/astro4/synpipe/inputs/star_9699_HSC-Z.fits']

In [4]:
glob.glob(starDir + '/*syn.fits')


Out[4]:
['/Users/song/astro4/synpipe/outputs/star/star1_HSC-Z_syn.fits',
 '/Users/song/astro4/synpipe/outputs/star/star1_HSC-G_syn.fits',
 '/Users/song/astro4/synpipe/outputs/star/star1_HSC-I_syn.fits',
 '/Users/song/astro4/synpipe/outputs/star/star2_HSC-G_syn.fits',
 '/Users/song/astro4/synpipe/outputs/star/star2_HSC-I_syn.fits',
 '/Users/song/astro4/synpipe/outputs/star/star2_HSC-R_syn.fits',
 '/Users/song/astro4/synpipe/outputs/star/star2_HSC-Y_syn.fits',
 '/Users/song/astro4/synpipe/outputs/star/star2_HSC-Z_syn.fits',
 '/Users/song/astro4/synpipe/outputs/star/star1_HSC-R_syn.fits',
 '/Users/song/astro4/synpipe/outputs/star/star1_HSC-Y_syn.fits']

Input catalogs


In [4]:
inputG1 = Table.read(os.path.join(inDir, 'star_8764_HSC-G.fits'), format='fits')
inputG2 = Table.read(os.path.join(inDir, 'star_9699_HSC-G.fits'), format='fits')

inputR1 = Table.read(os.path.join(inDir, 'star_8764_HSC-R.fits'), format='fits')
inputR2 = Table.read(os.path.join(inDir, 'star_9699_HSC-R.fits'), format='fits')

inputI1 = Table.read(os.path.join(inDir, 'star_8764_HSC-I.fits'), format='fits')
inputI2 = Table.read(os.path.join(inDir, 'star_9699_HSC-I.fits'), format='fits')

inputZ1 = Table.read(os.path.join(inDir, 'star_8764_HSC-Z.fits'), format='fits')
inputZ2 = Table.read(os.path.join(inDir, 'star_9699_HSC-Z.fits'), format='fits')

inputY1 = Table.read(os.path.join(inDir, 'star_8764_HSC-Y.fits'), format='fits')
inputY2 = Table.read(os.path.join(inDir, 'star_9699_HSC-Y.fits'), format='fits')

In [8]:
print(inputG1.colnames)


['RA', 'Dec', 'modelID', 'mag_G', 'mag_R', 'mag_I', 'mag_Z', 'mag_Y', 'ID', 'mag']

In [5]:
print(len(inputG1), len(inputG2))


120363 119616

Matches with the Synthetic-added images


In [5]:
starG1 = os.path.join(starDir, 'star1_HSC-G_syn.fits') 
starR1 = os.path.join(starDir, 'star1_HSC-R_syn.fits') 
starI1 = os.path.join(starDir, 'star1_HSC-I_syn.fits') 
starZ1 = os.path.join(starDir, 'star1_HSC-Z_syn.fits') 
starY1 = os.path.join(starDir, 'star1_HSC-Y_syn.fits') 

starG2 = os.path.join(starDir, 'star2_HSC-G_syn.fits') 
starR2 = os.path.join(starDir, 'star2_HSC-R_syn.fits') 
starI2 = os.path.join(starDir, 'star2_HSC-I_syn.fits') 
starZ2 = os.path.join(starDir, 'star2_HSC-Z_syn.fits') 
starY2 = os.path.join(starDir, 'star2_HSC-Y_syn.fits')

In [6]:
catG1 = Table.read(starG1, format='fits')
catR1 = Table.read(starR1, format='fits')
catI1 = Table.read(starI1, format='fits')
catZ1 = Table.read(starZ1, format='fits')
catY1 = Table.read(starY1, format='fits')

catG2 = Table.read(starG2, format='fits')
catR2 = Table.read(starR2, format='fits')
catI2 = Table.read(starI2, format='fits')
catZ2 = Table.read(starZ2, format='fits')
catY2 = Table.read(starY2, format='fits')

Matches with the Original images


In [7]:
oriG1 = os.path.join(starDir, 'star1_HSC-G_ori.fits') 
oriR1 = os.path.join(starDir, 'star1_HSC-R_ori.fits') 
oriI1 = os.path.join(starDir, 'star1_HSC-I_ori.fits') 
oriZ1 = os.path.join(starDir, 'star1_HSC-Z_ori.fits') 
oriY1 = os.path.join(starDir, 'star1_HSC-Y_ori.fits') 

oriG2 = os.path.join(starDir, 'star2_HSC-G_ori.fits') 
oriR2 = os.path.join(starDir, 'star2_HSC-R_ori.fits') 
oriI2 = os.path.join(starDir, 'star2_HSC-I_ori.fits') 
oriZ2 = os.path.join(starDir, 'star2_HSC-Z_ori.fits') 
oriY2 = os.path.join(starDir, 'star2_HSC-Y_ori.fits')

In [8]:
oriG1 = Table.read(oriG1, format='fits')
oriR1 = Table.read(oriR1, format='fits')
oriI1 = Table.read(oriI1, format='fits')
oriZ1 = Table.read(oriZ1, format='fits')
oriY1 = Table.read(oriY1, format='fits')

oriG2 = Table.read(oriG2, format='fits')
oriR2 = Table.read(oriR2, format='fits')
oriI2 = Table.read(oriI2, format='fits')
oriZ2 = Table.read(oriZ2, format='fits')
oriY2 = Table.read(oriY2, format='fits')

Useful columns


In [9]:
print("# Number of columns : %d" % len(catG1.colnames))
print("\n# Columns related to flux")
print([col for col in catG1.colnames if 'flux' in col])
print("\n# Columns related to mag")
print([col for col in catG1.colnames if 'mag' in col])
print("\n# Columns related to coord")
print([col for col in catG1.colnames if 'coord' in col])
print("\n# Columns related to fake")
print([col for col in catG1.colnames if 'fake' in col.lower()])
print("\n# Columns related to id")
print([col for col in catG1.colnames if 'id' in col.lower()])
print("\n# Columns related to blend")
print([col for col in catG1.colnames if 'blend' in col.lower()])
print("\n# Columns related to flag")
print([col for col in catG1.colnames if 'flag' in col.lower()])


# Number of columns : 356

# Columns related to flux
['blendedness.abs.flux', 'blendedness.abs.flux.child', 'blendedness.abs.flux.parent', 'blendedness.raw.flux', 'blendedness.raw.flux.child', 'blendedness.raw.flux.parent', 'cmodel.dev.flux', 'cmodel.dev.flux.apcorr', 'cmodel.dev.flux.apcorr.err', 'cmodel.dev.flux.err', 'cmodel.dev.flux.flags', 'cmodel.dev.flux.flags.apcorr', 'cmodel.dev.flux.inner', 'cmodel.exp.flux', 'cmodel.exp.flux.apcorr', 'cmodel.exp.flux.apcorr.err', 'cmodel.exp.flux.err', 'cmodel.exp.flux.flags', 'cmodel.exp.flux.flags.apcorr', 'cmodel.exp.flux.inner', 'cmodel.flux', 'cmodel.flux.apcorr', 'cmodel.flux.apcorr.err', 'cmodel.flux.err', 'cmodel.flux.flags', 'cmodel.flux.flags.apcorr', 'cmodel.flux.inner', 'cmodel.initial.flux', 'cmodel.initial.flux.err', 'cmodel.initial.flux.flags', 'cmodel.initial.flux.inner', 'deblend.has.stray.flux', 'deblend.psf-flux', 'flux.aperture', 'flux.aperture.err', 'flux.aperture.flags', 'flux.aperture.nInterpolatedPixel', 'flux.aperture.nProfile', 'flux.gaussian', 'flux.gaussian.apcorr', 'flux.gaussian.apcorr.err', 'flux.gaussian.err', 'flux.gaussian.flags', 'flux.gaussian.flags.apcorr', 'flux.kron', 'flux.kron.apcorr', 'flux.kron.apcorr.err', 'flux.kron.err', 'flux.kron.flags', 'flux.kron.flags.apcorr', 'flux.kron.flags.badShape', 'flux.kron.flags.edge', 'flux.kron.flags.radius', 'flux.kron.flags.smallRadius', 'flux.kron.flags.usedMinimumRadius', 'flux.kron.flags.usedPsfRadius', 'flux.kron.psfRadius', 'flux.kron.radius', 'flux.kron.radiusForRadius', 'flux.naive', 'flux.naive.err', 'flux.naive.flags', 'flux.psf', 'flux.psf.apcorr', 'flux.psf.apcorr.err', 'flux.psf.err', 'flux.psf.flags', 'flux.psf.flags.apcorr', 'flux.sinc', 'flux.sinc.err', 'flux.sinc.flags', 'force.cmodel.dev.flux', 'force.cmodel.dev.flux.apcorr', 'force.cmodel.dev.flux.apcorr.err', 'force.cmodel.dev.flux.err', 'force.cmodel.exp.flux', 'force.cmodel.exp.flux.apcorr', 'force.cmodel.exp.flux.apcorr.err', 'force.cmodel.exp.flux.err', 'force.cmodel.flux', 'force.cmodel.flux.apcorr', 'force.cmodel.flux.apcorr.err', 'force.cmodel.flux.err', 'force.flux.kron', 'force.flux.kron.apcorr', 'force.flux.kron.apcorr.err', 'force.flux.kron.err', 'force.flux.psf', 'force.flux.psf.apcorr', 'force.flux.psf.apcorr.err', 'force.flux.psf.err']

# Columns related to mag
['flags.pixel.offimage', 'cmodel.dev.mag', 'cmodel.dev.mag.err', 'cmodel.dev.mag.apcorr', 'cmodel.dev.mag.apcorr.err', 'cmodel.exp.mag', 'cmodel.exp.mag.err', 'cmodel.exp.mag.apcorr', 'cmodel.exp.mag.apcorr.err', 'cmodel.mag', 'cmodel.mag.err', 'cmodel.mag.apcorr', 'cmodel.mag.apcorr.err', 'cmodel.initial.mag', 'cmodel.initial.mag.err', 'mag.aperture', 'mag.aperture.err', 'mag.gaussian', 'mag.gaussian.err', 'mag.gaussian.apcorr', 'mag.gaussian.apcorr.err', 'mag.kron', 'mag.kron.err', 'mag.kron.apcorr', 'mag.kron.apcorr.err', 'mag.naive', 'mag.naive.err', 'mag.psf', 'mag.psf.err', 'mag.psf.apcorr', 'mag.psf.apcorr.err', 'mag.sinc', 'mag.sinc.err', 'force.cmodel.dev.mag', 'force.cmodel.dev.mag.err', 'force.cmodel.dev.mag.apcorr', 'force.cmodel.dev.mag.apcorr.err', 'force.cmodel.exp.mag', 'force.cmodel.exp.mag.err', 'force.cmodel.exp.mag.apcorr', 'force.cmodel.exp.mag.apcorr.err', 'force.cmodel.mag', 'force.cmodel.mag.err', 'force.cmodel.mag.apcorr', 'force.cmodel.mag.apcorr.err', 'force.mag.kron', 'force.mag.kron.err', 'force.mag.kron.apcorr', 'force.mag.kron.apcorr.err', 'force.mag.psf', 'force.mag.psf.err', 'force.mag.psf.apcorr', 'force.mag.psf.apcorr.err', 'mag_G', 'mag_R', 'mag_I', 'mag_Z', 'mag_Y', 'mag']

# Columns related to coord
['coord_ra', 'coord_dec']

# Columns related to fake
['fakeClosest', 'fakeId', 'fakeOffR', 'fakeOffX', 'fakeOffY']

# Columns related to id
['blendedness.flags.noCentroid', 'centroid.distorted', 'centroid.naive', 'centroid.naive.err', 'centroid.naive.flags', 'centroid.sdss', 'centroid.sdss.err', 'centroid.sdss.flags', 'cmodel.flags.badCentroid', 'fakeId', 'flags.badcentroid', 'id', 'shape.hsm.moments.centroid', 'shape.hsm.moments.centroid.err', 'shape.hsm.moments.centroid.flags', 'shape.hsm.psfMoments.centroid', 'shape.hsm.psfMoments.centroid.err', 'shape.hsm.psfMoments.centroid.flags', 'shape.sdss.centroid', 'shape.sdss.centroid.err', 'shape.sdss.centroid.flags', 'modelID']

# Columns related to blend
['blendedness.abs.flux', 'blendedness.abs.flux.child', 'blendedness.abs.flux.parent', 'blendedness.abs.shape.child_a', 'blendedness.abs.shape.child_q', 'blendedness.abs.shape.child_theta', 'blendedness.abs.shape.parent_a', 'blendedness.abs.shape.parent_q', 'blendedness.abs.shape.parent_theta', 'blendedness.flags', 'blendedness.flags.noCentroid', 'blendedness.flags.noShape', 'blendedness.old', 'blendedness.raw.flux', 'blendedness.raw.flux.child', 'blendedness.raw.flux.parent', 'blendedness.raw.shape.child_a', 'blendedness.raw.shape.child_q', 'blendedness.raw.shape.child_theta', 'blendedness.raw.shape.parent_a', 'blendedness.raw.shape.parent_q', 'blendedness.raw.shape.parent_theta', 'deblend.deblended-as-psf', 'deblend.has.stray.flux', 'deblend.masked', 'deblend.nchild', 'deblend.parent-too-big', 'deblend.patched.template', 'deblend.psf-center', 'deblend.psf-flux', 'deblend.ramped.template', 'deblend.skipped', 'deblend.too-many-peaks', 'force.deblend.nchild']

# Columns related to flag
['blendedness.flags', 'blendedness.flags.noCentroid', 'blendedness.flags.noShape', 'centroid.naive.flags', 'centroid.sdss.flags', 'cmodel.dev.flags.maxIter', 'cmodel.dev.flags.numericError', 'cmodel.dev.flags.trSmall', 'cmodel.dev.flux.flags', 'cmodel.dev.flux.flags.apcorr', 'cmodel.exp.flags.maxIter', 'cmodel.exp.flags.numericError', 'cmodel.exp.flags.trSmall', 'cmodel.exp.flux.flags', 'cmodel.exp.flux.flags.apcorr', 'cmodel.flags.badCentroid', 'cmodel.flags.noCalib', 'cmodel.flags.noPsf', 'cmodel.flags.noShape', 'cmodel.flags.noWcs', 'cmodel.flags.region.maxArea', 'cmodel.flags.region.maxBadPixelFraction', 'cmodel.flags.region.usedFootprintArea', 'cmodel.flags.region.usedInitialEllipseMax', 'cmodel.flags.region.usedInitialEllipseMin', 'cmodel.flags.region.usedPsfArea', 'cmodel.flags.smallShape', 'cmodel.flux.flags', 'cmodel.flux.flags.apcorr', 'cmodel.initial.flags.maxIter', 'cmodel.initial.flags.numericError', 'cmodel.initial.flags.trSmall', 'cmodel.initial.flux.flags', 'flags.badcentroid', 'flags.negative', 'flags.pixel.bad', 'flags.pixel.bright.object.any', 'flags.pixel.bright.object.center', 'flags.pixel.clipped.any', 'flags.pixel.cr.any', 'flags.pixel.cr.center', 'flags.pixel.edge', 'flags.pixel.interpolated.any', 'flags.pixel.interpolated.center', 'flags.pixel.offimage', 'flags.pixel.saturated.any', 'flags.pixel.saturated.center', 'flags.pixel.suspect.any', 'flags.pixel.suspect.center', 'flux.aperture.flags', 'flux.gaussian.flags', 'flux.gaussian.flags.apcorr', 'flux.kron.flags', 'flux.kron.flags.apcorr', 'flux.kron.flags.badShape', 'flux.kron.flags.edge', 'flux.kron.flags.radius', 'flux.kron.flags.smallRadius', 'flux.kron.flags.usedMinimumRadius', 'flux.kron.flags.usedPsfRadius', 'flux.naive.flags', 'flux.psf.flags', 'flux.psf.flags.apcorr', 'flux.sinc.flags', 'multishapelet.psf.flags', 'multishapelet.psf.flags.constraint.q', 'multishapelet.psf.flags.constraint.r', 'multishapelet.psf.flags.maxiter', 'multishapelet.psf.flags.tinystep', 'shape.hsm.moments.centroid.flags', 'shape.hsm.moments.flags', 'shape.hsm.psfMoments.centroid.flags', 'shape.hsm.psfMoments.flags', 'shape.hsm.regauss.flags', 'shape.sdss.centroid.flags', 'shape.sdss.flags', 'shape.sdss.flags.maxiter', 'shape.sdss.flags.psf', 'shape.sdss.flags.shift', 'shape.sdss.flags.unweighted', 'shape.sdss.flags.unweightedbad']

Selection of Useful Stars

Remove the ambiguously blended stars

Generate new catalogs


In [10]:
# HSC-G
print(len(oriG1), len(oriR1), len(oriI1), len(oriZ1), len(oriY1))
print("# HSC-G band")
ambG1 = oriG1[oriG1['id'] > 0]
ambG2 = oriG2[oriG2['id'] > 0]
print("## Star1: %d fake stars got ambiguously blended with real objects" % len(ambG1))
print("## Star2: %d fake stars got ambiguously blended with real objects" % len(ambG2))

# HSC-R
print("\n# HSC-R band")
ambR1 = oriR1[oriR1['id'] > 0]
ambR2 = oriR2[oriR2['id'] > 0]
print("## Star1: %d fake stars got ambiguously blended with real objects" % len(ambR1))
print("## Star2: %d fake stars got ambiguously blended with real objects" % len(ambR2))

# HSC-I
print("\n# HSC-I band")
ambI1 = oriI1[oriI1['id'] > 0]
ambI2 = oriI2[oriI2['id'] > 0]
print("## Star1: %d fake stars got ambiguously blended with real objects" % len(ambI1))
print("## Star2: %d fake stars got ambiguously blended with real objects" % len(ambI2))

# HSC-Z
print("\n# HSC-Z band")
ambZ1 = oriZ1[oriZ1['id'] > 0]
ambZ2 = oriZ2[oriZ2['id'] > 0]
print("## Star1: %d fake stars got ambiguously blended with real objects" % len(ambZ1))
print("## Star2: %d fake stars got ambiguously blended with real objects" % len(ambZ2))

# HSC-Y
print("\n# HSC-Y band")
ambY1 = oriY1[oriY1['id'] > 0]
ambY2 = oriY2[oriY2['id'] > 0]
print("## Star1: %d fake stars got ambiguously blended with real objects" % len(ambY1))
print("## Star2: %d fake stars got ambiguously blended with real objects" % len(ambY2))


132365 132393 132394 132394 132391
# HSC-G band
## Star1: 4667 fake stars got ambiguously blended with real objects
## Star2: 3719 fake stars got ambiguously blended with real objects

# HSC-R band
## Star1: 4725 fake stars got ambiguously blended with real objects
## Star2: 3740 fake stars got ambiguously blended with real objects

# HSC-I band
## Star1: 4679 fake stars got ambiguously blended with real objects
## Star2: 3756 fake stars got ambiguously blended with real objects

# HSC-Z band
## Star1: 4688 fake stars got ambiguously blended with real objects
## Star2: 3684 fake stars got ambiguously blended with real objects

# HSC-Y band
## Star1: 4732 fake stars got ambiguously blended with real objects
## Star2: 3735 fake stars got ambiguously blended with real objects

In [13]:
useG1 = copy.deepcopy(catG1)
useG2 = copy.deepcopy(catG2)
useG1.remove_rows(np.nonzero(np.in1d(useG1['fakeId'], ambG1['fakeId']))[0])
useG2.remove_rows(np.nonzero(np.in1d(useG2['fakeId'], ambG2['fakeId']))[0])

useR1 = copy.deepcopy(catR1)
useR2 = copy.deepcopy(catR2)
useR1.remove_rows(np.nonzero(np.in1d(useR1['fakeId'], ambR1['fakeId']))[0])
useR2.remove_rows(np.nonzero(np.in1d(useR2['fakeId'], ambR2['fakeId']))[0])

useI1 = copy.deepcopy(catI1)
useI2 = copy.deepcopy(catI2)
useI1.remove_rows(np.nonzero(np.in1d(useI1['fakeId'], ambI1['fakeId']))[0])
useI2.remove_rows(np.nonzero(np.in1d(useI2['fakeId'], ambI2['fakeId']))[0])

useZ1 = copy.deepcopy(catZ1)
useZ2 = copy.deepcopy(catZ2)
useZ1.remove_rows(np.nonzero(np.in1d(useZ1['fakeId'], ambZ1['fakeId']))[0])
useZ2.remove_rows(np.nonzero(np.in1d(useZ2['fakeId'], ambZ2['fakeId']))[0])

useY1 = copy.deepcopy(catY1)
useY2 = copy.deepcopy(catY2)
useY1.remove_rows(np.nonzero(np.in1d(useY1['fakeId'], ambY1['fakeId']))[0])
useY2.remove_rows(np.nonzero(np.in1d(useY2['fakeId'], ambY2['fakeId']))[0])

Write the tables


In [30]:
useG1.write(os.path.join(starDir, 'star1_HSC-G_use.fits'), format='fits', overwrite=True)
useG2.write(os.path.join(starDir, 'star2_HSC-G_use.fits'), format='fits', overwrite=True)

useR1.write(os.path.join(starDir, 'star1_HSC-R_use.fits'), format='fits', overwrite=True)
useR2.write(os.path.join(starDir, 'star2_HSC-R_use.fits'), format='fits', overwrite=True)

useI1.write(os.path.join(starDir, 'star1_HSC-I_use.fits'), format='fits', overwrite=True)
useI2.write(os.path.join(starDir, 'star2_HSC-I_use.fits'), format='fits', overwrite=True)

useZ1.write(os.path.join(starDir, 'star1_HSC-Z_use.fits'), format='fits', overwrite=True)
useZ2.write(os.path.join(starDir, 'star2_HSC-Z_use.fits'), format='fits', overwrite=True)

useY1.write(os.path.join(starDir, 'star1_HSC-Y_use.fits'), format='fits', overwrite=True)
useY2.write(os.path.join(starDir, 'star2_HSC-Y_use.fits'), format='fits', overwrite=True)

Read the available tables


In [12]:
useG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_use.fits'), format='fits')
useG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_use.fits'), format='fits')

useR1 = Table.read(os.path.join(starDir, 'star1_HSC-R_use.fits'), format='fits')
useR2 = Table.read(os.path.join(starDir, 'star2_HSC-R_use.fits'), format='fits')

useI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_use.fits'), format='fits')
useI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_use.fits'), format='fits')

useZ1 = Table.read(os.path.join(starDir, 'star1_HSC-Z_use.fits'), format='fits')
useZ2 = Table.read(os.path.join(starDir, 'star2_HSC-Z_use.fits'), format='fits')

useY1 = Table.read(os.path.join(starDir, 'star1_HSC-Y_use.fits'), format='fits')
useY2 = Table.read(os.path.join(starDir, 'star2_HSC-Y_use.fits'), format='fits')

Select matched ones, isolate the unmatched ones

Generate new catalogs


In [14]:
# Star1 
print("# HSC-G band")
print("# Star1 catalog has %d objects" % len(useG1))

# Matched ones 
matchG1 = useG1[useG1['id'] > 0]
unMatchG1 = useG1[useG1['id'] == 0]
print("## %d synthetic stars are matched" % len(matchG1))
print("## %d synthetic stars are not matched" % len(unMatchG1))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchG1['mag_I']), 
                                                                             np.median(matchG1['mag_I'])))

# Star2
print("# \nStar2 catalog has %d objects" % len(useG2))

# Matched ones 
matchG2 = useG2[useG2['id'] > 0]
unMatchG2 = useG2[useG2['id'] == 0]
print("## %d synthetic stars are matched" % len(matchG2))
print("## %d synthetic stars are not matched" % len(unMatchG2))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchG2['mag_I']), 
                                                                             np.median(matchG2['mag_I'])))


# HSC-G band
# Star1 catalog has 188443 objects
## 186392 synthetic stars are matched
## 2051 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.720, 21.313
# 
Star2 catalog has 190551 objects
## 187580 synthetic stars are matched
## 2971 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.771, 21.308

In [15]:
# Star1 
print("# HSC-R band")
print("# Star1 catalog has %d objects" % len(useR1))

# Matched ones 
matchR1 = useR1[useR1['id'] > 0]
unMatchR1 = useR1[useR1['id'] == 0]
print("## %d synthetic stars are matched" % len(matchR1))
print("## %d synthetic stars are not matched" % len(unMatchR1))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchR1['mag_I']), 
                                                                             np.median(matchR1['mag_I'])))

# Star2
print("# \nStar2 catalog has %d objects" % len(useR2))

# Matched ones 
matchR2 = useR2[useR2['id'] > 0]
unMatchR2 = useR2[useR2['id'] == 0]
print("## %d synthetic stars are matched" % len(matchR2))
print("## %d synthetic stars are not matched" % len(unMatchR2))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchR2['mag_I']), 
                                                                             np.median(matchR2['mag_I'])))


# HSC-R band
# Star1 catalog has 188933 objects
## 187264 synthetic stars are matched
## 1669 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.741, 21.322
# 
Star2 catalog has 191009 objects
## 188448 synthetic stars are matched
## 2561 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.821, 21.314

In [16]:
# Star1 
print("# HSC-I band")
print("# Star1 catalog has %d objects" % len(useI1))

# Matched ones 
matchI1 = useI1[useI1['id'] > 0]
unMatchI1 = useI1[useI1['id'] == 0]
print("## %d synthetic stars are matched" % len(matchI1))
print("## %d synthetic stars are not matched" % len(unMatchI1))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchI1['mag_I']), 
                                                                             np.median(matchI1['mag_I'])))

# Star2
print("# \nStar2 catalog has %d objects" % len(useI2))

# Matched ones 
matchI2 = useI2[useI2['id'] > 0]
unMatchI2 = useI2[useI2['id'] == 0]
print("## %d synthetic stars are matched" % len(matchI2))
print("## %d synthetic stars are not matched" % len(unMatchI2))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchI2['mag_I']), 
                                                                             np.median(matchI2['mag_I'])))


# HSC-I band
# Star1 catalog has 189031 objects
## 187439 synthetic stars are matched
## 1592 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.813, 21.320
# 
Star2 catalog has 191034 objects
## 188573 synthetic stars are matched
## 2461 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.862, 21.316

In [17]:
# Star1 
print("# HSC-Z band")
print("# Star1 catalog has %d objects" % len(useZ1))

# Matched ones 
matchZ1 = useZ1[useZ1['id'] > 0]
unMatchZ1 = useZ1[useZ1['id'] == 0]
print("## %d synthetic stars are matched" % len(matchZ1))
print("## %d synthetic stars are not matched" % len(unMatchZ1))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchZ1['mag_I']), 
                                                                             np.median(matchZ1['mag_I'])))

# Star2
print("# \nStar2 catalog has %d objects" % len(useZ2))

# Matched ones 
matchZ2 = useZ2[useZ2['id'] > 0]
unMatchZ2 = useZ2[useZ2['id'] == 0]
print("## %d synthetic stars are matched" % len(matchZ2))
print("## %d synthetic stars are not matched" % len(unMatchZ2))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchZ2['mag_I']), 
                                                                             np.median(matchZ2['mag_I'])))


# HSC-Z band
# Star1 catalog has 188985 objects
## 187421 synthetic stars are matched
## 1564 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.819, 21.323
# 
Star2 catalog has 191178 objects
## 188764 synthetic stars are matched
## 2414 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.850, 21.315

In [18]:
# Star1 
print("# HSC-Y band")
print("# Star1 catalog has %d objects" % len(useY1))

# Matched ones 
matchY1 = useY1[useY1['id'] > 0]
unMatchY1 = useY1[useY1['id'] == 0]
print("## %d synthetic stars are matched" % len(matchY1))
print("## %d synthetic stars are not matched" % len(unMatchY1))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchY1['mag_I']), 
                                                                             np.median(matchY1['mag_I'])))

# Star2
print("# \nStar2 catalog has %d objects" % len(useY2))

# Matched ones 
matchY2 = useY2[useY2['id'] > 0]
unMatchY2 = useY2[useY2['id'] == 0]
print("## %d synthetic stars are matched" % len(matchY2))
print("## %d synthetic stars are not matched" % len(unMatchY2))
# Median I-band magntiudes of the unmatched and matched ones
print("## Median magnitude for unmatched and matched stars: %5.3f, %5.3f" % (np.median(unMatchY2['mag_I']), 
                                                                             np.median(matchY2['mag_I'])))


# HSC-Y band
# Star1 catalog has 188903 objects
## 187185 synthetic stars are matched
## 1718 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.886, 21.320
# 
Star2 catalog has 190999 objects
## 188364 synthetic stars are matched
## 2635 synthetic stars are not matched
## Median magnitude for unmatched and matched stars: 22.970, 21.313

Write the catalogs


In [31]:
matchG1.write(os.path.join(starDir, 'star1_HSC-G_match.fits'), format='fits', overwrite=True)
matchG2.write(os.path.join(starDir, 'star2_HSC-G_match.fits'), format='fits', overwrite=True)
unMatchG1.write(os.path.join(starDir, 'star1_HSC-G_unmatch.fits'), format='fits', overwrite=True)
unMatchG2.write(os.path.join(starDir, 'star2_HSC-G_unmatch.fits'), format='fits', overwrite=True)

matchR1.write(os.path.join(starDir, 'star1_HSC-R_match.fits'), format='fits', overwrite=True)
matchR2.write(os.path.join(starDir, 'star2_HSC-R_match.fits'), format='fits', overwrite=True)
unMatchR1.write(os.path.join(starDir, 'star1_HSC-R_unmatch.fits'), format='fits', overwrite=True)
unMatchR2.write(os.path.join(starDir, 'star2_HSC-R_unmatch.fits'), format='fits', overwrite=True)

matchI1.write(os.path.join(starDir, 'star1_HSC-I_match.fits'), format='fits', overwrite=True)
matchI2.write(os.path.join(starDir, 'star2_HSC-I_match.fits'), format='fits', overwrite=True)
unMatchI1.write(os.path.join(starDir, 'star1_HSC-I_unmatch.fits'), format='fits', overwrite=True)
unMatchI2.write(os.path.join(starDir, 'star2_HSC-I_unmatch.fits'), format='fits', overwrite=True)

matchZ1.write(os.path.join(starDir, 'star1_HSC-Z_match.fits'), format='fits', overwrite=True)
matchZ2.write(os.path.join(starDir, 'star2_HSC-Z_match.fits'), format='fits', overwrite=True)
unMatchZ1.write(os.path.join(starDir, 'star1_HSC-Z_unmatch.fits'), format='fits', overwrite=True)
unMatchZ2.write(os.path.join(starDir, 'star2_HSC-Z_unmatch.fits'), format='fits', overwrite=True)

matchY1.write(os.path.join(starDir, 'star1_HSC-Y_match.fits'), format='fits', overwrite=True)
matchY2.write(os.path.join(starDir, 'star2_HSC-Y_match.fits'), format='fits', overwrite=True)
unMatchY1.write(os.path.join(starDir, 'star1_HSC-Y_unmatch.fits'), format='fits', overwrite=True)
unMatchY2.write(os.path.join(starDir, 'star2_HSC-Y_unmatch.fits'), format='fits', overwrite=True)

Read the catalogs


In [6]:
matchG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_match.fits'), format='fits')
matchG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_match.fits'), format='fits')
unMatchG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_unmatch.fits'), format='fits')
unMatchG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_unmatch.fits'), format='fits')

matchR1 = Table.read(os.path.join(starDir, 'star1_HSC-R_match.fits'), format='fits')
matchR2 = Table.read(os.path.join(starDir, 'star2_HSC-R_match.fits'), format='fits')
unMatchR1 = Table.read(os.path.join(starDir, 'star1_HSC-R_unmatch.fits'), format='fits')
unMatchR2 = Table.read(os.path.join(starDir, 'star2_HSC-R_unmatch.fits'), format='fits')

matchI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_match.fits'), format='fits')
matchI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_match.fits'), format='fits')
unMatchI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_unmatch.fits'), format='fits')
unMatchI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_unmatch.fits'), format='fits')

matchZ1 = Table.read(os.path.join(starDir, 'star1_HSC-Z_match.fits'), format='fits')
matchZ2 = Table.read(os.path.join(starDir, 'star2_HSC-Z_match.fits'), format='fits')
unMatchZ1 = Table.read(os.path.join(starDir, 'star1_HSC-Z_unmatch.fits'), format='fits')
unMatchZ2 = Table.read(os.path.join(starDir, 'star2_HSC-Z_unmatch.fits'), format='fits')

matchY1 = Table.read(os.path.join(starDir, 'star1_HSC-Y_match.fits'), format='fits')
matchY2 = Table.read(os.path.join(starDir, 'star2_HSC-Y_match.fits'), format='fits')
unMatchY1 = Table.read(os.path.join(starDir, 'star1_HSC-Y_unmatch.fits'), format='fits')
unMatchY2 = Table.read(os.path.join(starDir, 'star2_HSC-Y_unmatch.fits'), format='fits')

Select the primary and non-parent detections

Generate new catalogs


In [22]:
print([col for col in catG1.colnames if 'primary' in col.lower()])
print([col for col in catG1.colnames if 'match' in col.lower()])
print([col for col in catG1.colnames if 'child' in col.lower()])
print([col for col in catG1.colnames if 'close' in col.lower()])
print([col for col in catG1.colnames if 'extend' in col.lower()])


['detect.is-primary', 'nPrimary']
['nMatched', 'rMatched']
['blendedness.abs.flux.child', 'blendedness.abs.shape.child_a', 'blendedness.abs.shape.child_q', 'blendedness.abs.shape.child_theta', 'blendedness.raw.flux.child', 'blendedness.raw.shape.child_a', 'blendedness.raw.shape.child_q', 'blendedness.raw.shape.child_theta', 'deblend.nchild', 'force.deblend.nchild', 'nNoChild']
['fakeClosest']
['classification.extendedness', 'force.classification.extendedness']

In [19]:
print("# HSC-G band")
primaryG1 = matchG1[(matchG1['detect.is-primary']) &
                    (matchG1['deblend.nchild'] == 0) & 
                    (matchG1['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryG1))

primaryG2 = matchG2[(matchG2['detect.is-primary']) &
                    (matchG2['deblend.nchild'] == 0) & 
                    (matchG2['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryG2))


# HSC-G band
# 86778 stars are primary, non-parent, closest matches
# 87736 stars are primary, non-parent, closest matches

In [20]:
print("# HSC-R band")
primaryR1 = matchR1[(matchR1['detect.is-primary']) &
                    (matchR1['deblend.nchild'] == 0) & 
                    (matchR1['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryR1))

primaryR2 = matchR2[(matchR2['detect.is-primary']) &
                    (matchR2['deblend.nchild'] == 0) & 
                    (matchR2['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryR2))


# HSC-R band
# 86383 stars are primary, non-parent, closest matches
# 88232 stars are primary, non-parent, closest matches

In [21]:
print("# HSC-I band")
primaryI1 = matchI1[(matchI1['detect.is-primary']) &
                    (matchI1['deblend.nchild'] == 0) & 
                    (matchI1['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryI1))

primaryI2 = matchI2[(matchI2['detect.is-primary']) &
                    (matchI2['deblend.nchild'] == 0) & 
                    (matchI2['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryI2))


# HSC-I band
# 85762 stars are primary, non-parent, closest matches
# 86519 stars are primary, non-parent, closest matches

In [22]:
print("# HSC-Z band")
primaryZ1 = matchZ1[(matchZ1['detect.is-primary']) &
                    (matchZ1['deblend.nchild'] == 0) & 
                    (matchZ1['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryZ1))

primaryZ2 = matchZ2[(matchZ2['detect.is-primary']) &
                    (matchZ2['deblend.nchild'] == 0) & 
                    (matchZ2['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryZ2))


# HSC-Z band
# 87837 stars are primary, non-parent, closest matches
# 86836 stars are primary, non-parent, closest matches

In [23]:
print("# HSC-Y band")
primaryY1 = matchY1[(matchY1['detect.is-primary']) &
                    (matchY1['deblend.nchild'] == 0) & 
                    (matchY1['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryY1))

primaryY2 = matchY2[(matchY2['detect.is-primary']) &
                    (matchY2['deblend.nchild'] == 0) & 
                    (matchY2['fakeClosest'])] 
print("# %d stars are primary, non-parent, closest matches" % len(primaryY2))


# HSC-Y band
# 87357 stars are primary, non-parent, closest matches
# 87208 stars are primary, non-parent, closest matches

Write the catalogs


In [18]:
primaryG1.write(os.path.join(starDir, 'star1_HSC-G_primary.fits'), format='fits', overwrite=True)
primaryG2.write(os.path.join(starDir, 'star2_HSC-G_primary.fits'), format='fits', overwrite=True)

primaryR1.write(os.path.join(starDir, 'star1_HSC-R_primary.fits'), format='fits', overwrite=True)
primaryR2.write(os.path.join(starDir, 'star2_HSC-R_primary.fits'), format='fits', overwrite=True)

primaryI1.write(os.path.join(starDir, 'star1_HSC-I_primary.fits'), format='fits', overwrite=True)
primaryI2.write(os.path.join(starDir, 'star2_HSC-I_primary.fits'), format='fits', overwrite=True)

primaryZ1.write(os.path.join(starDir, 'star1_HSC-Z_primary.fits'), format='fits', overwrite=True)
primaryZ2.write(os.path.join(starDir, 'star2_HSC-Z_primary.fits'), format='fits', overwrite=True)

primaryY1.write(os.path.join(starDir, 'star1_HSC-Y_primary.fits'), format='fits', overwrite=True)
primaryY2.write(os.path.join(starDir, 'star2_HSC-Y_primary.fits'), format='fits', overwrite=True)

Read the new catalogs


In [23]:
primaryG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_primary.fits'), format='fits')
primaryG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_primary.fits'), format='fits')

primaryR1 = Table.read(os.path.join(starDir, 'star1_HSC-R_primary.fits'), format='fits')
primaryR2 = Table.read(os.path.join(starDir, 'star2_HSC-R_primary.fits'), format='fits')

primaryI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_primary.fits'), format='fits')
primaryI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_primary.fits'), format='fits')

primaryZ1 = Table.read(os.path.join(starDir, 'star1_HSC-Z_primary.fits'), format='fits')
primaryZ2 = Table.read(os.path.join(starDir, 'star2_HSC-Z_primary.fits'), format='fits')

primaryY1 = Table.read(os.path.join(starDir, 'star1_HSC-Y_primary.fits'), format='fits')
primaryY2 = Table.read(os.path.join(starDir, 'star2_HSC-Y_primary.fits'), format='fits')

Quality control

Generate new catalogs


In [13]:
print([col for col in catG1.colnames if 'flag' in col.lower()])


['blendedness.flags', 'blendedness.flags.noCentroid', 'blendedness.flags.noShape', 'centroid.naive.flags', 'centroid.sdss.flags', 'cmodel.dev.flags.maxIter', 'cmodel.dev.flags.numericError', 'cmodel.dev.flags.trSmall', 'cmodel.dev.flux.flags', 'cmodel.dev.flux.flags.apcorr', 'cmodel.exp.flags.maxIter', 'cmodel.exp.flags.numericError', 'cmodel.exp.flags.trSmall', 'cmodel.exp.flux.flags', 'cmodel.exp.flux.flags.apcorr', 'cmodel.flags.badCentroid', 'cmodel.flags.noCalib', 'cmodel.flags.noPsf', 'cmodel.flags.noShape', 'cmodel.flags.noWcs', 'cmodel.flags.region.maxArea', 'cmodel.flags.region.maxBadPixelFraction', 'cmodel.flags.region.usedFootprintArea', 'cmodel.flags.region.usedInitialEllipseMax', 'cmodel.flags.region.usedInitialEllipseMin', 'cmodel.flags.region.usedPsfArea', 'cmodel.flags.smallShape', 'cmodel.flux.flags', 'cmodel.flux.flags.apcorr', 'cmodel.initial.flags.maxIter', 'cmodel.initial.flags.numericError', 'cmodel.initial.flags.trSmall', 'cmodel.initial.flux.flags', 'flags.badcentroid', 'flags.negative', 'flags.pixel.bad', 'flags.pixel.bright.object.any', 'flags.pixel.bright.object.center', 'flags.pixel.clipped.any', 'flags.pixel.cr.any', 'flags.pixel.cr.center', 'flags.pixel.edge', 'flags.pixel.interpolated.any', 'flags.pixel.interpolated.center', 'flags.pixel.offimage', 'flags.pixel.saturated.any', 'flags.pixel.saturated.center', 'flags.pixel.suspect.any', 'flags.pixel.suspect.center', 'flux.aperture.flags', 'flux.gaussian.flags', 'flux.gaussian.flags.apcorr', 'flux.kron.flags', 'flux.kron.flags.apcorr', 'flux.kron.flags.badShape', 'flux.kron.flags.edge', 'flux.kron.flags.radius', 'flux.kron.flags.smallRadius', 'flux.kron.flags.usedMinimumRadius', 'flux.kron.flags.usedPsfRadius', 'flux.naive.flags', 'flux.psf.flags', 'flux.psf.flags.apcorr', 'flux.sinc.flags', 'multishapelet.psf.flags', 'multishapelet.psf.flags.constraint.q', 'multishapelet.psf.flags.constraint.r', 'multishapelet.psf.flags.maxiter', 'multishapelet.psf.flags.tinystep', 'shape.hsm.moments.centroid.flags', 'shape.hsm.moments.flags', 'shape.hsm.psfMoments.centroid.flags', 'shape.hsm.psfMoments.flags', 'shape.hsm.regauss.flags', 'shape.sdss.centroid.flags', 'shape.sdss.flags', 'shape.sdss.flags.maxiter', 'shape.sdss.flags.psf', 'shape.sdss.flags.shift', 'shape.sdss.flags.unweighted', 'shape.sdss.flags.unweightedbad']

In [24]:
def stellarQC(cat):
    """Quanlity control cuts."""
    use = cat[(~cat['centroid.sdss.flags']) & 
              (~cat['blendedness.flags']) &
              (~cat['flags.badcentroid']) & 
              (~cat['flags.pixel.bad']) &
              (~cat['flags.pixel.cr.any']) &
              (~cat['flags.pixel.edge']) & 
              (~cat['flags.pixel.interpolated.any']) &
              (~cat['flags.pixel.offimage']) &
              (~cat['flags.pixel.saturated.any']) & 
              (~cat['flags.pixel.suspect.any']) &
              (~cat['flux.aperture.flags']) &
              (~cat['flux.gaussian.flags']) & 
              (~cat['flux.psf.flags']) &
              (~cat['flux.psf.flags.apcorr']) &
              (~cat['shape.sdss.flags']) &
              (~cat['shape.hsm.moments.flags']) &
              (~cat['shape.sdss.flags.psf']) &
              (np.isfinite(cat['force.classification.extendedness'])) &
              (np.isfinite(cat['classification.extendedness'])) &
              (np.isfinite(cat['mag.psf'])) &
              (np.isfinite(cat['mag.psf.err'])) &
              (np.isfinite(cat['mag.psf.apcorr'])) &
              (np.isfinite(cat['force.mag.psf.apcorr'])) &
              (np.isfinite(cat['force.mag.psf.err'])) &
              (np.isfinite(cat['force.mag.psf']))]
    
    return use

In [25]:
print("# HSC-G band")
starUseG1 = stellarQC(primaryG1)
print("## %d / %d stars are useful" % (len(starUseG1), len(primaryG1)))
starUseG2 = stellarQC(primaryG2)
print("## %d / %d stars are useful" % (len(starUseG2), len(primaryG2)))

print("\n# HSC-R band")
starUseR1 = stellarQC(primaryR1)
print("## %d / %d stars are useful" % (len(starUseR1), len(primaryR1)))
starUseR2 = stellarQC(primaryR2)
print("## %d / %d stars are useful" % (len(starUseR2), len(primaryR2)))

print("\n# HSC-I band")
starUseI1 = stellarQC(primaryI1)
print("## %d / %d stars are useful" % (len(starUseI1), len(primaryI1)))
starUseI2 = stellarQC(primaryI2)
print("## %d / %d stars are useful" % (len(starUseI2), len(primaryI2)))

print("\n# HSC-Z band")
starUseZ1 = stellarQC(primaryZ1)
print("## %d / %d stars are useful" % (len(starUseZ1), len(primaryZ1)))
starUseZ2 = stellarQC(primaryZ2)
print("## %d / %d stars are useful" % (len(starUseZ2), len(primaryZ2)))

print("\n# HSC-Y band")
starUseY1 = stellarQC(primaryY1)
print("## %d / %d stars are useful" % (len(starUseY1), len(primaryY1)))
starUseY2 = stellarQC(primaryY2)
print("## %d / %d stars are useful" % (len(starUseY2), len(primaryY2)))


# HSC-G band
## 82898 / 86778 stars are useful
## 84394 / 87736 stars are useful

# HSC-R band
## 83522 / 86383 stars are useful
## 85956 / 88232 stars are useful

# HSC-I band
## 81916 / 85762 stars are useful
## 83943 / 86519 stars are useful

# HSC-Z band
## 85437 / 87837 stars are useful
## 84667 / 86836 stars are useful

# HSC-Y band
## 82974 / 87357 stars are useful
## 82866 / 87208 stars are useful

Write the catalogs


In [ ]:
starUseG1.write(os.path.join(starDir, 'star1_HSC-G_use.fits'), format='fits', overwrite=True)
starUseG2.write(os.path.join(starDir, 'star2_HSC-G_use.fits'), format='fits', overwrite=True)

starUseR1.write(os.path.join(starDir, 'star1_HSC-R_use.fits'), format='fits', overwrite=True)
starUseR2.write(os.path.join(starDir, 'star2_HSC-R_use.fits'), format='fits', overwrite=True)

starUseI1.write(os.path.join(starDir, 'star1_HSC-I_use.fits'), format='fits', overwrite=True)
starUseI2.write(os.path.join(starDir, 'star2_HSC-I_use.fits'), format='fits', overwrite=True)

starUseZ1.write(os.path.join(starDir, 'star1_HSC-Z_use.fits'), format='fits', overwrite=True)
starUseZ2.write(os.path.join(starDir, 'star2_HSC-Z_use.fits'), format='fits', overwrite=True)

starUseY1.write(os.path.join(starDir, 'star1_HSC-Y_use.fits'), format='fits', overwrite=True)
starUseY2.write(os.path.join(starDir, 'star2_HSC-Y_use.fits'), format='fits', overwrite=True)

Read the catalogs


In [8]:
starUseG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_use.fits'), format='fits')
starUseG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_use.fits'), format='fits')

starUseR1 = Table.read(os.path.join(starDir, 'star1_HSC-R_use.fits'), format='fits')
starUseR2 = Table.read(os.path.join(starDir, 'star2_HSC-R_use.fits'), format='fits')

starUseI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_use.fits'), format='fits')
starUseI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_use.fits'), format='fits')

starUseZ1 = Table.read(os.path.join(starDir, 'star1_HSC-Z_use.fits'), format='fits')
starUseZ2 = Table.read(os.path.join(starDir, 'star2_HSC-Z_use.fits'), format='fits')

starUseY1 = Table.read(os.path.join(starDir, 'star1_HSC-Y_use.fits'), format='fits')
starUseY2 = Table.read(os.path.join(starDir, 'star2_HSC-Y_use.fits'), format='fits')

Isolate the stars that got misclassified

Generate new catalogs


In [26]:
print("# HSC-G band")
misClassG1 = starUseG1[(starUseG1['force.classification.extendedness'] > 0.5)]
starGoodG1 = starUseG1[(starUseG1['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassG1))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassG1['mag_G']), 
                                                                              np.nanmedian(starGoodG1['mag_G'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassG1['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodG1['blendedness.abs.flux'])))

misClassG2 = starUseG2[(starUseG2['force.classification.extendedness'] > 0.5)]
starGoodG2 = starUseG2[(starUseG2['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassG2))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassG2['mag_G']), 
                                                                              np.nanmedian(starGoodG2['mag_G'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassG2['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodG2['blendedness.abs.flux'])))

print("# \nHSC-R band")
misClassR1 = starUseR1[(starUseR1['force.classification.extendedness'] > 0.5)]
starGoodR1 = starUseR1[(starUseR1['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassR1))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassR1['mag_R']), 
                                                                              np.nanmedian(starGoodR1['mag_R'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassR1['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodR1['blendedness.abs.flux'])))

misClassR2 = starUseR2[(starUseR2['force.classification.extendedness'] > 0.5)]
starGoodR2 = starUseR2[(starUseR1['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassR2))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassR2['mag_R']), 
                                                                              np.nanmedian(starGoodR2['mag_R'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassR2['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodR2['blendedness.abs.flux'])))

print("# \nHSC-I band")
misClassI1 = starUseI1[(starUseI1['force.classification.extendedness'] > 0.5)]
starGoodI1 = starUseI1[(starUseI1['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassI1))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassI1['mag_I']), 
                                                                              np.nanmedian(starGoodI1['mag_I'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassI1['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodI1['blendedness.abs.flux'])))

misClassI2 = starUseI2[(starUseI2['force.classification.extendedness'] > 0.5)]
starGoodI2 = starUseI2[(starUseI2['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassI2))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassI2['mag_I']), 
                                                                              np.nanmedian(starGoodI2['mag_I'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassI2['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodI2['blendedness.abs.flux'])))

print("# \nHSC-Z band")
misClassZ1 = starUseZ1[(starUseZ1['force.classification.extendedness'] > 0.5)]
starGoodZ1 = starUseZ1[(starUseZ1['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassZ1))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassZ1['mag_Z']), 
                                                                              np.nanmedian(starGoodZ1['mag_Z'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassZ1['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodZ1['blendedness.abs.flux'])))

misClassZ2 = starUseZ2[(starUseZ2['force.classification.extendedness'] > 0.5)]
starGoodZ2 = starUseZ2[(starUseZ2['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassZ2))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassZ2['mag_Z']), 
                                                                              np.nanmedian(starGoodZ2['mag_Z'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassZ2['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodZ2['blendedness.abs.flux'])))

print("# \nHSC-Y band")
misClassY1 = starUseY1[(starUseY1['force.classification.extendedness'] > 0.5)]
starGoodY1 = starUseY1[(starUseY1['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassY1))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassY1['mag_Y']), 
                                                                              np.nanmedian(starGoodY1['mag_Y'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassY1['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodY1['blendedness.abs.flux'])))

misClassY2 = starUseY2[(starUseY2['force.classification.extendedness'] > 0.5)]
starGoodY2 = starUseY2[(starUseY2['force.classification.extendedness'] <= 0.5)]
print("# %d stars are mis-classified as extended objects" % len(misClassY2))
print("## median magnitude for misclassified and good stars: %5.3f, %5.3f" % (np.nanmedian(misClassY2['mag_Y']), 
                                                                              np.nanmedian(starGoodY2['mag_Y'])))
print("## median blendedness for misclassified and good stars: %6.4f, %6.4f" % (np.nanmedian(misClassY2['blendedness.abs.flux']), 
                                                                                np.nanmedian(starGoodY2['blendedness.abs.flux'])))

# Need to see the magnitude and blendedness distributions of these objects


# HSC-G band
# 11525 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 24.989, 23.596
## median blendedness for misclassified and good stars: 0.0009, 0.0002
# 8258 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 25.001, 23.604
## median blendedness for misclassified and good stars: 0.0007, 0.0000
# 
HSC-R band
# 6782 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 23.742, 22.640
## median blendedness for misclassified and good stars: 0.0000, 0.0000
/Users/song/anaconda/lib/python2.7/site-packages/astropy/table/table.py:764: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 85956 but corresponding boolean dimension is 83522
  newcol = col[slice_]
# 8825 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 23.951, 22.668
## median blendedness for misclassified and good stars: 0.0002, 0.0000
# 
HSC-I band
# 6485 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 22.703, 21.695
## median blendedness for misclassified and good stars: 0.0000, 0.0000
# 7566 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 23.296, 21.613
## median blendedness for misclassified and good stars: 0.0003, 0.0000
# 
HSC-Z band
# 8529 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 22.210, 21.253
## median blendedness for misclassified and good stars: 0.0000, 0.0000
# 9518 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 22.739, 21.189
## median blendedness for misclassified and good stars: 0.0001, 0.0000
# 
HSC-Y band
# 7263 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 22.688, 21.018
## median blendedness for misclassified and good stars: 0.0001, 0.0000
# 8080 stars are mis-classified as extended objects
## median magnitude for misclassified and good stars: 22.713, 20.984
## median blendedness for misclassified and good stars: 0.0003, 0.0000

Write the catalogs


In [40]:
starGoodG1.write(os.path.join(starDir, 'star1_HSC-G_good.fits'), format='fits', overwrite=True)
starGoodG2.write(os.path.join(starDir, 'star2_HSC-G_good.fits'), format='fits', overwrite=True)

misClassG1.write(os.path.join(starDir, 'star1_HSC-G_misclass.fits'), format='fits', overwrite=True)
misClassG2.write(os.path.join(starDir, 'star2_HSC-G_misclass.fits'), format='fits', overwrite=True)

starGoodR1.write(os.path.join(starDir, 'star1_HSC-R_good.fits'), format='fits', overwrite=True)
starGoodR2.write(os.path.join(starDir, 'star2_HSC-R_good.fits'), format='fits', overwrite=True)

misClassR1.write(os.path.join(starDir, 'star1_HSC-R_misclass.fits'), format='fits', overwrite=True)
misClassR2.write(os.path.join(starDir, 'star2_HSC-R_misclass.fits'), format='fits', overwrite=True)

starGoodI1.write(os.path.join(starDir, 'star1_HSC-I_good.fits'), format='fits', overwrite=True)
starGoodI2.write(os.path.join(starDir, 'star2_HSC-I_good.fits'), format='fits', overwrite=True)

misClassI1.write(os.path.join(starDir, 'star1_HSC-I_misclass.fits'), format='fits', overwrite=True)
misClassI2.write(os.path.join(starDir, 'star2_HSC-I_misclass.fits'), format='fits', overwrite=True)

starGoodZ1.write(os.path.join(starDir, 'star1_HSC-Z_good.fits'), format='fits', overwrite=True)
starGoodZ2.write(os.path.join(starDir, 'star2_HSC-Z_good.fits'), format='fits', overwrite=True)

misClassZ1.write(os.path.join(starDir, 'star1_HSC-Z_misclass.fits'), format='fits', overwrite=True)
misClassZ2.write(os.path.join(starDir, 'star2_HSC-Z_misclass.fits'), format='fits', overwrite=True)

starGoodY1.write(os.path.join(starDir, 'star1_HSC-Y_good.fits'), format='fits', overwrite=True)
starGoodY2.write(os.path.join(starDir, 'star2_HSC-Y_good.fits'), format='fits', overwrite=True)

misClassY1.write(os.path.join(starDir, 'star1_HSC-Y_misclass.fits'), format='fits', overwrite=True)
misClassY2.write(os.path.join(starDir, 'star2_HSC-Y_misclass.fits'), format='fits', overwrite=True)

Read the catalogs


In [9]:
starGoodG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_good.fits'), format='fits')
starGoodG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_good.fits'), format='fits')

misClassG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_misclass.fits'), format='fits')
misClassG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_misclass.fits'), format='fits')

starGoodR1 = Table.read(os.path.join(starDir, 'star1_HSC-R_good.fits'), format='fits')
starGoodR2 = Table.read(os.path.join(starDir, 'star2_HSC-R_good.fits'), format='fits')

misClassR1 = Table.read(os.path.join(starDir, 'star1_HSC-R_misclass.fits'), format='fits')
misClassR2 = Table.read(os.path.join(starDir, 'star2_HSC-R_misclass.fits'), format='fits')

starGoodI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_good.fits'), format='fits')
starGoodI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_good.fits'), format='fits')

misClassI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_misclass.fits'), format='fits')
misClassI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_misclass.fits'), format='fits')

starGoodZ1 = Table.read(os.path.join(starDir, 'star1_HSC-Z_good.fits'), format='fits')
starGoodZ2 = Table.read(os.path.join(starDir, 'star2_HSC-Z_good.fits'), format='fits')

misClassZ1 = Table.read(os.path.join(starDir, 'star1_HSC-Z_misclass.fits'), format='fits')
misClassZ2 = Table.read(os.path.join(starDir, 'star2_HSC-Z_misclass.fits'), format='fits')

starGoodY1 = Table.read(os.path.join(starDir, 'star1_HSC-Y_good.fits'), format='fits')
starGoodY2 = Table.read(os.path.join(starDir, 'star2_HSC-Y_good.fits'), format='fits')

misClassY1 = Table.read(os.path.join(starDir, 'star1_HSC-Y_misclass.fits'), format='fits')
misClassY2 = Table.read(os.path.join(starDir, 'star2_HSC-Y_misclass.fits'), format='fits')

In [88]:
misClassI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_misclass.fits'), format='fits')
misClassI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_misclass.fits'), format='fits')

In [14]:
starGoodI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_good.fits'), format='fits')
starGoodI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_good.fits'), format='fits')

In [36]:
starGoodG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_good.fits'), format='fits')
starGoodG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_good.fits'), format='fits')

Basic distributions of magnitudes and blendedness

Distributions of input stars


In [68]:
xtickFormat, ytickFormat = r'$\mathbf{%4.1f}$', r'$\mathbf{%4.1f}\ $'
ytickFormat2 = r'$\mathbf{%3.1f}$'

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(30,6))
fig.subplots_adjust(left=0.02, right=0.99, bottom=0.15, top=0.99, 
                    hspace=0.0, wspace=0.0)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1 = fig.add_subplot(151)
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=25, xlabel=25, border=4.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

## X, Y limits
xmin, xmax = 17.2, 26.9
ymin, ymax = -0.001, 0.309

# Good seeing
xx = starGoodI1['mag_G']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax1.fill(xPlot[:, None], np.exp(log_dens), facecolor=GCMAP(0.5), edgecolor=GCMAP(0.8), 
         alpha=0.6, linewidth=4.0, label=r'$\mathrm{Good\ Seeing}$')

# Bad seeing
xx = starGoodI2['mag_G']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax1.plot(xPlot, np.exp(log_dens), color=GCMAP(0.9), alpha=0.8, linewidth=6.0, 
         linestyle='--', dashes=(40,8), label=r'$\mathrm{Bad\ Seeing}$')

ax1.yaxis.set_major_formatter(NullFormatter())

xlabel = r'$g\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$\#$'
ax1.set_xlabel(xlabel, size=26)
ax1.set_ylabel(ylabel, size=26)

ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
ax1.legend(l_handles, l_labels, loc=(0.04, 0.72), shadow=True, fancybox=True, 
           numpoints=1, fontsize=24, scatterpoints=1, 
           markerscale=1.2, borderpad=0.2, handletextpad=0.2)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(GCMAP(0.6))
legend.legendHandles[1].set_color(GCMAP(0.9))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2 = fig.add_subplot(152)
ax2.grid()
ax2 = songPlotSetup(ax2, ylabel=25, xlabel=25, border=4.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

# Good seeing
xx = starGoodI1['mag_R']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax2.fill(xPlot[:, None], np.exp(log_dens), facecolor=RCMAP(0.5), edgecolor=RCMAP(0.8), 
         alpha=0.6, linewidth=4.0)

# Bad seeing
xx = starGoodI2['mag_R']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax2.plot(xPlot, np.exp(log_dens), color=RCMAP(0.9), alpha=0.8, linewidth=6.0, 
         linestyle='--', dashes=(40,8))

ax2.set_ylim(ax1.get_ylim())
ax2.yaxis.set_major_formatter(NullFormatter())

xlabel = r'$r\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ax2.set_xlabel(xlabel, size=26)

## X, Y limits
xmin, xmax = 17.2, 26.9
ax2.set_xlim(xmin, xmax)

# --------------------------------------------------------------------------------------- #
## Ax3
ax3 = fig.add_subplot(153)
ax3.grid()
ax3 = songPlotSetup(ax3, ylabel=25, xlabel=25, border=4.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

# Good seeing
xx = starGoodI1['mag_I']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax3.fill(xPlot[:, None], np.exp(log_dens), facecolor=ICMAP(0.5), edgecolor=ICMAP(0.8), 
         alpha=0.6, linewidth=4.0)

# Bad seeing
xx = starGoodI2['mag_I']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax3.plot(xPlot, np.exp(log_dens), color=ICMAP(0.9), alpha=0.8, linewidth=6.0, 
         linestyle='--', dashes=(40,8))

ax3.set_ylim(ax1.get_ylim())
ax3.yaxis.set_major_formatter(NullFormatter())

xlabel = r'$i\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ax3.set_xlabel(xlabel, size=26)

## X, Y limits
xmin, xmax = 17.2, 26.9
ax3.set_xlim(xmin, xmax)

# --------------------------------------------------------------------------------------- #
## Ax4
ax4 = fig.add_subplot(154)
ax4.grid()
ax4 = songPlotSetup(ax4, ylabel=25, xlabel=25, border=4.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

# Good seeing
xx = starGoodI1['mag_Z']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax4.fill(xPlot[:, None], np.exp(log_dens), facecolor=ZCMAP(0.5), edgecolor=ZCMAP(0.8), 
         alpha=0.6, linewidth=4.0)

# Bad seeing
xx = starGoodI2['mag_Z']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax4.plot(xPlot, np.exp(log_dens), color=ZCMAP(0.9), alpha=0.8, linewidth=6.0, 
         linestyle='--', dashes=(40,8))

ax4.set_ylim(ax1.get_ylim())
ax4.yaxis.set_major_formatter(NullFormatter())

xlabel = r'$z\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ax4.set_xlabel(xlabel, size=26)

## X, Y limits
xmin, xmax = 17.2, 26.9
ax4.set_xlim(xmin, xmax)

# --------------------------------------------------------------------------------------- #
## Ax5
ax5 = fig.add_subplot(155)
ax5.grid()
ax5 = songPlotSetup(ax5, ylabel=25, xlabel=25, border=4.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

# Good seeing
xx = starGoodI1['mag_Y']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax5.fill(xPlot[:, None], np.exp(log_dens), facecolor=YCMAP(0.5), edgecolor=YCMAP(0.8), 
         alpha=0.6, linewidth=4.0)

# Bad seeing
xx = starGoodI2['mag_Y']
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax5.plot(xPlot, np.exp(log_dens), color=YCMAP(0.9), alpha=0.8, linewidth=6.0, 
         linestyle='--', dashes=(40,8))

ax5.set_ylim(ax1.get_ylim())
ax5.yaxis.set_major_formatter(NullFormatter())

xlabel = r'$Y\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ax5.set_xlabel(xlabel, size=26)

## X, Y limits
xmin, xmax = 17.2, 26.9
ax5.set_xlim(xmin, xmax)

# --------------------------------------------------------------------------------------- #
fig.savefig(os.path.join(figDir, 'star1_hist_input_mag.pdf'), 
            format='pdf', dpi=90)



In [44]:
# --------------------------------------------------------------------------------------- #
## Prepare the data

xmin, xmax = -0.59, 2.49
ymin, ymax = -0.59, 2.89

xx = inputI1['mag_G'] - inputI1['mag_R']
yy = inputI1['mag_R'] - inputI1['mag_I']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= xmin) & (xTemp <= xmax) &
        (yTemp >= ymin) & (yTemp <= ymax)]
yy = yy[(xTemp >= xmin) & (xTemp <= xmax) &
        (yTemp >= ymin) & (yTemp <= ymax)]

xx2 = inputI2['mag_G'] - inputI2['mag_R']
yy2 = inputI2['mag_R'] - inputI2['mag_I']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]
yy2 = yy2[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]

xlabel = r'$(g-r)_{\mathrm{PSF}}} \mathrm{(mag)}$'
ylabel = r'$(r-i)_{\mathrm{PSF}}} \mathrm{(mag)}$'

xtickFormat, ytickFormat = r'$\mathbf{%5.1f}$', r'$\mathbf{%5.1f}\ $'
ytickFormat2 = r'$\mathbf{%3.1f}$'

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = plt.axes(EC1)
ax2 = plt.axes(EC2)
ax3 = plt.axes(EC3)

ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)
ax2 = songPlotSetup(ax2, ylabel=50, xlabel=50, border=7.0, 
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat2)
ax3 = songPlotSetup(ax3, ylabel=50, xlabel=50, border=7.0, 
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat2)
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()

# HexBin
HB = ax1.hexbin(xx, yy, cmap=RCMAP, mincnt=1,
                alpha=0.7, gridsize=[30, 20], label=r'$\mathrm{Good\ Seeing}$',
                marginals=False, vmin=10, vmax=1250, 
                edgecolor=RCMAP(0.3))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(140, 140))
H = gaussian_filter(H, 2)
levels = np.linspace(1, H.max(), 6)
Nx, Ny = len(xbins), len(ybins)
CS = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                 colors=(RCMAP(0.6), RCMAP(0.6)),
                 linewidths=6, levels=levels, alpha=0.7)

# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=54)

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
l_handles[0] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS.collections[-1])
l_labels[0] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.52, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.2, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(RCMAP(0.3))
legend.legendHandles[1].set_color(RCMAP(0.8))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2

ax2.grid()
# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(xx[:, None])
xPlot = np.linspace(xmin, xmax, 500)
log_dens = kde.score_samples(xPlot[:, None])
ax2.fill(xPlot[:, None], np.exp(log_dens), facecolor=RCMAP(0.3), edgecolor=RCMAP(0.6), 
         alpha=0.7, linewidth=4.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(xx2[:, None])
log_dens = kde.score_samples(xPlot[:, None])
ax2.fill(xPlot[:, None], np.exp(log_dens), facecolor='None', edgecolor=RCMAP(0.9), 
         alpha=0.6, linewidth=7.0, linestyle='-')

ax2.set_xlim(ax1.get_xlim())
ax2.yaxis.set_major_formatter(NullFormatter())
ax2.xaxis.set_major_formatter(NullFormatter())
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax3

ax3.grid()
# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax3.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=RCMAP(0.3), edgecolor=RCMAP(0.6),
                  alpha=0.7, linewidth=4.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax3.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', edgecolor=RCMAP(0.9),
                  alpha=0.6, linewidth=7.0, linestyle='-')

ax3.set_ylim(ax1.get_ylim())
ax3.yaxis.set_major_formatter(NullFormatter())
ax3.xaxis.set_major_formatter(NullFormatter())
# --------------------------------------------------------------------------------------- #

fig.savefig(os.path.join(figDir, 'star1_HSC-G-R-input.pdf'), 
            format='pdf', dpi=90)