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

New keyword argument supports user-defined halo boundary #995

Merged
merged 7 commits into from
Sep 18, 2020
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
16 changes: 10 additions & 6 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ The simplest way to install the latest release of the code is with pip. Before i

pip install halotools

Alternatively, you can install using conda::
Alternatively, you can install using the astropy channel on conda::

conda install -c astropy halotools

or via conda-forge:

conda install -c conda-forge halotools

Either pip or conda will install the latest official release of the code.
If instead you want the latest master branch,
you will need to build the code from source following the instructions in the next section.
Expand Down Expand Up @@ -58,13 +62,13 @@ The first step is to clone the halotools repository::
Installing one of the official releases
------------------------------------------

All official releases of the code are tagged with their version name, e.g., v0.5.
All official releases of the code are tagged with their version name, e.g., v0.7.
To install a particular release::

git checkout v0.5
git checkout v0.7
python setup.py install

This will install the v0.5 release of the code. Other official release versions (e.g., v0.1) can be installed similarly.
This will install the v0.7 release of the code. Other official release versions (e.g., v0.5) can be installed similarly.

Installing the most recent master branch
------------------------------------------
Expand Down Expand Up @@ -113,15 +117,15 @@ The h5py package is used for fast I/O of large simulated datasets.

If you did not use pip, then you should be aware of the following strict requirements:

- `Python <http://www.python.org/>`_: 2.7.x or 3.x
- `Python <http://www.python.org/>`_: 3.7.x

- `Numpy <http://www.numpy.org/>`_: 1.9 or later

- `Scipy <http://www.scipy.org/>`_: 0.15 or later

- `Cython <http://www.cython.org/>`_: 0.23 or later

- `Astropy`_: 1.0 or later
- `Astropy`_: 4.0 or later

- `BeautifulSoup <http://www.crummy.com/software/BeautifulSoup/>`_: For crawling the web for halo catalogs.

Expand Down
6 changes: 3 additions & 3 deletions docs/installing_halotools_with_virtualenv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ create a virtual environment that will automatically have compatible versions of
By installing into a virtual environment, you will not change any of the
packages that are already installed system-wide on your machine. In the example below, we will use conda to create a virtual environment with all the dependencies handled automatically::

conda create -n halotools_env python=3.7 astropy numpy scipy h5py requests beautifulsoup4 cython
conda create -n ht07 python=3.7 halotools=0.7 h5py ipython jupyter matplotlib

In order to activate this environment::

source activate halotools_env
source activate ht07

Then install halotools into this environment::

pip install halotools

Or, alternatively, you can install the latest master branch by following the :ref:`install_from_source` instructions.

Any additional packages you install into the ``halotools_env`` virtual environment will not impact your system-wide environment. Whenever you want to do science involving Halotools,
Any additional packages you install into the ``ht07`` virtual environment will not impact your system-wide environment. Whenever you want to do science involving Halotools,
just activate the environment and import the code. When you are done
and wish to return to your normal system environment::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@
from .....custom_exceptions import HalotoolsError
from .....sim_manager import FakeSim

__all__ = ('test_zheng07_composite1', 'test_zheng07_composite2')
__all__ = ("test_zheng07_composite1", "test_zheng07_composite2")


def test_zheng07_composite1():
""" Ensure that the ``zheng07`` pre-built model does not accept non-Zheng07Cens.
"""
model1 = PrebuiltHodModelFactory('zheng07')
model2 = PrebuiltHodModelFactory('zheng07', modulate_with_cenocc=True)
model1 = PrebuiltHodModelFactory("zheng07")
model2 = PrebuiltHodModelFactory("zheng07", modulate_with_cenocc=True)

with pytest.raises(HalotoolsError) as err:
__ = PrebuiltHodModelFactory('zheng07', modulate_with_cenocc=True, cenocc_model=0)
substr = "Do not pass in the ``cenocc_model`` keyword to ``zheng07_model_dictionary``"
__ = PrebuiltHodModelFactory(
"zheng07", modulate_with_cenocc=True, cenocc_model=0
)
substr = (
"Do not pass in the ``cenocc_model`` keyword to ``zheng07_model_dictionary``"
)
assert substr in err.value.args[0]


Expand All @@ -31,31 +35,39 @@ def test_zheng07_composite2():
"""

class MyCenModel(OccupationComponent):

def __init__(self, threshold):
OccupationComponent.__init__(self, gal_type='centrals',
threshold=threshold, upper_occupation_bound=1.)

self.param_dict['new_cen_param'] = 0.5
OccupationComponent.__init__(
self,
gal_type="centrals",
threshold=threshold,
upper_occupation_bound=1.0,
)

self.param_dict["new_cen_param"] = 0.5
self._suppress_repeated_param_warning = True

def mean_occupation(self, **kwargs):
halo_table = kwargs['table']
result = np.zeros(len(halo_table)) + self.param_dict['new_cen_param']
halo_table = kwargs["table"]
result = np.zeros(len(halo_table)) + self.param_dict["new_cen_param"]
return result

centrals_occupation = MyCenModel(threshold=-20)
satellites_occupation = Zheng07Sats(threshold=-20,
modulate_with_cenocc=True, cenocc_model=centrals_occupation,
_suppress_repeated_param_warning=True)
satellites_occupation = Zheng07Sats(
threshold=-20,
modulate_with_cenocc=True,
cenocc_model=centrals_occupation,
_suppress_repeated_param_warning=True,
)

centrals_profile = TrivialPhaseSpace()
satellites_profile = NFWPhaseSpace()

model_dict = ({'centrals_occupation': centrals_occupation,
'centrals_profile': centrals_profile,
'satellites_occupation': satellites_occupation,
'satellites_profile': satellites_profile})
model_dict = {
"centrals_occupation": centrals_occupation,
"centrals_profile": centrals_profile,
"satellites_occupation": satellites_occupation,
"satellites_profile": satellites_profile,
}

composite_model = HodModelFactory(**model_dict)

Expand All @@ -67,27 +79,42 @@ def test_modulate_with_cenocc1():
""" Regression test for Issue #646. Verify that the ``modulate_with_cenocc``
keyword argument is actually passed to the satellite occupation component.
"""
model1 = PrebuiltHodModelFactory('zheng07', modulate_with_cenocc=True)
assert model1.model_dictionary[u'satellites_occupation'].modulate_with_cenocc is True
model1 = PrebuiltHodModelFactory("zheng07", modulate_with_cenocc=True)
assert (
model1.model_dictionary[u"satellites_occupation"].modulate_with_cenocc is True
)


def test_modulate_with_cenocc2():
""" Regression test for Issue #646. Verify that the ``modulate_with_cenocc``
keyword argument results in behavior that is properly modified by the centrals.
"""
model = PrebuiltHodModelFactory('zheng07', modulate_with_cenocc=True)
model = PrebuiltHodModelFactory("zheng07", modulate_with_cenocc=True)
test_mass = 1e12
ncen1 = model.mean_occupation_satellites(prim_haloprop=test_mass)
model.param_dict['logMmin'] *= 1.5
model.param_dict["logMmin"] *= 1.5
ncen2 = model.mean_occupation_satellites(prim_haloprop=test_mass)
assert ncen1 != ncen2


def test_host_centric_distance():
model = PrebuiltHodModelFactory('zheng07')
halocat = FakeSim(seed=43)
model.populate_mock(halocat, seed=43)
model = PrebuiltHodModelFactory("zheng07")
halocat = FakeSim(seed=43)
model.populate_mock(halocat, seed=43)

msg = "host_centric_distance key was never mapped during mock population"
assert np.any(model.mock.galaxy_table['host_centric_distance'] > 0), msg
msg = "host_centric_distance key was never mapped during mock population"
assert np.any(model.mock.galaxy_table["host_centric_distance"] > 0), msg


def test_mass_definition_flexibility():
""" Regression test for Issue #993.
"""
model = PrebuiltHodModelFactory(
"zheng07", mdef="200m", halo_boundary_key="halo_radius_arbitrary"
)
halocat = FakeSim(seed=43)
halocat.halo_table["halo_m200m"] = np.copy(halocat.halo_table["halo_mvir"])
halocat.halo_table["halo_radius_arbitrary"] = np.copy(
halocat.halo_table["halo_mvir"]
)
model.populate_mock(halocat, seed=43)
Loading