<jupyter_start><jupyter_text>Calculate $V_{\rm max}$ percentile for host halos<jupyter_code>from halotools.sim_manager import CachedHaloCatalog
halocat = CachedHaloCatalog(simname='bolplanck')
host_halos = halocat.halo_table[halocat.halo_table['halo_upid']==-1]

from halotools.utils import sliding_conditional_percentile
x = host_halos['halo_mvir']
y = host_halos['halo_vmax']
nwin = 301
host_halos['vmax_percentile'] = sliding_conditional_percentile(x, y, nwin)<jupyter_output><empty_output><jupyter_text>Calculate median luminosity for every galaxy<jupyter_code>from halotools.empirical_models import Cacciato09Cens
model = Cacciato09Cens()
host_halos['median_luminosity'] = model.median_prim_galprop(
        prim_haloprop=host_halos['halo_mvir'])<jupyter_output><empty_output><jupyter_text>Generate Monte Carlo log-normal luminosity realization using CAM<jupyter_code>from scipy.stats import norm

host_halos['luminosity'] = 10**norm.isf(1-host_halos['vmax_percentile'], 
                                   loc=np.log10(host_halos['median_luminosity']),
                                       scale=0.2)<jupyter_output><empty_output><jupyter_text>Plot the results<jupyter_code>xmin, xmax = 10**10.75, 10**13.5

fig, ax = plt.subplots(1, 1)
__=ax.loglog()

__=ax.scatter(host_halos['halo_mvir'][::100], 
              host_halos['luminosity'][::100], s=0.1, color='gray', label='')

from scipy.stats import binned_statistic
log_mass_bins = np.linspace(np.log10(xmin), np.log10(xmax), 25)
mass_mids = 10**(0.5*(log_mass_bins[:-1] + log_mass_bins[1:]))

median_lum, __, __ = binned_statistic(
    host_halos['halo_mvir'], host_halos['luminosity'], bins=10**log_mass_bins, 
    statistic='median')

high_vmax_mask = host_halos['vmax_percentile'] > 0.8
median_lum_high_vmax, __, __ = binned_statistic(
    host_halos['halo_mvir'][high_vmax_mask], host_halos['luminosity'][high_vmax_mask], 
    bins=10**log_mass_bins, statistic='median')

mid_high_vmax_mask = host_halos['vmax_percentile'] < 0.8
mid_high_vmax_mask *= host_halos['vmax_percentile'] > 0.6
median_lum_mid_high_vmax, __, __ = binned_statistic(
    host_halos['halo_mvir'][mid_high_vmax_mask], host_halos['luminosity'][mid_high_vmax_mask], 
    bins=10**log_mass_bins, statistic='median')

mid_low_vmax_mask = host_halos['vmax_percentile'] < 0.4
mid_low_vmax_mask *= host_halos['vmax_percentile'] > 0.2
median_lum_mid_low_vmax, __, __ = binned_statistic(
    host_halos['halo_mvir'][mid_low_vmax_mask], host_halos['luminosity'][mid_low_vmax_mask], 
    bins=10**log_mass_bins, statistic='median')


low_vmax_mask = host_halos['vmax_percentile'] < 0.2
median_lum_low_vmax, __, __ = binned_statistic(
    host_halos['halo_mvir'][low_vmax_mask], host_halos['luminosity'][low_vmax_mask], 
    bins=10**log_mass_bins, statistic='median')

__=ax.plot(mass_mids, median_lum_high_vmax, color='red', 
          label=r'$V_{\rm max}\ {\rm percentile} > 0.8$')
__=ax.plot(mass_mids, median_lum_mid_high_vmax, color='orange',
          label=r'$V_{\rm max}\ {\rm percentile} \approx 0.7$')
__=ax.plot(mass_mids, median_lum, color='k', 
          label=r'$V_{\rm max}\ {\rm percentile} \approx 0.5$')
__=ax.plot(mass_mids, median_lum_mid_low_vmax, color='blue', 
          label=r'$V_{\rm max}\ {\rm percentile} \approx 0.3$')
__=ax.plot(mass_mids, median_lum_low_vmax, color='purple',
          label=r'$V_{\rm max}\ {\rm percentile} < 0.2$')

xlim = ax.set_xlim(xmin, xmax/1.2)
ylim = ax.set_ylim(10**7.5, 10**11)
legend = ax.legend()

xlabel = ax.set_xlabel(r'${\rm M_{vir}/M_{\odot}}$')
ylabel = ax.set_ylabel(r'${\rm L/L_{\odot}}$')
title = ax.set_title(r'${\rm CLF\ with\ assembly\ bias}$')

figname = 'cam_example_assembias_clf.png'
fig.savefig(figname, bbox_extra_artists=[xlabel, ylabel], bbox_inches='tight')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15248880695285752, 'fraction_numerical': 0.0237029233605478, 'mean_word_length': 6.033333333333333, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '122227', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1522, 'n_words': 198, 'path': 'docs/notebooks/cam_modeling/cam_decorated_clf.ipynb', 'repo_name': 'pllim/halotools', 'size': '3797'}