Reference
avenir_goals_scenario.draw_simulations(definition_path, base_year, n_simulations=100, seed=None)
¶
Draw scenario simulations in memory from a scenario definitions file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition_path
|
Path | str
|
Path to the input CSV scenario definitions file. |
required |
n_simulations
|
int
|
Number of simulations drawn per scenario. |
100
|
seed
|
int | None
|
Optional integer seed for reproducible draws. |
None
|
base_year
|
int
|
If provided, used as the minimum value for |
required |
Returns:
| Type | Description |
|---|---|
ScenarioSimulations
|
A |
ScenarioSimulations
|
all scenarios and their draws. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If |
Source code in src/avenir_goals_scenario/scenarios.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
avenir_goals_scenario.write_simulations(simulations, path)
¶
Write scenario simulations to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulations
|
ScenarioSimulations
|
The scenario simulations to write. |
required |
path
|
Path | str
|
Destination path for the JSON file. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved path that was written to. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the parent directory of |
Source code in src/avenir_goals_scenario/scenarios.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
avenir_goals_scenario.read_simulations(path)
¶
Read scenario simulations from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Path to the scenario simulations JSON file. |
required |
Returns:
| Type | Description |
|---|---|
ScenarioSimulations
|
The loaded |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If the file contents fail schema validation. |
Source code in src/avenir_goals_scenario/scenarios.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
avenir_goals_scenario.run_scenario_analysis(config, simulations)
¶
Run scenario analysis across a directory of PJNZ files.
Converts each PJNZ to leapfrog params once in the main process, dumps them
to a temporary file using pickle.dump, then distributes
(PJNZ, scenario) work units across worker processes. Workers load
params via pickle.load.
Results are written to Parquet files under config.output_dir, one file
per PJNZ/scenario combination at
{output_dir}/{pjnz_stem}/scenario_{id}.parquet. Each file contains one
dataset per indicator with shape (n_simulations, *indicator_dims).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RunConfig
|
Validated run configuration. |
required |
simulations
|
ScenarioSimulations
|
Scenario simulations to run. Use
|
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no PJNZ files are found in |
ValueError
|
If any output indicator is not present in the Goals output, or if a PJNZ file cannot be parsed. |
Source code in src/avenir_goals_scenario/runner.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
avenir_goals_scenario.RunConfig
¶
Bases: BaseModel
Configuration for avenir_goals_scenario.run_scenario_analysis.
Field names are case-insensitive: PJNZ_Dir, pjnz_dir, and
PJNZ_DIR are all accepted.
output_dir is created if it does not exist, but only one level deep -
its parent must already exist.
Attributes:
| Name | Type | Description |
|---|---|---|
pjnz_dir |
Path
|
Directory containing |
definition_path |
Path | None
|
Path to the scenario definition CSV file.
Required for the |
scenario_path |
Path | None
|
Path to a scenario simulations JSON file.
For |
output_dir |
Path
|
Directory where per-PJNZ result subdirectories are written. Created automatically if absent (parent must exist). |
base_year |
int
|
First year of the output projection range. |
output_indicators |
list[str]
|
Names of the Goals output indicators to
write. Each name must be a key in the dict returned by |
n_simulations |
int
|
Number of simulations drawn per scenario (default
100). Ignored when loading draws from an existing |
seed |
int | None
|
Optional RNG seed for reproducible draws. |
n_workers |
int
|
Number of parallel worker processes. Follows joblib
conventions: |
Source code in src/avenir_goals_scenario/models/run_config.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |