Skip to content

Commit

Permalink
minor update to plotting routines
Browse files Browse the repository at this point in the history
  • Loading branch information
dangilman committed Apr 25, 2024
1 parent 4bc48f7 commit 34d77d0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pyHalo/Halos/galacticus_truncation/interp_mass_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def evaluate_mean_mass_loss(self, log10_concentration_infall, time_since_infall,
:param log10_concentration_infall: log10(c) where c is the halo concentration at infall
:param time_since_infall: the time ellapsed since infall and the deflector redshift
:param host_concentration: the concentration of the host halo
:return: bound mass divided by the infall mass
:return: log10 bound mass divided by the infall mass
"""
point = (time_since_infall, host_concentration, log10_concentration_infall)
y = self._mfrac_interp(point)
Expand Down
80 changes: 41 additions & 39 deletions pyHalo/plotting_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,46 +201,48 @@ def plot_subhalo_bound_mass(realization, ax=None, color='k', kwargs_plot={},
ax.set_xscale('log')
ax.set_yscale('log')


def plot_subhalo_mass_functon(realization, log_m_low=6.0, log_m_high=10.0, bound_mass_function=False, nbins=20,
n_bootstrap=10, ax=None, color='k', kwargs_plot={}, rescale_amp=1.0):
"""
Makes a log-log plot of the infall mass versus the final bound mass of tidally stripped subhalos
:param realization: an instance of Realization
:param log_mlow: minimum infall halo mass along x axis
:param log_mhigh: maximum infall halo mass along x axis
:param bound_mass_function:
:param nbins: number of bins along x axis
:param n_bootstrap: number of bootstrap resampling iteratins to compute vertical error bars
:param ax: figure axis
:param color: color for the lines
:param kwargs_plot: keyword arguments passed to plot
:param rescale_amp: rescales the plotted mass function
:return:
"""
if ax is None:
fig = plt.figure()
ax = plt.subplot(111)
masses = []
for halo in realization.halos:
if halo.is_subhalo:
if bound_mass_function:
masses.append(halo.bound_mass)
else:
masses.append(halo.mass)
h = np.empty((n_bootstrap, nbins))
for i in range(0, n_bootstrap):
inds = np.random.randint(0, len(masses), len(masses))
_h, _x = np.histogram(np.log10(masses)[inds], bins=nbins, range=(log_m_low, log_m_high))
h[i, :] = _h
median = np.median(h, axis=0)
standard_dev = np.std(h, axis=0)
logm = _x[1:] - (_x[1] - _x[0])/2
ax.errorbar(logm, rescale_amp*median, yerr=standard_dev, fmt='none', color=color)
ax.plot(logm, rescale_amp*median, color=color, **kwargs_plot)
ax.set_ylim(median[-1] / 2, median[0] * 2)
ax.set_xlabel('infall halo mass ' + r'$\left[\log_{10} M_{\odot}\right]$', fontsize=15)
ax.set_ylabel(r'$n\left(m\right)$', fontsize=15)
ax.set_yscale('log')
n_bootstrap=10, ax=None, color='k', kwargs_plot={}, rescale_amp=1.0):
"""
Makes a log-log plot of the infall mass versus the final bound mass of tidally stripped subhalos
:param realization: an instance of Realization
:param log_mlow: minimum infall halo mass along x axis
:param log_mhigh: maximum infall halo mass along x axis
:param bound_mass_function:
:param nbins: number of bins along x axis
:param n_bootstrap: number of bootstrap resampling iteratins to compute vertical error bars
:param ax: figure axis
:param color: color for the lines
:param kwargs_plot: keyword arguments passed to plot
:param rescale_amp: rescales the plotted mass function
:return:
"""
if ax is None:
fig = plt.figure()
ax = plt.subplot(111)
masses = []
for halo in realization.halos:
if halo.is_subhalo:
if bound_mass_function:
masses.append(halo.bound_mass)
else:
masses.append(halo.mass)
h = np.empty((n_bootstrap, nbins))
for i in range(0, n_bootstrap):
inds = np.random.randint(0, len(masses), len(masses))
_h, _x = np.histogram(np.log10(masses)[inds], bins=nbins, range=(log_m_low, log_m_high))
h[i, :] = _h
median = np.median(h, axis=0)
standard_dev = np.std(h, axis=0)
logm = _x[1:] - (_x[1] - _x[0]) / 2
ax.errorbar(logm, rescale_amp * median, yerr=standard_dev, fmt='none', color=color)
ax.plot(logm, rescale_amp * median, color=color, **kwargs_plot)
ax.set_ylim(median[-1] / 2, median[0] * 2)
ax.set_xlabel('infall halo mass ' + r'$\left[\log_{10} M_{\odot}\right]$', fontsize=15)
ax.set_ylabel(r'$n\left(m\right)$', fontsize=15)
ax.set_yscale('log')
return (logm, median, standard_dev)

def plot_subhalo_concentration_versus_bound_mass(realization, ax=None, color='k', kwargs_plot={},
log_mlow=6.0, log_mhigh=10.0):
Expand Down

0 comments on commit 34d77d0

Please sign in to comment.