diffstar 0.3.1__tar.gz → 0.3.3__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- diffstar-0.3.1/.github/workflows/linting.yml → diffstar-0.3.3/.github/workflows/linting.yaml +2 -3
- diffstar-0.3.1/.github/workflows/monthly-warning-test.yml → diffstar-0.3.3/.github/workflows/monthly-warning-test.yaml +2 -4
- diffstar-0.3.1/.github/workflows/test_releases.yml → diffstar-0.3.3/.github/workflows/test_releases.yaml +2 -4
- diffstar-0.3.1/.github/workflows/tests_cron.yml → diffstar-0.3.3/.github/workflows/tests_cron.yaml +2 -4
- {diffstar-0.3.1 → diffstar-0.3.3}/CHANGES.rst +10 -0
- {diffstar-0.3.1/diffstar.egg-info → diffstar-0.3.3}/PKG-INFO +4 -4
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/__init__.py +2 -1
- diffstar-0.3.3/diffstar/_version.py +1 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/data_loaders/load_bpl.py +2 -1
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/data_loaders/load_smah_data.py +172 -20
- diffstar-0.3.3/diffstar/data_loaders/tests/test_load_smah_data.py +28 -0
- diffstar-0.3.3/diffstar/data_loaders/tests/testing_data/subvol_000_diffmah_fits.h5 +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/defaults.py +3 -2
- diffstar-0.3.3/diffstar/diffstarnet/diffstarnet_tdata.py +226 -0
- diffstar-0.3.3/diffstar/diffstarnet/tests/test_diffstarnet_tdata.py +80 -0
- diffstar-0.3.3/diffstar/fitting_helpers/fit_smah_helpers_tpeak.py +466 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/fitting_kernels.py +18 -47
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/param_clippers.py +2 -1
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/tests/test_fitting_kernels.py +9 -53
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/tests/test_fitting_kernels_are_frozen.py +24 -27
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/tests/test_fitting_smah_helpers.py +9 -10
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/tests/test_param_clippers.py +2 -1
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/tests/test_stars.py +2 -1
- diffstar-0.3.3/diffstar/kernels/__init__.py +4 -0
- diffstar-0.3.1/diffstar/kernels/history_kernel_builders.py → diffstar-0.3.3/diffstar/kernels/history_kernel_builders_tpeak.py +21 -20
- diffstar-0.3.1/diffstar/kernels/main_sequence_kernels.py → diffstar-0.3.3/diffstar/kernels/main_sequence_kernels_tpeak.py +5 -18
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/tests/test_quenching_kernels.py +1 -0
- diffstar-0.3.1/diffstar/sfh_model.py → diffstar-0.3.3/diffstar/sfh_model_tpeak.py +5 -1
- diffstar-0.3.3/diffstar/tests/__init__.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/test_defaults.py +2 -1
- diffstar-0.3.3/diffstar/tests/test_sfh_model_tpeak.py +62 -0
- {diffstar-0.3.1 → diffstar-0.3.3/diffstar.egg-info}/PKG-INFO +4 -4
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar.egg-info/SOURCES.txt +17 -21
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar.egg-info/requires.txt +1 -1
- diffstar-0.3.3/docs/source/_static/README.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/docs/source/index.rst +0 -1
- {diffstar-0.3.1 → diffstar-0.3.3}/docs/source/rtd_environment.yaml +2 -2
- {diffstar-0.3.1 → diffstar-0.3.3}/pyproject.toml +3 -3
- diffstar-0.3.3/requirements.txt +4 -0
- diffstar-0.3.3/scripts/history_fitting_script_SMDPL_tpeak.py +189 -0
- diffstar-0.3.1/diffstar/_version.py +0 -1
- diffstar-0.3.1/diffstar/fitting_helpers/fit_smah_helpers.py +0 -1833
- diffstar-0.3.1/diffstar/kernels/__init__.py +0 -5
- diffstar-0.3.1/diffstar/kernels/kernel_builders.py +0 -249
- diffstar-0.3.1/diffstar/kernels/tests/test_frozen_diffstar_kernels.py +0 -121
- diffstar-0.3.1/diffstar/kernels/tests/test_kernel_builders.py +0 -161
- diffstar-0.3.1/diffstar/sfh.py +0 -220
- diffstar-0.3.1/diffstar/tests/test_gas.py +0 -40
- diffstar-0.3.1/diffstar/tests/test_lax_main_sequence.py +0 -153
- diffstar-0.3.1/diffstar/tests/test_lax_sfh.py +0 -154
- diffstar-0.3.1/diffstar/tests/test_main_sequence_kernels.py +0 -28
- diffstar-0.3.1/diffstar/tests/test_sfh.py +0 -198
- diffstar-0.3.1/diffstar/tests/test_sfh_model.py +0 -156
- diffstar-0.3.1/docs/source/demo_diffstar_fitter.ipynb +0 -339
- diffstar-0.3.1/docs/source/demos.rst +0 -8
- diffstar-0.3.1/requirements.txt +0 -4
- {diffstar-0.3.1 → diffstar-0.3.3}/.coveragerc +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/.git_archival.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/.gitattributes +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/.gitignore +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/.readthedocs.yml +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/LICENSE.rst +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/README.md +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/data_loaders/__init__.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/data_loaders/tests/__init__.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/data_loaders/tests/test_load_bpl.py +0 -0
- {diffstar-0.3.1/diffstar/fitting_helpers/tests → diffstar-0.3.3/diffstar/diffstarnet}/__init__.py +0 -0
- {diffstar-0.3.1/diffstar/kernels → diffstar-0.3.3/diffstar/diffstarnet}/tests/__init__.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/__init__.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/stars.py +0 -0
- {diffstar-0.3.1/diffstar → diffstar-0.3.3/diffstar/fitting_helpers}/tests/__init__.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/fitting_helpers/utils.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/gas_consumption.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/quenching_kernels.py +0 -0
- /diffstar-0.3.1/docs/source/_static/README.txt → /diffstar-0.3.3/diffstar/kernels/tests/__init__.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/tests/testing_data/mah_params_testing_v0.1.0.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/tests/testing_data/ms_params_testing_v0.1.0.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/tests/testing_data/q_params_testing_v0.1.0.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/tests/testing_data/sfh_table_testing_v0.1.0.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/tests/testing_data/t_table_testing_v0.1.0.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/tests/testing_data/u_ms_params_testing_v0.1.0.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/kernels/tests/testing_data/u_q_params_testing_v0.1.0.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/test_quenching.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/test_utils.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/default_params_test_diffmah_params.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/default_params_test_dmhdt.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/default_params_test_dt.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/default_params_test_lgt.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/default_params_test_log_mah.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/default_params_test_sfh.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/default_params_test_u_ms_params.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/default_params_test_u_q_params.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/dt_bpl.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/halo_ids_test_sample.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/lgt_bpl.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/mah_params_test_sample.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/ms_u_params_test_sample.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/q_u_params_test_sample.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/tests/testing_data/sfh_test_sample.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar/utils.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar.egg-info/dependency_links.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/diffstar.egg-info/top_level.txt +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/docs/Makefile +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/docs/make.bat +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/docs/source/citation.rst +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/docs/source/conf.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/docs/source/demo_diffstar_sfh.ipynb +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/docs/source/installation.rst +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/docs/source/reference.rst +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/scripts/generate_unit_testing_data.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/scripts/history_fitting_script.py +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/setup.cfg +0 -0
- {diffstar-0.3.1 → diffstar-0.3.3}/setup.py +0 -0
diffstar-0.3.1/.github/workflows/linting.yml → diffstar-0.3.3/.github/workflows/linting.yaml
RENAMED
@@ -21,15 +21,14 @@ jobs:
|
|
21
21
|
channel-priority: strict
|
22
22
|
show-channel-urls: true
|
23
23
|
miniforge-version: latest
|
24
|
-
miniforge-variant: Mambaforge
|
25
24
|
|
26
25
|
- name: configure conda and install code
|
27
26
|
shell: bash -l {0}
|
28
27
|
run: |
|
29
|
-
|
28
|
+
conda install --quiet \
|
30
29
|
--file=requirements.txt
|
31
30
|
python -m pip install --no-deps -e .
|
32
|
-
|
31
|
+
conda install -y -q \
|
33
32
|
flake8
|
34
33
|
|
35
34
|
- name: lint
|
@@ -23,18 +23,16 @@ jobs:
|
|
23
23
|
channel-priority: strict
|
24
24
|
show-channel-urls: true
|
25
25
|
miniforge-version: latest
|
26
|
-
miniforge-variant: Mambaforge
|
27
|
-
use-mamba: true
|
28
26
|
|
29
27
|
- name: configure conda and install code
|
30
28
|
# Test against current main branch of diffmah and dsps
|
31
29
|
shell: bash -l {0}
|
32
30
|
run: |
|
33
31
|
conda config --set always_yes yes
|
34
|
-
|
32
|
+
conda install --quiet \
|
35
33
|
--file=requirements.txt
|
36
34
|
python -m pip install --no-deps -e .
|
37
|
-
|
35
|
+
conda install -y -q \
|
38
36
|
flake8 \
|
39
37
|
pytest \
|
40
38
|
pytest-xdist \
|
@@ -27,18 +27,16 @@ jobs:
|
|
27
27
|
channel-priority: strict
|
28
28
|
show-channel-urls: true
|
29
29
|
miniforge-version: latest
|
30
|
-
miniforge-variant: Mambaforge
|
31
|
-
use-mamba: true
|
32
30
|
|
33
31
|
- name: configure conda and install code
|
34
32
|
# Test against current confa-forge release of diffmah
|
35
33
|
shell: bash -l {0}
|
36
34
|
run: |
|
37
35
|
conda config --set always_yes yes
|
38
|
-
|
36
|
+
conda install --quiet \
|
39
37
|
--file=requirements.txt
|
40
38
|
python -m pip install --no-deps -e .
|
41
|
-
|
39
|
+
conda install -y -q \
|
42
40
|
flake8 \
|
43
41
|
pytest \
|
44
42
|
pytest-xdist \
|
diffstar-0.3.1/.github/workflows/tests_cron.yml → diffstar-0.3.3/.github/workflows/tests_cron.yaml
RENAMED
@@ -27,18 +27,16 @@ jobs:
|
|
27
27
|
channel-priority: strict
|
28
28
|
show-channel-urls: true
|
29
29
|
miniforge-version: latest
|
30
|
-
miniforge-variant: Mambaforge
|
31
|
-
use-mamba: true
|
32
30
|
|
33
31
|
- name: configure conda and install code
|
34
32
|
# Test against current main branch of diffmah and dsps
|
35
33
|
shell: bash -l {0}
|
36
34
|
run: |
|
37
35
|
conda config --set always_yes yes
|
38
|
-
|
36
|
+
conda install --quiet \
|
39
37
|
--file=requirements.txt
|
40
38
|
python -m pip install --no-deps -e .
|
41
|
-
|
39
|
+
conda install -y -q \
|
42
40
|
flake8 \
|
43
41
|
pytest \
|
44
42
|
pytest-xdist \
|
@@ -1,3 +1,13 @@
|
|
1
|
+
0.3.3 (2025-01-15)
|
2
|
+
------------------
|
3
|
+
- Clean out old code so that only tpeak-based diffmah models remain (https://github.com/ArgonneCPAC/diffstar/pull/72)
|
4
|
+
|
5
|
+
|
6
|
+
0.3.2 (2024-10-25)
|
7
|
+
------------------
|
8
|
+
- Adapt sfh kernels to be compatible with diffmah 0.6.1
|
9
|
+
|
10
|
+
|
1
11
|
0.3.1 (2024-6-19)
|
2
12
|
------------------
|
3
13
|
- Performance improvements for calc_sfh_galpop and calc_sfh_singlegal
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: diffstar
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.3
|
4
4
|
Summary: Differentiable Star Formation Histories
|
5
5
|
Author-email: Alex Alarcon <alexalarcongonzalez@gmail.com>
|
6
6
|
License: BSD 3-Clause License
|
@@ -35,10 +35,10 @@ License: BSD 3-Clause License
|
|
35
35
|
|
36
36
|
Project-URL: home, https://github.com/ArgonneCPAC/diffstar
|
37
37
|
Classifier: Programming Language :: Python :: 3
|
38
|
-
Requires-Python: >=3.
|
38
|
+
Requires-Python: >=3.11
|
39
39
|
Description-Content-Type: text/markdown
|
40
40
|
License-File: LICENSE.rst
|
41
|
-
Requires-Dist: diffmah>=0.
|
41
|
+
Requires-Dist: diffmah>=0.7.0
|
42
42
|
Requires-Dist: numpy
|
43
43
|
Requires-Dist: jax
|
44
44
|
Requires-Dist: h5py
|
@@ -1,5 +1,6 @@
|
|
1
1
|
"""
|
2
2
|
"""
|
3
|
+
|
3
4
|
# flake8: noqa
|
4
5
|
from ._version import __version__
|
5
6
|
from .defaults import (
|
@@ -14,4 +15,4 @@ from .defaults import (
|
|
14
15
|
get_bounded_diffstar_params,
|
15
16
|
get_unbounded_diffstar_params,
|
16
17
|
)
|
17
|
-
from .
|
18
|
+
from .sfh_model_tpeak import calc_sfh_galpop, calc_sfh_singlegal
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = '0.3.3'
|
@@ -1,5 +1,6 @@
|
|
1
1
|
"""
|
2
2
|
"""
|
3
|
+
|
3
4
|
import os
|
4
5
|
from collections import OrderedDict
|
5
6
|
|
@@ -13,7 +14,7 @@ try:
|
|
13
14
|
except ImportError:
|
14
15
|
HAS_ASTROPY = False
|
15
16
|
|
16
|
-
from ..kernels.
|
17
|
+
from ..kernels.main_sequence_kernels_tpeak import _get_bounded_sfr_params_vmap
|
17
18
|
from ..kernels.quenching_kernels import _get_bounded_q_params_vmap
|
18
19
|
from ..utils import _jax_get_dt_array
|
19
20
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
"""
|
2
2
|
"""
|
3
|
+
|
3
4
|
import os
|
4
5
|
import warnings
|
5
6
|
|
@@ -9,21 +10,31 @@ import numpy as np
|
|
9
10
|
from ..defaults import SFR_MIN
|
10
11
|
from ..utils import _get_dt_array
|
11
12
|
|
13
|
+
try:
|
14
|
+
from umachine_pyio.load_mock import load_mock_from_binaries
|
15
|
+
|
16
|
+
HAS_UM_LOADER = True
|
17
|
+
except ImportError:
|
18
|
+
HAS_UM_LOADER = False
|
19
|
+
|
12
20
|
TASSO = "/Users/aphearin/work/DATA/diffmah_data"
|
13
21
|
BEBOP = "/lcrc/project/halotools/diffmah_data"
|
14
22
|
LAPTOP = "/Users/alarcon/Documents/diffmah_data"
|
15
|
-
|
23
|
+
BEBOP_SMDPL = os.path.join(
|
24
|
+
"/lcrc/project/galsampler/SMDPL/",
|
25
|
+
"dr1_no_merging_upidh/sfh_binary_catalogs/a_1.000000/",
|
26
|
+
)
|
16
27
|
H_BPL = 0.678
|
17
28
|
H_TNG = 0.6774
|
18
29
|
H_MDPL = H_BPL
|
19
30
|
|
20
31
|
|
21
|
-
def load_fit_mah(
|
32
|
+
def load_fit_mah(basename, data_drn=BEBOP):
|
22
33
|
"""Load the best fit diffmah parameter data
|
23
34
|
|
24
35
|
Parameters
|
25
36
|
----------
|
26
|
-
|
37
|
+
basename : string
|
27
38
|
Name of the h5 file where the diffmah best fit parameters are stored
|
28
39
|
|
29
40
|
data_drn : string
|
@@ -38,30 +49,107 @@ def load_fit_mah(filename, data_drn=BEBOP):
|
|
38
49
|
logmp: ndarray of shape (n_gal, )
|
39
50
|
Base-10 logarithm of the present day peak halo mass
|
40
51
|
|
52
|
+
logmp: ndarray of shape (n_gal, )
|
53
|
+
Base-10 logarithm of the present day peak halo mass
|
41
54
|
"""
|
42
|
-
fitting_data = dict()
|
43
55
|
|
44
|
-
fn = os.path.join(data_drn,
|
56
|
+
fn = os.path.join(data_drn, basename)
|
45
57
|
with h5py.File(fn, "r") as hdf:
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
fitting_data["fit_mah_k"],
|
56
|
-
fitting_data["fit_early_index"],
|
57
|
-
fitting_data["fit_late_index"],
|
58
|
-
]
|
59
|
-
).T
|
60
|
-
logmp = fitting_data["fit_logmp_fit"]
|
58
|
+
mah_fit_params = np.array(
|
59
|
+
[
|
60
|
+
hdf["logm0"][:],
|
61
|
+
hdf["logtc"][:],
|
62
|
+
hdf["early_index"][:],
|
63
|
+
hdf["late_index"][:],
|
64
|
+
]
|
65
|
+
).T
|
66
|
+
logmp = hdf["logm0"][:]
|
61
67
|
|
62
68
|
return mah_fit_params, logmp
|
63
69
|
|
64
70
|
|
71
|
+
def load_fit_mah_tpeak(basename, data_drn=BEBOP):
|
72
|
+
"""Load the best fit diffmah parameter data
|
73
|
+
|
74
|
+
Parameters
|
75
|
+
----------
|
76
|
+
basename : string
|
77
|
+
Name of the h5 file where the diffmah best fit parameters are stored
|
78
|
+
|
79
|
+
data_drn : string
|
80
|
+
Filepath where the Diffstar best-fit parameters are stored
|
81
|
+
|
82
|
+
Returns
|
83
|
+
-------
|
84
|
+
mah_fit_params: ndarray of shape (n_gal, 4)
|
85
|
+
Best fit parameters for each halo:
|
86
|
+
(logtc, k, early_index, late_index)
|
87
|
+
|
88
|
+
logmp: ndarray of shape (n_gal, )
|
89
|
+
Base-10 logarithm of the present day peak halo mass
|
90
|
+
|
91
|
+
logmp: ndarray of shape (n_gal, )
|
92
|
+
Base-10 logarithm of the present day peak halo mass
|
93
|
+
"""
|
94
|
+
|
95
|
+
fn = os.path.join(data_drn, basename)
|
96
|
+
with h5py.File(fn, "r") as hdf:
|
97
|
+
mah_fit_params = np.array(
|
98
|
+
[
|
99
|
+
hdf["logm0"][:],
|
100
|
+
hdf["logtc"][:],
|
101
|
+
hdf["early_index"][:],
|
102
|
+
hdf["late_index"][:],
|
103
|
+
]
|
104
|
+
).T
|
105
|
+
t_peak = hdf["t_peak"][:]
|
106
|
+
logmp = hdf["logm0"][:]
|
107
|
+
|
108
|
+
return mah_fit_params, logmp, t_peak
|
109
|
+
|
110
|
+
|
111
|
+
def load_fit_sfh(basename, data_drn=BEBOP):
|
112
|
+
"""Load the best fit diffmah parameter data
|
113
|
+
|
114
|
+
Parameters
|
115
|
+
----------
|
116
|
+
basename : string
|
117
|
+
Name of the h5 file where the diffmah best fit parameters are stored
|
118
|
+
|
119
|
+
data_drn : string
|
120
|
+
Filepath where the Diffstar best-fit parameters are stored
|
121
|
+
|
122
|
+
Returns
|
123
|
+
-------
|
124
|
+
sfh_fit_params: ndarray of shape (n_gal, 4)
|
125
|
+
Best fit parameters for each halo:
|
126
|
+
(logtc, k, early_index, late_index)
|
127
|
+
|
128
|
+
"""
|
129
|
+
|
130
|
+
fn = os.path.join(data_drn, basename)
|
131
|
+
with h5py.File(fn, "r") as hdf:
|
132
|
+
ms_fit_params = np.array(
|
133
|
+
[
|
134
|
+
hdf["lgmcrit"][:],
|
135
|
+
hdf["lgy_at_mcrit"][:],
|
136
|
+
hdf["indx_lo"][:],
|
137
|
+
hdf["indx_hi"][:],
|
138
|
+
hdf["tau_dep"][:],
|
139
|
+
]
|
140
|
+
).T
|
141
|
+
q_fit_params = np.array(
|
142
|
+
[
|
143
|
+
hdf["lg_qt"][:],
|
144
|
+
hdf["qlglgdt"][:],
|
145
|
+
hdf["lg_drop"][:],
|
146
|
+
hdf["lg_rejuv"][:],
|
147
|
+
]
|
148
|
+
).T
|
149
|
+
|
150
|
+
return ms_fit_params, q_fit_params
|
151
|
+
|
152
|
+
|
65
153
|
def load_bolshoi_data(gal_type, data_drn=BEBOP):
|
66
154
|
"""Load the stellar mass histories from UniverseMachine simulation
|
67
155
|
applied to the Bolshoi-Planck (BPL) simulation.
|
@@ -397,3 +485,67 @@ def load_mdpl_small_data(gal_type, data_drn=BEBOP):
|
|
397
485
|
log_smahs = np.where(sm_cumsum == 0, 0, np.log10(sm_cumsum))
|
398
486
|
|
399
487
|
return halo_ids, log_smahs, sfrh, mdpl_t, dt
|
488
|
+
|
489
|
+
|
490
|
+
def load_SMDPL_data(subvols, data_drn=BEBOP_SMDPL):
|
491
|
+
"""Load the stellar mass histories from UniverseMachine simulation
|
492
|
+
applied to the Bolshoi-Planck (BPL) simulation.
|
493
|
+
|
494
|
+
The loaded stellar mass data has units of Msun assuming the h = H_BPL
|
495
|
+
from the cosmology of the underlying simulation.
|
496
|
+
|
497
|
+
The output stellar mass data has units of Msun/h, or units of
|
498
|
+
Mstar[h=H_BPL] using the h value of the simulation.
|
499
|
+
|
500
|
+
H_BPL is defined at the top of the module.
|
501
|
+
|
502
|
+
Parameters
|
503
|
+
----------
|
504
|
+
gal_type : string
|
505
|
+
Name of the galaxy type of the file being loaded. Options are
|
506
|
+
'cens': central galaxies
|
507
|
+
'sats': satellite galaxies
|
508
|
+
'orphans': orphan galaxies
|
509
|
+
data_drn : string
|
510
|
+
Filepath where the Diffstar best-fit parameters are stored.
|
511
|
+
|
512
|
+
Returns
|
513
|
+
-------
|
514
|
+
halo_ids: ndarray of shape (n_gal, )
|
515
|
+
IDs of the halos in the file.
|
516
|
+
log_smahs: ndarray of shape (n_gal, n_times)
|
517
|
+
Cumulative stellar mass history in units of Msun assuming h=1.
|
518
|
+
sfrh: ndarray of shape (n_gal, n_times)
|
519
|
+
Star formation rate history in units of Msun/yr assuming h=1.
|
520
|
+
bpl_t : ndarray of shape (n_times, )
|
521
|
+
Cosmic time of each simulated snapshot in Gyr
|
522
|
+
dt : ndarray of shape (n_times, )
|
523
|
+
Cosmic time steps between each simulated snapshot in Gyr
|
524
|
+
"""
|
525
|
+
if not HAS_UM_LOADER:
|
526
|
+
raise ImportError("Must have umachine_pyio installed to load this dataset")
|
527
|
+
|
528
|
+
galprops = ["halo_id", "sfr_history_main_prog", "mpeak_history_main_prog"]
|
529
|
+
mock = load_mock_from_binaries(subvols, root_dirname=data_drn, galprops=galprops)
|
530
|
+
|
531
|
+
SMDPL_t = np.loadtxt(os.path.join(data_drn, "smdpl_cosmic_time.txt"))
|
532
|
+
|
533
|
+
halo_ids = mock["halo_id"]
|
534
|
+
dt = _get_dt_array(SMDPL_t)
|
535
|
+
sfrh = mock["sfr_history_main_prog"]
|
536
|
+
sm_cumsum = np.cumsum(sfrh * dt, axis=1) * 1e9
|
537
|
+
|
538
|
+
with warnings.catch_warnings():
|
539
|
+
warnings.simplefilter("ignore")
|
540
|
+
log_smahs = np.where(sm_cumsum == 0, 0, np.log10(sm_cumsum))
|
541
|
+
|
542
|
+
lgmh_min = 7.0
|
543
|
+
mh_min = 10**lgmh_min
|
544
|
+
msk = mock["mpeak_history_main_prog"] < mh_min
|
545
|
+
clipped_mahs = np.where(msk, 1.0, mock["mpeak_history_main_prog"])
|
546
|
+
log_mahs = np.log10(clipped_mahs)
|
547
|
+
log_mahs = np.maximum.accumulate(log_mahs, axis=1)
|
548
|
+
|
549
|
+
logmp = log_mahs[:, -1]
|
550
|
+
|
551
|
+
return halo_ids, log_smahs, sfrh, SMDPL_t, dt, log_mahs, logmp
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"""
|
2
|
+
"""
|
3
|
+
|
4
|
+
import os
|
5
|
+
|
6
|
+
import numpy as np
|
7
|
+
|
8
|
+
from ..load_smah_data import load_fit_mah_tpeak
|
9
|
+
|
10
|
+
_THIS_DRNAME = os.path.dirname(os.path.abspath(__file__))
|
11
|
+
|
12
|
+
|
13
|
+
def test_load_fit_mah_tpeak():
|
14
|
+
basename = "subvol_000_diffmah_fits.h5"
|
15
|
+
data_drn = os.path.join(_THIS_DRNAME, "testing_data")
|
16
|
+
_res = load_fit_mah_tpeak(basename, data_drn=data_drn)
|
17
|
+
for x in _res:
|
18
|
+
assert np.all(np.isfinite(x))
|
19
|
+
mah_fit_params, logmp, t_peak = _res
|
20
|
+
n_halos, n_params = mah_fit_params.shape
|
21
|
+
|
22
|
+
assert logmp.shape == (n_halos,)
|
23
|
+
assert np.all(logmp > 10)
|
24
|
+
assert np.all(logmp < 16)
|
25
|
+
|
26
|
+
assert t_peak.shape == (n_halos,)
|
27
|
+
assert np.all(t_peak > 0)
|
28
|
+
assert np.all(t_peak < 14)
|
Binary file
|
@@ -1,10 +1,11 @@
|
|
1
1
|
"""
|
2
2
|
"""
|
3
|
+
|
3
4
|
# flake8: noqa
|
4
5
|
from collections import namedtuple
|
5
6
|
|
6
7
|
import numpy as np
|
7
|
-
from diffmah.
|
8
|
+
from diffmah.diffmah_kernels import DEFAULT_MAH_PARAMS, DEFAULT_MAH_PDICT
|
8
9
|
from jax import jit as jjit
|
9
10
|
|
10
11
|
TODAY = 13.8
|
@@ -20,7 +21,7 @@ DEFAULT_N_STEPS = 50
|
|
20
21
|
|
21
22
|
|
22
23
|
from .kernels.gas_consumption import FB
|
23
|
-
from .kernels.
|
24
|
+
from .kernels.main_sequence_kernels_tpeak import (
|
24
25
|
DEFAULT_MS_PARAMS,
|
25
26
|
DEFAULT_MS_PDICT,
|
26
27
|
DEFAULT_U_MS_PARAMS,
|
@@ -0,0 +1,226 @@
|
|
1
|
+
"""
|
2
|
+
"""
|
3
|
+
|
4
|
+
from collections import namedtuple
|
5
|
+
|
6
|
+
import numpy as np
|
7
|
+
from diffmah.diffmah_kernels import DEFAULT_MAH_PARAMS
|
8
|
+
from diffmah.diffmahpop_kernels.bimod_censat_params import DEFAULT_DIFFMAHPOP_PARAMS
|
9
|
+
from diffmah.diffmahpop_kernels.mc_bimod_cens import _mc_diffmah_singlecen_vmap_kern
|
10
|
+
from jax import numpy as jnp
|
11
|
+
from jax import random as jran
|
12
|
+
|
13
|
+
from ..defaults import (
|
14
|
+
DEFAULT_DIFFSTAR_U_PARAMS,
|
15
|
+
DEFAULT_Q_PARAMS_UNQUENCHED,
|
16
|
+
DEFAULT_U_MS_PARAMS,
|
17
|
+
DEFAULT_U_Q_PARAMS,
|
18
|
+
FB,
|
19
|
+
LGT0,
|
20
|
+
T_TABLE_MIN,
|
21
|
+
get_bounded_diffstar_params,
|
22
|
+
)
|
23
|
+
from ..kernels.main_sequence_kernels_tpeak import MS_PARAM_BOUNDS_PDICT
|
24
|
+
from ..sfh_model_tpeak import calc_sfh_galpop
|
25
|
+
|
26
|
+
T0 = 10**LGT0
|
27
|
+
N_SFH_TABLE = 200
|
28
|
+
LGMH_MIN = 10.5
|
29
|
+
LGSM0_MIN = 5.0
|
30
|
+
|
31
|
+
TAU_INST = MS_PARAM_BOUNDS_PDICT["tau_dep"][0] + 1e-4
|
32
|
+
|
33
|
+
_TDATA_SFH_ROOTKEYS = ["sfh_params", "sfh", "smh"]
|
34
|
+
_TDATA_NOQ_KEYS = [key + "_noq" for key in _TDATA_SFH_ROOTKEYS]
|
35
|
+
_TDATA_NOQ_NOLAG_KEYS = [key + "_nolag" for key in _TDATA_NOQ_KEYS]
|
36
|
+
SFH_KEYS = _TDATA_SFH_ROOTKEYS + _TDATA_NOQ_KEYS + _TDATA_NOQ_NOLAG_KEYS
|
37
|
+
TDATA_KEYS = ["mah_params", "log_mah"] + SFH_KEYS
|
38
|
+
TData = namedtuple("TData", TDATA_KEYS)
|
39
|
+
|
40
|
+
|
41
|
+
def tdata_generator(
|
42
|
+
ran_key,
|
43
|
+
logm0_sample,
|
44
|
+
n_sfh_table=N_SFH_TABLE,
|
45
|
+
logsm0_min=LGSM0_MIN,
|
46
|
+
n_epochs=float("inf"),
|
47
|
+
):
|
48
|
+
"""Training data generator for diffstarnet
|
49
|
+
|
50
|
+
Parameters
|
51
|
+
----------
|
52
|
+
ran_key : jax.random.key
|
53
|
+
|
54
|
+
logm0_sample : array, shape (n_halos, )
|
55
|
+
Array of values of diffmah parameter logm0
|
56
|
+
|
57
|
+
logsm0_min : float, optional
|
58
|
+
Minimum z=0 stellar mass in the training data
|
59
|
+
Default is set by LGSM0_MIN at top of module
|
60
|
+
|
61
|
+
n_epochs : int, optional
|
62
|
+
maximum number of batches to yield. Default is infinite
|
63
|
+
|
64
|
+
Yields
|
65
|
+
------
|
66
|
+
tdata : namedtuple
|
67
|
+
mah_params, t_peak, log_mah, sfh_params, sfh, smh
|
68
|
+
sfh_params_noq, sfh_noq, smh_noq
|
69
|
+
sfh_params_noq_nolag, sfh_noq_nolag, smh_noq_nolag
|
70
|
+
|
71
|
+
"""
|
72
|
+
batchnum = 0
|
73
|
+
while batchnum < n_epochs:
|
74
|
+
ran_key, batch_key = jran.split(ran_key, 2)
|
75
|
+
tdata = _compute_tdata(batch_key, logm0_sample, n_sfh_table, logsm0_min)
|
76
|
+
yield tdata
|
77
|
+
batchnum += 1
|
78
|
+
|
79
|
+
|
80
|
+
def _compute_tdata(
|
81
|
+
ran_key, logm0_sample, n_sfh_table=N_SFH_TABLE, logsm0_min=LGSM0_MIN
|
82
|
+
):
|
83
|
+
""""""
|
84
|
+
tarr = np.linspace(T_TABLE_MIN, T0, n_sfh_table)
|
85
|
+
|
86
|
+
mah_key, early_late_key, sfh_key = jran.split(ran_key, 3)
|
87
|
+
|
88
|
+
_reslist = mc_diffmah_halo_sample(mah_key, tarr, logm0_sample)
|
89
|
+
mah_params_early, dmhdt_early, log_mah_early = _reslist[:3]
|
90
|
+
mah_params_late, dmhdt_late, log_mah_late = _reslist[3:6]
|
91
|
+
frac_early = _reslist[6]
|
92
|
+
|
93
|
+
n_halos = mah_params_early.logm0.size
|
94
|
+
uran_mah = jran.uniform(early_late_key, minval=0, maxval=1, shape=(n_halos,))
|
95
|
+
msk_mah = frac_early < uran_mah
|
96
|
+
mah_params = DEFAULT_MAH_PARAMS._make(
|
97
|
+
[
|
98
|
+
jnp.where(
|
99
|
+
msk_mah, getattr(mah_params_early, key), getattr(mah_params_late, key)
|
100
|
+
)
|
101
|
+
for key in mah_params_late._fields
|
102
|
+
]
|
103
|
+
)
|
104
|
+
|
105
|
+
log_mah = jnp.where(msk_mah.reshape((-1, 1)), log_mah_early, log_mah_late)
|
106
|
+
|
107
|
+
ZZ = np.zeros(n_halos)
|
108
|
+
|
109
|
+
uran = jran.uniform(sfh_key, minval=-100, maxval=100, shape=(8, n_halos))
|
110
|
+
|
111
|
+
u_ms_late_index = np.zeros(n_halos) + DEFAULT_U_MS_PARAMS.u_indx_hi
|
112
|
+
u_ms_params = [uran[0], uran[1], uran[2], u_ms_late_index, uran[3]]
|
113
|
+
u_ms_params = DEFAULT_U_MS_PARAMS._make(u_ms_params)
|
114
|
+
u_q_params = DEFAULT_U_Q_PARAMS._make([uran[i, :] for i in range(4, 8)])
|
115
|
+
|
116
|
+
sfh_u_params = DEFAULT_DIFFSTAR_U_PARAMS._make((u_ms_params, u_q_params))
|
117
|
+
sfh_params = get_bounded_diffstar_params(sfh_u_params)
|
118
|
+
|
119
|
+
q_params_noq = u_q_params._make([ZZ + x for x in DEFAULT_Q_PARAMS_UNQUENCHED])
|
120
|
+
sfh_params_noq = sfh_params._replace(q_params=q_params_noq)
|
121
|
+
|
122
|
+
ms_params_nolag = sfh_params.ms_params._replace(tau_dep=TAU_INST + ZZ)
|
123
|
+
sfh_params_noq_nolag = sfh_params_noq._replace(ms_params=ms_params_nolag)
|
124
|
+
|
125
|
+
sfh, smh = calc_sfh_galpop(
|
126
|
+
sfh_params,
|
127
|
+
mah_params,
|
128
|
+
tarr,
|
129
|
+
lgt0=LGT0,
|
130
|
+
fb=FB,
|
131
|
+
return_smh=True,
|
132
|
+
)
|
133
|
+
logsm0 = np.log10(smh)[:, -1]
|
134
|
+
|
135
|
+
sfh_noq, smh_noq = calc_sfh_galpop(
|
136
|
+
sfh_params_noq,
|
137
|
+
mah_params,
|
138
|
+
tarr,
|
139
|
+
lgt0=LGT0,
|
140
|
+
fb=FB,
|
141
|
+
return_smh=True,
|
142
|
+
)
|
143
|
+
logsm0_noq = np.log10(smh_noq)[:, -1]
|
144
|
+
|
145
|
+
sfh_noq_nolag, smh_noq_nolag = calc_sfh_galpop(
|
146
|
+
sfh_params_noq_nolag,
|
147
|
+
mah_params,
|
148
|
+
tarr,
|
149
|
+
lgt0=LGT0,
|
150
|
+
fb=FB,
|
151
|
+
return_smh=True,
|
152
|
+
)
|
153
|
+
logsm0_noq_nolag = np.log10(smh_noq_nolag)[:, -1]
|
154
|
+
|
155
|
+
# Implement stellar mass cut
|
156
|
+
msk = (
|
157
|
+
(logsm0 > logsm0_min)
|
158
|
+
& (logsm0_noq > logsm0_min)
|
159
|
+
& (logsm0_noq_nolag > logsm0_min)
|
160
|
+
)
|
161
|
+
|
162
|
+
mah_params_out = mah_params._make([x[msk] for x in mah_params])
|
163
|
+
log_mah_out = log_mah[msk]
|
164
|
+
sfh_out = sfh[msk]
|
165
|
+
smh_out = smh[msk]
|
166
|
+
sfh_noq_out = sfh_noq[msk]
|
167
|
+
smh_noq_out = smh_noq[msk]
|
168
|
+
sfh_noq_nolag_out = sfh_noq_nolag[msk]
|
169
|
+
smh_noq_nolag_out = smh_noq_nolag[msk]
|
170
|
+
|
171
|
+
ms_params = sfh_params.ms_params._make([x[msk] for x in sfh_params.ms_params])
|
172
|
+
q_params = sfh_params.q_params._make([x[msk] for x in sfh_params.q_params])
|
173
|
+
sfh_params_out = sfh_params._make((ms_params, q_params))
|
174
|
+
|
175
|
+
ms_params_noq_out = sfh_params_noq.ms_params._make(
|
176
|
+
[x[msk] for x in sfh_params_noq.ms_params]
|
177
|
+
)
|
178
|
+
q_params_noq_out = sfh_params_noq.q_params._make(
|
179
|
+
[x[msk] for x in sfh_params_noq.q_params]
|
180
|
+
)
|
181
|
+
sfh_params_noq_out = sfh_params_noq._make((ms_params_noq_out, q_params_noq_out))
|
182
|
+
|
183
|
+
ms_params_noq_nolag_out = sfh_params_noq_nolag.ms_params._make(
|
184
|
+
[x[msk] for x in sfh_params_noq_nolag.ms_params]
|
185
|
+
)
|
186
|
+
sfh_params_noq_nolag_out = sfh_params_noq_out._replace(
|
187
|
+
ms_params=ms_params_noq_nolag_out
|
188
|
+
)
|
189
|
+
|
190
|
+
return TData(
|
191
|
+
mah_params_out,
|
192
|
+
log_mah_out,
|
193
|
+
sfh_params_out,
|
194
|
+
sfh_out,
|
195
|
+
smh_out,
|
196
|
+
sfh_params_noq_out,
|
197
|
+
sfh_noq_out,
|
198
|
+
smh_noq_out,
|
199
|
+
sfh_params_noq_nolag_out,
|
200
|
+
sfh_noq_nolag_out,
|
201
|
+
smh_noq_nolag_out,
|
202
|
+
)
|
203
|
+
|
204
|
+
|
205
|
+
def mc_diffmah_halo_sample(ran_key, tarr, logm0_sample):
|
206
|
+
n_halos = logm0_sample.size
|
207
|
+
ZZ = np.zeros(n_halos)
|
208
|
+
t_0 = tarr[-1]
|
209
|
+
t_obs = t_0 + ZZ
|
210
|
+
lgt0 = np.log10(t_0)
|
211
|
+
ran_keys = jran.split(ran_key, n_halos)
|
212
|
+
_reslist = _mc_diffmah_singlecen_vmap_kern(
|
213
|
+
DEFAULT_DIFFMAHPOP_PARAMS, tarr, logm0_sample, t_obs, ran_keys, lgt0
|
214
|
+
)
|
215
|
+
mah_params_early, dmhdt_early, log_mah_early = _reslist[:3]
|
216
|
+
mah_params_late, dmhdt_late, log_mah_late = _reslist[3:6]
|
217
|
+
frac_early = _reslist[6]
|
218
|
+
return (
|
219
|
+
mah_params_early,
|
220
|
+
dmhdt_early,
|
221
|
+
log_mah_early,
|
222
|
+
mah_params_late,
|
223
|
+
dmhdt_late,
|
224
|
+
log_mah_late,
|
225
|
+
frac_early,
|
226
|
+
)
|