Skip to content

Commit

Permalink
Merge pull request #320 from ihmeuw/develop
Browse files Browse the repository at this point in the history
releave v0.11.0
  • Loading branch information
stevebachmeier authored Jun 1, 2023
2 parents 06879f5 + 11ea0f2 commit 32ecb45
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
defaults:
run:
shell: bash -le {0}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.11'
- name: Install dependencies
run: |
python --version
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
**0.11.0 - 06/01/23**

- Support Python 3.8-3.11
- Update vivarium pin
- Handle FutureWarning
- Refactor to create a 'get_transition_names' function

**0.10.24 - 05/11/23**

- Standardize builder, cause argument order in state get data functions
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from setuptools import find_packages, setup

if __name__ == "__main__":

base_dir = os.path.dirname(__file__)
src_dir = os.path.join(base_dir, "src")

Expand All @@ -16,7 +15,7 @@
long_description = f.read()

install_requirements = [
"vivarium>=1.1.0",
"vivarium>=1.2.0",
"numpy",
"pandas",
"scipy",
Expand Down
2 changes: 1 addition & 1 deletion src/vivarium_public_health/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__summary__ = "Components for modelling diseases, risks, and interventions with ``vivarium``"
__uri__ = "https://github.com/ihmeuw/vivarium_public_health"

__version__ = "0.10.24"
__version__ = "0.11.0"

__author__ = "The vivarium_public_health developers"
__email__ = "[email protected]"
Expand Down
4 changes: 1 addition & 3 deletions src/vivarium_public_health/disease/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def transition_names(self) -> List[TransitionString]:
states = {s.name.split(".")[1]: s for s in self.states}
transitions = []
for state in states.values():
for trans in state.transition_set.transitions:
_, _, init_state, _, end_state = trans.name.split(".")
transitions.append(TransitionString(f"{init_state}_TO_{end_state}"))
transitions += state.get_transition_names()
return transitions

def setup(self, builder):
Expand Down
1 change: 0 additions & 1 deletion src/vivarium_public_health/disease/special_disease.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ def with_condition(self, index):
return with_condition

def get_exposure_filter(self, distribution, exposure_pipeline, threshold):

if distribution in ["dichotomous", "ordered_polytomous", "unordered_polytomous"]:

def categorical_filter(index):
Expand Down
14 changes: 13 additions & 1 deletion src/vivarium_public_health/disease/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
This module contains tools to manage standard disease states.
"""
from typing import Callable, Dict
from typing import Callable, Dict, List

import numpy as np
import pandas as pd
Expand All @@ -17,6 +17,7 @@
from vivarium_public_health.disease.transition import (
ProportionTransition,
RateTransition,
TransitionString,
)
from vivarium_public_health.utilities import is_non_zero

Expand Down Expand Up @@ -94,6 +95,17 @@ def _transition_side_effect(self, index, event_time):
if self.side_effect_function is not None:
self.side_effect_function(index, event_time)

##################
# Public methods #
##################

def get_transition_names(self) -> List[str]:
transitions = []
for trans in self.transition_set.transitions:
_, _, init_state, _, end_state = trans.name.split(".")
transitions.append(TransitionString(f"{init_state}_TO_{end_state}"))
return transitions

def add_transition(
self,
output: State,
Expand Down
61 changes: 33 additions & 28 deletions src/vivarium_public_health/population/data_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def rescale_binned_proportions(
values are rescaled to reflect their smaller representation.
"""
col_order = pop_data.columns.copy()
if age_start > pop_data.age_end.max():
if age_start > pop_data["age_end"].max():
raise ValueError(
"Provided population data is insufficient to model the requested age range."
)

age_start = max(pop_data.age_start.min(), age_start)
age_end = min(pop_data.age_end.max(), age_end) - 1e-8
age_start = max(pop_data["age_start"].min(), age_start)
age_end = min(pop_data["age_end"].max(), age_end) - 1e-8
pop_data = _add_edge_age_groups(pop_data.copy())

columns_to_scale = [
Expand All @@ -123,12 +123,13 @@ def rescale_binned_proportions(
"value",
]
for _, sub_pop in pop_data.groupby(["sex", "location"]):
min_bin = sub_pop[
(sub_pop["age_start"] <= age_start) & (age_start < sub_pop["age_end"])
]
padding_bin = sub_pop[sub_pop["age_end"] == float(min_bin["age_start"].iloc[0])]

min_bin = sub_pop[(sub_pop.age_start <= age_start) & (age_start < sub_pop.age_end)]
padding_bin = sub_pop[sub_pop.age_end == float(min_bin.age_start)]

min_scale = (float(min_bin.age_end) - age_start) / float(
min_bin.age_end - min_bin.age_start
min_scale = (float(min_bin["age_end"].iloc[0]) - age_start) / float(
min_bin["age_end"].iloc[0] - min_bin["age_start"].iloc[0]
)

remainder = pop_data.loc[min_bin.index, columns_to_scale].values * (1 - min_scale)
Expand All @@ -138,11 +139,11 @@ def rescale_binned_proportions(
pop_data.loc[min_bin.index, "age_start"] = age_start
pop_data.loc[padding_bin.index, "age_end"] = age_start

max_bin = sub_pop[(sub_pop.age_end > age_end) & (age_end >= sub_pop.age_start)]
padding_bin = sub_pop[sub_pop.age_start == float(max_bin.age_end)]
max_bin = sub_pop[(sub_pop["age_end"] > age_end) & (age_end >= sub_pop["age_start"])]
padding_bin = sub_pop[sub_pop["age_start"] == float(max_bin["age_end"].iloc[0])]

max_scale = (age_end - float(max_bin.age_start)) / float(
max_bin.age_end - max_bin.age_start
max_scale = (age_end - float(max_bin["age_start"].iloc[0])) / float(
max_bin["age_end"].iloc[0] - max_bin["age_start"].iloc[0]
)

remainder = pop_data.loc[max_bin.index, columns_to_scale] * (1 - max_scale)
Expand Down Expand Up @@ -239,20 +240,21 @@ def smooth_ages(
"""
simulants = simulants.copy()
for (sex, location), sub_pop in population_data.groupby(["sex", "location"]):

ages = sorted(sub_pop.age.unique())
younger = [float(sub_pop.loc[sub_pop.age == ages[0], "age_start"])] + ages[:-1]
older = ages[1:] + [float(sub_pop.loc[sub_pop.age == ages[-1], "age_end"])]
ages = sorted(sub_pop["age"].unique())
younger = [float(sub_pop.loc[sub_pop["age"] == ages[0], "age_start"].iloc[0])] + ages[
:-1
]
older = ages[1:] + [float(sub_pop.loc[sub_pop["age"] == ages[-1], "age_end"].iloc[0])]

uniform_all = randomness.get_draw(simulants.index)

for age_set in zip(ages, younger, older):
age = AgeValues(*age_set)

has_correct_demography = (
(simulants.age == age.current)
& (simulants.sex == sex)
& (simulants.location == location)
(simulants["age"] == age.current)
& (simulants["sex"] == sex)
& (simulants["location"] == location)
)
affected = simulants[has_correct_demography]

Expand Down Expand Up @@ -319,15 +321,15 @@ def _get_bins_and_proportions(
)
"""
left = float(pop_data.loc[pop_data.age == age.current, "age_start"])
right = float(pop_data.loc[pop_data.age == age.current, "age_end"])
left = float(pop_data.loc[pop_data["age"] == age.current, "age_start"].iloc[0])
right = float(pop_data.loc[pop_data["age"] == age.current, "age_end"].iloc[0])

if not pop_data.loc[pop_data.age == age.young, "age_start"].empty:
lower_left = float(pop_data.loc[pop_data.age == age.young, "age_start"])
if not pop_data.loc[pop_data["age"] == age.young, "age_start"].empty:
lower_left = float(pop_data.loc[pop_data["age"] == age.young, "age_start"].iloc[0])
else:
lower_left = left
if not pop_data.loc[pop_data.age == age.old, "age_end"].empty:
upper_right = float(pop_data.loc[pop_data.age == age.old, "age_end"])
if not pop_data.loc[pop_data["age"] == age.old, "age_end"].empty:
upper_right = float(pop_data.loc[pop_data["age"] == age.old, "age_end"].iloc[0])
else:
upper_right = right

Expand All @@ -338,18 +340,21 @@ def _get_bins_and_proportions(
# in order to back out a point estimate for the probability density at the center
# of the interval. This not the best assumption, but it'll do.
p_age = float(
pop_data.loc[pop_data.age == age.current, proportion_column] / (right - left)
pop_data.loc[pop_data["age"] == age.current, proportion_column].iloc[0]
/ (right - left)
)
p_young = (
float(
pop_data.loc[pop_data.age == age.young, proportion_column] / (left - lower_left)
pop_data.loc[pop_data["age"] == age.young, proportion_column].iloc[0]
/ (left - lower_left)
)
if age.young != left
else p_age
)
p_old = (
float(
pop_data.loc[pop_data.age == age.old, proportion_column] / (upper_right - right)
pop_data.loc[pop_data["age"] == age.old, proportion_column].iloc[0]
/ (upper_right - right)
)
if age.old != right
else 0
Expand Down
1 change: 0 additions & 1 deletion src/vivarium_public_health/population/mortality.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@


class Mortality:

configuration_defaults = {"unmodeled_causes": []}

def __init__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@


class LBWSGDistribution(PolytomousDistribution):

configuration_defaults = {
"lbwsg_distribution": {
"age_column": "age",
Expand Down Expand Up @@ -211,7 +210,6 @@ def _parse_description(axis: str, description: str) -> pd.Interval:


class LBWSGRisk(Risk):

AXES = [BIRTH_WEIGHT, GESTATIONAL_AGE]

def __init__(self):
Expand Down Expand Up @@ -316,7 +314,6 @@ def _get_current_exposure(self, index: pd.Index) -> pd.DataFrame:


class LBWSGRiskEffect(RiskEffect):

TMREL_BIRTH_WEIGHT_INTERVAL: pd.Interval = pd.Interval(3500.0, 4500.0)
TMREL_GESTATIONAL_AGE_INTERVAL: pd.Interval = pd.Interval(38.0, 42.0)

Expand Down
1 change: 0 additions & 1 deletion tests/disease/test_disease.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def get_test_prevalence(simulation, key):


def test_dwell_time(assign_cause_mock, base_config, base_plugins, disease, base_data):

time_step = 10
assign_cause_mock.side_effect = lambda population, *args: pd.DataFrame(
{"condition_state": "healthy"}, index=population.index
Expand Down
2 changes: 0 additions & 2 deletions tests/metrics/test_stratification.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


class FavoriteColor:

OPTIONS = ["red", "green", "orange"]

@property
Expand All @@ -34,7 +33,6 @@ def setup(self, builder: Builder):


class FavoriteNumber:

OPTIONS = [7, 42, 14312]

@property
Expand Down
1 change: 0 additions & 1 deletion tests/population/test_add_new_birth_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

@pytest.fixture()
def config(base_config):

base_config.update(
{
"population": {
Expand Down

0 comments on commit 32ecb45

Please sign in to comment.