vivarium-public-health 3.1.3__tar.gz → 3.1.4__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.github/workflows/build.yml +1 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/CHANGELOG.rst +6 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/PKG-INFO +2 -2
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/setup.py +1 -1
- vivarium_public_health-3.1.4/src/vivarium_public_health/_version.py +1 -0
- vivarium_public_health-3.1.4/src/vivarium_public_health/disease/exceptions.py +5 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/disease/model.py +116 -112
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/disease/state.py +215 -79
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/disease/transition.py +78 -21
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health.egg-info/PKG-INFO +2 -2
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health.egg-info/SOURCES.txt +1 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health.egg-info/requires.txt +1 -1
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/disease/test_disease.py +108 -84
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/plugins/test_parser.py +1 -1
- vivarium_public_health-3.1.3/src/vivarium_public_health/_version.py +0 -1
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.bandit +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.flake8 +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.gitattributes +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.github/CODEOWNERS +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.github/pull_request_template.md +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.github/workflows/deploy.yml +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.gitignore +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.pylintrc +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.readthedocs.yml +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/.zenodo.json +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/CODE_OF_CONDUCT.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/CONTRIBUTING.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/Jenkinsfile +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/LICENSE.txt +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/MANIFEST.in +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/Makefile +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/README.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/Makefile +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/nitpick-exceptions +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/_static/style.css +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/_templates/layout.html +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/disease/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/disease/model.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/disease/models.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/disease/special_disease.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/disease/state.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/disease/transition.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/mslt/delay.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/mslt/disease.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/mslt/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/mslt/intervention.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/mslt/magic_wand_components.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/mslt/observer.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/mslt/population.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/plugins/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/plugins/parser.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/population/add_new_birth_cohorts.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/population/base_population.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/population/data_transformations.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/population/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/population/mortality.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/results/disability.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/results/disease.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/results/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/results/mortality.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/results/observer.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/results/risk.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/results/simple_cause.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/results/stratification.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/risks/base_risk.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/risks/data_transformations.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/risks/distributions.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/risks/effect.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/risks/implementations/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/risks/implementations/low_birth_weight_and_short_gestation.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/risks/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/treatment/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/treatment/magic_wand.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/treatment/scale_up.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/treatment/therapeutic_inertia.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/api_reference/utilities.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/conf.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/tutorials/index.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/docs/source/tutorials/risk_exposure.rst +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/pyproject.toml +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/setup.cfg +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/__about__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/disease/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/disease/models.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/disease/special_disease.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/mslt/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/mslt/delay.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/mslt/disease.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/mslt/intervention.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/mslt/magic_wand_components.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/mslt/observer.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/mslt/population.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/plugins/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/plugins/parser.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/population/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/population/add_new_birth_cohorts.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/population/base_population.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/population/data_transformations.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/population/mortality.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/results/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/results/columns.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/results/disability.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/results/disease.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/results/mortality.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/results/observer.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/results/risk.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/results/simple_cause.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/results/stratification.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/risks/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/risks/base_risk.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/risks/data_transformations.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/risks/distributions.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/risks/effect.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/risks/implementations/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/risks/implementations/low_birth_weight_and_short_gestation.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/treatment/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/treatment/magic_wand.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/treatment/scale_up.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/treatment/therapeutic_inertia.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health/utilities.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health.egg-info/dependency_links.txt +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health.egg-info/not-zip-safe +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/src/vivarium_public_health.egg-info/top_level.txt +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/conftest.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/disease/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/disease/test_special_disease.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/mock_artifact.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/plugins/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/population/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/population/conftest.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/population/test_add_new_birth_cohort.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/population/test_base_population.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/population/test_data_transformations.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/population/test_mortality.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/results/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/results/test_categorical_risk_observer.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/results/test_disability.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/results/test_disability_observer.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/results/test_disease_observer.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/results/test_mortality_observer.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/results/test_stratification.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/risks/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/risks/conftest.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/risks/test_base_risk.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/risks/test_data_transformations.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/risks/test_distributions.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/risks/test_effect.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/risks/test_low_birth_weight_and_short_gestation.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/test_utilities.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/treatment/__init__.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tests/treatment/test_scale_up.py +0 -0
- {vivarium_public_health-3.1.3 → vivarium_public_health-3.1.4}/tox.ini +0 -0
@@ -1,3 +1,9 @@
|
|
1
|
+
**3.1.4 - 11/22/24**
|
2
|
+
|
3
|
+
- Feature: Enable initializing a population of all newborns
|
4
|
+
- Feature: Enable setting data sources directly on DiseaseModel components
|
5
|
+
- Refactor: Update DiseaseModel to leverage the on_initialize_simulants method of Machine
|
6
|
+
|
1
7
|
**3.1.3 - 12/03/24**
|
2
8
|
|
3
9
|
- Feature: Create relative risk pipeline
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: vivarium_public_health
|
3
|
-
Version: 3.1.
|
3
|
+
Version: 3.1.4
|
4
4
|
Summary: Components for modelling diseases, risks, and interventions with ``vivarium``
|
5
5
|
Home-page: https://github.com/ihmeuw/vivarium_public_health
|
6
6
|
Author: The vivarium developers
|
@@ -26,7 +26,7 @@ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
26
26
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
27
27
|
Classifier: Topic :: Software Development :: Libraries
|
28
28
|
License-File: LICENSE.txt
|
29
|
-
Requires-Dist: vivarium>=3.2.
|
29
|
+
Requires-Dist: vivarium>=3.2.3
|
30
30
|
Requires-Dist: layered_config_tree>=1.0.1
|
31
31
|
Requires-Dist: loguru
|
32
32
|
Requires-Dist: numpy<2.0.0
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "3.1.4"
|
@@ -10,24 +10,20 @@ transitions at simulation initialization and during transitions.
|
|
10
10
|
"""
|
11
11
|
import warnings
|
12
12
|
from collections.abc import Callable, Iterable
|
13
|
+
from functools import partial
|
13
14
|
from typing import Any
|
14
15
|
|
15
|
-
import numpy as np
|
16
16
|
import pandas as pd
|
17
|
-
from vivarium.exceptions import VivariumError
|
18
17
|
from vivarium.framework.engine import Builder
|
19
|
-
from vivarium.framework.event import Event
|
20
18
|
from vivarium.framework.population import SimulantData
|
21
19
|
from vivarium.framework.state_machine import Machine
|
20
|
+
from vivarium.types import DataInput, LookupTableData
|
22
21
|
|
22
|
+
from vivarium_public_health.disease.exceptions import DiseaseModelError
|
23
23
|
from vivarium_public_health.disease.state import BaseDiseaseState, SusceptibleState
|
24
24
|
from vivarium_public_health.disease.transition import TransitionString
|
25
25
|
|
26
26
|
|
27
|
-
class DiseaseModelError(VivariumError):
|
28
|
-
pass
|
29
|
-
|
30
|
-
|
31
27
|
class DiseaseModel(Machine):
|
32
28
|
|
33
29
|
##############
|
@@ -82,57 +78,77 @@ class DiseaseModel(Machine):
|
|
82
78
|
cause_type: str = "cause",
|
83
79
|
states: Iterable[BaseDiseaseState] = (),
|
84
80
|
residual_state: BaseDiseaseState | None = None,
|
85
|
-
|
86
|
-
):
|
87
|
-
super().__init__(cause, states=states
|
81
|
+
cause_specific_mortality_rate: DataInput | None = None,
|
82
|
+
) -> None:
|
83
|
+
super().__init__(cause, states=states)
|
88
84
|
self.cause = cause
|
89
85
|
self.cause_type = cause_type
|
86
|
+
self.residual_state = self._get_residual_state(initial_state, residual_state)
|
87
|
+
self._csmr_source = cause_specific_mortality_rate
|
88
|
+
self._get_data_functions = (
|
89
|
+
get_data_functions if get_data_functions is not None else {}
|
90
|
+
)
|
90
91
|
|
91
|
-
if
|
92
|
+
if get_data_functions is not None:
|
92
93
|
warnings.warn(
|
93
|
-
"
|
94
|
-
"
|
95
|
-
" retain the current behavior of defining a residual state, use"
|
96
|
-
" the 'residual_state' argument.",
|
94
|
+
"The argument 'get_data_functions' has been deprecated. Use"
|
95
|
+
" cause_specific_mortality_rate instead.",
|
97
96
|
DeprecationWarning,
|
98
97
|
stacklevel=2,
|
99
98
|
)
|
100
99
|
|
101
|
-
if
|
100
|
+
if cause_specific_mortality_rate is not None:
|
102
101
|
raise DiseaseModelError(
|
103
|
-
"
|
104
|
-
"
|
102
|
+
"It is not allowed to pass cause_specific_mortality_rate"
|
103
|
+
" both as a stand-alone argument and as part of"
|
104
|
+
" get_data_functions."
|
105
105
|
)
|
106
106
|
|
107
|
-
self.residual_state = initial_state.state_id
|
108
|
-
elif residual_state is not None:
|
109
|
-
self.residual_state = residual_state.state_id
|
110
|
-
else:
|
111
|
-
self.residual_state = self._get_default_residual_state()
|
112
|
-
|
113
|
-
self._get_data_functions = (
|
114
|
-
get_data_functions if get_data_functions is not None else {}
|
115
|
-
)
|
116
|
-
|
117
107
|
def setup(self, builder: Builder) -> None:
|
118
108
|
"""Perform this component's setup."""
|
119
109
|
super().setup(builder)
|
120
110
|
|
121
111
|
self.configuration_age_start = builder.configuration.population.initialization_age_min
|
122
112
|
self.configuration_age_end = builder.configuration.population.initialization_age_max
|
113
|
+
|
123
114
|
builder.value.register_value_modifier(
|
124
115
|
"cause_specific_mortality_rate",
|
125
116
|
self.adjust_cause_specific_mortality_rate,
|
126
117
|
requires_columns=["age", "sex"],
|
127
118
|
)
|
128
|
-
|
119
|
+
|
120
|
+
def on_initialize_simulants(self, pop_data: SimulantData) -> None:
|
121
|
+
"""Initialize the simulants in the population.
|
122
|
+
|
123
|
+
If all simulants are initialized at age 0, birth prevalence is used.
|
124
|
+
Otherwise, prevalence is used.
|
125
|
+
|
126
|
+
Parameters
|
127
|
+
----------
|
128
|
+
pop_data
|
129
|
+
The population data object.
|
130
|
+
"""
|
131
|
+
if pop_data.user_data.get("age_end", self.configuration_age_end) == 0:
|
132
|
+
initialization_table_name = "birth_prevalence"
|
133
|
+
else:
|
134
|
+
initialization_table_name = "prevalence"
|
135
|
+
|
136
|
+
for state in self.states:
|
137
|
+
state.lookup_tables["initialization_weights"] = state.lookup_tables[
|
138
|
+
initialization_table_name
|
139
|
+
]
|
140
|
+
|
141
|
+
super().on_initialize_simulants(pop_data)
|
129
142
|
|
130
143
|
#################
|
131
144
|
# Setup methods #
|
132
145
|
#################
|
133
146
|
|
134
147
|
def load_cause_specific_mortality_rate(self, builder: Builder) -> float | pd.DataFrame:
|
135
|
-
if
|
148
|
+
if (
|
149
|
+
"cause_specific_mortality_rate" not in self._get_data_functions
|
150
|
+
and self._csmr_source is None
|
151
|
+
):
|
136
152
|
only_morbid = builder.data.load(f"cause.{self.cause}.restrictions")["yld_only"]
|
137
153
|
if only_morbid:
|
138
154
|
csmr_data = 0.0
|
@@ -140,64 +156,14 @@ class DiseaseModel(Machine):
|
|
140
156
|
csmr_data = builder.data.load(
|
141
157
|
f"{self.cause_type}.{self.cause}.cause_specific_mortality_rate"
|
142
158
|
)
|
159
|
+
elif self._csmr_source is not None:
|
160
|
+
csmr_data = self.get_data(builder, self._csmr_source)
|
143
161
|
else:
|
144
162
|
csmr_data = self._get_data_functions["cause_specific_mortality_rate"](
|
145
163
|
self.cause, builder
|
146
164
|
)
|
147
165
|
return csmr_data
|
148
166
|
|
149
|
-
########################
|
150
|
-
# Event-driven methods #
|
151
|
-
########################
|
152
|
-
|
153
|
-
def on_initialize_simulants(self, pop_data: SimulantData) -> None:
|
154
|
-
population = self.population_view.subview(["age", "sex"]).get(pop_data.index)
|
155
|
-
|
156
|
-
assert self.residual_state in {s.state_id for s in self.states}
|
157
|
-
|
158
|
-
if pop_data.user_data["sim_state"] == "setup": # simulation start
|
159
|
-
if self.configuration_age_start != self.configuration_age_end != 0:
|
160
|
-
state_names, weights_bins = self.get_state_weights(
|
161
|
-
pop_data.index, "prevalence"
|
162
|
-
)
|
163
|
-
else:
|
164
|
-
raise NotImplementedError(
|
165
|
-
"We do not currently support an age 0 cohort. "
|
166
|
-
"configuration.population.initialization_age_min and "
|
167
|
-
"configuration.population.initialization_age_max "
|
168
|
-
"cannot both be 0."
|
169
|
-
)
|
170
|
-
|
171
|
-
else: # on time step
|
172
|
-
if pop_data.user_data["age_start"] == pop_data.user_data["age_end"] == 0:
|
173
|
-
state_names, weights_bins = self.get_state_weights(
|
174
|
-
pop_data.index, "birth_prevalence"
|
175
|
-
)
|
176
|
-
else:
|
177
|
-
state_names, weights_bins = self.get_state_weights(
|
178
|
-
pop_data.index, "prevalence"
|
179
|
-
)
|
180
|
-
|
181
|
-
if state_names and not population.empty:
|
182
|
-
# only do this if there are states in the model that supply prevalence data
|
183
|
-
population["sex_id"] = population.sex.apply({"Male": 1, "Female": 2}.get)
|
184
|
-
|
185
|
-
condition_column = self.assign_initial_status_to_simulants(
|
186
|
-
population,
|
187
|
-
state_names,
|
188
|
-
weights_bins,
|
189
|
-
self.randomness.get_draw(population.index),
|
190
|
-
)
|
191
|
-
|
192
|
-
condition_column = condition_column.rename(
|
193
|
-
columns={"condition_state": self.state_column}
|
194
|
-
)
|
195
|
-
else:
|
196
|
-
condition_column = pd.Series(
|
197
|
-
self.residual_state, index=population.index, name=self.state_column
|
198
|
-
)
|
199
|
-
self.population_view.update(condition_column)
|
200
|
-
|
201
167
|
##################################
|
202
168
|
# Pipeline sources and modifiers #
|
203
169
|
##################################
|
@@ -209,40 +175,78 @@ class DiseaseModel(Machine):
|
|
209
175
|
# Helper functions #
|
210
176
|
####################
|
211
177
|
|
212
|
-
def
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
return susceptible_states[0].state_id
|
217
|
-
|
218
|
-
def get_state_weights(
|
219
|
-
self, pop_index: pd.Index, prevalence_type: str
|
220
|
-
) -> tuple[list[str], np.ndarray | None]:
|
221
|
-
states = [state for state in self.states if state.lookup_tables.get(prevalence_type)]
|
222
|
-
|
223
|
-
if not states:
|
224
|
-
return states, None
|
178
|
+
def _get_residual_state(
|
179
|
+
self, initial_state: BaseDiseaseState, residual_state: BaseDiseaseState
|
180
|
+
) -> BaseDiseaseState:
|
181
|
+
"""Get the residual state for the DiseaseModel.
|
225
182
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
183
|
+
This will be the residual state if it is provided, otherwise it will be
|
184
|
+
the model's SusceptibleState. This method also calculates the residual
|
185
|
+
state's birth_prevalence and prevalence.
|
186
|
+
"""
|
187
|
+
if initial_state is not None:
|
188
|
+
warnings.warn(
|
189
|
+
"In the future, the 'initial_state' argument to DiseaseModel"
|
190
|
+
" will be used to initialize all simulants into that state. To"
|
191
|
+
" retain the current behavior of defining a residual state, use"
|
192
|
+
" the 'residual_state' argument.",
|
193
|
+
DeprecationWarning,
|
194
|
+
stacklevel=2,
|
195
|
+
)
|
230
196
|
|
231
|
-
|
232
|
-
|
197
|
+
if residual_state:
|
198
|
+
raise DiseaseModelError(
|
199
|
+
"A DiseaseModel cannot be initialized with both"
|
200
|
+
" 'initial_state and 'residual_state'."
|
201
|
+
)
|
233
202
|
|
234
|
-
|
203
|
+
residual_state = initial_state
|
204
|
+
elif residual_state is None:
|
205
|
+
susceptible_states = [s for s in self.states if isinstance(s, SusceptibleState)]
|
206
|
+
if len(susceptible_states) != 1:
|
207
|
+
raise DiseaseModelError(
|
208
|
+
"Disease model must have exactly one SusceptibleState."
|
209
|
+
)
|
210
|
+
residual_state = susceptible_states[0]
|
235
211
|
|
236
|
-
|
212
|
+
if residual_state not in self.states:
|
213
|
+
raise DiseaseModelError(
|
214
|
+
f"Residual state '{self.residual_state}' must be one of the"
|
215
|
+
f" states: {self.states}."
|
216
|
+
)
|
237
217
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
218
|
+
residual_state.birth_prevalence = partial(
|
219
|
+
self._get_residual_state_probabilities, table_name="birth_prevalence"
|
220
|
+
)
|
221
|
+
residual_state.prevalence = partial(
|
222
|
+
self._get_residual_state_probabilities, table_name="prevalence"
|
223
|
+
)
|
243
224
|
|
244
|
-
|
245
|
-
|
225
|
+
return residual_state
|
226
|
+
|
227
|
+
def _get_residual_state_probabilities(
|
228
|
+
self, builder: Builder, table_name: str
|
229
|
+
) -> LookupTableData:
|
230
|
+
"""Calculate the probabilities of the residual state based on the other states."""
|
231
|
+
non_residual_states = [s for s in self.states if s != self.residual_state]
|
232
|
+
non_residual_probabilities = 0
|
233
|
+
for state in non_residual_states:
|
234
|
+
weights_source = builder.configuration[state.name].data_sources[table_name]
|
235
|
+
weights = state.get_data(builder, weights_source)
|
236
|
+
if isinstance(weights, pd.DataFrame):
|
237
|
+
weights = weights.set_index(
|
238
|
+
[c for c in weights.columns if c != "value"]
|
239
|
+
).squeeze()
|
240
|
+
non_residual_probabilities += weights
|
241
|
+
|
242
|
+
residual_probabilities = 1 - non_residual_probabilities
|
243
|
+
|
244
|
+
if pd.Series(residual_probabilities < 0).any():
|
245
|
+
raise ValueError(
|
246
|
+
f"The {table_name} for the states in the DiseaseModel must sum"
|
247
|
+
" to less than 1."
|
248
|
+
)
|
249
|
+
if isinstance(residual_probabilities, pd.Series):
|
250
|
+
residual_probabilities = residual_probabilities.reset_index()
|
246
251
|
|
247
|
-
|
248
|
-
return simulants
|
252
|
+
return residual_probabilities
|