Store scenario metadata on exported Brightway databases - #303
Merged
Conversation
* Store scenario metadata on exported Brightway databases
Databases written to Brightway only encoded the IAM model, pathway and
year in their name. Attach them to the Brightway database metadata
instead, together with an ISO 8601 `representative_time` timestamp of the
point in time the database represents, the ecoinvent version, the system
model and the premise version.
Superstructure and scenario-array databases list their scenarios under
`scenarios`, and only carry `year`/`representative_time` at the top level
when all their scenarios share the same year.
* Address review: drop redundant year, expand docs example
- `year` is dropped from the metadata: it is already carried by the ISO
8601 `representative_time` timestamp.
- The changelog entry moves under `[Unreleased]`.
- The docs example shows the fields brightway writes itself next to the
ones premise adds, and notes that `bd.databases["db_name"]` and
`bd.Database("db_name").metadata` are the same mapping.
- The `metadata` argument docstrings are removed from both writers.
romainsacchi
approved these changes
Aug 21, 2026
Collaborator
|
Very nice, thanks @TimoDiepers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Writing new databases did not save any metadata on what the databases represent. This PR attaches information on the used scenario, years, etc. to the Brightway database metadata, next to the fields brightway maintains itself:
{ # written by brightway "format": "Ecoinvent XML", "depends": ["ecoinvent-3.10.1-biosphere"], "backend": "sqlite", "number": 43648, "modified": "2026-08-14T12:09:25.945746", "processed": "2026-08-14T12:09:56.124243", "geocollections": ["world"], "searchable": True, # written by premise "premise_version": "2.4.9.1", "iam_model": "remind", "pathway": "SSP2-PkBudg500", "representative_time": "2050-01-01T00:00:00", "ecoinvent_version": "3.10.1", "system_model": "cutoff", }bd.databases["db_name"]andbd.Database("db_name").metadataare the same mapping, so the fields can be read either way.User (external) scenarios, if any, are listed under
external_scenarios. Superstructure and scenario-array databases list their scenarios underscenarios, and only carryrepresentative_timeat the top level when all their scenarios share the same year.How
scenario_metadata()anddatabase_metadata()inpremise/utils.py.write_brightway_database()in bothpremise/brightway2.pyandpremise/brightway25.pytakes an optionalmetadataargument, applied after the database is registered (fast and regular write paths).NewDatabase.write_db_to_brightway,write_superstructure_db_to_brightwayandwrite_scenario_array_db_to_brightwaypass the metadata of the scenario(s) they write.Tests
New
tests/test_database_metadata.py; existing writer test doubles updated for the new keyword argument.