Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug in ZuMandelbaum15SmHm #747

Merged
merged 1 commit into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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