LCA Processor¶
Time-explicit LCA data processing for optimization.
This module provides classes and utilities for performing time-explicit Life Cycle Assessment (LCA) computations using Brightway. It processes temporal distributions of product demands, constructs foreground and background inventory tensors, and prepares characterization factors for optimization.
Key Classes¶
LCAConfig: Configuration dataclass for LCA computationsLCADataProcessor: Main class for time-explicit LCA processing
Module Reference¶
Time-explicit LCA data processing for optimization.
This module provides classes and utilities for performing time-explicit Life Cycle Assessment (LCA) computations using Brightway. It processes temporal distributions of product demands, constructs foreground and background inventory tensors, and prepares characterization factors for optimization.
Key classes: - LCAConfig: Configuration for LCA computations - LCADataProcessor: Main class for time-explicit LCA processing
Classes¶
MetricEnum
¶
Bases: str, Enum
Supported metrics for dynamic impact characterization.
Attributes: GWP: Global Warming Potential - time-dependent radiative forcing metric CRF: Cumulative Radiative Forcing - integrated radiative forcing over time horizon
TemporalResolutionEnum
¶
Bases: str, Enum
Supported temporal resolutions for the optimization model.
Attributes: year: Annual time steps (currently the only supported resolution)
CharacterizationMethodConfig
¶
Bases: BaseModel
Configuration for a single LCIA characterization method.
Attributes: category_name: User-defined identifier for the impact category (e.g., 'climate_change_dynamic_gwp'). brightway_method: Brightway method identifier tuple, either 2 or 3 elements (e.g., ('GWP', 'example') or ('IPCC', 'climate change', 'GWP 100a')). metric: Impact metric used for dynamic characterization. None implies static method. Supported values: 'GWP', 'CRF'.
TemporalConfig
¶
Bases: BaseModel
Configuration related to temporal aspects of the model.
Attributes:
start_date: The start date of the time horizon.
temporal_resolution: Temporal resolution for the model.
Options: 'year', 'month', 'day'.
time_horizon: Length of the time horizon (in units of temporal_resolution).
fixed_time_horizon: If True, the time horizon is calculated from the time of the functional
unit (FU) instead of the time of emission
database_dates: Mapping from database names to their respective reference dates.
BackgroundInventoryConfig
¶
Bases: BaseModel
Configuration for background inventory data.
Attributes:
cutoff: Optional number of top elementary flows to retain per intermediate flow, ranked by absolute inventory amount. None (default) keeps all non-zero flows.
restrict_to_characterized_flows: Drop elementary flows without a characterization factor in any category.
retain_flows: Elementary flow codes to keep regardless of characterization.
calculation_method: Method for calculating the inventory tensor. Options: 'sequential', 'parallel'.
n_jobs: Number of worker processes used by the 'parallel' method.
use_disk_cache: Whether calculated inventories are cached on disk between sessions.
disk_cache_dir: Directory for the on-disk cache; defaults to a folder in the Brightway project.
path_to_save: Optional path to save the inventory tensor.
path_to_load: Optional path to load the inventory tensor.
LCAConfig
¶
Bases: BaseModel
Configuration class for Life Cycle Assessment (LCA) data processing.
Attributes: demand: Dictionary {product_node: temporal_distribution} containing time-explicit demands for each product. Keys must be Brightway product node objects (bd.get_node(...)). temporal: Temporal configuration for model time behavior. characterization_methods: List of characterization method configurations. background_inventory: Configuration for background inventory data calculation. foreground_db_name: Name of the foreground Brightway database.
LCADataProcessor(config: LCAConfig, foreground_db_name: Optional[str] = None)
¶
Class to perform time-explicit Life Cycle Assessment (LCA) computations and gather necessary data for building an optimization model.
This class is primarily responsible for executing the LCA-based computations
required to collect all the data needed for building OptimizationModelInputs. It is reliant on
Brightway2, an open-source framework for Life Cycle Assessment, to perform the
calculations and retrieve LCA results.
Initialize the LCADataProcessor with the LCA configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LCAConfig
|
The configuration object containing all settings for demand, temporal parameters, characterization methods, and background inventory. |
required |
foreground_db_name
|
str
|
The name of the foreground Brightway database. Defaults to
|
None
|
Source code in src/optimex/lca_processor.py
Attributes¶
processes: dict
property
¶
Read-only access to the processes dictionary.
intermediate_flows: dict
property
¶
Read-only access to the intermediate flows dictionary.
elementary_flows: dict
property
¶
Read-only access to the elementary flows dictionary.
reference_products: set
property
¶
Read-only access to the functional flows list.
system_time: set
property
¶
Read-only access to the system time list.
category: set
property
¶
Read-only access to the impact categories list.
process_time: set
property
¶
Read-only access to the process time list.
foreground_technosphere: dict
property
¶
Read-only access to the foreground technosphere tensor.
foreground_biosphere: dict
property
¶
Read-only access to the foreground biosphere tensor.
foreground_production: dict
property
¶
Read-only access to the foreground production tensor.
background_inventory: dict
property
¶
Read-only access to the inventory tensor.
mapping: dict
property
¶
Read-only access to the mapping matrix.
characterization: dict
property
¶
Read-only access to the characterization matrix.
demand: dict
property
¶
Read-only access to the parsed demand dictionary.
operation_flow: dict
property
¶
Read-only access to the operation flow dictionary.
operation_time_limits: dict
property
¶
Read-only access to the operation time limits dictionary.
products: dict
property
¶
Read-only access to the products dictionary.
internal_demand_technosphere: dict
property
¶
Read-only access to the internal demand technosphere tensor.
foreground_technosphere_vintages: Optional[dict]
property
¶
Read-only access to vintage-specific technosphere values.
foreground_biosphere_vintages: Optional[dict]
property
¶
Read-only access to vintage-specific biosphere values.
foreground_production_vintages: Optional[dict]
property
¶
Read-only access to vintage-specific production values.
vintage_improvements: Optional[dict]
property
¶
Read-only access to vintage improvement scaling factors.
reference_vintages: Optional[list]
property
¶
Read-only access to reference vintage years.
Methods:¶
parallel_inventory_tensor_calculation(n_jobs: Optional[int] = None) -> None
¶
Compute the background inventory tensor for all background databases in parallel, one process per database.
Each database needs its own technosphere matrix built and factorized, which is the bulk of the work and is independent between databases. Results are merged into the module-level cache of the parent process, so a rerun in the same session is served from memory.
Worker processes are spawned, so a plain script calling this must guard its
entry point with if __name__ == "__main__":. Notebooks need no guard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_jobs
|
int
|
Number of worker processes. Defaults to one per background database, capped by the CPU count. |
None
|
Side Effects
- self._background_inventory: Combined inventory tensor for all
background databases.
- self._elementary_flows: Updated dictionary of all observed elementary
flows.
Source code in src/optimex/lca_processor.py
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 | |
Functions:¶
clear_lca_caches(include_disk: bool = False, cache_dir=None) -> None
¶
Clear the module-level background inventory and metadata caches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_disk
|
bool
|
Also delete the on-disk inventory cache of the current project. |
False
|
cache_dir
|
str or Path
|
Directory of the on-disk cache, if it is not in the default location. |
None
|
Source code in src/optimex/lca_processor.py
compute_db_inventory_entries(db_name: str, intermediate_flows: dict, cutoff: Optional[float] = None, biosphere_db_name: Optional[str] = None, project: Optional[str] = None, base_dirs: Optional[Tuple[str, str]] = None) -> dict
¶
Compute aggregated background inventories for the given intermediate flows.
All flows are solved against one technosphere matrix, factorized once when
there are enough of them to amortize it. For an intermediate flow :math:j with unit demand, the
aggregated elementary flow vector is :math:g_j = B x_j, i.e. the column of
:math:B A^{-1} belonging to that flow. The per-background-process breakdown
that LCA.lci() builds (B times diag(x_j)) is never needed here and is skipped,
since only the aggregate enters the optimization.
This is a module-level function so that it can also run in a worker process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_name
|
str
|
Name of the background database to analyze. |
required |
intermediate_flows
|
dict
|
Dictionary mapping intermediate flow codes (foreground reference codes) to identity metadata dicts with keys "name", "reference product", and "location". |
required |
cutoff
|
float
|
If given, keep only the |
None
|
biosphere_db_name
|
str
|
Biosphere database to read flow codes and names from. Defaults to the project's configured biosphere database. |
None
|
project
|
str
|
Brightway project to activate first. Needed when running in a worker process, which starts without an active project. |
None
|
base_dirs
|
tuple of str
|
|
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in src/optimex/lca_processor.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |