In [1]:
%pylab inline
%load_ext autoreload
%autoreload 2
from __future__ import division
from __future__ import print_function
import os
import copy
import argparse
import fnmatch
import numpy as np
import scipy
from scipy.interpolate import interp1d
# Astropy
from astropy.io import fits
from astropy import units as u
from astropy.stats import sigma_clip
# AstroML
from astroML.plotting import hist
# Matplotlib related
# Matplotlib default settings
rcdef = plt.rcParams.copy()
pylab.rcParams['figure.figsize'] = 12, 10
pylab.rcParams['xtick.major.size'] = 8.0
pylab.rcParams['xtick.major.width'] = 2.5
pylab.rcParams['xtick.minor.size'] = 4.0
pylab.rcParams['xtick.minor.width'] = 2.5
pylab.rcParams['ytick.major.size'] = 8.0
pylab.rcParams['ytick.major.width'] = 2.5
pylab.rcParams['ytick.minor.size'] = 4.0
pylab.rcParams['ytick.minor.width'] = 2.5
pylab.rcParams['legend.numpoints'] = 1
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
from matplotlib.ticker import NullFormatter
from matplotlib.ticker import MaxNLocator
In [7]:
sed_model = 'a_fsps_miles_chab'
#sed_model = 'b_bc03_stelib_chab'
In [8]:
z1Fits = 'sed/hsc_sed_z1' + sed_model + '_match.fits'
z2Fits = 'sed/hsc_sed_z2' + sed_model + '_match.fits'
z3Fits = 'sed/hsc_sed_z3' + sed_model + '_match.fits'
In [9]:
z1 = fits.open(z1Fits)[1].data
z2 = fits.open(z2Fits)[1].data
z3 = fits.open(z3Fits)[1].data
In [10]:
z1.columns
Out[10]:
In [11]:
z1Use = z1[(np.isfinite(z1['MSTAR'])) &
(z1['MSTAR'] >= 5.0) &
(z1['MSTAR'] <= 13.0)]
print("# Number of useful stellar mass / total number of galaxies in z1: %5d / %5d" % (len(z1Use), len(z1)))
z2Use = z2[(np.isfinite(z2['MSTAR'])) &
(z2['MSTAR'] >= 5.0) &
(z2['MSTAR'] <= 13.0)]
print("# Number of useful stellar mass / total number of galaxies in z2: %5d / %5d" % (len(z2Use), len(z2)))
z3Use = z3[(np.isfinite(z3['MSTAR'])) &
(z3['MSTAR'] >= 5.0) &
(z3['MSTAR'] <= 13.0)]
print("# Number of useful stellar mass / total number of galaxies in z3: %5d / %5d" % (len(z3Use), len(z3)))
In [12]:
print("# Mean error for logMstar of z1: %5.3f" % np.nanmean(z1['MSTAR_ERR']))
print("# Mean error for logMstar of z2: %5.3f" % np.nanmean(z2['MSTAR_ERR']))
print("# Mean error for logMstar of z3: %5.3f" % np.nanmean(z3['MSTAR_ERR']))
In [13]:
fig = plt.figure(figsize=(12, 12))
#fig.subplots_adjust(left=0.1, right=0.95, bottom=0.15)
rec = [0.10, 0.10, 0.89, 0.89]
ax1 = plt.axes(rec)
# ---------------------------------------------------------------------------
# Scatter plot
# Matched ones
ax1.scatter(z1['z_use'], z1['MSTAR'], s=20.0,
alpha=0.15, c='c', label='z1')
ax1.scatter(z2['z_use'], z2['MSTAR'], s=20.0,
alpha=0.15, c='g', label='z2')
ax1.scatter(z3['z_use'], z3['MSTAR'], s=20.0,
alpha=0.15, c='r', label='z3')
ax1.axhline(11.0, linewidth=4.0, linestyle='--')
# Axes setup
# Minor Ticks on
ax1.minorticks_on()
# Axes Thickness
for axis in ['top','bottom','left','right']:
ax1.spines[axis].set_linewidth(3.5)
# Tick Label Size
for tick in ax1.xaxis.get_major_ticks():
tick.label.set_fontsize(24)
for tick in ax1.yaxis.get_major_ticks():
tick.label.set_fontsize(24)
# Tick Length and Width
ax1.tick_params('both', length=10, width=3.0, which='major')
ax1.tick_params('both', length=6, width=2.5, which='minor')
# Label
ax1.set_xlabel('Redshift', size=40)
ax1.set_ylabel('$\log\ (M_{\star}/M_{\odot})$ (HSC)', size=40)
# Axis limits
ax1.set_xlim(0.0, 0.72)
ax1.set_ylim(8.0, 12.6)
ax1.legend(fontsize=25.0, loc=(0.8, 0.10), numpoints=1,
scatterpoints=1, markerscale=2.5)
ax1.text(0.10, 12.25, sed_model, fontweight='bold', fontsize=30)
fig.savefig('hsc_gama_sed_mass_redshift.png', dpi=90)
In [14]:
# definitions for the axes
left, width = 0.1, 0.71
right = left + width
bottom, height = 0.1, 0.88
bottom_h = left_h = left + width + 0.02
recScat = [left, bottom, width, height]
recHist = [right, bottom, 0.18, height]
In [15]:
z1Color = z1['gmag_cmodel'] - z1['rmag_cmodel']
z1Age = z1['AGE']
z1MsHSC = z1['MSTAR']
z1MsHSCErr = z1['MSTAR_ERR']
z1MsSDSS = z1['logms_gran']
z1MsGAMA = z1['logms_gama']
fig = plt.figure(figsize=(13, 9))
#fig.subplots_adjust(left=0.1, right=0.95, bottom=0.15)
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)
# ---------------------------------------------------------------------------
# Scatter plot
# SDSS v.s. HSC
p = ax1.scatter(z1MsSDSS, (z1MsHSC - z1MsSDSS),
c=z1Color, s=z1Age * 10.0, alpha=0.4,
label='z1/SDSS', vmin=-0.5, vmax=1.5)
# Color bar
cax = fig.add_axes([0.46, 0.88, 0.3, 0.05])
cb = plt.colorbar(p, orientation="horizontal", cax=cax)
cb.ax.set_xlabel(r'$(g-r)_{cmodel}$ (mag)', fontsize=20)
ax1.text(0.67, 0.75, 'Size: iSEDFit Age', fontsize=20,
transform = ax1.transAxes)
# Zero line
ax1.axhline(0.0, alpha=0.7, linewidth=2.0)
# Horizontal line
ax1.axhline(np.nanmean(z1MsHSCErr), linestyle='dashed', linewidth=3.5)
ax1.axhline(-1.0 * np.nanmean(z1MsHSCErr), linestyle='dashed',
linewidth=3.5)
ax1.axhline(np.nanmedian((z1MsHSC - z1MsSDSS)), color='k',
alpha=0.65, linewidth=3.0)
# Axes setup
# Minor Ticks on
ax1.minorticks_on()
# Axes Thickness
for axis in ['top','bottom','left','right']:
ax1.spines[axis].set_linewidth(3.5)
# Tick Label Size
for tick in ax1.xaxis.get_major_ticks():
tick.label.set_fontsize(24)
for tick in ax1.yaxis.get_major_ticks():
tick.label.set_fontsize(24)
# Tick Length and Width
ax1.tick_params('both', length=10, width=3.0, which='major')
ax1.tick_params('both', length=6, width=2.5, which='minor')
# Label
ax1.set_xlabel('$\log\ (M_{\star}/M_{\odot})$ (SDSS/Granada)', size=30)
ax1.set_ylabel('$\Delta\ [\log\ (M_{\star}/M_{\odot})]$ (HSC-SDSS)', size=30)
# Axis limits
ax1.set_xlim(6.5, 12.8)
ax1.set_ylim(-1.8, 2.0)
ax1.text(7.0, 1.7, '$0.0 < z < 0.2$', fontsize=30)
ax1.text(7.0, 1.5, sed_model, fontsize=22, fontweight='bold')
# ---------------------------------------------------------------------------
# Histogram
n, bins, patches=ax2.hist((z1MsHSC - z1MsSDSS), bins=60, range=[-1.8, 2.0],
orientation='horizontal', histtype='stepfilled',
color='g', alpha=0.4, normed=1)
#n, bins, patches=ax2.hist((yuse-xuse), bins=50, range=[-1.2, 4.2],
# orientation='horizontal', histtype='step',
# color='k', alpha=0.8, normed=1, linewidth=3.5)
ax2.set_ylim(ax1.get_ylim())
#ax2.legend(fontsize=15)
# Axes setup
# Minor Ticks on
ax2.minorticks_on()
# Axes Thickness
for axis in ['top','bottom','left','right']:
ax2.spines[axis].set_linewidth(3.5)
# Tick Label Size
for tick in ax2.xaxis.get_major_ticks():
tick.label.set_fontsize(24)
for tick in ax2.yaxis.get_major_ticks():
tick.label.set_fontsize(24)
# Tick Length and Width
ax2.tick_params('both', length=10, width=3.0, which='major')
ax2.tick_params('both', length=6, width=2.5, which='minor')
ax2.axhline(0.0, alpha=0.7, linewidth=2.0)
# Horizontal line
ax2.axhline(np.nanmean(z1MsHSCErr), linestyle='dashed', linewidth=3.5)
ax2.axhline(-1.0 * np.nanmean(z1MsHSCErr), linestyle='dashed',
linewidth=3.5)
ax2.axhline(np.nanmedian((z1MsHSC - z1MsSDSS)), color='k',
alpha=0.65, linewidth=3.0)
ax2.yaxis.set_major_formatter(NullFormatter())
ax2.xaxis.set_major_formatter(NullFormatter())
#fig.savefig('hsc_gama_cmodelmag_i_1.png', dpi=90)
In [16]:
z1Color = z1['gmag_cmodel'] - z1['rmag_cmodel']
z1Age = z1['AGE']
z1MsHSC = z1['MSTAR']
z1MsHSCErr = z1['MSTAR_ERR']
z1MsSDSS = z1['logms_gran']
z1MsGAMA = z1['logms_gama'] + np.log10(z1['fluxscale_gama'])
fig = plt.figure(figsize=(13, 9))
#fig.subplots_adjust(left=0.1, right=0.95, bottom=0.15)
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist)
# ---------------------------------------------------------------------------
# Scatter plot
# GAMA v.s. HSC
p = ax1.scatter(z1MsGAMA, (z1MsHSC - z1MsGAMA),
c=z1Color, s=z1Age * 10.0, alpha=0.4,
label='z1/GAMA', vmin=-0.5, vmax=1.5)
# Color bar
cax = fig.add_axes([0.46, 0.88, 0.3, 0.05])
cb = plt.colorbar(p, orientation="horizontal", cax=cax)
cb.ax.set_xlabel(r'$(g-r)_{cmodel}$ (mag)', fontsize=20)
ax1.text(0.67, 0.75, 'Size: iSEDFit Age', fontsize=20,
transform = ax1.transAxes)
# Zero line
ax1.axhline(0.0, alpha=0.7, linewidth=2.0)
# Horizontal line
ax1.axhline(np.nanmean(z1MsHSCErr), linestyle='dashed', linewidth=3.5)
ax1.axhline(-1.0 * np.nanmean(z1MsHSCErr), linestyle='dashed',
linewidth=3.5)
ax1.axhline(np.nanmedian((z1MsHSC - z1MsGAMA)), color='k',
alpha=0.65, linewidth=3.0)
# Axes setup
# Minor Ticks on
ax1.minorticks_on()
# Axes Thickness
for axis in ['top','bottom','left','right']:
ax1.spines[axis].set_linewidth(3.5)
# Tick Label Size
for tick in ax1.xaxis.get_major_ticks():
tick.label.set_fontsize(24)
for tick in ax1.yaxis.get_major_ticks():
tick.label.set_fontsize(24)
# Tick Length and Width
ax1.tick_params('both', length=10, width=3.0, which='major')
ax1.tick_params('both', length=6, width=2.5, which='minor')
# Label
ax1.set_xlabel('$\log\ (M_{\star}/M_{\odot})$ (GAMA)', size=30)
ax1.set_ylabel('$\Delta\ [\log\ (M_{\star}/M_{\odot})]$ (HSC-GAMA)', size=30)
# Axis limits
ax1.set_xlim(6.5, 12.8)
ax1.set_ylim(-1.8, 2.0)
ax1.text(7.0, 1.7, '$0.0 < z < 0.2$', fontsize=30)
ax1.text(7.0, 1.5, sed_model, fontsize=22, fontweight='bold')
# ---------------------------------------------------------------------------
# Histogram
n, bins, patches=ax2.hist((z1MsHSC - z1MsGAMA), bins=60, range=[-1.8, 2.0],
orientation='horizontal', histtype='stepfilled',
color='g', alpha=0.4, normed=1)
#n, bins, patches=ax2.hist((yuse-xuse), bins=50, range=[-1.2, 4.2],
# orientation='horizontal', histtype='step',
# color='k', alpha=0.8, normed=1, linewidth=3.5)
ax2.set_ylim(ax1.get_ylim())
#ax2.legend(fontsize=15)
# Axes setup
# Minor Ticks on
ax2.minorticks_on()
# Axes Thickness
for axis in ['top','bottom','left','right']:
ax2.spines[axis].set_linewidth(3.5)
# Tick Label Size
for tick in ax2.xaxis.get_major_ticks():
tick.label.set_fontsize(24)
for tick in ax2.yaxis.get_major_ticks():
tick.label.set_fontsize(24)
# Tick Length and Width
ax2.tick_params('both', length=10, width=3.0, which='major')
ax2.tick_params('both', length=6, width=2.5, which='minor')
ax2.axhline(0.0, alpha=0.7, linewidth=2.0)
# Horizontal line
ax2.axhline(np.nanmean(z1MsHSCErr), linestyle='dashed', linewidth=3.5)
ax2.axhline(-1.0 * np.nanmean(z1MsHSCErr), linestyle='dashed',
linewidth=3.5)
ax2.axhline(np.nanmedian((z1MsHSC - z1MsGAMA)), color='k',
alpha=0.65, linewidth=3.0)
ax2.yaxis.set_major_formatter(NullFormatter())
ax2.xaxis.set_major_formatter(NullFormatter())
#fig.savefig('hsc_gama_cmodelmag_i_1.png', dpi=90)