In [1]:
%pylab inline 

from __future__ import division

import os
import copy
import warnings

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
from astropy.table import Table, Column
from astropy.cosmology import WMAP9 as cosmo
# AstroML
from astroML.plotting import hist

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

import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
from matplotlib.ticker import NullFormatter
from matplotlib.ticker import MaxNLocator


Populating the interactive namespace from numpy and matplotlib

In [3]:
def decideCutoutSize(z, safe=False):

    """
    Decide the typical cutout size for certain redshift
    """

    if (z <= 0.15):
        if safe:
            return 1000
        else:
            return 1200
    if (z > 0.15) and (z < 0.25):
        if safe:
            return 650
        else:
            return 750
    if (z > 0.25) and (z < 0.35):
        if safe:
            return 550
        else:
            return 600
    if (z > 0.35) and (z < 0.45):
        if safe:
            return 350
        else:
            return 400
    if (z > 0.45) and (z < 0.65):
        if safe:
            return 300
        else:
            return 350
    if (z > 0.65):
        if safe:
            return 200
        else:
            return 250

The Master redMapper Catalogs


In [4]:
loc = '/Users/songhuang/Dropbox/work/hscs/redmapper/redmapper/'

# Cluster and BCG catalog
catC = os.path.join(loc, 'redmapper_dr8_public_v5.10_catalog_flat.fits')
# Member catalog
catM = os.path.join(loc, 'redmapper_dr8_public_v5.10_members_combined.fits')

redC = Table.read(catC, format='fits')
redM = Table.read(catM, format='fits')

In [5]:
redC.colnames


Out[5]:
['ID_CLUSTER',
 'NAME',
 'RA_BCG',
 'DEC_BCG',
 'Z_LAMBDA',
 'Z_LAMBDA_ERR',
 'LAMBDA_CLUSTER',
 'LAMBDA_ERR_CLUSTER',
 'S_CLUSTER',
 'Z_SPEC_BCG',
 'OBJID_BCG',
 'IMAG_BCG',
 'IMAG_ERR_BCG',
 'MODEL_MAG_u_BCG',
 'MODEL_MAG_g_BCG',
 'MODEL_MAG_r_BCG',
 'MODEL_MAG_i_BCG',
 'MODEL_MAG_z_BCG',
 'MODEL_MAGERR_u_BCG',
 'MODEL_MAGERR_g_BCG',
 'MODEL_MAGERR_r_BCG',
 'MODEL_MAGERR_i_BCG',
 'MODEL_MAGERR_z_BCG',
 'ILUM_BCG',
 'PZBINS_1',
 'PZBINS_2',
 'PZBINS_3',
 'PZ_1',
 'PZ_2',
 'PZ_3',
 'P_CEN_1',
 'P_CEN_2',
 'P_CEN_3',
 'P_CEN_4',
 'P_CEN_5',
 'RA_CEN_1',
 'RA_CEN_2',
 'RA_CEN_3',
 'RA_CEN_4',
 'RA_CEN_5',
 'DEC_CEN_1',
 'DEC_CEN_2',
 'DEC_CEN_3',
 'DEC_CEN_4',
 'DEC_CEN_5',
 'ID_CEN_1',
 'ID_CEN_2',
 'ID_CEN_3',
 'ID_CEN_4',
 'ID_CEN_5']

In [6]:
redM.colnames


Out[6]:
['ID_CLUSTER',
 'RA_MEM',
 'DEC_MEM',
 'R_MEM',
 'P_MEM',
 'P_SPEC',
 'P_FREE',
 'THETA_I_MEM',
 'THETA_R_MEM',
 'IMAG_MEM',
 'IMAG_ERR_MEM',
 'MODEL_MAG_u_MEM',
 'MODEL_MAG_g_MEM',
 'MODEL_MAG_r_MEM',
 'MODEL_MAG_i_MEM',
 'MODEL_MAG_z_MEM',
 'MODEL_MAGERR_u_MEM',
 'MODEL_MAGERR_g_MEM',
 'MODEL_MAGERR_r_MEM',
 'MODEL_MAGERR_i_MEM',
 'MODEL_MAGERR_z_MEM',
 'Z_SPEC_MEM',
 'OBJID_MEM',
 'NAME',
 'RA_BCG',
 'DEC_BCG',
 'Z_LAMBDA',
 'Z_LAMBDA_ERR',
 'LAMBDA_CLUSTER',
 'LAMBDA_ERR_CLUSTER',
 'S_CLUSTER',
 'Z_SPEC_BCG',
 'OBJID_BCG',
 'IMAG_BCG',
 'IMAG_ERR_BCG',
 'MODEL_MAG_u_BCG',
 'MODEL_MAG_g_BCG',
 'MODEL_MAG_r_BCG',
 'MODEL_MAG_i_BCG',
 'MODEL_MAG_z_BCG',
 'MODEL_MAGERR_u_BCG',
 'MODEL_MAGERR_g_BCG',
 'MODEL_MAGERR_r_BCG',
 'MODEL_MAGERR_i_BCG',
 'MODEL_MAGERR_z_BCG',
 'ILUM_BCG',
 'PZBINS_1',
 'PZ_1',
 'P_CEN_1',
 'GroupID',
 'GroupSize']

The redMapper Clusters that have HSC data (1509)


In [7]:
catCHsc = '/Users/songhuang/Dropbox/work/hscs/redmapper/1509/hsc_redmapper_cluster_1509.fits'
catMHsc = '/Users/songhuang/Dropbox/work/hscs/redmapper/1509/hsc_redmapper_member_1509.fits'

redCHsc = Table.read(catCHsc, format='fits')
redMHsc = Table.read(catMHsc, format='fits')

In [8]:
# definitions for the axes
recScat  = [0.1, 0.1,  0.72, 0.72]
recHist1 = [0.1, 0.82, 0.72, 0.17]
recHist2 = [0.82, 0.1, 0.17, 0.72]

Plot some basic properties of the sample


In [25]:
fig = plt.figure(figsize=(13, 13))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist1)
ax3 = plt.axes(recHist2)

# ---------------------------------------------------------------------------
# Scatter plot

ax1.axhline(20.0, linewidth=3.0, linestyle='dashed', c='k', 
            alpha=0.7)
ax1.axhline(30.0, linewidth=3.0, linestyle='dashed', c='k', 
            alpha=0.7)

# Matched ones 
ax1.scatter(redC['Z_LAMBDA'], redC['LAMBDA_CLUSTER'], s=10.0, 
            alpha=0.05, facecolor='k', edgecolor='none',
            label='All redMapper')

p = ax1.scatter(redCHsc['Z_LAMBDA'], redCHsc['LAMBDA_CLUSTER'], 
                c=redCHsc['P_CEN_1'], s=150.0, alpha=0.45, 
                label='HSC DR15A', vmin=0.2, vmax=1.00)

# Color bar 
cax = fig.add_axes([0.18, 0.75, 0.4, 0.04]) 
cb = plt.colorbar(p, orientation="horizontal", cax=cax)
cb.ax.set_xlabel('$\mathrm{P}\_\mathrm{CEN}$', fontsize=20)

# 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('$\mathrm{Redshift}$',    size=40)
ax1.set_ylabel( '$\Lambda$', size=40)
# Axis limits
ax1.set_xlim(0.06, 0.57)
ax1.set_ylim(10.5, 200.0)


# ---------------------------------------------------------------------------
# Histogram 1 
hist(redC['Z_LAMBDA'], bins='knuth', ax=ax2, orientation='vertical', 
     histtype='stepfilled', color='g', alpha=0.4, normed=1,
     label='$\mathrm{All}$')
hist(redCHsc['Z_LAMBDA'], bins='knuth', ax=ax2, orientation='vertical', 
     histtype='step', color='k', alpha=0.8, normed=1, linewidth=3.5,
     label='$\mathrm{Matched}$')

#ax2.axvline(0.32, linewidth=2.5, linestyle='dashed', c='k', 
#            alpha=0.7)
ax2.set_xlim(ax1.get_xlim())

ax2.legend(loc=(0.06, 0.50), shadow=True, fancybox=True, 
           numpoints=1, fontsize=18, scatterpoints=1, 
           markerscale=0.9, borderpad=0.25, handletextpad=0.2)

# Axes setup
#  Minor Ticks on 
ax2.minorticks_on()
ax2.tick_params(axis='y', which='minor', left='off', right='off')

#  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.axhline(0.0, color='k', linewidth=2, linestyle='--')

ax2.yaxis.set_major_formatter(NullFormatter())
ax2.xaxis.set_major_formatter(NullFormatter())

# ---------------------------------------------------------------------------
# Histogram 2
hist(redC['LAMBDA_CLUSTER'], bins='knuth', orientation='horizontal', 
     histtype='stepfilled', color='g', alpha=0.4, normed=1, ax=ax3)
hist(redCHsc['LAMBDA_CLUSTER'], bins='knuth', orientation='horizontal', 
     histtype='step', color='k', alpha=0.8, normed=1, linewidth=3.5, 
     label='HSC Matched', ax=ax3)

ax3.set_ylim(ax1.get_ylim())

# Axes setup
#  Minor Ticks on 
ax3.minorticks_on()
ax3.tick_params(axis='x', which='minor', bottom='off', top='off')

#  Axes Thickness
for axis in ['top','bottom','left','right']:
  ax3.spines[axis].set_linewidth(3.5)
#  Tick Label Size 
for tick in ax3.xaxis.get_major_ticks():
    tick.label.set_fontsize(24) 
for tick in ax3.yaxis.get_major_ticks():
    tick.label.set_fontsize(24) 
#  Tick Length and Width
ax3.tick_params('both', length=10, width=3.0, which='major')

#ax3.axhline(0.0, color='k', linewidth=2, linestyle='--')
ax3.axhline(20.0, linewidth=3.0, linestyle='dashed', c='k', 
            alpha=0.7)
ax3.axhline(30.0, linewidth=3.0, linestyle='dashed', c='k', 
            alpha=0.7)

ax3.yaxis.set_major_formatter(NullFormatter())
ax3.xaxis.set_major_formatter(NullFormatter())

fig.savefig('../figure/redmapper_redshift_lambda_1.png', dpi=300)



In [27]:
fig = plt.figure(figsize=(13, 13))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist1)
ax3 = plt.axes(recHist2)

# ---------------------------------------------------------------------------
# Scatter plot

#ax1.axvline(0.32, linewidth=2.5, linestyle='dashed', c='k', alpha=0.7)
ax1.axhline(0.80, linewidth=3.0, linestyle='dashed', c='k', 
            alpha=0.7)
    
# Matched ones 
ax1.scatter(redC['Z_LAMBDA'], redC['P_CEN_1'], s=10.0, 
            alpha=0.05, facecolor='k', edgecolor='none',
            label='All redMapper')

p = ax1.scatter(redCHsc['Z_LAMBDA'], redCHsc['P_CEN_1'], 
                c=redCHsc['LAMBDA_CLUSTER'], s=150.0, alpha=0.45, 
                label='HSC DR15A', vmin=20, vmax=90)

# Color bar 
cax = fig.add_axes([0.18, 0.16, 0.4, 0.04]) 
cb = plt.colorbar(p, orientation="horizontal", cax=cax)
cb.ax.set_xlabel('$\Lambda$', fontsize=20)

# 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('$\mathrm{Redshift}$', size=40)
ax1.set_ylabel('$\mathrm{P}_\mathrm{CEN}$',  size=40)
# Axis limits
ax1.set_xlim(0.06, 0.57)
ax1.set_ylim(0.21, 1.05)


# ---------------------------------------------------------------------------
# Histogram 1 
hist(redC['Z_LAMBDA'], bins='knuth', ax=ax2, orientation='vertical', 
     histtype='stepfilled', color='g', alpha=0.4, normed=1, 
     label='$\mathrm{All}$')
hist(redCHsc['Z_LAMBDA'], bins='knuth', ax=ax2, orientation='vertical', 
     histtype='step', color='k', alpha=0.8, normed=1, linewidth=3.5,
     label='$\mathrm{Matched}$')

#ax2.axvline(0.32, linewidth=2.5, linestyle='dashed', c='k', 
#            alpha=0.7)
ax2.set_xlim(ax1.get_xlim())

ax2.legend(loc=(0.06, 0.50), shadow=True, fancybox=True, 
           numpoints=1, fontsize=18, scatterpoints=1, 
           markerscale=0.9, borderpad=0.25, handletextpad=0.2)

# Axes setup
#  Minor Ticks on 
ax2.minorticks_on()
ax2.tick_params(axis='y', which='minor', left='off', right='off')

#  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, color='k', linewidth=2, linestyle='--')

ax2.yaxis.set_major_formatter(NullFormatter())
ax2.xaxis.set_major_formatter(NullFormatter())

# ---------------------------------------------------------------------------
# Histogram 2
hist(redC['P_CEN_1'], bins='blocks', ax=ax3, orientation='horizontal', 
     histtype='stepfilled', color='g', alpha=0.4, normed=1)
hist(redCHsc['P_CEN_1'], bins='blocks', ax=ax3, orientation='horizontal', 
     histtype='step', color='k', alpha=0.8, normed=1, linewidth=3.5, 
     label='HSC Matched')

ax3.set_xlim(0.0, 8.9)
ax3.set_ylim(ax1.get_ylim())

# Axes setup
#  Minor Ticks on 
ax3.minorticks_on()
ax3.tick_params(axis='x', which='minor', bottom='off', top='off')

#  Axes Thickness
for axis in ['top','bottom','left','right']:
  ax3.spines[axis].set_linewidth(3.5)
#  Tick Label Size 
for tick in ax3.xaxis.get_major_ticks():
    tick.label.set_fontsize(24) 
for tick in ax3.yaxis.get_major_ticks():
    tick.label.set_fontsize(24) 
#  Tick Length and Width
ax3.tick_params('both', length=10, width=3.0, which='major')
ax3.tick_params('both', length=6, width=2.5, which='minor')

ax3.axhline(0.8, color='k', linewidth=3.5, linestyle='--')

ax3.yaxis.set_major_formatter(NullFormatter())
ax3.xaxis.set_major_formatter(NullFormatter())

fig.savefig('../figure/redmapper_redshift_pcen1_1.png', dpi=300)



In [32]:
fig = plt.figure(figsize=(13, 13))
ax1 = plt.axes(recScat)
ax2 = plt.axes(recHist1)
ax3 = plt.axes(recHist2)

# ---------------------------------------------------------------------------
# Scatter plot

ax1.axvline(0.20, linewidth=3.5, linestyle='dashed', c='k', 
            alpha=0.7)
ax1.axvline(0.50, linewidth=3.5, linestyle='dashed', c='k', 
            alpha=0.7)

# Matched ones 
ax1.scatter(redC['Z_LAMBDA'], (redC['MODEL_MAG_g_BCG'] - redC['MODEL_MAG_i_BCG']), s=10.0, 
            alpha=0.05, facecolor='k', edgecolor='none', label='All redMapper')

p = ax1.scatter(redCHsc['Z_LAMBDA'], (redCHsc['MODEL_MAG_g_BCG'] - redCHsc['MODEL_MAG_i_BCG']), 
                c=redCHsc['LAMBDA_CLUSTER'], s=150.0, alpha=0.45, 
                label='HSC DR15A', vmin=20, vmax=90)

# Color bar 
cax = fig.add_axes([0.16, 0.75, 0.40, 0.04]) 
cb = plt.colorbar(p, orientation="horizontal", cax=cax)
cb.ax.set_xlabel(r'$\Lambda$', fontsize=20)

# 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('$\mathrm{Redshift}$', size=40)
ax1.set_ylabel('$(g-i)\ \mathrm{Color}\ (\mathrm{mag})$',  size=40)
# Axis limits
ax1.set_xlim(0.06, 0.57)
ax1.set_ylim(0.90, 3.60)


# ---------------------------------------------------------------------------
# Histogram 1 
hist(redC['Z_LAMBDA'], bins='knuth', ax=ax2, orientation='vertical', 
     histtype='stepfilled', color='g', alpha=0.4, normed=1,
     label='$\mathrm{All}$')
hist(redCHsc['Z_LAMBDA'], bins='knuth', ax=ax2, orientation='vertical', 
     histtype='step', color='k', alpha=0.8, normed=1, linewidth=3.5,
     label='$\mathrm{Matched}$')

ax2.axvline(0.2, linewidth=3.5, linestyle='dashed', c='k', 
            alpha=0.7)
ax2.axvline(0.5, linewidth=3.5, linestyle='dashed', c='k', 
            alpha=0.7)

ax2.set_xlim(ax1.get_xlim())

ax2.legend(loc=(0.06, 0.50), shadow=True, fancybox=True, 
           numpoints=1, fontsize=18, scatterpoints=1, 
           markerscale=0.9, borderpad=0.25, handletextpad=0.2)

# Axes setup
#  Minor Ticks on 
ax2.minorticks_on()
ax2.tick_params(axis='y', which='minor', left='off', right='off')

#  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, color='k', linewidth=2, linestyle='--')

ax2.yaxis.set_major_formatter(NullFormatter())
ax2.xaxis.set_major_formatter(NullFormatter())

# ---------------------------------------------------------------------------
# Histogram 2
hist((redC['MODEL_MAG_g_BCG'] - redC['MODEL_MAG_i_BCG']), bins='knuth', ax=ax3, 
     orientation='horizontal', histtype='stepfilled', 
     color='g', alpha=0.4, normed=1)
hist((redCHsc['MODEL_MAG_g_BCG'] - redCHsc['MODEL_MAG_i_BCG']), bins='knuth', ax=ax3, 
     orientation='horizontal', histtype='step', 
     color='k', alpha=0.8, normed=1, linewidth=3.5)

ax3.set_ylim(ax1.get_ylim())

# Axes setup
#  Minor Ticks on 
ax3.minorticks_on()
ax3.tick_params(axis='x', which='minor', bottom='off', top='off')

#  Axes Thickness
for axis in ['top','bottom','left','right']:
  ax3.spines[axis].set_linewidth(3.5)
#  Tick Label Size 
for tick in ax3.xaxis.get_major_ticks():
    tick.label.set_fontsize(24) 
for tick in ax3.yaxis.get_major_ticks():
    tick.label.set_fontsize(24) 
#  Tick Length and Width
ax3.tick_params('both', length=10, width=3.0, which='major')
ax3.tick_params('both', length=6, width=2.5, which='minor')

ax3.axhline(0.0, color='k', linewidth=2, linestyle='--')

ax3.yaxis.set_major_formatter(NullFormatter())
ax3.xaxis.set_major_formatter(NullFormatter())

fig.savefig('../figure/redmapper_redshift_gicolor_1.png', dpi=300)