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

Results docs cleanup #479

Merged
merged 3 commits into from
Aug 29, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
**3.0.5 - 08/29/24**

- Add missing results module-level docstrings
- Strengthen the SimpleCause docstring
- Rename the SimpleCause class method

**3.0.4 - 08/28/24**

- Strengthen results docstrings and clean up others throughout
Expand Down
8 changes: 4 additions & 4 deletions src/vivarium_public_health/results/disability.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
===================
Disability Observer
===================
====================
Disability Observers
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The risk docstring was plural so I wanted to be consistent. I prefer plural to leave room for future observers in each module

====================

This module contains tools for observing years lived with disability (YLDs)
in the simulation.
Expand Down Expand Up @@ -102,7 +102,7 @@ def set_causes_of_disability(self, builder: Builder) -> None:
)
# Convert to SimpleCause instances and add on all_causes
causes_of_disability = [
SimpleCause.create_from_disease_state(cause) for cause in causes_of_disability
SimpleCause.create_from_specific_cause(cause) for cause in causes_of_disability
] + [SimpleCause("all_causes", "all_causes", "cause")]

excluded_causes = (
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium_public_health/results/disease.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
================
Disease Observer
================
=================
Disease Observers
=================

This module contains tools for observing disease incidence and prevalence
in the simulation.
Expand Down
8 changes: 4 additions & 4 deletions src/vivarium_public_health/results/mortality.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
==================
Mortality Observer
==================
===================
Mortality Observers
===================

This module contains tools for observing cause-specific and
excess mortality in the simulation, including "other causes".
Expand Down Expand Up @@ -130,7 +130,7 @@ def set_causes_of_death(self, builder: Builder) -> None:

# Convert to SimpleCauses and add on other_causes and not_dead
self.causes_of_death = [
SimpleCause.create_from_disease_state(cause) for cause in causes_of_death
SimpleCause.create_from_specific_cause(cause) for cause in causes_of_death
] + [
SimpleCause("not_dead", "not_dead", "cause"),
SimpleCause("other_causes", "other_causes", "cause"),
Expand Down
10 changes: 10 additions & 0 deletions src/vivarium_public_health/results/observer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""
===============
Basic Observers
===============

This module contains convenience classes for building concrete observers in
public health models.

"""

from typing import Callable, List, Optional, Union

import pandas as pd
Expand Down
31 changes: 25 additions & 6 deletions src/vivarium_public_health/results/simple_cause.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
"""
============
Simple Cause
============

This module contains tools for creating a minimal representation of a cause
as required by observers.

"""

from dataclasses import dataclass


@dataclass
class SimpleCause:
"""A simple dataclass to represent the bare minimum information needed
for observers, e.g. 'all_causes' as a cause of disability.
"""A simple dataclass to represent the bare minimum information needed by observers.

It also includes a class method to convert a provided disease state into a
It also includes a class method to convert a provided cause into a
``SimpleCause`` instance.

"""
Expand All @@ -19,6 +28,16 @@ class SimpleCause:
"""The cause type of the cause."""

@classmethod
def create_from_disease_state(cls, disease_state: type) -> "SimpleCause":
"""Create a SimpleCause instance from a"""
return cls(disease_state.state_id, disease_state.model, disease_state.cause_type)
def create_from_specific_cause(cls, cause: type) -> "SimpleCause":
"""Create a SimpleCause instance from a more specific cause.

Parameters
----------
cause
The cause to be converted into a SimpleCause instance.

Returns
-------
A SimpleCause instance.
"""
return cls(cause.state_id, cause.model, cause.cause_type)
Loading