Skip to content

Commit c66913d

Browse files
committed
more docs
1 parent f37d148 commit c66913d

4 files changed

Lines changed: 84 additions & 13 deletions

File tree

demos/models/rebalancing.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,46 @@
1111
import time
1212
from logging_logic import log_execution_time
1313

14-
@orca.step('household_rebalancing')
14+
STEP_NAME = "household_rebalancing"
15+
16+
@orca.step(STEP_NAME)
1517
def household_rebalancing(households, persons, year, get_new_households, get_new_person_id, rebalanced_households, rebalanced_persons):
18+
"""
19+
Adjust household counts to match control totals by geography and household size.
20+
21+
This step compares current household counts with control totals and duplicates or removes
22+
households as needed. It maintains population consistency by also updating the persons table
23+
and stores removed records for tracking purposes.
24+
25+
Parameters
26+
----------
27+
households : orca.Table
28+
The households table containing household-level attributes.
29+
persons : orca.Table
30+
The persons table containing individual-level attributes.
31+
year : int
32+
The current simulation year.
33+
get_new_households : callable
34+
Function to generate new unique household IDs.
35+
get_new_person_id : callable
36+
Function to generate new unique person IDs.
37+
rebalanced_households : orca.Table
38+
Table for storing removed household records.
39+
rebalanced_persons : orca.Table
40+
Table for storing removed person records.
41+
42+
Returns
43+
-------
44+
None
45+
46+
Notes
47+
-----
48+
- Modifies households and persons tables in place by adding/removing records.
49+
- Uses module configuration to determine control table and column mappings.
50+
- Tracks marital status before and after operations in marital_rebalanced table.
51+
- Skips processing if no control data exists for the current year.
52+
- Sampling with replacement occurs when duplicating more households than available.
53+
"""
1654
start_time = time.time()
1755

1856
# Load calibration config
@@ -43,8 +81,6 @@ def household_rebalancing(households, persons, year, get_new_households, get_new
4381
indices = index_df.groupby([GEOID_COL, CONTROL_COL]).indices
4482
current_count = index_df.groupby([GEOID_COL, CONTROL_COL]).size()
4583
hh_difference = control_table_wrapped.local.loc[year].astype({GEOID_COL: "str", CONTROL_COL:"str"}).set_index([GEOID_COL, CONTROL_COL])[value_column].loc[current_count.index] - current_count
46-
47-
# TODO: Add assertions about rows being enough to make the sampling
4884

4985
to_remove_hh = []
5086
to_duplicate_hh = []

docs/source/api/configuration_module.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ DEMOS Configuration Structure
33

44
.. autoclass:: demos.config.DEMOSConfig
55
:members:
6-
:exclude-members: __init__, update, require_persons_and_households
6+
:exclude-members: __init__, update, require_persons_and_households, model_post_init
77

88
Individual Modules configuration
99
--------------------------------
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Household Rebalancing Module
2+
============================
3+
4+
This module adjusts the synthetic population to match observed household size distributions by geography.
5+
It duplicates or removes households to align current counts with control totals, maintaining population
6+
consistency while preserving demographic characteristics. The module tracks marital status before and
7+
after rebalancing operations and stores removed households/persons in separate tables.
8+
9+
Key features:
10+
11+
- Matches household counts to control totals by geography and household size.
12+
- Duplicates households (and their members) when counts are below target.
13+
- Removes households (and their members) when counts exceed target.
14+
- Preserves demographic characteristics through exact duplication/removal.
15+
- Tracks marital status changes for validation purposes.
16+
- Stores removed records in rebalanced_households and rebalanced_persons tables.
17+
18+
Caveats:
19+
20+
- Requires a control table with year, geography, household size, and target count columns.
21+
- The control table index must be 'year' and must have exactly 3 columns.
22+
- Sampling with replacement is used when duplicating more households than available.
23+
- Most errors are handled with assertions; users should ensure data consistency.
24+
- Geographic and household size columns must match between households and control tables.
25+
26+
Module function
27+
---------------
28+
29+
Module configuration options: :py:class:`~demos.config.HHRebalancingModuleConfig`
30+
31+
.. autofunction:: demos.models.rebalancing.household_rebalancing

docs/source/pages/intro.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This document summarizes instructions to install, configure and run DEMOS. Secti
2727
```
2828

2929
**Build Docker Image** *(Development only)*
30+
> NOTE: Ideally, our DEMOS Docker image is hosted in a public image registry so users will not need to build it themselves
3031
```bash
3132
docker build -t demos:0.0.1 --platform=linux/amd64 -f Dockerfile .
3233
```
@@ -86,7 +87,7 @@ open build/html/index.html
8687
8788
## 2. Preparing Your Configuration
8889
89-
DEMOS is configured via a TOML file (see [example configuration](default_configuration) for a full example).
90+
DEMOS is configured via a TOML file (see [example configuration](default_configuration) for a full example and [configuration API](../api/configuration_module.rst) for descriptions on each of the accepted parameters).
9091
At minimum, you must define the `persons` and `households` tables:
9192
9293
```toml
@@ -170,17 +171,20 @@ To run DEMOS, organize your files as follows:
170171
```
171172
DEMOS_NREL/
172173
├── configuration/
173-
│ └── demos_config.toml # Main configuration file (TOML)
174+
│ └── demos_config.toml # Main configuration file (TOML)
174175
├── data/
175-
| ├── custom_mpo_06197001_model_data.h5 # Example HDF5 data file
176-
│ ├── relmap_06197001.csv # Example CSV data file
177-
│ ├── income_rates_06197001.csv # Example CSV data file
178-
│ ├── hsize_ct_06197001.csv # Example CSV data file
179-
| └── calibrated_configs/ # Here is were the parameters of the estimated models go
176+
| ├── custom_mpo_06197001_model_data.h5 # Example HDF5 data file
177+
│ ├── relmap_06197001.csv # Example CSV data file
178+
│ ├── income_rates_06197001.csv # Example CSV data file
179+
│ ├── hsize_ct_06197001.csv # Example CSV data file
180+
| └── calibrated_configs/ # Here is were the parameters of the estimated models go
180181
| └── ...
181182
├── demos/ # Source code
182-
| └── simulate.py # Main entry point for running DEMOS
183-
├── docs/ # Documentation
183+
| ├── simulate.py # Main entry point for running DEMOS
184+
| ├── models # Logic of individual modules
185+
| └── ...
186+
| └── ...
187+
├── docs/ # Documentation
184188
└── ...
185189
```
186190

0 commit comments

Comments
 (0)