Step 3: Generating balancing presamples

Introduction

Randomly sampling exchange values will usually break the intended balance across balances in a given activity (e.g. the ratio of water in to water out for a given activity will be very different across Monte Carlo iterations). This optional step generates balanced water and land transformation exchanges for a given LCI database, and stores each in a dedicated presamples package. The only function that the user needs for this step is generate_balancing_presamples, which is imported in the namespace with from bw2preagg import *.

Warning

The calculation of these balanced exchanges takes a long time (on the order of a few hours). However, it is only done once - this is the advantage of bw2preagg.

The presamples packages are also stored in the presamples subdirectory of the result_dir directory, and a corresponding presamples resource is added to a campaign with the same samples_batch id.

Balancing presamples are typically used to replace values in base presamples with the corresponding samples_batch id during LCI calculations.

For more information on the balancing itself, consult the dedicated water exchange and land transformation exchange balancing packages.

Technical reference

bw2preagg.balancing_presamples.generate_balancing_presamples(project_name, database_name, result_dir, iterations, samples_batch, overwrite_ps=True, balance_water=True, balance_land=True, ecoinvent_version='3.6', land_from_patterns=['Transformation, from'], land_to_patterns=['Transformation, to'], expect_base_presamples=True)

Generate balancing presamples for a given db

These can be sampled for water exchanges and/or land transformation exchanges. The presamples are stored in a presamples resource in result_dir and added to a presamples campaign for easy reuse. It is recommended that presamples are generated in batches (e.g. of 1000 iterations each). This is implemented via the samples_batch argument.

Parameters:
  • project_name (str) – Name of the brightway2 project where the database is imported
  • database_name (str) – Name of the LCI database
  • result_dir (str) – Path to directory where results are stored
  • iterations (int) – Number of iterations to include in sample
  • samples_batch (int, default=0) – Integer id for sample batch. Used for campaigns names and for generating a seed for the RNG. The maximum value is 14.
  • overwrite_ps (bool, default=True) – Overwrite presamples package if it exists
  • balance_water (bool, default=True) – Balance water exchanges
  • balance_land (bool, default=True) – Balance land transformation exchanges
  • ecoinvent_version (str, default="3.6") – Release number of ecoinvent database
  • land_from_patterns (list of string, default=['Transformation, from']) – Patterns used to identify land transformation inputs
  • land_to_patterns (list of string, default=['Transformation, to']) – Patterns used to identify land transformation outputs
  • expect_base_presamples (bool, default=True) – If True, ValueError is raised if base presamples package for corresponding samples_batch is missing
Returns:

Return type:

None