Skip to content

Commit

Permalink
Merge pull request #747 from aphearin/zu_mandelbaum15_bugfix
Browse files Browse the repository at this point in the history
Fixed bug in ZuMandelbaum15SmHm
  • Loading branch information
aphearin authored May 7, 2017
2 parents 8be977e + 319e088 commit c957b1b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def mean_scatter(self, **kwargs):
elif 'prim_haloprop' in list(kwargs.keys()):
mass = kwargs['prim_haloprop']
else:
raise KeyError("Must pass one of the following keyword arguments to mean_occupation:\n"
raise KeyError("Must pass one of the following keyword arguments to mean_scatter:\n"
"``table`` or ``prim_haloprop``")

self._update_interpol()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
"""
from __future__ import division, print_function, absolute_import, unicode_literals

import numpy as np

from ...smhm_models import ZuMandelbaum15SmHm


__all__ = ('test_mc_scatter1', )


def test_mc_scatter1():
model = ZuMandelbaum15SmHm()
sm = model.mc_stellar_mass(prim_haloprop=1e12)
25 changes: 25 additions & 0 deletions halotools/empirical_models/smhm_models/zu_mandelbaum15.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import division, print_function, absolute_import, unicode_literals
import numpy as np
from warnings import warn
from astropy.utils.misc import NumpyRNGContext

from ..component_model_templates import PrimGalpropModel

Expand Down Expand Up @@ -185,3 +186,27 @@ def scatter_ln_mstar(self, halo_mass):
eta = self.param_dict['smhm_sigma_slope']

return np.where(halo_mass < m1, sigma, sigma + eta*np.log10(halo_mass/m1))

def mean_scatter(self, **kwargs):
if 'table' in kwargs.keys():
halo_mass = kwargs['table'][self.prim_haloprop_key]
else:
halo_mass = np.atleast_1d(kwargs['prim_haloprop'])
return np.log10(np.e)*self.scatter_ln_mstar(halo_mass)

def scatter_realization(self, **kwargs):
""" Monte Carlo realization of stellar mass stochasticity
"""
seed = kwargs.get('seed', None)

scatter_scale = np.atleast_1d(self.mean_scatter(**kwargs))

# initialize result with zero scatter result
result = np.zeros(len(scatter_scale))

# only draw from a normal distribution for non-zero values of scatter
mask = (scatter_scale > 0.0)
with NumpyRNGContext(seed):
result[mask] = np.random.normal(loc=0, scale=scatter_scale[mask])

return result

0 comments on commit c957b1b

Please sign in to comment.