<jupyter_start><jupyter_text>Lets check out the CAMELS data<jupyter_code>import os
import h5py
import numpy as np 
import scipy.stats as sp
from uhod import camels as CAMELS
import corner as DFM
import matplotlib.pyplot as plt
dat_dir = '/Users/chahah/data/uhod/'
fof = h5py.File(os.path.join(dat_dir, 'fof_subhalo_tab_033.hdf5'), 'r')
fof.keys()
pos_h = fof['Group/GroupPos'][...]
pos_cm_h = fof['Group/GroupCM'][...]
vel_h = fof['Group/GroupVel'][...]
logm_h = np.log10(fof['Group/GroupMass'][...]) + 10
radius_h = fof['Group/Group_R_Crit200'][...]
sfr_h = fof['Group/GroupSFR'][...]
metal_h = fof['Group/GroupStarMetallicity'][...]
ngal_h = fof['Group/GroupNsubs'][...]
icen_h = fof['Group/GroupFirstSub'][...]

print('%i halos' % len(logm_h))
has_central = (icen_h >= 0)
print('%i halos have centrals' % np.sum(has_central))
# Flag field indicating suitability of this subhalo for certain types of analysis. 
# If zero, this subhalo should generally be excluded, and is not thought to be of cosmological origin. 
# If one, this subhalo should be considered a 'galaxy' or 'satellite' 
# flag_g = fof['Subhalo/SubhaloFlag'][...] 
pos_g = fof['Subhalo/SubhaloPos'][...]
vel_g = fof['Subhalo/SubhaloVel'][...]
logm_g = np.log10(fof['Subhalo/SubhaloMassType'][...][:,4]) + 10 # log(stellar mass)

print('%i galaxies' % len(logm_g))
vel_g[icen_h[has_central]]
vel_h[has_central]
fig = plt.figure(figsize=(6,6))
sub = fig.add_subplot(111)
sub.scatter(pos_h[has_central,0], pos_h[has_central,1], s=10, c='k')
sub.scatter(pos_g[icen_h[has_central],0], pos_g[icen_h[has_central],1], s=2, c='C1')
sub.set_xlim(0, 5e3)
sub.set_ylim(0, 5e3)<jupyter_output><empty_output><jupyter_text>Lets just focus on central galaxies for now<jupyter_code>fig = plt.figure(figsize=(6,6))
sub = fig.add_subplot(111)
sub.scatter(pos_h[has_central,0], pos_h[has_central,1], s=10, c='k') # halo
sub.scatter(pos_g[:,0], pos_g[:,1], s=2, c='C0') # satellites
sub.scatter(pos_g[icen_h[has_central],0], pos_g[icen_h[has_central],1], s=2, c='C1') # centrals
sub.set_xlabel('x', fontsize=20)
sub.set_xlim(0, 1e4)
sub.set_ylabel('y', fontsize=20)
sub.set_ylim(0, 1e4)
ncen_h = np.zeros(len(pos_h))
ncen_h[has_central] = 1.

ncen_logmcut_h = np.zeros(len(pos_h))
ncen_logmcut_h[np.arange(len(pos_h))[has_central][logm_g[icen_h[has_central]] > 9.]] = 1.
ncen_mh, mh_edges, _ = sp.binned_statistic(logm_h, ncen_h, bins=30, range=(8., 14))
ncen_mh_logmcut, _, _ = sp.binned_statistic(logm_h, ncen_logmcut_h, bins=30, range=(8., 14))
fig = plt.figure(figsize=(8,6))
sub = fig.add_subplot(111)
sub.plot(0.5*(mh_edges[:-1] + mh_edges[1:]), ncen_mh, label='hosts central')
sub.plot(0.5*(mh_edges[:-1] + mh_edges[1:]), ncen_mh_logmcut, label=r'hosts central $\log M_* > 9$')
sub.legend(loc='lower right', fontsize=10)
sub.set_xlabel(r'$M_{\rm halo}$', fontsize=25)
sub.set_ylabel(r'$<N_{\rm cen}>$', fontsize=25)
halos_all = np.vstack([logm_h, np.log10(radius_h), np.log10(sfr_h) - logm_h, np.log10(metal_h)]).T
halos_logmcut = halos_all[ncen_logmcut_h.astype(bool)]
fig = DFM.corner(halos_all, range=[(8., 14.), (0.6, 3), (-15, -9), (-8, 0)])
_ = DFM.corner(halos_logmcut, color='C1',                 
               range=[(8., 14.), (0.6, 3), (-15, -9), (-8, 0)],
               labels=[r'$\log M_h$', r'$\log R_{\rm Crit200}$', r'${\rm SFR_h}$', r'$Z_h$'], 
               label_kwargs={'fontsize': 25}, 
               fig=fig)
#DFM.overplot_points(fig, halos_logmcut, color='C1')
dpos_cen = pos_g[icen_h[has_central]][logm_g[icen_h[has_central]] > 9.] - pos_cm_h[has_central][logm_g[icen_h[has_central]] > 9.]
fig = DFM.corner(np.concatenate([dpos_cen, halos_logmcut], axis=1), 
                 range=[(-100, 100), (-100, 100), (-100, 100), (10.5, 14.), (1.5, 3), (-13, -9), (-4, 0)], 
                 labels=[r'$\Delta x$', r'$\Delta y$', r'$\Delta z$', r'$\log M_h$', r'$\log R_{\rm Crit200}$', r'${\rm SFR_h}$', r'$Z_h$'], 
                 label_kwargs={'fontsize': 25}, smooth=True)
dvel_cen = vel_g[icen_h[has_central]][logm_g[icen_h[has_central]] > 9.] - vel_h[has_central][logm_g[icen_h[has_central]] > 9.]
fig = DFM.corner(np.concatenate([dvel_cen, halos_logmcut], axis=1), 
                 range=[(-30, 30), (-30, 30), (-30, 30), (10.5, 14.), (1.5, 3), (-13, -9), (-4, 0)], 
                 labels=[r'$\Delta v_x$', r'$\Delta v_y$', r'$\Delta v_z$', r'$\log M_h$', r'$\log R_{\rm Crit200}$', r'${\rm SFR_h}$', r'$Z_h$'], 
                 label_kwargs={'fontsize': 25}, smooth=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.214126559714795, 'fraction_numerical': 0.04567736185383244, 'mean_word_length': 4.7625160462130935, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '586116', 'license': 'MIT', 'n_tokens_mistral': 2136, 'n_tokens_neox': 1974, 'n_words': 343, 'path': 'nb/camels.ipynb', 'repo_name': 'changhoonhahn/uhod', 'size': '4488'}