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

import os
import sys
import copy
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
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
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.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
tickFormat = FormatStrFormatter('$\mathbf{%g}$') 

# Personal
import hscUtils as hUtil
#import galSBP
import coaddCutoutGalfitSimple as gSimple 

# 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 = [left,   bottom, width, height]
recHist = [right,  bottom,  0.20, height]
SBP1 = [0.124, 0.085, 0.865, 0.33]
SBP2 = [0.124, 0.41, 0.865, 0.55]
EC1 = [0.135, 0.072, 0.862, 0.295]
EC2 = [0.135, 0.366, 0.862, 0.295]
EC3 = [0.135, 0.666, 0.862, 0.295]
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'

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

import seaborn as sns
sns.set(color_codes=True)

Location and Files


In [14]:
# 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')

In [15]:
print("# The shuang_photo catalog:")
print("# Number of objects: %d" % len(cosPho))
print("# Columns:")
print(cosPho.colnames)

print("\n# The shuang_laige catalog:")
print("# Number of objects: %d" % len(cosHsc))
print("# Columns:")
print(cosHsc.colnames)


# The shuang_photo catalog:
# Number of objects: 58210
# Columns:
['ID', 'mag', 'sersic_n', 'reff', 'b_a', 'theta', 'MPFIT_STATUS_SERSIC', 'DOF_SERSIC', 'MAD_SERSIC', 'MAD_SERSIC_MASK', 'CHISQ_SERSIC', 'CHISQ_SERSIC_MASK', 'ra_cosmos', 'dec_cosmos', 'SUBARU_G', 'SUBARU_R', 'SUBARU_I', 'Y_MAG_AUTO', 'Y_MAGERR_AUTO', 'V_MAG_AUTO', 'V_MAGERR_AUTO', 'ip_MAG_AUTO', 'ip_MAGERR_AUTO', 'r_MAG_AUTO', 'r_MAGERR_AUTO', 'zp_MAG_AUTO', 'zp_MAGERR_AUTO', 'yHSC_MAG_AUTO', 'yHSC_MAGERR_AUTO', 'ID2006', 'ID2008', 'ID2013', 'PHOTOZ', 'TYPE', 'ZPDF', 'ZPDF_L68', 'ZPDF_H68', 'ZMINCHI2', 'MASS_MED', 'MASS_MED_MIN68', 'MASS_MED_MAX68', 'MASS_BEST', 'SFR_MED', 'SFR_MED_MIN68', 'SFR_MED_MAX68', 'SFR_BEST', 'SSFR_MED', 'SSFR_MED_MIN68', 'SSFR_MED_MAX68', 'SSFR_BEST']

# The shuang_laige catalog:
# Number of objects: 58210
# Columns:
['ID', 'mag', 'sersic_n', 'reff', 'b_a', 'theta', 'MPFIT_STATUS_SERSIC', 'DOF_SERSIC', 'MAD_SERSIC', 'MAD_SERSIC_MASK', 'CHISQ_SERSIC', 'CHISQ_SERSIC_MASK', 'ra_cosmos', 'dec_cosmos', 'SUBARU_G', 'SUBARU_R', 'SUBARU_I', 'Y_MAG_AUTO', 'Y_MAGERR_AUTO', 'V_MAG_AUTO', 'V_MAGERR_AUTO', 'ip_MAG_AUTO', 'ip_MAGERR_AUTO', 'r_MAG_AUTO', 'r_MAGERR_AUTO', 'zp_MAG_AUTO', 'zp_MAGERR_AUTO', 'yHSC_MAG_AUTO', 'yHSC_MAGERR_AUTO', 'ID2006', 'ID2008', 'ID2013', 'PHOTOZ', 'TYPE', 'ZPDF', 'ZPDF_L68', 'ZPDF_H68', 'ZMINCHI2', 'MASS_MED', 'MASS_MED_MIN68', 'MASS_MED_MAX68', 'MASS_BEST', 'SFR_MED', 'SFR_MED_MIN68', 'SFR_MED_MAX68', 'SFR_BEST', 'SSFR_MED', 'SSFR_MED_MIN68', 'SSFR_MED_MAX68', 'SSFR_BEST', 'a_g', 'a_r', 'a_i', 'a_z', 'a_y', 'specz_id', 'specz_redshift', 'specz_redshift_err', 'gmag_kron', 'gmag_kron_err', 'rmag_kron', 'rmag_kron_err', 'imag_kron', 'imag_kron_err', 'zmag_kron', 'zmag_kron_err', 'ymag_kron', 'ymag_kron_err', 'gcmodel_mag', 'gcmodel_mag_err', 'rcmodel_mag', 'rcmodel_mag_err', 'icmodel_mag', 'icmodel_mag_err', 'zcmodel_mag', 'zcmodel_mag_err', 'ycmodel_mag', 'ycmodel_mag_err', 'gcountinputs', 'rcountinputs', 'icountinputs', 'zcountinputs', 'ycountinputs', 'gclassification_extendedness', 'rclassification_extendedness', 'iclassification_extendedness', 'zclassification_extendedness', 'yclassification_extendedness', 'gflux_kron_flags', 'rflux_kron_flags', 'iflux_kron_flags', 'zflux_kron_flags', 'yflux_kron_flags', 'gcmodel_flux_flags', 'rcmodel_flux_flags', 'icmodel_flux_flags', 'zcmodel_flux_flags', 'ycmodel_flux_flags', 'gflags_pixel_interpolated_any', 'rflags_pixel_interpolated_any', 'iflags_pixel_interpolated_any', 'zflags_pixel_interpolated_any', 'yflags_pixel_interpolated_any', 'gflags_pixel_saturated_any', 'rflags_pixel_saturated_any', 'iflags_pixel_saturated_any', 'zflags_pixel_saturated_any', 'yflags_pixel_saturated_any', 'gflags_pixel_saturated_center', 'yflags_pixel_saturated_center', 'gflags_pixel_cr_any', 'rflags_pixel_cr_any', 'iflags_pixel_cr_any', 'zflags_pixel_cr_any', 'yflags_pixel_cr_any', 'gflags_pixel_cr_center', 'yflags_pixel_cr_center', 'gflags_pixel_bad', 'yflags_pixel_bad', 'gflags_pixel_suspect_center', 'rflags_pixel_suspect_center', 'iflags_pixel_suspect_center', 'zflags_pixel_suspect_center', 'yflags_pixel_suspect_center', 'gflags_pixel_suspect_any', 'rflags_pixel_suspect_any', 'iflags_pixel_suspect_any', 'zflags_pixel_suspect_any', 'yflags_pixel_suspect_any', 'gflags_pixel_clipped_any', 'rflags_pixel_clipped_any', 'iflags_pixel_clipped_any', 'zflags_pixel_clipped_any', 'yflags_pixel_clipped_any', 'gflags_pixel_bright_object_center', 'rflags_pixel_bright_object_center', 'iflags_pixel_bright_object_center', 'zflags_pixel_bright_object_center', 'yflags_pixel_bright_object_center', 'gflags_pixel_bright_object_any', 'rflags_pixel_bright_object_any', 'iflags_pixel_bright_object_any', 'zflags_pixel_bright_object_any', 'yflags_pixel_bright_object_any']

In [66]:
iAcs = cosHsc['mag']

iHsc = cosHsc['icmodel_mag'] + cosHsc['a_i']
gHsc = cosHsc['gcmodel_mag'] + cosHsc['a_g']
rHsc = cosHsc['rcmodel_mag'] + cosHsc['a_r']
zHsc = cosHsc['zcmodel_mag'] + cosHsc['a_z']
yHsc = cosHsc['ycmodel_mag'] + cosHsc['a_y']

gCos = cosHsc['SUBARU_G']
rCos = cosHsc['r_MAG_AUTO']
iCos = cosHsc['ip_MAG_AUTO']
zCos = cosHsc['zp_MAG_AUTO']
yCos = cosHsc['yHSC_MAG_AUTO']

redCos = cosHsc['PHOTOZ']
redHsc = cosHsc['specz_redshift']

Comparisons of magnitudes


In [87]:
xx, yy = iAcs, iHsc

#-----------------------------------------------------------------#
fig = plt.figure(figsize=(10, 10))
fig.subplots_adjust(left=0.17, right=0.995, 
                    bottom=0.17, top=0.995,
                    wspace=0.00, hspace=0.00)

#-----------------------------------------------------------------#
# logM100 - C82
ax1 = fig.add_subplot(111)
ax1 = songPlotSetup(ax1, xlabel=30, ylabel=30, border=0,
                    majorTickL=0, minorTickL=0,
                    majorTickW=0, minorTickW=0,
                    xtickFormat='$\mathrm{%4.1f}$', 
                    ytickFormat='$\mathrm{%4.1f}$')

ax1.scatter(xx, yy+0.3, marker='o', edgecolor='none', cmap=ORG, s=10,
            c=ORG(0.5), alpha=0.20, rasterized=True)

# Scaling Relations
ax1.set_rasterization_zorder(0) 
lin = np.linspace(15.0, 28.0, 100)
ax1.plot(lin, lin, linestyle='--', color=BLK(0.95), alpha=0.7, 
         linewidth=8.0, zorder=2, dashes=(30,6))

# X, Y Label
ax1.set_xlabel('$i_{\mathrm{ACS}}\ (\mathrm{mag})$', size=60)
ax1.set_ylabel('$i_{\mathrm{HSC}+0.3}\ (\mathrm{mag})$', size=60)

# X, Y limits
ax1.set_xlim(18.9, 25.9)
ax1.set_ylim(18.9, 25.9)

#ax1.legend(loc=(0.03, 0.74),
#           shadow=True, fancybox=True, 
#           numpoints=1, fontsize=38, scatterpoints=1, 
#           markerscale=1.8, borderpad=0.3, handletextpad=0.5)

#-----------------------------------------------------------------#
#fig.savefig(os.path.join(figDir, 'redbcg_mass_r50.pdf'), dpi=150)

plt.show()



In [88]:
xx, yy = iAcs, iCos

#-----------------------------------------------------------------#
fig = plt.figure(figsize=(10, 10))
fig.subplots_adjust(left=0.17, right=0.995, 
                    bottom=0.17, top=0.995,
                    wspace=0.00, hspace=0.00)

#-----------------------------------------------------------------#
# logM100 - C82
ax1 = fig.add_subplot(111)
ax1 = songPlotSetup(ax1, xlabel=30, ylabel=30, border=0,
                    majorTickL=0, minorTickL=0,
                    majorTickW=0, minorTickW=0,
                    xtickFormat='$\mathrm{%4.1f}$', 
                    ytickFormat='$\mathrm{%4.1f}$')

ax1.scatter(xx, yy+0.3, marker='o', edgecolor='none', cmap=ORG, s=10,
            c=ORG(0.5), alpha=0.20, rasterized=True)

# Scaling Relations
ax1.set_rasterization_zorder(0) 
lin = np.linspace(15.0, 28.0, 100)
ax1.plot(lin, lin, linestyle='--', color=BLK(0.95), alpha=0.7, 
         linewidth=8.0, zorder=2, dashes=(30,6))

# X, Y Label
ax1.set_xlabel('$i_{\mathrm{ACS}}\ (\mathrm{mag})$', size=60)
ax1.set_ylabel('$i_{\mathrm{Cosmos}+0.3}\ (\mathrm{mag})$', size=60)


# X, Y limits
ax1.set_xlim(18.9, 25.9)
ax1.set_ylim(18.9, 25.9)

#ax1.legend(loc=(0.03, 0.74),
#           shadow=True, fancybox=True, 
#           numpoints=1, fontsize=38, scatterpoints=1, 
#           markerscale=1.8, borderpad=0.3, handletextpad=0.5)

#-----------------------------------------------------------------#
#fig.savefig(os.path.join(figDir, 'redbcg_mass_r50.pdf'), dpi=150)

plt.show()



In [89]:
xx, yy = iHsc, iCos

#-----------------------------------------------------------------#
fig = plt.figure(figsize=(10, 10))
fig.subplots_adjust(left=0.17, right=0.995, 
                    bottom=0.17, top=0.995,
                    wspace=0.00, hspace=0.00)

#-----------------------------------------------------------------#
# logM100 - C82
ax1 = fig.add_subplot(111)
ax1 = songPlotSetup(ax1, xlabel=30, ylabel=30, border=0,
                    majorTickL=0, minorTickL=0,
                    majorTickW=0, minorTickW=0,
                    xtickFormat='$\mathrm{%4.1f}$', 
                    ytickFormat='$\mathrm{%4.1f}$')

ax1.scatter(xx, yy, marker='o', edgecolor='none', cmap=ORG, s=10,
            c=ORG(0.5), alpha=0.20, rasterized=True)

# Scaling Relations
ax1.set_rasterization_zorder(0) 
lin = np.linspace(15.0, 28.0, 100)
ax1.plot(lin, lin, linestyle='--', color=BLK(0.95), alpha=0.7, 
         linewidth=8.0, zorder=2, dashes=(30,6))

# X, Y Label
ax1.set_xlabel('$i_{\mathrm{HSC}}\ (\mathrm{mag})$', size=60)
ax1.set_ylabel('$i_{\mathrm{Cosmos}}\ (\mathrm{mag})$', size=60)

# X, Y limits
ax1.set_xlim(18.9, 25.9)
ax1.set_ylim(18.9, 25.9)

#ax1.legend(loc=(0.03, 0.74),
#           shadow=True, fancybox=True, 
#           numpoints=1, fontsize=38, scatterpoints=1, 
#           markerscale=1.8, borderpad=0.3, handletextpad=0.5)

#-----------------------------------------------------------------#
#fig.savefig(os.path.join(figDir, 'redbcg_mass_r50.pdf'), dpi=150)

plt.show()