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)
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')
In [3]:
glob.glob(inDir + '/*star*')
Out[3]:
In [4]:
glob.glob(starDir + '/*syn.fits')
Out[4]:
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)
In [5]:
print(len(inputG1), len(inputG2))
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')
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')
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()])
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))
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])
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)
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')
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'])))
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'])))
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'])))
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'])))
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'])))
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)
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')
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()])
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))
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))
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))
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))
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))
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)
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')
In [13]:
print([col for col in catG1.colnames if 'flag' in col.lower()])
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)))
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)
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')
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
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)
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')
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)