Step 5: Generating LCIA samples

Introduction

This optional step converts the stored LCI arrays into method-specific arrays of LCIA scores.

LCIA arrays can be distinguished by:

  • number of columns:

    • one column: a deterministic results (result_type=deterministic)
    • n columns: one column per MonteCarlo iteration (use function result_type=probabilistic)
  • number of rows:

    • one row: representing the sum of characterized elementary flows (return_total=True)
    • m rows: m characterized elementary flows (return_per_exchange=True).

While functions such as calculate_lcia_array_from_activity_code can calculate LCIA arrays for specific activities, use save_all_lcia_score_arrays to generate and save LCIA arrays for all activities.

The resulting LCIA arrays are stored in a method-specific subdirectory of the result_dir directory. The name of the subdirectory is a string abbreviation of the method name (see here for more detail on method abbreviations). Totals and per reference flow are further separated in subdirectories, and finally each samples_batch has its own subdirectory.

Note

It is absolutely necessary to have access to the biosphere dictionary of the LCA object that was used to generate the samples, the ref_bio_dict. It is stored in the common_files directory.

Technical reference

Top level functions

save_all_lcia_score_arrays

bw2preagg.lcia.save_all_lcia_score_arrays(result_dir, method, result_type='probabilistic', samples_batch=0, dtype=<class 'numpy.float32'>, return_total=True, return_per_exchange=True, ignore_missing=True, project_name=None)

Calculate and save LCIA score arrays for given set of LCI arrays and method

Parameters:
  • result_dir (str) – Path to directory where results are stored
  • method (tuple) – LCIA method identification in brightway2 (tuple)
  • result_type (str, default='probabilistic') – Specify whether probabilistic or deterministic results should be generated
  • 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.
  • dtype (str or dtype) – dtype to which the resulting LCIA array must be converted
  • return_total (bool, default=True) – If True, LCIA array with total scores across elementary flows are saved
  • return_per_exchange (bool, default=None) – If True, LCIA array with scores per elementary flows are saved
  • ignore_missing (bool, default=True) – If True, will calculate LCIA score arrays for all files in the corresponding LCI folder. If False, the calculation of LCIA score arrays will only proceed if all expected LCI arrays are found in the LCI array.
  • project_name (str) – Name of the brightway2 project where the database is imported
Returns:

Return type:

None

calculate_lcia_array_from_activity_code

bw2preagg.lcia.calculate_lcia_array_from_activity_code(result_dir, act_code, method, samples_batch=0, dtype=<class 'numpy.float32'>, return_total=True, project_name=False)

Retrieves LCI array and calculates LCIA array for a given method

Parameters:
  • result_dir (str) – Path to directory where results are stored
  • act_code (str) – Code of the activity
  • method (tuple) – LCIA method identification in brightway2 (tuple)
  • 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.
  • dtype (dtype or string, default=np.float32) – dtype the result should be converted to.
  • return_total (bool, default=True) – If True, the function returns an array of total scores If False, the function returns an array of characterized elementary flows
  • project_name (str) – Name of the brightway2 project where the database is imported

Helper functions

get_cf_with_indices

bw2preagg.lcia.get_cf_with_indices(method, ref_bio_dict, project_name)

Extract row indices of biosphere matrix and associated cfs for given method

A reference biosphere dictionary, associated with a given LCA object, must be supplied to ensure that the biosphere row indices are correct.

Parameters:
  • method (tuple) – Identification of the LCIA method, using Brightway2 tuple identifiers
  • ref_bio_dict (dict) – Dictionary mapping elementary flow keys to matrix rows
  • project_name (str) – Name of the brightway2 project where the database is imported
Returns:

  • B_row_indices (list of int) – List of biosphere matrix row indices
  • cfs (list of float) – List of associated characterization factors

calculate_lcia_array_from_arrays

bw2preagg.lcia.calculate_lcia_array_from_arrays(LCI_array, B_row_indices, cfs, dtype=<class 'numpy.float32'>, return_total=True)

Calculation of LCIA from array LCI array, B row indices and cfs

Used by other functions to carry out actual calculations.

Parameters:
  • LCI_array (numpy array) – Life cycle inventory array, with rows equal to elementary flows and columns equal to separate LCI, e.g. from different MonteCarlo iterations
  • B_row_indices (list of int) – List of biosphere matrix row indices
  • cfs (list of float) – List of associated characterization factors
  • dtype (str or dtype) – dtype to which the resulting LCIA array must be converted
  • return_total (bool, default=True) – If True, sum LCIA array rows, returning total scores If False, returns an LCIA array with the same dimension as the LCI array
Returns:

lcia_array – Array of LCIA scores

Return type:

numpy.ndarray