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

Update docs #110

Merged
merged 1 commit into from
Sep 26, 2023
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
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# diffmah

## Installation
The latest release of diffmah is 0.4.1:
The latest release of diffmah is available for installation with pip or conda:
```
$ conda install diffmah
```
Expand All @@ -10,14 +10,14 @@ To install diffmah into your environment from the source code:

```
$ cd /path/to/root/diffmah
$ python setup.py install
$ pip install .
```

### Environment configuration
For a typical development environment in conda:

```
$ conda create -n diffit python=3.9 numpy numba flake8 pytest jax ipython jupyter matplotlib scipy h5py diffmah
$ conda create -n diffit python=3.9 numpy jax pytest ipython jupyter matplotlib scipy h5py diffmah
```

## Project data
Expand All @@ -27,11 +27,7 @@ Data for this project can be found [at this URL](https://portal.nersc.gov/projec
Online documentation for Diffmah is available [diffmah.readthedocs.io](https://diffmah.readthedocs.io/en/latest/).

## Scripts and demo notebooks
The `diffmah_halo_populations.ipynb` notebook demonstrates how to calculate the MAHs as a function of the diffmah parameters using the `calc_halo_history` function. This notebook also demonstrates how to use the `mc_halo_population` function to generate Monte Carlo realizations of cosmologically representative populations of halos.

The `diffmah_fitter_demo.ipynb` notebook demonstrates how to fit the MAH of a simulated halo with a diffmah approximation.

See `history_fitting_script.py` for an example of how to fit the MAHs of a large number of simulated halos in parallel with mpi4py.
The `diffmah_fitter_demo.ipynb` notebook demonstrates how to fit the MAH of a simulated halo with a diffmah approximation. See `history_fitting_script.py` for an example of how to fit the MAHs of a large number of simulated halos in parallel with mpi4py.

## Citing diffmah
[The diffmah paper](https://astro.theoj.org/article/26991-a-differentiable-model-of-the-assembly-of-individual-and-populations-of-dark-matter-halos) has been published by the [Open Journal of Astrophysics](https://astro.theoj.org/). Citation information for the paper can be found at [this ADS link](https://ui.adsabs.harvard.edu/abs/2021OJAp....4E...7H/abstract), copied below for convenience:
Expand Down
149 changes: 149 additions & 0 deletions docs/source/diffmah_halo_populations.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "recorded-display",
"metadata": {},
"source": [
"# Overview of Diffmah and DiffmahPop\n",
"\n",
"Starting from a collection of best-fitting approximations to halo merger trees, you can use the `calc_halo_history` function to compute the assembly history for every halo in the sample. Here we'll just demonstrate a few simple cases.\n",
"\n",
"Note that in these examples, we pass in arbitrary values for the early- and late-time indices. However, for real halos (and also for the results returned by the diffmah-provided MAH fitting script), $0 < \\alpha_{\\rm late} < \\alpha_{\\rm early}.$"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8dc6f535",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"import matplotlib.cm as cm"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "plain-arbor",
"metadata": {},
"outputs": [],
"source": [
"from diffmah import calc_halo_history\n",
"\n",
"n_halos, n_times = 50, 100\n",
"tarr = np.linspace(0.5, 13.8, n_times)\n",
"colors=cm.coolwarm(np.linspace(1, 0, n_halos)) # red first\n",
"\n",
"tauc = np.linspace(1, 5, n_halos)\n",
"logmp = 12\n",
"early, late = 2, 1\n",
"dmhdt, log_mah = calc_halo_history(tarr, tarr[-1], logmp, tauc, early, late)\n",
"\n",
"fig, ax = plt.subplots(1, 1)\n",
"__=ax.loglog()\n",
"for ih in range(n_halos):\n",
" __=ax.plot(tarr, 10**log_mah[ih, :], color=colors[ih])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "completed-macro",
"metadata": {},
"outputs": [],
"source": [
"tauc = 2.0\n",
"early = np.linspace(1, 3, n_halos)\n",
"late = 1\n",
"dmhdt, log_mah = calc_halo_history(tarr, tarr[-1], logmp, tauc, early, late)\n",
"\n",
"\n",
"fig, ax = plt.subplots(1, 1)\n",
"__=ax.loglog()\n",
"for ih in range(n_halos):\n",
" __=ax.plot(tarr, 10**log_mah[ih, :], color=colors[ih])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "constant-thunder",
"metadata": {},
"outputs": [],
"source": [
"tauc = 2.0\n",
"early = 3\n",
"late = np.linspace(0.01, 3, n_halos)\n",
"dmhdt, log_mah = calc_halo_history(tarr, tarr[-1], logmp, tauc, early, late)\n",
"\n",
"fig, ax = plt.subplots(1, 1)\n",
"__=ax.loglog()\n",
"for ih in range(n_halos):\n",
" __=ax.plot(tarr, 10**log_mah[ih, :], color=colors[ih])"
]
},
{
"cell_type": "markdown",
"id": "acknowledged-exhibition",
"metadata": {},
"source": [
"## Generating Monte Carlo realizations of halo MAHs with DiffmahPop"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "imported-jungle",
"metadata": {},
"outputs": [],
"source": [
"from diffmah import mc_halo_population\n",
"\n",
"cosmic_time = np.linspace(0.5, 13.8, 100)\n",
"\n",
"n_halos = 5_000\n",
"logmh = np.zeros(n_halos) + 12\n",
"\n",
"_res = mc_halo_population(cosmic_time, cosmic_time[-1], logmh)\n",
"dmhdt, log_mah, early, late, lgtc, mah_type_arr = _res\n",
"\n",
"fig, ax = plt.subplots(1, 1)\n",
"__=ax.loglog()\n",
"for ih in range(5):\n",
" __=ax.plot(tarr, 10**log_mah[ih, :])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fixed-fluid",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
15 changes: 10 additions & 5 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
Welcome to the diffmah documentation
====================================

Diffmah is a differentiable model for the mass assembly history
of individual and populations of dark matter halos.
The code is open-source and is publicly available on
`GitHub <https://github.com/ArgonneCPAC/diffmah/>`__.
You can find more information about diffmah in
`our paper <https://astro.theoj.org/article/26991-a-differentiable-model-of-the-assembly-of-individual-and-populations-of-dark-matter-halos/>`__.

.. toctree::
:maxdepth: 1
:caption: Contents:

installation.rst
diffmah_halo_populations.ipynb
citation.rst

.. toctree::
:maxdepth: 1

citation.rst


18 changes: 6 additions & 12 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@ Installation instructions
Dependencies
------------

``diffmah`` requires `numpy <https://numpy.org/>`__
and `jax <https://jax.readthedocs.io/en/latest/>`__.
diffmah requires python>=3.9, and has the following dependencies:

- `numpy <https://numpy.org/>`__
- `jax <https://jax.readthedocs.io/en/latest/>`__

Installation
------------

The latest release of ``diffmah`` is available on conda-forge:
The latest release of diffmah is available on pip and conda-forge:

conda install -c conda-forge diffmah

You can also install dsps by downloading the source code or cloning the GitHub
You can also install diffmah by downloading the source code or cloning the GitHub
repository and running the standard::

python setup.py install

command or its usual variants, such as::

python setup.py install --prefix=/PATH/TO/INSTALL/DIRECTORY

or::

pip install .

To use the latest code on the main branch, you'll need to install from source.
231 changes: 0 additions & 231 deletions notebooks/diffmah_halo_populations.ipynb

This file was deleted.

Loading