Skip to content

Scenario uncertainty - #302

Merged
romainsacchi merged 2 commits into
masterfrom
scenario_uncertainty
Aug 19, 2026
Merged

Scenario uncertainty#302
romainsacchi merged 2 commits into
masterfrom
scenario_uncertainty

Conversation

@romainsacchi

Copy link
Copy Markdown
Collaborator

This PR adds a Brightway export for evaluating multiple premise scenarios from one database and one compressed bw_processing package.

array_path = ndb.write_scenario_array_db_to_brightway(
name="scenario-ensemble",
)

The method writes:

  • one union database to the active Brightway project;
  • one ZIP containing synchronized technosphere and biosphere scenario arrays;
  • columns ordered as original, followed by ndb.scenarios.

The initial LCA uses original. Each next(lca) selects the next complete scenario, with iteration wrapping to original after the final scenario.

Motivation

Writing one Brightway database per scenario is expensive and makes large scenario ensembles cumbersome. Existing superstructure exports target Activity Browser and require a scenario-difference file.

This export allows deterministic scenario enumeration directly through bw2calc.

Usage

demand, data_objs, remapping = bd.prepare_lca_inputs(
{functional_unit: 1},
method=method,
)

lca = bc.LCA(
demand,
data_objs=[*data_objs, array_path],
remapping_dicts=remapping,
use_arrays=True,
)

lca.lci()
lca.lcia()

scores = [lca.score] # original
for _ in ndb.scenarios:
next(lca)
scores.append(lca.score)

The ZIP must be appended after the database datapackages so its changing coordinates override the base database.

Implementation

  • Supports modern Brightway only (bw2data >= 4).
  • Adds bw_processing >= 1.0 to the bw25 optional dependencies.
  • Stores only coordinates that vary across scenarios.
  • Writes float64 values and Brightway-native indices.
  • Advances technosphere and biosphere arrays together.
  • Uses sequential selection without distributions, weights, seeds, or random sampling.
  • Writes ZIP files with deflate compression and atomic replacement.
  • Stores project, database, ecoinvent, premise, and scenario metadata.
  • Leaves the written database at its original values when the array package is not loaded.
  • Preserves the existing write_superstructure_db_to_brightway() behavior and return type.

The array ZIP is tied to the active Brightway project and its assigned node IDs. It must be regenerated after moving, deleting, or rewriting the database.

Documentation

The PR adds:

  • a complete executable workflow to the examples notebook;
  • detailed API and lifecycle guidance to the Brightway loading documentation;
  • a concise README introduction;
  • release notes for the upcoming 2.4.9.2 release.

@romainsacchi
romainsacchi merged commit e537463 into master Aug 19, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant