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)



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

xmin, xmax = -0.29, 1.19
ymin, ymax = -0.29, 0.59

xx = inputI1['mag_I'] - inputI1['mag_Z']
yy = inputI1['mag_Z'] - inputI1['mag_Y']
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_I'] - inputI2['mag_Z']
yy2 = inputI2['mag_Z'] - inputI2['mag_Y']
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'$(i-z)_{\mathrm{PSF}}} \mathrm{(mag)}$'
ylabel = r'$(z-y)_{\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=ICMAP, mincnt=5,
                alpha=0.7, gridsize=[30, 20], label=r'$\mathrm{Good\ Seeing}$',
                marginals=False, vmin=200, vmax=1450, 
                edgecolor=ICMAP(0.3))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(140, 140))
H = gaussian_filter(H, 2)
levels = np.linspace(3, H.max(), 6)
Nx, Ny = len(xbins), len(ybins)
CS = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                 colors=(ICMAP(0.6), ICMAP(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(ICMAP(0.3))
legend.legendHandles[1].set_color(ICMAP(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=ICMAP(0.3), edgecolor=ICMAP(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=ICMAP(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=ICMAP(0.3), edgecolor=ICMAP(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=ICMAP(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-I-Z-input.pdf'), 
            format='pdf', dpi=90)


Distributions of matched stars


In [27]:
print(np.nanmin(starGoodI1['blendedness.abs.flux']), np.nanmax(starGoodI1['blendedness.abs.flux']))
print(np.nanmin(misClassI1['blendedness.abs.flux']), np.nanmax(misClassI1['blendedness.abs.flux']))
print(np.nanmin(starGoodI2['blendedness.abs.flux']), np.nanmax(starGoodI2['blendedness.abs.flux']))
print(np.nanmin(misClassI2['blendedness.abs.flux']), np.nanmax(misClassI2['blendedness.abs.flux']))

print(np.nanmin(starGoodI1['mag.psf']), np.nanmax(starGoodI1['mag.psf']))
print(np.nanmin(misClassI1['mag.psf']), np.nanmax(misClassI1['mag.psf']))
print(np.nanmin(starGoodI2['mag.psf']), np.nanmax(starGoodI2['mag.psf']))
print(np.nanmin(misClassI2['mag.psf']), np.nanmax(misClassI2['mag.psf']))

print(np.nanmin(starGoodI1['mag_I']), np.nanmax(starGoodI1['mag_I']))
print(np.nanmin(misClassI1['mag_I']), np.nanmax(misClassI1['mag_I']))
print(np.nanmin(starGoodI2['mag_I']), np.nanmax(starGoodI2['mag_I']))
print(np.nanmin(misClassI2['mag_I']), np.nanmax(misClassI2['mag_I']))


-0.00258181519312 0.991145476813
-0.00165442957128 0.981002450917
-0.000955921037206 0.998589308475
-0.000602350170097 0.984584409845
18.0849032864 28.7662631992
18.2382063413 27.0870937781
18.1641694704 29.1231548671
18.2086401323 27.6511607623
18.0581322 26.3101006
18.2412472 26.190958
18.143528 26.2213783
18.2221642 26.1256161

In [11]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starGoodI1['mag_I']
yy = starGoodI1['blendedness.abs.flux']
xx = xx[np.isfinite(yy) & (yy > 0.0)]
yy = yy[np.isfinite(yy) & (yy > 0.0)]
yy = np.log10(yy)

xx2 = starGoodI2['mag_I']
yy2 = starGoodI2['blendedness.abs.flux']
xx2 = xx2[np.isfinite(yy2) & (yy2 > 0.0)]
yy2 = yy2[np.isfinite(yy2) & (yy2 > 0.0)]
yy2 = np.log10(yy2)

xmin, xmax = 18.01, 25.6
ymin, ymax = -5.9, 0.15

xlabel = r'$i\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$\mathrm{Blendedness}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax3 = plt.axes(recHist)

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


hb1 = ax1.hexbin(xx, yy, cmap=ICMAP, mincnt=3,
                 alpha=1.0, gridsize=[46, 70], label='$\mathrm{Good}$',
                 marginals=False, vmin=3, vmax=110, 
                 edgecolor=ICMAP(0.2))

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

ax1.axhline(-1.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)
ax1.text(0.19, 0.87, '$\mathrm{Blended}$', 
         verticalalignment='bottom', horizontalalignment='center',
         fontsize=56.0, transform=ax1.transAxes, weight='bold', 
         color='k')

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.03), 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(ICMAP(0.3))
legend.legendHandles[1].set_color(ICMAP(0.8))
# --------------------------------------------------------------------------------------- #

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

ax3.grid()
# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.05).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=ICMAP(0.4), edgecolor=ICMAP(0.05),
                  alpha=0.8, linewidth=4.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.05).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax3.plot(np.exp(log_dens), yPlot, color=ICMAP(0.9), alpha=0.7, linewidth=5.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=ICMAP(0.7),
#                  alpha=0.6, linewidth=4.0, linestyle='--')

ax3.axhline(-1.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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-I_magI_blendedness.pdf'), 
            format='pdf', dpi=90)


Separate the isolated and blended stars


In [28]:
starIsoG1 = starGoodG1[(np.isfinite(starGoodG1['blendedness.abs.flux'])) &
                       (starGoodG1['blendedness.abs.flux'] <= 0.05)]
starIsoG2 = starGoodG2[(starGoodG2['blendedness.abs.flux'] > 0.0) &
                       (starGoodG2['blendedness.abs.flux'] <= 0.05)]

starBldG1 = starGoodG1[(starGoodG1['blendedness.abs.flux'] > 0.05)]
starBldG2 = starGoodG2[(starGoodG2['blendedness.abs.flux'] > 0.05)]

starIsoR1 = starGoodR1[(starGoodR1['blendedness.abs.flux'] > 0.0) &
                       (starGoodR1['blendedness.abs.flux'] <= 0.05)]
starIsoR2 = starGoodR2[(starGoodR2['blendedness.abs.flux'] > 0.0) &
                       (starGoodR2['blendedness.abs.flux'] <= 0.05)]

starBldR1 = starGoodR1[(starGoodR1['blendedness.abs.flux'] > 0.05)]
starBldR2 = starGoodR2[(starGoodR2['blendedness.abs.flux'] > 0.05)]

starIsoI1 = starGoodI1[(starGoodI1['blendedness.abs.flux'] > 0.0) &
                       (starGoodI1['blendedness.abs.flux'] <= 0.05)]
starIsoI2 = starGoodI2[(starGoodI2['blendedness.abs.flux'] > 0.0) &
                       (starGoodI2['blendedness.abs.flux'] <= 0.05)]

starBldI1 = starGoodI1[(starGoodI1['blendedness.abs.flux'] > 0.05)]
starBldI2 = starGoodI2[(starGoodI2['blendedness.abs.flux'] > 0.05)]

starIsoZ1 = starGoodZ1[(starGoodZ1['blendedness.abs.flux'] > 0.0) &
                       (starGoodZ1['blendedness.abs.flux'] <= 0.05)]
starIsoZ2 = starGoodZ2[(starGoodZ2['blendedness.abs.flux'] > 0.0) &
                       (starGoodZ2['blendedness.abs.flux'] <= 0.05)]

starBldZ1 = starGoodZ1[(starGoodZ1['blendedness.abs.flux'] > 0.05)]
starBldZ2 = starGoodZ2[(starGoodZ2['blendedness.abs.flux'] > 0.05)]

starIsoY1 = starGoodY1[(starGoodY1['blendedness.abs.flux'] > 0.0) &
                       (starGoodY1['blendedness.abs.flux'] <= 0.05)]
starIsoY2 = starGoodY2[(starGoodY2['blendedness.abs.flux'] > 0.0) &
                       (starGoodY2['blendedness.abs.flux'] <= 0.05)]

starBldY1 = starGoodY1[(starGoodY1['blendedness.abs.flux'] > 0.05)]
starBldY2 = starGoodY2[(starGoodY2['blendedness.abs.flux'] > 0.05)]

In [29]:
print(len(starGoodG1), len(starIsoG1), len(starBldG1))
print(len(starGoodG1[starGoodG1['blendedness.abs.flux'] <= 0.05]))


71373 63579 7794
63579

Write the catalogs


In [96]:
print(len(starIsoG1), len(starBldG1))
print(len(starIsoG2), len(starBldG2))
starIsoG1.write(os.path.join(starDir, 'star1_HSC-G_isolate.fits'), format='fits', overwrite=True)
starIsoG2.write(os.path.join(starDir, 'star2_HSC-G_isolate.fits'), format='fits', overwrite=True)
starBldG1.write(os.path.join(starDir, 'star1_HSC-G_blended.fits'), format='fits', overwrite=True)
starBldG2.write(os.path.join(starDir, 'star2_HSC-G_blended.fits'), format='fits', overwrite=True)

print(len(starIsoR1), len(starBldR1))
print(len(starIsoR2), len(starBldR2))
starIsoR1.write(os.path.join(starDir, 'star1_HSC-R_isolate.fits'), format='fits', overwrite=True)
starIsoR2.write(os.path.join(starDir, 'star2_HSC-R_isolate.fits'), format='fits', overwrite=True)
starBldR1.write(os.path.join(starDir, 'star1_HSC-R_blended.fits'), format='fits', overwrite=True)
starBldR2.write(os.path.join(starDir, 'star2_HSC-R_blended.fits'), format='fits', overwrite=True)

print(len(starIsoI1), len(starBldI1))
print(len(starIsoI2), len(starBldI2))
starIsoI1.write(os.path.join(starDir, 'star1_HSC-I_isolate.fits'), format='fits', overwrite=True)
starIsoI2.write(os.path.join(starDir, 'star2_HSC-I_isolate.fits'), format='fits', overwrite=True)
starBldI1.write(os.path.join(starDir, 'star1_HSC-I_blended.fits'), format='fits', overwrite=True)
starBldI2.write(os.path.join(starDir, 'star2_HSC-I_blended.fits'), format='fits', overwrite=True)

print(len(starIsoZ1), len(starBldZ1))
print(len(starIsoZ2), len(starBldZ2))
starIsoZ1.write(os.path.join(starDir, 'star1_HSC-Z_isolate.fits'), format='fits', overwrite=True)
starIsoZ2.write(os.path.join(starDir, 'star2_HSC-Z_isolate.fits'), format='fits', overwrite=True)
starBldZ1.write(os.path.join(starDir, 'star1_HSC-Z_blended.fits'), format='fits', overwrite=True)
starBldZ2.write(os.path.join(starDir, 'star2_HSC-Z_blended.fits'), format='fits', overwrite=True)

print(len(starIsoY1), len(starBldY1))
print(len(starIsoY2), len(starBldY2))
starIsoY1.write(os.path.join(starDir, 'star1_HSC-Y_isolate.fits'), format='fits', overwrite=True)
starIsoY2.write(os.path.join(starDir, 'star2_HSC-Y_isolate.fits'), format='fits', overwrite=True)
starBldY1.write(os.path.join(starDir, 'star1_HSC-Y_blended.fits'), format='fits', overwrite=True)
starBldY2.write(os.path.join(starDir, 'star2_HSC-Y_blended.fits'), format='fits', overwrite=True)


46452 4999
47614 3775
46488 3543
45980 3801
42486 2758
46518 2639
47383 1753
45721 1534
49937 2582
48404 2664

Read the catalogs


In [10]:
starIsoG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_isolate.fits'), format='fits')
starIsoG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_isolate.fits'), format='fits')
starBldG1 = Table.read(os.path.join(starDir, 'star1_HSC-G_blended.fits'), format='fits')
starBldG2 = Table.read(os.path.join(starDir, 'star2_HSC-G_blended.fits'), format='fits')

starIsoR1 = Table.read(os.path.join(starDir, 'star1_HSC-R_isolate.fits'), format='fits')
starIsoR2 = Table.read(os.path.join(starDir, 'star2_HSC-R_isolate.fits'), format='fits')
starBldR1 = Table.read(os.path.join(starDir, 'star1_HSC-R_blended.fits'), format='fits')
starBldR2 = Table.read(os.path.join(starDir, 'star2_HSC-R_blended.fits'), format='fits')

starIsoI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_isolate.fits'), format='fits')
starIsoI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_isolate.fits'), format='fits')
starBldI1 = Table.read(os.path.join(starDir, 'star1_HSC-I_blended.fits'), format='fits')
starBldI2 = Table.read(os.path.join(starDir, 'star2_HSC-I_blended.fits'), format='fits')

starIsoZ1 = Table.read(os.path.join(starDir, 'star1_HSC-Z_isolate.fits'), format='fits')
starIsoZ2 = Table.read(os.path.join(starDir, 'star2_HSC-Z_isolate.fits'), format='fits')
starBldZ1 = Table.read(os.path.join(starDir, 'star1_HSC-Z_blended.fits'), format='fits')
starBldZ2 = Table.read(os.path.join(starDir, 'star2_HSC-Z_blended.fits'), format='fits')

starIsoY1 = Table.read(os.path.join(starDir, 'star1_HSC-Y_isolate.fits'), format='fits')
starIsoY2 = Table.read(os.path.join(starDir, 'star2_HSC-Y_isolate.fits'), format='fits')
starBldY1 = Table.read(os.path.join(starDir, 'star1_HSC-Y_blended.fits'), format='fits')
starBldY2 = Table.read(os.path.join(starDir, 'star2_HSC-Y_blended.fits'), format='fits')

Astrometric accuracy


In [159]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoI1['coord_ra'] - starIsoI1['RA']
yy = starIsoI1['coord_dec'] - starIsoI1['DEC']
xx *= 3600.0
yy *= 3600.0

xx2 = starBldI1['coord_ra'] - starBldI1['RA']
yy2 = starBldI1['coord_dec'] - starBldI1['DEC']
xx2 *= 3600.0
yy2 *= 3600.0

xx3 = starIsoI2['coord_ra'] - starIsoI2['RA']
yy3 = starIsoI2['coord_dec'] - starIsoI2['Dec']
xx3 *= 3600.0
yy3 *= 3600.0

xmin, xmax = -0.142, 0.142
ymin, ymax = -0.142, 0.142

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)]

xlabel = r'$\Delta\ \mathrm{R.A}\ (\mathrm{arcsec})$'
ylabel = r'$\Delta\ \mathrm{Dec}\ (\mathrm{arcsec})$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(16, 16))
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()

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 2)
levels = np.linspace(1, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ICMAP(0.2), ICMAP(0.4), ICMAP(0.6), ICMAP(0.8), ICMAP(1.0)),
                   linewidths=10, levels=levels, alpha=1.0)

## Contour 2
H, xbins, ybins = np.histogram2d(xx3, yy3, bins=(100, 100))
H = gaussian_filter(H, 2.0)
levels = np.linspace(1, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(YCMAP(0.4), YCMAP(0.5), YCMAP(0.6), YCMAP(0.7), YCMAP(0.8)),
                  linewidths=6, levels=levels, alpha=1.0)

ax1.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)
ax1.axvline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

# --------------------------------------------------------------------------------------- #
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()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
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(ICMAP(0.5))
legend.legendHandles[1].set_color(YCMAP(0.6))
# --------------------------------------------------------------------------------------- #

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

ax2.grid()
# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.002).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=ICMAP(0.4), edgecolor=ICMAP(0.1), 
         alpha=1.0, linewidth=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.002).fit(xx3[:, None])
log_dens = kde.score_samples(xPlot[:, None])
ax2.fill(xPlot[:, None], np.exp(log_dens), facecolor='None', edgecolor=YCMAP(0.7), 
         alpha=0.8, linewidth=6.0, linestyle='-')

ax2.axvline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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.002).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=ICMAP(0.4), edgecolor=ICMAP(0.1),
                  alpha=1.0, linewidth=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.002).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax3.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', edgecolor=YCMAP(0.7),
                  alpha=0.8, linewidth=6.0, linestyle='-')

ax3.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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-I_dRA_dDec_new.pdf'), 
            format='pdf', dpi=90)


Flux & S/N


In [160]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoI1['mag_I']
yy = np.log10(starIsoI1['flux.psf'] / starIsoI1['flux.psf.err'])

xx2 = starIsoI2['mag_I']
yy2 = np.log10(starIsoI2['flux.psf'] / starIsoI2['flux.psf.err'])

xx3 = starBldI1['mag_I']
yy3 = np.log10(starBldI1['flux.psf'] / starBldI1['flux.psf.err'])

xmin, xmax = 17.29, 26.99
ymin, ymax = 0.4, 3.89 

xlabel = r'$i\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$\log_{10}\ (\mathrm{S}/\mathrm{N})_{\mathrm{PSF}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.15, right=0.99, 
                    bottom=0.15, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(120, 100))
H = gaussian_filter(H, 0.8)
levels = np.linspace(2, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ORG(0.3), ORG(0.5), ORG(0.8)),
                   linewidths=10, levels=levels, alpha=1.0)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(120, 100))
H = gaussian_filter(H, 0.8)
levels = np.linspace(2, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(YCMAP(0.4), YCMAP(0.6), YCMAP(0.8)), linestyles='dashed',
                  linewidths=4, levels=levels, alpha=0.8)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.6), edgecolor='none', 
                  alpha=0.2, s=15, label='$\mathrm{Blended}$', rasterized=True)

ax1.axhline(np.log10(5.0), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')

ax1.legend(l_handles, l_labels, loc=(0.07, 0.12), shadow=True, fancybox=True, 
           numpoints=1, fontsize=45, scatterpoints=1, 
           markerscale=2.5, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.7))
legend.legendHandles[1].set_color(ICMAP(0.3))
legend.legendHandles[2].set_color(YCMAP(0.7))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=60)

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

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



In [148]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoG1['mag_G']
yy = np.log10(starIsoG1['flux.psf'] / starIsoG1['flux.psf.err'])

xx2 = starIsoG2['mag_G']
yy2 = np.log10(starIsoG2['flux.psf'] / starIsoG2['flux.psf.err'])

xx3 = starBldG1['mag_G']
yy3 = np.log10(starBldG1['flux.psf'] / starBldG1['flux.psf.err'])

xmin, xmax = 17.29, 26.99
ymin, ymax = 0.4, 3.89 

xlabel = r'$g\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$\log_{10}\ (\mathrm{S}/\mathrm{N})_{\mathrm{PSF}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.15, right=0.99, 
                    bottom=0.15, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)
# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(120, 100))
H = gaussian_filter(H, 0.8)
levels = np.linspace(2, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(GCMAP(0.2), GCMAP(0.4), GCMAP(0.7)),
                   linewidths=10, levels=levels, alpha=1.0)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(120, 100))
H = gaussian_filter(H, 0.8)
levels = np.linspace(2, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(YCMAP(0.5), YCMAP(0.7), YCMAP(0.9)), linestyles='dashed',
                  linewidths=4, levels=levels, alpha=0.8)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.6), edgecolor='none', 
                  alpha=0.2, s=15, label='$\mathrm{Blended}$', rasterized=True)

ax1.axhline(np.log10(5.0), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')

ax1.legend(l_handles, l_labels, loc=(0.07, 0.12), shadow=True, fancybox=True, 
           numpoints=1, fontsize=45, scatterpoints=1, 
           markerscale=2.5, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.7))
legend.legendHandles[1].set_color(GCMAP(0.2))
legend.legendHandles[2].set_color(YCMAP(0.7))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=60)

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

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



In [31]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoG1['mag_G']
yy = np.log10(starIsoG1['flux.psf'] / starIsoG1['flux.psf.err'])

xx2 = starIsoG2['mag_G']
yy2 = np.log10(starIsoG2['flux.psf'] / starIsoG2['flux.psf.err'])

xx3 = starBldG1['mag_G']
yy3 = np.log10(starBldG1['flux.psf'] / starBldG1['flux.psf.err'])

xmin, xmax = 17.29, 26.99
ymin, ymax = 0.4, 3.89 

xlabel = r'$g\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$\log\ (\mathrm{S}/\mathrm{N})_{\mathrm{PSF}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.15, right=0.99, 
                    bottom=0.15, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

## Sscatter
ax1.scatter(xx3, yy3, color=GCMAP(0.4), marker='o', edgecolor='None', alpha=0.9, 
            zorder=0, s=30, label='$\mathrm{Blended}$')

## HexBin
hb1 = ax1.hexbin(xx, yy, cmap=GCMAP, mincnt=1,
                 alpha=0.7, gridsize=[45, 25], label='$\mathrm{Good}$',
                 marginals=False, vmin=1, vmax=1100, 
                 edgecolor=GCMAP(0.2))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 2)
levels = np.linspace(50, H.max(), 3)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(GCMAP(0.6), GCMAP(0.6)),
                  linewidths=4, levels=levels, alpha=0.9)

ax1.axhline(np.log10(5.0), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
l_handles[1] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS1.collections[-1])
l_labels[1] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.61, 0.12), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(GCMAP(0.3))
legend.legendHandles[1].set_color(GCMAP(0.6))
legend.legendHandles[2].set_color(GCMAP(0.8))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=60)

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

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



In [112]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoR1['mag_R']
yy = np.log10(starIsoR1['flux.psf'] / starIsoR1['flux.psf.err'])

xx2 = starIsoR2['mag_R']
yy2 = np.log10(starIsoR2['flux.psf'] / starIsoR2['flux.psf.err'])

xx3 = starBldR1['mag_R']
yy3 = np.log10(starBldR1['flux.psf'] / starBldR1['flux.psf.err'])

xmin, xmax = 17.19, 27.4
ymin, ymax = 0.4, 3.89 

xlabel = r'$r\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$r\ \mathrm{Band}\ \log\ (\mathrm{S}/\mathrm{N})_{\mathrm{PSF}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.15, right=0.99, 
                    bottom=0.15, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

## HexBin
hb1 = ax1.hexbin(xx, yy, cmap=RCMAP, mincnt=1,
                 alpha=0.7, gridsize=[36, 22], label='$\mathrm{Good}$',
                 marginals=False, vmin=1, vmax=1200, 
                 edgecolor=RCMAP(0.2))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 2)
levels = np.linspace(50, H.max(), 3)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(RCMAP(0.6), RCMAP(0.6)),
                  linewidths=4, levels=levels, alpha=0.9)

## Sscatter
ax1.scatter(xx3, yy3, color=RCMAP(0.4), marker='o', edgecolor='None', alpha=0.9, 
            zorder=0, s=30, label='$\mathrm{Blended}$')

ax1.axhline(np.log10(5.0), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
l_handles[0] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS1.collections[-1])
l_labels[0] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.61, 0.12), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, 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.6))
legend.legendHandles[2].set_color(RCMAP(0.8))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=54)

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

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



In [111]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoZ1['mag_Z']
yy = np.log10(starIsoZ1['flux.psf'] / starIsoZ1['flux.psf.err'])

xx2 = starIsoZ2['mag_Z']
yy2 = np.log10(starIsoZ2['flux.psf'] / starIsoZ2['flux.psf.err'])

xx3 = starBldZ1['mag_Z']
yy3 = np.log10(starBldZ1['flux.psf'] / starBldZ1['flux.psf.err'])

xmin, xmax = 17.09, 26.9
ymin, ymax = 0.4, 3.89 

xlabel = r'$z\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$z\ \mathrm{Band}\ \log\ (\mathrm{S}/\mathrm{N})_{\mathrm{PSF}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.15, right=0.99, 
                    bottom=0.15, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

## HexBin
hb1 = ax1.hexbin(xx, yy, cmap=ZCMAP, mincnt=1,
                 alpha=0.7, gridsize=[36, 22], label='$\mathrm{Good}$',
                 marginals=False, vmin=1, vmax=1200, 
                 edgecolor=ZCMAP(0.2))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 2)
levels = np.linspace(50, H.max(), 3)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ZCMAP(0.6), ZCMAP(0.6)),
                  linewidths=4, levels=levels, alpha=0.9)

## Sscatter
ax1.scatter(xx3, yy3, color=ZCMAP(0.4), marker='o', edgecolor='None', alpha=0.9, 
            zorder=0, s=30, label='$\mathrm{Blended}$')

ax1.axhline(np.log10(5.0), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
l_handles[0] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS1.collections[-1])
l_labels[0] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.61, 0.12), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(ZCMAP(0.3))
legend.legendHandles[1].set_color(ZCMAP(0.6))
legend.legendHandles[2].set_color(ZCMAP(0.8))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=54)

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

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



In [71]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoY1['mag_Y']
yy = np.log10(starIsoY1['flux.psf'] / starIsoY1['flux.psf.err'])

xx2 = starIsoY2['mag_Y']
yy2 = np.log10(starIsoY2['flux.psf'] / starIsoY2['flux.psf.err'])

xx3 = starBldY1['mag_Y']
yy3 = np.log10(starBldY1['flux.psf'] / starBldY1['flux.psf.err'])

xmin, xmax = 16.89, 26.19
ymin, ymax = 0.4, 3.89 

xlabel = r'$\mathrm{y\ Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$\mathrm{y\ Band}\ \log\ (\mathrm{S}/\mathrm{N})_{\mathrm{PSF}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.15, right=0.99, 
                    bottom=0.15, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

## HexBin
hb1 = ax1.hexbin(xx, yy, cmap=YCMAP, mincnt=1,
                 alpha=0.7, gridsize=[36, 22], label='$\mathrm{Good}$',
                 marginals=False, vmin=1, vmax=1200, 
                 edgecolor=YCMAP(0.2))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 2)
levels = np.linspace(50, H.max(), 3)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(YCMAP(0.6), YCMAP(0.6)),
                  linewidths=4, levels=levels, alpha=0.9)

## Sscatter
ax1.scatter(xx3, yy3, color=YCMAP(0.4), marker='o', edgecolor='None', alpha=0.9, 
            zorder=0, s=30, label='$\mathrm{Blended}$')

ax1.axhline(np.log10(5.0), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
l_handles[0] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS1.collections[-1])
l_labels[0] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.61, 0.12), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.3))
legend.legendHandles[1].set_color(YCMAP(0.6))
legend.legendHandles[2].set_color(YCMAP(0.8))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=54)

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

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



In [115]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starGoodI1['force.mag.psf']
yy = np.log10(starGoodI1['flux.psf'] / starGoodI1['flux.psf.err'])

xx2 = starGoodI2['force.mag.psf']
yy2 = np.log10(starGoodI2['flux.psf'] / starGoodI2['flux.psf.err'])

xx3 = starBldI1['force.mag.psf']
yy3 = np.log10(starBldI1['flux.psf'] / starBldI1['flux.psf.err'])

xmin, xmax = 17.49, 27.4
ymin, ymax = 0.4, 3.89 

xlabel = r'$i\ \mathrm{Band\ Forced\ PSF\ Magnitude\ (mag)}$'
ylabel = r'$i\ \mathrm{Band}\ \log\ (\mathrm{S}/\mathrm{N})_{\mathrm{PSF}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.15, right=0.99, 
                    bottom=0.15, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

## HexBin
hb1 = ax1.hexbin(xx, yy, cmap=ICMAP, mincnt=1,
                 alpha=0.7, gridsize=[36, 22], label='$\mathrm{Good}$',
                 marginals=False, vmin=1, vmax=1600, 
                 edgecolor=ICMAP(0.2))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 2)
levels = np.linspace(50, H.max(), 3)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.6), ICMAP(0.6)),
                  linewidths=4, levels=levels, alpha=0.9)

## Sscatter
ax1.scatter(xx3, yy3, color=ICMAP(0.4), marker='o', edgecolor='None', alpha=0.9, 
            zorder=0, s=30, label='$\mathrm{Blended}$')

ax1.axhline(np.log10(5.0), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
l_handles[0] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS1.collections[-1])
l_labels[0] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.61, 0.12), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(ICMAP(0.3))
legend.legendHandles[1].set_color(ICMAP(0.6))
legend.legendHandles[2].set_color(ICMAP(0.8))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=54)

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

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


Flux accuracy

Differences between the unforced and PSF forced photometry


In [178]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoG1['mag_G']
yy = starIsoG1['mag.psf'] - starIsoG1['force.mag.psf']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 16.9) & (xTemp <= 27.4) &
        (yTemp >= -0.14) & (yTemp <= 0.14)]
yy = yy[(xTemp >= 16.9) & (xTemp <= 27.4) &
        (yTemp >= -0.14) & (yTemp <= 0.14)]
## 
zz = starIsoG1['force.mag.psf.err']
zz = zz[(xTemp >= 16.9) & (xTemp <= 27.4) &
        (yTemp >= -0.14) & (yTemp <= 0.14)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])

xx2 = starIsoG2['mag_G']
yy2 = starIsoG2['mag.psf'] - starIsoG2['force.mag.psf']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]
yy2 = yy2[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]

xx3 = starBldG1['mag_G']
yy3 = starBldG1['mag.psf'] - starBldG1['force.mag.psf']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]
yy3 = yy3[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]

xmin, xmax = 16.9, 27.49
ymin, ymax = -0.099, 0.099

xlabel = r'$g\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$g_{\mathrm{\ Unforced},\ {\mathrm{PSF}}} - g_{\mathrm{\ Forced},\ {\mathrm{PSF}}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(18, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(GCMAP(0.3), GCMAP(0.5), GCMAP(0.7), GCMAP(1.0)),
                   linewidths=10, levels=levels, alpha=1.0)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(GCMAP(0.6), GCMAP(0.8), GCMAP(0.9), GCMAP(1.0)), linestyles='--',
                  linewidths=6, levels=levels, alpha=1.0)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.5), edgecolor='none', 
                  alpha=0.15, s=25, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## 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_labels[0] = '$\mathrm{Good\ Seeing}$'
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.6))
legend.legendHandles[1].set_color(GCMAP(0.3))
legend.legendHandles[2].set_color(GCMAP(0.7))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.002).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=GCMAP(0.3), 
                  edgecolor=GCMAP(0.1), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.002).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, c=GCMAP(0.6), alpha=1.0, linewidth=6.0, 
         linestyle='--', dashes=(20, 6))

kde = KernelDensity(kernel='gaussian', bandwidth=0.005).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=YCMAP(0.5), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

fig.savefig(os.path.join(figDir, 'star1_HSC-G_magG_dPSF-dfPSF_new.pdf'), 
            format='pdf', dpi=90)



In [20]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoR1['mag_R']
yy = starIsoR1['mag.psf'] - starIsoR1['force.mag.psf']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 16.9) & (xTemp <= 27.4) &
        (yTemp >= -0.14) & (yTemp <= 0.14)]
yy = yy[(xTemp >= 16.9) & (xTemp <= 27.4) &
        (yTemp >= -0.14) & (yTemp <= 0.14)]
## 
zz = starIsoR1['force.mag.psf.err']
zz = zz[(xTemp >= 16.9) & (xTemp <= 27.4) &
        (yTemp >= -0.14) & (yTemp <= 0.14)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])

xx2 = starIsoR2['mag_R']
yy2 = starIsoR2['mag.psf'] - starIsoR2['force.mag.psf']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]
yy2 = yy2[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]

xx3 = starBldR1['mag_R']
yy3 = starBldR1['mag.psf'] - starBldR1['force.mag.psf']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]
yy3 = yy3[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]

xmin, xmax = 16.9, 27.49
ymin, ymax = -0.099, 0.099

xlabel = r'$r\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$r_{\mathrm{\ Unforced},\ {\mathrm{PSF}}} - r_{\mathrm{\ Forced},\ {\mathrm{PSF}}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

## Scatter
ax1.scatter(xx3, yy3, color=RCMAP(0.4), marker='o', edgecolor='None', alpha=0.8, 
            zorder=0, s=30, label='$\mathrm{Blended}$')

## HexBin
hb1 = ax1.hexbin(xx, yy, cmap=RCMAP, mincnt=1,
                 alpha=0.7, gridsize=[42, 40], 
                 marginals=False, vmin=12, vmax=800, 
                 edgecolor=RCMAP(0.25))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(10, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(RCMAP(0.8), RCMAP(0.6)),
                  linewidths=4, levels=levels, alpha=0.9)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.8, c=BLK(0.8))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.8, c=BLK(0.8))

ax1.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

## 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[1] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS1.collections[-1])
l_labels[1] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, 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.6))
legend.legendHandles[2].set_color(RCMAP(0.8))
# --------------------------------------------------------------------------------------- #

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

ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.002).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=RCMAP(0.3), 
                  edgecolor=RCMAP(0.1), alpha=0.8, linewidth=3.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.002).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=RCMAP(0.7), alpha=0.8, linewidth=5.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.005).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=RCMAP(0.8), alpha=0.8, linewidth=6.0, 
                  linestyle='--')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

fig.savefig(os.path.join(figDir, 'star1_HSC-R_magR_dPSF-dfPSF.pdf'), 
            format='pdf', dpi=90)



In [177]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoY1['mag_Y']
yy = starIsoY1['mag.psf'] - starIsoY1['force.mag.psf']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 16.9) & (xTemp <= 27.4) &
        (yTemp >= -0.14) & (yTemp <= 0.14)]
yy = yy[(xTemp >= 16.9) & (xTemp <= 27.4) &
        (yTemp >= -0.14) & (yTemp <= 0.14)]
## 
zz = starIsoY1['force.mag.psf.err']
zz = zz[(xTemp >= 16.9) & (xTemp <= 27.4) &
        (yTemp >= -0.14) & (yTemp <= 0.14)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])

xx2 = starIsoY2['mag_Y']
yy2 = starIsoY2['mag.psf'] - starIsoY2['force.mag.psf']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]
yy2 = yy2[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]

xx3 = starBldY1['mag_Y']
yy3 = starBldY1['mag.psf'] - starBldY1['force.mag.psf']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]
yy3 = yy3[(xTemp >= 16.9) & (xTemp <= 27.4) &
          (yTemp >= -0.14) & (yTemp <= 0.14)]

xmin, xmax = 16.9, 27.49
ymin, ymax = -0.099, 0.099

xlabel = r'$y\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$y_{\mathrm{\ Unforced},\ {\mathrm{PSF}}} - y_{\mathrm{\ Forced},\ {\mathrm{PSF}}}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(18, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(YCMAP(0.3), YCMAP(0.5), YCMAP(0.7), YCMAP(1.0)),
                   linewidths=10, levels=levels, alpha=1.0)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(YCMAP(0.6), YCMAP(0.8), YCMAP(0.9), YCMAP(1.0)), linestyles='--',
                  linewidths=6, levels=levels, alpha=1.0)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.7), edgecolor='none', 
                  alpha=0.2, s=25, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## 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_labels[0] = '$\mathrm{Good\ Seeing}$'
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.6))
legend.legendHandles[1].set_color(YCMAP(0.3))
legend.legendHandles[2].set_color(YCMAP(0.7))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.002).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=YCMAP(0.3), 
                  edgecolor=YCMAP(0.1), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.002).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, c=YCMAP(0.6), alpha=1.0, linewidth=6.0, 
         linestyle='--', dashes=(20, 6))

kde = KernelDensity(kernel='gaussian', bandwidth=0.005).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=YCMAP(0.5), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

fig.savefig(os.path.join(figDir, 'star1_HSC-Y_magY_dPSF-dfPSF_new.pdf'), 
            format='pdf', dpi=90)


i-band forced PSF photometry


In [65]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoI1['mag_I']
yy = starIsoI1['force.mag.psf'] - starIsoI1['mag_I'] - starIsoI1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]

## 
zz = np.sqrt(starIsoI1['force.mag.psf.err'] ** 2.0 + starIsoI1['force.mag.psf.apcorr.err'] ** 2.0)
zz = zz[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])
yyErr = np.asarray([np.nanstd(yy[idx==k]) for k in range(total_bins)])

xx2 = starIsoI2['mag_I']
yy2 = starIsoI2['force.mag.psf'] - starIsoI2['mag_I'] - starIsoI2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy2 = yy2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xx3 = starBldI1['mag_I']
yy3 = starBldI1['force.mag.psf'] - starBldI1['mag_I'] - starBldI1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy3 = yy3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xmin, xmax = 16.9, 27.29
ymin, ymax = -0.42, 0.59

xlabel = r'$i\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$i_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - i_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

## Scatter
ax1.scatter(xx3, yy3, color=ICMAP(0.4), marker='o', edgecolor='None', alpha=0.8, 
            zorder=0, s=30, label='$\mathrm{Blended}$')

## HexBin
hb1 = ax1.hexbin(xx, yy, cmap=ICMAP, mincnt=1,
                 alpha=0.7, gridsize=[42, 38], 
                 marginals=False, vmin=10, vmax=900, 
                 edgecolor=ICMAP(0.25))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(6, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.8), ICMAP(0.6)),
                  linewidths=4, levels=levels, alpha=0.9)


## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.8, c=BLK(0.8))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.8, c=BLK(0.8))

ax1.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

## 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[1] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS1.collections[-1])
l_labels[1] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(ICMAP(0.3))
legend.legendHandles[1].set_color(ICMAP(0.6))
legend.legendHandles[2].set_color(ICMAP(0.8))
# --------------------------------------------------------------------------------------- #

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

ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=ICMAP(0.3), 
                  edgecolor=ICMAP(0.1), alpha=0.8, linewidth=3.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=ICMAP(0.7), alpha=0.8, linewidth=5.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=ICMAP(0.8), alpha=0.8, linewidth=6.0, 
                  linestyle='--')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

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



In [185]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoI1['mag_I']
yy = starIsoI1['force.mag.psf'] - starIsoI1['mag_I'] - starIsoI1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]

## 
zz = np.sqrt(starIsoI1['force.mag.psf.err'] ** 2.0 + starIsoI1['force.mag.psf.apcorr.err'] ** 2.0)
zz = zz[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])
yyErr = np.asarray([np.nanstd(yy[idx==k]) for k in range(total_bins)])

xx2 = starIsoI2['mag_I']
yy2 = starIsoI2['force.mag.psf'] - starIsoI2['mag_I'] - starIsoI2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy2 = yy2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xx3 = starBldI1['mag_I']
yy3 = starBldI1['force.mag.psf'] - starBldI1['mag_I'] - starBldI1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy3 = yy3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xmin, xmax = 16.9, 27.29
ymin, ymax = -0.42, 0.59

xlabel = r'$i\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$i_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - i_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ICMAP(0.3), ICMAP(0.5), ICMAP(0.7), ICMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.6), ICMAP(0.7), ICMAP(0.8), ICMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.6), edgecolor='none', 
                  alpha=0.2, s=20, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.6))
legend.legendHandles[1].set_color(ICMAP(0.3))
legend.legendHandles[2].set_color(ICMAP(0.5))
# --------------------------------------------------------------------------------------- #

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

ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=ICMAP(0.25), 
                  edgecolor=ICMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=ICMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=YCMAP(0.5), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

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



In [115]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" i-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoI1['mag_I']
yy = starIsoI1['force.mag.psf'] - starIsoI1['mag_I'] - starIsoI1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 25.5) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 25.5) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(yyStd[0:])
print(yyErr[0:])
print("#--------------------------------------------------------------------------------")
xx = starIsoI1['mag_I']
yy = starIsoI1['mag.psf'] - starIsoI1['mag_I'] - starIsoI1['mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 25.5) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 25.5) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Unforced PSF; W/ apcorr")
print(yyStd[0:])
print(yyErr[0:])
print("#--------------------------------------------------------------------------------")
xx = starIsoI2['mag_I']
yy = starIsoI2['force.mag.psf'] - starIsoI2['mag_I'] - starIsoI2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 25.5) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 25.5) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Bad Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starBldI1['mag_I']
yy = starBldI1['force.mag.psf'] - starBldI1['mag_I'] - starBldI1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 25.5) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 25.5) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Blended; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 i-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 0.01492199  0.01528478  0.01689738  0.01802866  0.02044271  0.0304658
  0.05321417]
[ 0.00180156  0.00188405  0.00205636  0.00200315  0.00186728  0.00163372
  0.00310233]
#--------------------------------------------------------------------------------
# Good Seeing; Unforced PSF; W/ apcorr
[ 0.01492199  0.01528478  0.01689738  0.01802866  0.02044271  0.03046581
  0.05321418]
[ 0.00180157  0.00188405  0.00205636  0.00200308  0.00186729  0.00163371
  0.00310233]
#--------------------------------------------------------------------------------
# Bad Seeing; Force PSF; W/ apcorr
[ 0.01171937  0.0117774   0.0133373   0.0159043   0.02207009  0.04313538
  0.0942921 ]
[ 0.00113782  0.00155433  0.0016484   0.00183816  0.00147036  0.00124263
 -0.01235741]
#--------------------------------------------------------------------------------
# Blended; Force PSF; W/ apcorr
[ 0.13486975  0.0972115   0.10116885  0.11026892  0.12052387  0.12544492
  0.14877403]
[ 0.09541111  0.09158471  0.08875934  0.10311096  0.11527948  0.14633977
  0.15948915]
#--------------------------------------------------------------------------------

In [116]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" i-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoI1['mag_I'] + starIsoI1['force.mag.psf.apcorr']
ff = 10.0 ** ((27.0 - xx) / 2.5)
yy = starIsoI1['force.mag.psf'] - starIsoI1['mag_I'] - starIsoI1['force.mag.psf.apcorr']
zz = ((starIsoI1['force.flux.psf'] - ff) / ff) * 100.0
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 25.0) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 25.0) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
zz = zz[(xTemp >= 18.5) & (xTemp <= 25.0) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
zzStd = np.asarray([np.nanstd(zz[idx==k+1]) for k in range(total_bins)])
zzErr = np.asarray([np.nanmedian(zz[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(zzStd[1:])
print(zzErr[1:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 i-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 1.41083597  1.54092951  1.67134256  1.85482714  2.7407359   4.30685421]
[-0.17955078 -0.18271941 -0.18776713 -0.16757561 -0.15685824 -0.11987689]
#--------------------------------------------------------------------------------

g-band forced PSF photometry


In [186]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoG1['mag_G']
yy = starIsoG1['force.mag.psf'] - starIsoG1['mag_G'] - starIsoG1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]

## 
zz = np.sqrt(starIsoG1['force.mag.psf.err'] ** 2.0 + starIsoG1['force.mag.psf.apcorr.err'] ** 2.0)
zz = zz[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])

xx2 = starIsoG2['mag_G']
yy2 = starIsoG2['force.mag.psf'] - starIsoG2['mag_G'] - starIsoG2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy2 = yy2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xx3 = starBldG1['mag_G']
yy3 = starBldG1['force.mag.psf'] - starBldG1['mag_G'] - starBldG1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy3 = yy3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xmin, xmax = 16.9, 27.29
ymin, ymax = -0.42, 0.59

xlabel = r'$g\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$g_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - g_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(1, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(GCMAP(0.3), GCMAP(0.5), GCMAP(0.7), GCMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(1, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(GCMAP(0.6), GCMAP(0.7), GCMAP(0.9), GCMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.6), edgecolor='none', 
                  alpha=0.2, s=20, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.6))
legend.legendHandles[1].set_color(GCMAP(0.3))
legend.legendHandles[2].set_color(GCMAP(0.5))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=GCMAP(0.2), 
                  edgecolor=GCMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=GCMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=YCMAP(0.5), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

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



In [188]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" g-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoG1['mag_G']
yy = starIsoG1['force.mag.psf'] - starIsoG1['mag_G'] - starIsoG1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoG1['mag_G']
yy = starIsoG1['mag.psf'] - starIsoG1['mag_G'] - starIsoG1['mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Unforced PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoG2['mag_G']
yy = starIsoG2['force.mag.psf'] - starIsoG2['mag_G'] - starIsoG2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Bad Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starBldG1['mag_G']
yy = starBldG1['force.mag.psf'] - starBldG1['mag_G'] - starBldG1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Blended; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 g-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 0.01604048  0.01756406  0.01943131  0.02273397  0.02854424  0.04321879
  0.09873925]
[ 0.00862774  0.00944708  0.00888849  0.00861611  0.0086989   0.00753327
 -0.00298937]
#--------------------------------------------------------------------------------
# Good Seeing; Unforced PSF; W/ apcorr
[ 0.01601553  0.01752628  0.01946987  0.02222948  0.02880181  0.04365548
  0.09828601]
[ 0.00775902  0.0086725   0.00813111  0.00785306  0.00767041  0.00630893
 -0.00759899]
#--------------------------------------------------------------------------------
# Bad Seeing; Force PSF; W/ apcorr
[ 0.01582389  0.01825851  0.01856946  0.02123339  0.02586989  0.03903757
  0.09054315]
[ 0.00706221  0.00606451  0.00603984  0.00511228  0.00443811  0.00323667
 -0.00246973]
#--------------------------------------------------------------------------------
# Blended; Force PSF; W/ apcorr
[        nan  0.03408057  0.07865285  0.07616222  0.09672412  0.12321678
  0.17632373]
[        nan  0.07872479  0.07211655  0.07448555  0.07525942  0.06618183
  0.01961287]
#--------------------------------------------------------------------------------

In [189]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7

print("#--------------------------------------------------------------------------------")
print(" g-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoG1['mag_G'] + starIsoG1['force.mag.psf.apcorr']
ff = 10.0 ** ((27.0 - xx) / 2.5)
yy = starIsoG1['force.mag.psf'] - starIsoG1['mag_G'] - starIsoG1['force.mag.psf.apcorr']
zz = ((starIsoG1['force.flux.psf'] - ff) / ff) * 100.0
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
zz = zz[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
zzStd = np.asarray([np.nanstd(zz[idx==k+1]) for k in range(total_bins)])
zzErr = np.asarray([np.nanmedian(zz[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(zzStd[1:])
print(zzErr[1:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 g-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 1.61243224  1.81124655  2.11355505  2.6714781   4.08443994  9.27765298]
[-0.85597443 -0.81725333 -0.79440456 -0.79250566 -0.69439846  0.22763424]
#--------------------------------------------------------------------------------

r-band forced PSF photometry


In [191]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoR1['mag_R']
yy = starIsoR1['force.mag.psf'] - starIsoR1['mag_R'] - starIsoR1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]

## 
zz = np.sqrt(starIsoR1['force.mag.psf.err'] ** 2.0 + starIsoR1['force.mag.psf.apcorr.err'] ** 2.0)
zz = zz[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])

xx2 = starIsoR2['mag_R']
yy2 = starIsoR2['force.mag.psf'] - starIsoR2['mag_R'] - starIsoR2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy2 = yy2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xx3 = starBldR1['mag_R']
yy3 = starBldR1['force.mag.psf'] - starBldR1['mag_R'] - starBldR1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy3 = yy3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xmin, xmax = 16.9, 27.29
ymin, ymax = -0.42, 0.59

xlabel = r'$r\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$r_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - r_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(1, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(RCMAP(0.3), RCMAP(0.5), RCMAP(0.7), RCMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(2, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(RCMAP(0.6), RCMAP(0.7), RCMAP(0.9), RCMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.7), edgecolor='none', 
                  alpha=0.2, s=20, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.6))
legend.legendHandles[1].set_color(RCMAP(0.3))
legend.legendHandles[2].set_color(RCMAP(0.5))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=RCMAP(0.2), 
                  edgecolor=RCMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=RCMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=YCMAP(0.5), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

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



In [193]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" r-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoR1['mag_R']
yy = starIsoR1['force.mag.psf'] - starIsoR1['mag_R'] - starIsoR1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoR1['mag_R']
yy = starIsoR1['mag.psf'] - starIsoR1['mag_R'] - starIsoR1['mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Unforced PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoR2['mag_R']
yy = starIsoR2['force.mag.psf'] - starIsoR2['mag_R'] - starIsoR2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Bad Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starBldR1['mag_R']
yy = starBldR1['force.mag.psf'] - starBldR1['mag_R'] - starBldR1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Blended; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 r-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 0.02292495  0.02286481  0.02363365  0.02560947  0.02721667  0.03493716
  0.06392703]
[ 0.01152836  0.01100582  0.01178399  0.01145287  0.01167357  0.01060029
  0.01100477]
#--------------------------------------------------------------------------------
# Good Seeing; Unforced PSF; W/ apcorr
[ 0.02295619  0.02277675  0.02358924  0.02558431  0.02719425  0.03487396
  0.06404551]
[ 0.00920182  0.00897189  0.00960562  0.00939992  0.00939119  0.00826366
  0.00710492]
#--------------------------------------------------------------------------------
# Bad Seeing; Force PSF; W/ apcorr
[ 0.02649187  0.0292515   0.03081682  0.03420448  0.04074492  0.05447927
  0.09732689]
[ 0.00886422  0.00922705  0.00930817  0.00932084  0.00880397  0.00590043
  0.00050932]
#--------------------------------------------------------------------------------
# Blended; Force PSF; W/ apcorr
[ 0.1453582   0.12255462  0.10436992  0.10807754  0.12395712  0.13507733
  0.14788236]
[ 0.11206544  0.09384538  0.09823697  0.10400274  0.11175136  0.13434284
  0.11894564]
#--------------------------------------------------------------------------------

In [194]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7

print("#--------------------------------------------------------------------------------")
print(" r-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoR1['mag_R'] + starIsoR1['force.mag.psf.apcorr']
ff = 10.0 ** ((27.0 - xx) / 2.5)
yy = starIsoR1['force.mag.psf'] - starIsoR1['mag_R'] - starIsoR1['force.mag.psf.apcorr']
zz = ((starIsoR1['force.flux.psf'] - ff) / ff) * 100.0
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
zz = zz[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
zzStd = np.asarray([np.nanstd(zz[idx==k+1]) for k in range(total_bins)])
zzErr = np.asarray([np.nanmedian(zz[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(zzStd[1:])
print(zzErr[1:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 r-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 2.09791941  2.14818641  2.32486139  2.44129256  3.1663016   5.81965704]
[-1.01224536 -1.0760025  -1.04846126 -1.06852774 -0.97157215 -1.04413537]
#--------------------------------------------------------------------------------

z-band forced PSF photometry


In [198]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoZ1['mag_Z']
yy = starIsoZ1['force.mag.psf'] - starIsoZ1['mag_Z'] - starIsoZ1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]

## 
zz = np.sqrt(starIsoZ1['force.mag.psf.err'] ** 2.0 + starIsoZ1['force.mag.psf.apcorr.err'] ** 2.0)
zz = zz[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])

xx2 = starIsoZ2['mag_Z']
yy2 = starIsoZ2['force.mag.psf'] - starIsoZ2['mag_Z'] - starIsoZ2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy2 = yy2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xx3 = starBldZ1['mag_Z']
yy3 = starBldZ1['force.mag.psf'] - starBldZ1['mag_Z'] - starBldZ1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy3 = yy3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xmin, xmax = 16.9, 27.29
ymin, ymax = -0.42, 0.59

xlabel = r'$z\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$z_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - z_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ZCMAP(0.3), ZCMAP(0.5), ZCMAP(0.7), ZCMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(1.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ZCMAP(0.6), ZCMAP(0.7), ZCMAP(0.9), ZCMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.7), edgecolor='none', 
                  alpha=0.2, s=20, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.6))
legend.legendHandles[1].set_color(ZCMAP(0.3))
legend.legendHandles[2].set_color(ZCMAP(0.5))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=ZCMAP(0.2), 
                  edgecolor=ZCMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=ZCMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=YCMAP(0.5), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

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



In [203]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" z-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoZ1['mag_Z']
yy = starIsoZ1['force.mag.psf'] - starIsoZ1['mag_Z'] - starIsoZ1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoZ1['mag_Z']
yy = starIsoZ1['mag.psf'] - starIsoZ1['mag_Z'] - starIsoZ1['mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Unforced PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoZ2['mag_Z']
yy = starIsoZ2['force.mag.psf'] - starIsoZ2['mag_Z'] - starIsoZ2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Bad Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starBldZ1['mag_Z']
yy = starBldZ1['force.mag.psf'] - starBldZ1['mag_Z'] - starBldZ1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Blended; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 z-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 0.01145676  0.01268164  0.01383423  0.01570484  0.02551882  0.05257064
  0.10491381]
[ 0.00181902  0.00231512  0.00248033  0.0025165   0.00274894  0.00516665
 -0.00126393]
#--------------------------------------------------------------------------------
# Good Seeing; Unforced PSF; W/ apcorr
[ 0.0109896   0.01234829  0.01408835  0.01590101  0.02543104  0.05279224
  0.10315214]
[-0.00071982 -0.00032688 -0.00016274 -0.00014483 -0.0002145   0.00099144
 -0.0134226 ]
#--------------------------------------------------------------------------------
# Bad Seeing; Force PSF; W/ apcorr
[ 0.01951915  0.02006839  0.02127986  0.02484088  0.03824095  0.08146183
  0.15496451]
[ 0.00268264  0.00307505  0.00319223  0.00392599  0.00512212  0.00346129
 -0.00973434]
#--------------------------------------------------------------------------------
# Blended; Force PSF; W/ apcorr
[ 0.1001663   0.08966248  0.09503588  0.10578562  0.11495369  0.13620622
  0.17331282]
[ 0.08629127  0.08725566  0.09218801  0.10197652  0.12228563  0.13525281
  0.06516214]
#--------------------------------------------------------------------------------

In [200]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" z-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoZ1['mag_Z'] + starIsoZ1['force.mag.psf.apcorr']
ff = 10.0 ** ((27.0 - xx) / 2.5)
yy = starIsoZ1['force.mag.psf'] - starIsoZ1['mag_Z'] - starIsoZ1['force.mag.psf.apcorr']
zz = ((starIsoZ1['force.flux.psf'] - ff) / ff) * 100.0
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
zz = zz[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
zzStd = np.asarray([np.nanstd(zz[idx==k+1]) for k in range(total_bins)])
zzErr = np.asarray([np.nanmedian(zz[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(zzStd[1:])
print(zzErr[1:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 z-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 1.16749914  1.24794396  1.43318554  2.31317246  4.75412987  9.66528377]
[-0.20762449 -0.23004096 -0.22799097 -0.25377259 -0.43413538 -0.06096382]
#--------------------------------------------------------------------------------

y-band forced PSF photometry


In [204]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoY1['mag_Y']
yy = starIsoY1['force.mag.psf'] - starIsoY1['mag_Y'] - starIsoY1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]

## 
zz = np.sqrt(starIsoY1['force.mag.psf.err'] ** 2.0 + starIsoY1['force.mag.psf.apcorr.err'] ** 2.0)
zz = zz[(xTemp >= 16.9) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])

xx2 = starIsoY2['mag_Y']
yy2 = starIsoY2['force.mag.psf'] - starIsoY2['mag_Y'] - starIsoY2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx2), copy.deepcopy(yy2)
xx2 = xx2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy2 = yy2[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xx3 = starBldY1['mag_Y']
yy3 = starBldY1['force.mag.psf'] - starBldY1['mag_Y'] - starBldY1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]
yy3 = yy3[(xTemp >= 16.9) & (xTemp <= 26.9) &
          (yTemp >= -0.42) & (yTemp <= 0.59)]

xmin, xmax = 16.9, 27.29
ymin, ymax = -0.42, 0.59

xlabel = r'$y\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$y_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - y_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(YCMAP(0.3), YCMAP(0.5), YCMAP(0.7), YCMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1.0)
levels = np.linspace(1.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(YCMAP(0.6), YCMAP(0.7), YCMAP(0.9), YCMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.7), edgecolor='none', 
                  alpha=0.2, s=20, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.6))
legend.legendHandles[1].set_color(YCMAP(0.3))
legend.legendHandles[2].set_color(YCMAP(0.5))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=YCMAP(0.2), 
                  edgecolor=YCMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=YCMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=YCMAP(0.5), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

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



In [205]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" y-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoY1['mag_Y']
yy = starIsoY1['force.mag.psf'] - starIsoY1['mag_Y'] - starIsoY1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoY1['mag_Y']
yy = starIsoY1['mag.psf'] - starIsoY1['mag_Y'] - starIsoY1['mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Unforced PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoY2['mag_Y']
yy = starIsoY2['force.mag.psf'] - starIsoY2['mag_Y'] - starIsoY2['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Bad Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starBldY1['mag_Y']
yy = starBldY1['force.mag.psf'] - starBldY1['mag_Y'] - starBldY1['force.mag.psf.apcorr']
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Blended; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 y-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 0.01680352  0.01650242  0.02096231  0.03636639  0.07403357  0.13858148
  0.17731495]
[ 0.00644051  0.00630764  0.00634368  0.00641546 -0.00089085 -0.02605289
 -0.15729102]
#--------------------------------------------------------------------------------
# Good Seeing; Unforced PSF; W/ apcorr
[ 0.01674262  0.01646796  0.02085376  0.03623301  0.07376711  0.13526466
  0.1619954 ]
[ 0.00474735  0.00466768  0.00463202  0.00435041 -0.00538861 -0.04135756
 -0.21119925]
#--------------------------------------------------------------------------------
# Bad Seeing; Force PSF; W/ apcorr
[ 0.01870934  0.01999731  0.02279584  0.03722268  0.07679486  0.15352582
  0.22259359]
[ 0.00714796  0.00774028  0.0077216   0.0063072   0.00257275 -0.02412798
 -0.11526021]
#--------------------------------------------------------------------------------
# Blended; Force PSF; W/ apcorr
[ 0.08862614  0.07666804  0.10364346  0.11850524  0.1479997   0.19677536
  0.20656178]
[ 0.0750586   0.08443694  0.09193556  0.09867404  0.07798403 -0.00028306
 -0.11956707]
#--------------------------------------------------------------------------------

In [206]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" y-Band PSF")
print("#--------------------------------------------------------------------------------")
xx = starIsoY1['mag_Y'] + starIsoY1['force.mag.psf.apcorr']
ff = 10.0 ** ((27.0 - xx) / 2.5)
yy = starIsoY1['force.mag.psf'] - starIsoY1['mag_Y'] - starIsoY1['force.mag.psf.apcorr']
zz = ((starIsoY1['force.flux.psf'] - ff) / ff) * 100.0
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
yy = yy[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
zz = zz[(xTemp >= 19.1) & (xTemp <= 26.9) &
        (yTemp >= -0.42) & (yTemp <= 0.59)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
zzStd = np.asarray([np.nanstd(zz[idx==k+1]) for k in range(total_bins)])
zzErr = np.asarray([np.nanmedian(zz[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(zzStd[:])
print(zzErr[:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 y-Band PSF
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[  1.50451121   1.51798667   1.90826852   3.2672094    6.73807259
  12.96937856  17.58204458]
[ -0.5903039   -0.57924919  -0.5799659   -0.58035077   0.01845079
   2.37171814  15.5889744 ]
#--------------------------------------------------------------------------------

Point Source Selection


In [214]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xx = starIsoI1['mag_I']
yy = starIsoI1['mag.psf'] - starIsoI1['cmodel.mag'] 

xmin, xmax = 16.9, 26.9
ymin, ymax = -0.29, 0.49

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 = misClassI2['mag_I']
yy2 = misClassI2['mag.psf'] - misClassI2['cmodel.mag']
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)]

xx3 = misClassI1['mag_I']
yy3 = misClassI1['mag.psf'] - misClassI1['cmodel.mag']
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]
yy3 = yy3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]

xlabel = r'$i\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$i_{\mathrm{PSF}} - i_{\mathrm{cModel}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ICMAP(0.3), ICMAP(0.5), ICMAP(0.7), ICMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx3, yy3, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.6), ICMAP(0.7), ICMAP(0.8), ICMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx, yy, marker='o', facecolor=YCMAP(0.5), edgecolor='none', 
                  alpha=0.1, s=15, label='$\mathrm{Good\ Seeing}$', rasterized=True)

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Misclassified/Bad\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Misclassified/Good\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.6))
legend.legendHandles[1].set_color(ICMAP(0.3))
legend.legendHandles[2].set_color(ICMAP(0.5))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=ICMAP(0.25), 
                  edgecolor=ICMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=ICMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=YCMAP(0.5), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

fig.savefig(os.path.join(figDir, 'star1_HSC-I_magI_dPSF-cModel_new.pdf'), 
            format='pdf', dpi=90)


/Users/song/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:19: RuntimeWarning: invalid value encountered in greater_equal
/Users/song/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:19: RuntimeWarning: invalid value encountered in less_equal
/Users/song/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:21: RuntimeWarning: invalid value encountered in greater_equal
/Users/song/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:21: RuntimeWarning: invalid value encountered in less_equal
/Users/song/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:27: RuntimeWarning: invalid value encountered in greater_equal
/Users/song/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:27: RuntimeWarning: invalid value encountered in less_equal
/Users/song/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:29: RuntimeWarning: invalid value encountered in greater_equal
/Users/song/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:29: RuntimeWarning: invalid value encountered in less_equal

Color Accuracy

(g-i) Color


In [215]:
starIsoGI1 = join(starIsoG1, starIsoI1, join_type='inner', keys='id')
starIsoGI2 = join(starIsoG2, starIsoI2, join_type='inner', keys='id')
starBldGI1 = join(starBldG1, starBldI1, join_type='inner', keys='id')


WARNING: MergeConflictWarning: Cannot merge meta key 'EXTNAME' types <type 'str'> and <type 'str'>, choosing EXTNAME='/lustre/Subaru/SSP/rerun/song/fake/synpipe/add/star_9699_HSC-I.fi...' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'DATE-HDU' types <type 'str'> and <type 'str'>, choosing DATE-HDU='2016-10-20T18:19:02' [astropy.utils.metadata]

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

xmin, xmax = -1.19, 5.29
ymin, ymax = -0.79, 0.79

xx = starIsoGI1['mag_G_1'] - starIsoGI1['mag_I_1']
yy = (starIsoGI1['force.mag.psf_1'] - starIsoGI1['force.mag.psf.apcorr_1'] -
      starIsoGI1['force.mag.psf_2'] + starIsoGI1['force.mag.psf.apcorr_2']) - xx
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)]

zz = np.sqrt(starIsoGI1['force.mag.psf.err_1'] ** 2.0 + starIsoGI1['force.mag.psf.err_2'] ** 2.0 +
             starIsoGI1['force.mag.psf.apcorr.err_1'] ** 2.0 + starIsoGI1['force.mag.psf.apcorr.err_2'] ** 2.0)
zz = zz[(xTemp >= xmin) & (xTemp <= xmax) &
        (yTemp >= ymin) & (yTemp <= ymax)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])

xx2 = starIsoGI2['mag_G_1'] - starIsoGI2['mag_I_1']
yy2 = (starIsoGI2['force.mag.psf_1'] - starIsoGI2['force.mag.psf.apcorr_1'] -
       starIsoGI2['force.mag.psf_2'] + starIsoGI2['force.mag.psf.apcorr_2']) - xx2
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)]

xx3 = starBldGI1['mag_G_1'] - starBldGI1['mag_I_1']
yy3 = (starBldGI1['force.mag.psf_1'] - starBldGI1['force.mag.psf.apcorr_1'] -
       starBldGI1['force.mag.psf_2'] + starBldGI1['force.mag.psf.apcorr_2']) - xx3
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]
yy3 = yy3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]


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

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1.5)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ICMAP(0.3), ICMAP(0.5), ICMAP(0.7), ICMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1.5)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.6), ICMAP(0.7), ICMAP(0.8), ICMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.8), edgecolor='none', 
                  alpha=0.2, s=20, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.8))
legend.legendHandles[1].set_color(ICMAP(0.3))
legend.legendHandles[2].set_color(ICMAP(0.5))
# --------------------------------------------------------------------------------------- #

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

ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=ICMAP(0.25), 
                  edgecolor=ICMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=ICMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', 
                  edgecolor=YCMAP(0.8), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

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



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

xmin, xmax = 17.2, 26.9
ymin, ymax = -0.79, 0.79

xx = starIsoGI1['mag_I_1']
yy = (starIsoGI1['force.mag.psf_1'] - starIsoGI1['force.mag.psf.apcorr_1'] -
      starIsoGI1['force.mag.psf_2'] + starIsoGI1['force.mag.psf.apcorr_2']) - (
      starIsoGI1['mag_G_1'] - starIsoGI1['mag_I_1'])
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)]


zz = np.sqrt(starIsoGI1['force.mag.psf.err_1'] ** 2.0 + starIsoGI1['force.mag.psf.err_2'] ** 2.0 +
             starIsoGI1['force.mag.psf.apcorr.err_1'] ** 2.0 + starIsoGI1['force.mag.psf.apcorr.err_2'] ** 2.0)
zz = zz[(xTemp >= xmin) & (xTemp <= xmax) &
        (yTemp >= ymin) & (yTemp <= ymax)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])


xx2 = starIsoGI2['mag_I_1']
yy2 = (starIsoGI2['force.mag.psf_1'] - starIsoGI2['force.mag.psf.apcorr_1'] -
       starIsoGI2['force.mag.psf_2'] + starIsoGI2['force.mag.psf.apcorr_2']) - (
       starIsoGI2['mag_G_1'] - starIsoGI2['mag_I_1'])
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)]

xx3 = starBldGI1['mag_I_1']
yy3 = (starBldGI1['force.mag.psf_1'] - starBldGI1['force.mag.psf.apcorr_1'] -
       starBldGI1['force.mag.psf_2'] + starBldGI1['force.mag.psf.apcorr_2']) - (
       starBldGI1['mag_G_1'] - starBldGI1['mag_I_1'])
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]
yy3 = yy3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]

xlabel = r'$i\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$(g-i)_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - (g-i)_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1.2)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ICMAP(0.3), ICMAP(0.5), ICMAP(0.7), ICMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1.2)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.6), ICMAP(0.7), ICMAP(0.8), ICMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.8), edgecolor='none', 
                  alpha=0.2, s=20, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.8))
legend.legendHandles[1].set_color(ICMAP(0.3))
legend.legendHandles[2].set_color(ICMAP(0.5))
# --------------------------------------------------------------------------------------- #

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

ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=ICMAP(0.25), 
                  edgecolor=ICMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=ICMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens) * 2.0, facecolor='None', 
                  edgecolor=YCMAP(0.8), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

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



In [243]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" g-i PSF color")
print("#--------------------------------------------------------------------------------")
xx = starIsoGI1['mag_I_1']
yy = (starIsoGI1['force.mag.psf_1'] - starIsoGI1['force.mag.psf.apcorr_1'] -
      starIsoGI1['force.mag.psf_2'] + starIsoGI1['force.mag.psf.apcorr_2']) - (
      starIsoGI1['mag_G_1'] - starIsoGI1['mag_I_1'])
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoGI2['mag_I_1']
yy = (starIsoGI2['force.mag.psf_1'] - starIsoGI2['force.mag.psf.apcorr_1'] -
      starIsoGI2['force.mag.psf_2'] + starIsoGI2['force.mag.psf.apcorr_2']) - (
      starIsoGI2['mag_G_1'] - starIsoGI2['mag_I_1'])
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Bad Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starBldGI1['mag_I_1']
yy = (starBldGI1['force.mag.psf_1'] - starBldGI1['force.mag.psf.apcorr_1'] -
      starBldGI1['force.mag.psf_2'] + starBldGI1['force.mag.psf.apcorr_2']) - (
      starBldGI1['mag_G_1'] - starBldGI1['mag_I_1'])
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Blended; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 g-i PSF color
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 0.02253657  0.02636285  0.03725434  0.05443754  0.07778959  0.10514873
  0.11789936]
[ 0.00775018  0.00667818  0.00586082  0.00250016 -0.00183938 -0.00862218
 -0.03541246]
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# Bad Seeing; Force PSF; W/ apcorr
[ 0.02064016  0.02534535  0.03346169  0.0511773   0.07493225  0.10537755
  0.13675691]
[ 0.00393631  0.00265831  0.002129    0.00077762 -0.00058973 -0.00182855
  0.00701855]
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# Blended; Force PSF; W/ apcorr
[ 0.18359274  0.14684505  0.14894063  0.17186229  0.18698728  0.21532259
  0.23444694]
[ 0.02030427  0.0113013   0.00767305 -0.02154599 -0.05596531 -0.07731443
 -0.16433544]
#--------------------------------------------------------------------------------

(i-y) Color


In [221]:
starIsoIY1 = join(starIsoI1, starIsoY1, join_type='inner', keys='id')
starIsoIY2 = join(starIsoI2, starIsoY2, join_type='inner', keys='id')
starBldIY1 = join(starBldI1, starBldY1, join_type='inner', keys='id')

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

xmin, xmax = -0.99, 1.99
ymin, ymax = -0.79, 0.79

xx = starIsoIY1['mag_I_1'] - starIsoIY1['mag_Y_1']
yy = (starIsoIY1['force.mag.psf_1'] - starIsoIY1['force.mag.psf.apcorr_1'] -
      starIsoIY1['force.mag.psf_2'] + starIsoIY1['force.mag.psf.apcorr_2']) - xx
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)]

zz = np.sqrt(starIsoIY1['force.mag.psf.err_1'] ** 2.0 + starIsoIY1['force.mag.psf.err_2'] ** 2.0 +
             starIsoIY1['force.mag.psf.apcorr.err_1'] ** 2.0 + starIsoIY1['force.mag.psf.apcorr.err_2'] ** 2.0)
zz = zz[(xTemp >= xmin) & (xTemp <= xmax) &
        (yTemp >= ymin) & (yTemp <= ymax)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])


xx2 = starIsoIY2['mag_I_1'] - starIsoIY2['mag_Y_1']
yy2 = (starIsoIY2['force.mag.psf_1'] - starIsoIY2['force.mag.psf.apcorr_1'] -
       starIsoIY2['force.mag.psf_2'] + starIsoIY2['force.mag.psf.apcorr_2']) - xx2
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)]

xx3 = starBldIY1['mag_I_1'] - starBldIY1['mag_Y_1']
yy3 = (starBldIY1['force.mag.psf_1'] - starBldIY1['force.mag.psf.apcorr_1'] -
       starBldIY1['force.mag.psf_2'] + starBldIY1['force.mag.psf.apcorr_2']) - xx3
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]
yy3 = yy3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]

xlabel = r'$(i-y)\ \mathrm{Input\ Color\ (mag)}$'
ylabel = r'$(i-y)_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - (i-y)_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1.2)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ZCMAP(0.3), ZCMAP(0.5), ZCMAP(0.7), ZCMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1.2)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ZCMAP(0.6), ZCMAP(0.7), ZCMAP(0.8), ZCMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.8), edgecolor='none', 
                  alpha=0.2, s=20, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.8))
legend.legendHandles[1].set_color(ZCMAP(0.3))
legend.legendHandles[2].set_color(ZCMAP(0.5))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=ZCMAP(0.25), 
                  edgecolor=ZCMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=ZCMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens) * 2.0, facecolor='None', 
                  edgecolor=YCMAP(0.8), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

fig.savefig(os.path.join(figDir, 'star1_HSC-I-Y_iyInput_iyPSF_new.pdf'), 
            format='pdf', dpi=90)



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

xmin, xmax = 16.8, 26.9
ymin, ymax = -0.79, 0.79

xx = starIsoIY1['mag_I_1']
yy = (starIsoIY1['force.mag.psf_1'] - starIsoIY1['force.mag.psf.apcorr_1'] -
      starIsoIY1['force.mag.psf_2'] + starIsoIY1['force.mag.psf.apcorr_2']) - (
      starIsoIY1['mag_I_1'] - starIsoIY1['mag_Y_1'])
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)]

zz = np.sqrt(starIsoIY1['force.mag.psf.err_1'] ** 2.0 + starIsoIY1['force.mag.psf.err_2'] ** 2.0 +
             starIsoIY1['force.mag.psf.apcorr.err_1'] ** 2.0 + starIsoIY1['force.mag.psf.apcorr.err_2'] ** 2.0)
zz = zz[(xTemp >= xmin) & (xTemp <= xmax) &
        (yTemp >= ymin) & (yTemp <= ymax)]
total_bins = 20
bins = np.linspace(xx.min(), xx.max(), total_bins)
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins - delta / 2.0)
zzErr = np.asarray([np.nanmedian(zz[idx==k]) for k in range(total_bins)])

xx2 = starIsoIY2['mag_I_1']
yy2 = (starIsoIY2['force.mag.psf_1'] - starIsoIY2['force.mag.psf.apcorr_1'] -
       starIsoIY2['force.mag.psf_2'] + starIsoIY2['force.mag.psf.apcorr_2']) - (
       starIsoIY2['mag_I_1'] - starIsoIY2['mag_Y_1'])
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)]

xx3 = starBldIY1['mag_I_1']
yy3 = (starBldIY1['force.mag.psf_1'] - starBldIY1['force.mag.psf.apcorr_1'] -
       starBldIY1['force.mag.psf_2'] + starBldIY1['force.mag.psf.apcorr_2']) - (
       starBldIY1['mag_I_1'] - starBldIY1['mag_Y_1'])
xTemp, yTemp = copy.deepcopy(xx3), copy.deepcopy(yy3)
xx3 = xx3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]
yy3 = yy3[(xTemp >= xmin) & (xTemp <= xmax) &
          (yTemp >= ymin) & (yTemp <= ymax)]

xlabel = r'$i\ \mathrm{Band\ Input\ Magnitude\ (mag)}$'
ylabel = r'$(i-y)_{\mathrm{Forced},\ {\mathrm{PSF}}} - (i-y)_{\mathrm{Input}}\ \mathrm{(mag)}$'

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

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(17, 15))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)

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)

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

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1.2)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ZCMAP(0.3), ZCMAP(0.5), ZCMAP(0.7), ZCMAP(1.0)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1.2)
levels = np.linspace(0.5, H.max(), 4)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ZCMAP(0.6), ZCMAP(0.7), ZCMAP(0.8), ZCMAP(1.0)),
                  linestyles='--', linewidths=6, levels=levels, alpha=0.9)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

## Scatter
CS3 = ax1.scatter(xx3, yy3, marker='o', facecolor=YCMAP(0.8), edgecolor='none', 
                  alpha=0.2, s=20, label='$\mathrm{Blended}$', rasterized=True)

## Running medians
ax1.plot(xxCen, zzErr,'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))
ax1.plot(xxCen, zzErr * (-1.0),'--', lw=4, alpha=0.6, c=BLK(0.7), dashes=(40,10))

ax1.axhline(0.0, color=BLK(0.7), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.8)

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

## X, Y limits
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(ymin, ymax)
# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.09, 0.05), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=2.0, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(YCMAP(0.8))
legend.legendHandles[1].set_color(ZCMAP(0.3))
legend.legendHandles[2].set_color(ZCMAP(0.5))
# --------------------------------------------------------------------------------------- #

# --------------------------------------------------------------------------------------- #
## Ax2
ax2.grid()

# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy[:, None])
yPlot = np.linspace(ymin, ymax, 500)
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor=ZCMAP(0.25), 
                  edgecolor=ZCMAP(0.05), alpha=1.0, linewidth=1.0, linestyle='-')

kde = KernelDensity(kernel='gaussian', bandwidth=0.001).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.plot(np.exp(log_dens), yPlot, linestyle='--', dashes=(20, 6), linewidth=6.0,
         color=ZCMAP(0.6), alpha=1.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.01).fit(yy3[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax2.fill_betweenx(yPlot, 0.0, np.exp(log_dens) * 2.0, facecolor='None', 
                  edgecolor=YCMAP(0.8), alpha=0.8, linewidth=6.0, 
                  linestyle='-')

ax2.axhline(0.0, color=BLK(0.8), linewidth=5.0, linestyle='--', dashes=(40, 10), 
            alpha=0.9)

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

fig.savefig(os.path.join(figDir, 'star1_HSC-I-Y_imag_iyPSF_new.pdf'), 
            format='pdf', dpi=90)



In [225]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
total_bins = 7
bins = np.asarray([18.5, 19.5, 20.5, 21.5, 22.5, 23.5, 24.5])

print("#--------------------------------------------------------------------------------")
print(" i-y PSF color")
print("#--------------------------------------------------------------------------------")
xx = starIsoIY1['mag_I_1']
yy = (starIsoIY1['force.mag.psf_1'] - starIsoIY1['force.mag.psf.apcorr_1'] -
      starIsoIY1['force.mag.psf_2'] + starIsoIY1['force.mag.psf.apcorr_2']) - (
      starIsoIY1['mag_I_1'] - starIsoIY1['mag_Y_1'])
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("Magnitude bins: ", xxCen)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starIsoIY2['mag_I_1']
yy = (starIsoIY2['force.mag.psf_1'] - starIsoIY2['force.mag.psf.apcorr_1'] -
      starIsoIY2['force.mag.psf_2'] + starIsoIY2['force.mag.psf.apcorr_2']) - (
      starIsoIY2['mag_I_1'] - starIsoIY2['mag_Y_1'])
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")
xx = starBldIY1['mag_I_1']
yy = (starBldIY1['force.mag.psf_1'] - starBldIY1['force.mag.psf.apcorr_1'] -
      starBldIY1['force.mag.psf_2'] + starBldIY1['force.mag.psf.apcorr_2']) - (
      starBldIY1['mag_I_1'] - starBldIY1['mag_Y_1'])
xTemp, yTemp = copy.deepcopy(xx), copy.deepcopy(yy)
xx = xx[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
yy = yy[(xTemp >= 18.5) & (xTemp <= 26.9) &
        (yTemp >= -0.62) & (yTemp <= 0.69)]
delta = (bins[1] - bins[0])
idx  = np.digitize(xx, bins)
xxCen = (bins + delta / 2.0)
print("#--------------------------------------------------------------------------------")
yyStd = np.asarray([np.nanstd(yy[idx==k+1]) for k in range(total_bins)])
yyErr = np.asarray([np.nanmedian(yy[idx==k+1]) for k in range(total_bins)])
print("# Good Seeing; Force PSF; W/ apcorr")
print(yyStd[:])
print(yyErr[:])
print("#--------------------------------------------------------------------------------")


#--------------------------------------------------------------------------------
 i-y PSF color
#--------------------------------------------------------------------------------
Magnitude bins:  [ 19.  20.  21.  22.  23.  24.  25.]
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 0.01922692  0.01956234  0.02160422  0.03059128  0.05843245  0.10891587
  0.18915238]
[-0.00440313 -0.00425602 -0.00369999 -0.00363815 -0.00269938  0.01126505
  0.06447616]
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 0.01935267  0.02038691  0.02126169  0.03068027  0.05732484  0.12272108
  0.22129306]
[-0.00644505 -0.00611746 -0.005602   -0.00514993 -0.00495023 -0.00150081
  0.06404136]
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# Good Seeing; Force PSF; W/ apcorr
[ 0.11124422  0.10324821  0.13338463  0.12901018  0.16250795  0.19893096
  0.23767885]
[ 0.00391462  0.01179811  0.00220357  0.01182004  0.03657123  0.12508115
  0.22691305]
#--------------------------------------------------------------------------------

Color-Color distributions


In [227]:
starIsoGR1 = join(starIsoG1, starIsoR1, join_type='inner', keys='id')
starIsoGR2 = join(starIsoG2, starIsoR2, join_type='inner', keys='id')
starBldGR1 = join(starBldG1, starBldR1, join_type='inner', keys='id')
print(len(starIsoGR1), len(starIsoGR2), len(starBldR1))

starIsoGRI1 = join(starIsoGR1, starIsoI1, join_type='inner', keys='id')
starIsoGRI2 = join(starIsoGR2, starIsoI2, join_type='inner', keys='id')
starBldGRI1 = join(starBldGR1, starBldI1, join_type='inner', keys='id')
print(len(starIsoGRI1), len(starIsoGRI2), len(starBldGRI1))


30858 31205 5544
22500 25286 2154

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

xmin, xmax = -0.39, 1.99
ymin, ymax = -0.39, 2.49


xx = starIsoGRI1['mag_G_1'] - starIsoGRI1['mag_R_1']
yy = starIsoGRI1['mag_R_1'] - starIsoGRI1['mag_I_1']
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 = (starIsoGRI1['force.mag.psf_1'] - starIsoGRI1['force.mag.psf.apcorr_1'] -
       starIsoGRI1['force.mag.psf_2'] + starIsoGRI1['force.mag.psf.apcorr_2'])
yy2 = (starIsoGRI1['force.mag.psf_2'] - starIsoGRI1['force.mag.psf.apcorr_2'] -
       starIsoGRI1['force.mag.psf'] + starIsoGRI1['force.mag.psf.apcorr'])
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()

## Contour
H, xbins, ybins = np.histogram2d(xx, yy, bins=(90, 90))
H = gaussian_filter(H, 1.2)
levels = np.linspace(1, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS3 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(BLK(0.3), BLK(0.5), BLK(0.7), BLK(0.9)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(90, 90))
H = gaussian_filter(H, 1.2)
levels = np.linspace(1, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(GCMAP(0.6), GCMAP(0.7), GCMAP(0.8), GCMAP(0.9)),
                  linewidths=6, levels=levels, alpha=0.8)

# --------------------------------------------------------------------------------------- #
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 = []
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS3.collections]
l_handles.append(proxy[0])
l_handles.append(CS2.collections[-1])
l_labels = []
l_labels.append('$\mathrm{Input}$')
l_labels.append('$\mathrm{Forced\ PSF}$')
ax1.legend(l_handles, l_labels, loc=(0.07, 0.80), 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(BLK(0.3))
legend.legendHandles[1].set_color(GCMAP(0.8))
# --------------------------------------------------------------------------------------- #

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

ax2.grid()
# Gaussian KDE
kde = KernelDensity(kernel='gaussian', bandwidth=0.008).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=BLK(0.3), edgecolor=BLK(0.0), 
         alpha=0.9, linewidth=4.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.008).fit(xx2[:, None])
log_dens = kde.score_samples(xPlot[:, None])
ax2.fill(xPlot[:, None], np.exp(log_dens), facecolor='None', edgecolor=GCMAP(0.8), 
         alpha=0.9, 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=BLK(0.3), edgecolor=BLK(0.0),
                  alpha=0.9, linewidth=4.0)

kde = KernelDensity(kernel='gaussian', bandwidth=0.02).fit(yy2[:, None])
log_dens = kde.score_samples(yPlot[:, None])
ax3.fill_betweenx(yPlot, 0.0, np.exp(log_dens), facecolor='None', edgecolor=GCMAP(0.8),
                  alpha=0.9, 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-I_grPSF_riPSF_new.pdf'), 
            format='pdf', dpi=90)



In [231]:
starIsoIZY1 = join(starIsoIY1, starIsoZ1, join_type='inner', keys='id')
starIsoIZY2 = join(starIsoIY2, starIsoZ2, join_type='inner', keys='id')
starBldIZY1 = join(starBldIY1, starBldZ1, join_type='inner', keys='id')
print(len(starIsoIZY1), len(starIsoIZY2), len(starBldIZY1))


24178 27201 1718

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

xmin, xmax = -0.29, 1.19
ymin, ymax = -0.29, 0.59

xx = starIsoIZY1['mag_I_1'] - starIsoIZY1['mag_Z_1']
yy = starIsoIZY1['mag_Z_1'] - starIsoIZY1['mag_Y_1']
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 = (starIsoIZY1['force.mag.psf_1'] - starIsoIZY1['force.mag.psf.apcorr_1'] -
       starIsoIZY1['force.mag.psf'] + starIsoIZY1['force.mag.psf.apcorr'])
yy2 = (starIsoIZY1['force.mag.psf'] - starIsoIZY1['force.mag.psf.apcorr'] -
       starIsoIZY1['force.mag.psf_2'] + starIsoIZY1['force.mag.psf.apcorr_2'])
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'$(i-z)_{\mathrm{PSF}}} \mathrm{(mag)}$'
ylabel = r'$(z-y)_{\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()

## Contour
H, xbins, ybins = np.histogram2d(xx, yy, bins=(90, 90))
H = gaussian_filter(H, 1.2)
levels = np.linspace(1, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS3 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(BLK(0.3), BLK(0.5), BLK(0.7), BLK(0.9)),
                   linewidths=10, levels=levels, alpha=0.6)

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(90, 90))
H = gaussian_filter(H, 1.2)
levels = np.linspace(1, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.6), ICMAP(0.7), ICMAP(0.8), ICMAP(0.9)),
                  linewidths=6, levels=levels, alpha=0.8)


# --------------------------------------------------------------------------------------- #
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 = []
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_handles.append(CS2.collections[-1])
l_labels = []
l_labels.append('$\mathrm{Input}$')
l_labels.append('$\mathrm{Forced\ PSF}$')
ax1.legend(l_handles, l_labels, loc=(0.07, 0.82), 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(BLK(0.3))
legend.legendHandles[1].set_color(ICMAP(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=BLK(0.3), edgecolor=BLK(0.0), 
         alpha=0.9, 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=ICMAP(0.8), 
         alpha=0.9, 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=BLK(0.3), edgecolor=BLK(0.0),
                  alpha=0.9, 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=ICMAP(0.8),
                  alpha=0.9, 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-I-Z-Y_izPSF_zyPSF_new.pdf'), 
            format='pdf', dpi=90)


Relation between Blendedness and Magnitude Error


In [83]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xmin, xmax = -6.69, 0.29
ymin, ymax = 0.00, 0.04

starUse1 = starGoodI1[(starGoodI1['blendedness.abs.flux'] > 0.0) & 
                      (starGoodI1['mag_I'] <= 24.0)]
starUse2 = starGoodI2[(starGoodI2['blendedness.abs.flux'] > 0.0) & 
                      (starGoodI2['mag_I'] <= 24.0)]

xx = np.log10(starUse1['blendedness.abs.flux'])
yy = starUse1['force.mag.psf.err']
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 = np.log10(starUse2['blendedness.abs.flux'])
yy2 = starUse2['force.mag.psf.err']
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'$\log\ (\mathrm{Blendedness})$'
ylabel = r'$i\ \mathrm{Band\ PSF\ Magnitude\ Error}$'

xtickFormat, ytickFormat = r'$\mathbf{%4.1f}$', r'$\mathbf{%5.2f}\ $'
ytickFormat2 = r'$\mathbf{%5.2f}$'

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.17, right=0.99, 
                    bottom=0.13, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

## HexBin
hb1 = ax1.hexbin(xx, yy, cmap=ICMAP, mincnt=3,
                 alpha=0.8, gridsize=[60, 35], label='$\mathrm{Good}$',
                 marginals=False, vmin=5, vmax=200, 
                 edgecolor=ICMAP(0.3))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(220, 200))
H = gaussian_filter(H, 2)
levels = np.linspace(2, H.max(), 6)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.8), ICMAP(0.6)),
                  linewidths=4, levels=levels, alpha=0.9)

ax1.axvline(np.log10(0.10), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
l_handles[0] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS1.collections[-1])
l_labels[0] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.05, 0.78), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(ICMAP(0.3))
legend.legendHandles[1].set_color(ICMAP(0.6))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=54)

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

# --------------------------------------------------------------------------------------- #

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



In [239]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xmin, xmax = -6.69, 0.29
ymin, ymax = -0.25, 0.55

starUse1 = starGoodI1[(starGoodI1['blendedness.abs.flux'] > 0.0) & 
                      (starGoodI1['mag_I'] <= 24.0)]
starUse2 = starGoodI2[(starGoodI2['blendedness.abs.flux'] > 0.0) & 
                      (starGoodI2['mag_I'] <= 24.0)]

xx = np.log10(starUse1['blendedness.abs.flux'])
yy = starUse1['force.mag.psf'] - starUse1['mag_I'] - starUse1['force.mag.psf.apcorr']
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 = np.log10(starUse2['blendedness.abs.flux'])
yy2 = starUse2['force.mag.psf'] - starUse2['mag_I'] - starUse2['force.mag.psf.apcorr']
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'$\log_{10}\ (\mathrm{Blendedness})$'
ylabel = r'$i_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - i_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

xtickFormat, ytickFormat = r'$\mathbf{%4.1f}$', r'$\mathbf{%5.2f}\ $'
ytickFormat2 = r'$\mathbf{%5.2f}$'

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.20, right=0.99, 
                    bottom=0.13, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(0.5, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ICMAP(0.2), ICMAP(0.3), ICMAP(0.4), ICMAP(0.6), ICMAP(0.8)),
                   linewidths=10, levels=levels, alpha=1.0)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(0.5, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.5), ICMAP(0.6), ICMAP(0.7), ICMAP(0.8), ICMAP(0.9)),
                  linestyles='--', linewidths=6, levels=levels, alpha=1.0)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

ax1.axhline(0.0, color=BLK(0.9), linewidth=4.0, 
            linestyle='-', alpha=0.9, zorder=0)
ax1.axvline(np.log10(0.10), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.05, 0.78), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(ICMAP(0.2))
legend.legendHandles[1].set_color(ICMAP(0.5))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=54)

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

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


Relation between blendedness and color error


In [240]:
starGoodGI1 = join(starGoodG1, starGoodI1, join_type='inner', keys='id')
starGoodGI2 = join(starGoodG2, starGoodI2, join_type='inner', keys='id')

In [87]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xmin, xmax = -6.69, 0.29
ymin, ymax = 0.02, 0.21

starUse1 = starGoodGI1[(starGoodGI1['blendedness.abs.flux_1'] > 0.0) & 
                       (starGoodGI1['force.mag.psf_2'] <= 24.0)]
starUse2 = starGoodGI2[(starGoodGI2['blendedness.abs.flux_1'] > 0.0) & 
                       (starGoodGI2['force.mag.psf_2'] <= 24.0)]

xx = np.log10(starUse1['blendedness.abs.flux_1'])
yy = np.sqrt(starUse1['force.mag.psf.err_1'] ** 2.0 + starUse1['force.mag.psf.err_2'] ** 2.0 +
             starUse1['force.mag.psf.apcorr.err_1'] ** 2.0 + starUse1['force.mag.psf.apcorr.err_2'] ** 2.0)
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 = np.log10(starUse2['blendedness.abs.flux_1'])
yy2 = np.sqrt(starUse2['force.mag.psf.err_1'] ** 2.0 + starUse2['force.mag.psf.err_2'] ** 2.0 +
              starUse2['force.mag.psf.apcorr.err_1'] ** 2.0 + starUse2['force.mag.psf.apcorr.err_2'] ** 2.0)
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'$\log\ (\mathrm{Blendedness})$'
ylabel = r'$(g-i)\ \mathrm{PSF\ Color\ Error}$'

xtickFormat, ytickFormat = r'$\mathbf{%4.1f}$', r'$\mathbf{%5.2f}\ $'
ytickFormat2 = r'$\mathbf{%5.2f}$'

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.20, right=0.99, 
                    bottom=0.13, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

## HexBin
hb1 = ax1.hexbin(xx, yy, cmap=ICMAP, mincnt=3,
                 alpha=0.8, gridsize=[60, 35], label='$\mathrm{Good}$',
                 marginals=False, vmin=5, vmax=100, 
                 edgecolor=ICMAP(0.3))

## Contour
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(250, 250))
H = gaussian_filter(H, 2)
levels = np.linspace(0.5, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.6), ICMAP(0.6)),
                  linewidths=4, levels=levels, alpha=0.9)

ax1.axvline(np.log10(0.10), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
l_handles[0] = mpatches.RegularPolygon((0,0), 6)
l_handles.append(CS1.collections[-1])
l_labels[0] = '$\mathrm{Good\ Seeing}$'
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.05, 0.78), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(ICMAP(0.3))
legend.legendHandles[1].set_color(ICMAP(0.6))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=54)

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

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



In [244]:
# --------------------------------------------------------------------------------------- #
## Prepare the data
xmin, xmax = -6.69, 0.29
ymin, ymax = -0.69, 0.69

starUse1 = starGoodGI1[(starGoodGI1['blendedness.abs.flux_1'] > 0.0) & 
                       (starGoodGI1['force.mag.psf_2'] <= 24.0)]
starUse2 = starGoodGI2[(starGoodGI2['blendedness.abs.flux_1'] > 0.0) & 
                       (starGoodGI2['force.mag.psf_2'] <= 24.0)]

xx = np.log10(starUse1['blendedness.abs.flux_1'])
yy = (starUse1['force.mag.psf_1'] - starUse1['force.mag.psf.apcorr_1'] -
      starUse1['force.mag.psf_2'] + starUse1['force.mag.psf.apcorr_2']) - (
      starUse1['mag_G_1'] - starUse1['mag_I_1'])
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 = np.log10(starUse2['blendedness.abs.flux_1'])
yy2 = (starUse2['force.mag.psf_1'] - starUse2['force.mag.psf.apcorr_1'] -
       starUse2['force.mag.psf_2'] + starUse2['force.mag.psf.apcorr_2']) - (
       starUse2['mag_G_1'] - starUse2['mag_I_1'])
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'$\log_{10}\ (\mathrm{Blendedness})$'
#ylabel = r'$i\ \mathrm{Band\ PSF\ Magnitude\ Error}$'
ylabel = r'$(g-i)_{\mathrm{\ Forced},\ {\mathrm{PSF}}} - (g-i)_{\mathrm{\ Input}}\ \mathrm{(mag)}$'

xtickFormat, ytickFormat = r'$\mathbf{%4.1f}$', r'$\mathbf{%5.2f}\ $'
ytickFormat2 = r'$\mathbf{%5.2f}$'

# --------------------------------------------------------------------------------------- #
## Setup up figure
fig = plt.figure(figsize=(15, 15))
ax1 = fig.add_subplot(111)
fig.subplots_adjust(left=0.20, right=0.99, 
                    bottom=0.13, top=0.99,
                    wspace=0.00, hspace=0.00)

# --------------------------------------------------------------------------------------- #
## Ax1
ax1.grid()
ax1 = songPlotSetup(ax1, ylabel=50, xlabel=50, border=7.0,
                    xtickFormat=xtickFormat, ytickFormat=ytickFormat)

# Contour 1
H, xbins, ybins = np.histogram2d(xx, yy, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(1, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS1 = ax1.contourf(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                   colors=(ICMAP(0.2), ICMAP(0.3), ICMAP(0.4), ICMAP(0.6), ICMAP(0.8)),
                   linewidths=10, levels=levels, alpha=1.0)

## Contour 2
H, xbins, ybins = np.histogram2d(xx2, yy2, bins=(100, 100))
H = gaussian_filter(H, 1)
levels = np.linspace(1, H.max(), 5)
Nx, Ny = len(xbins), len(ybins)
CS2 = ax1.contour(H.T, extent=[xbins[0], xbins[-1], ybins[0], ybins[-1]], 
                  colors=(ICMAP(0.5), ICMAP(0.6), ICMAP(0.7), ICMAP(0.8), ICMAP(0.9)),
                  linestyles='--', linewidths=6, levels=levels, alpha=1.0)
for c in CS2.collections:
    c.set_dashes([(0, (20, 6.0))])

ax1.axhline(0.0, color=BLK(0.9), linewidth=4.0, 
            linestyle='-', alpha=0.9, zorder=0)
ax1.axvline(np.log10(0.10), color=BLK(0.8), linewidth=5.0, 
            linestyle='--', dashes=(40, 10), alpha=0.9)

# --------------------------------------------------------------------------------------- #
## Legend
l_handles, l_labels = ax1.get_legend_handles_labels()
proxy = [plt.Rectangle((0,0), 1, 1, fc = pc.get_facecolor()[0]) 
         for pc in CS1.collections]
l_handles.append(proxy[0])
l_handles.append(CS2.collections[-1])
l_labels.append('$\mathrm{Good\ Seeing}$')
l_labels.append('$\mathrm{Bad\ Seeing}$')
ax1.legend(l_handles, l_labels, loc=(0.05, 0.78), shadow=True, fancybox=True, 
           numpoints=1, fontsize=40, scatterpoints=1, 
           markerscale=1.1, borderpad=0.2, handletextpad=0.3)
legend = ax1.get_legend()
legend.legendHandles[0].set_color(ICMAP(0.2))
legend.legendHandles[1].set_color(ICMAP(0.5))
# --------------------------------------------------------------------------------------- #
ax1.set_xlabel(xlabel, size=54)
ax1.set_ylabel(ylabel, size=54)

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

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