bw2io.extractors.simapro_csv#

Module Contents#

Classes#

SimaProCSVExtractor

Extract datasets from SimaPro CSV export files.

Functions#

replace_with_uppercase(string, names, precompiled)

Replace all occurrences of elements of names in string with their uppercase equivalents.

to_number(obj)

Convert a string to a number.

Attributes#

INTRODUCTION

SIMAPRO_END_OF_DATASETS

SIMAPRO_PRODUCTS

SIMAPRO_TECHNOSPHERE

strip_whitespace_and_delete

uppercase_expression

exception bw2io.extractors.simapro_csv.EndOfDatasets[source]#

Bases: Exception

Inheritance diagram of bw2io.extractors.simapro_csv.EndOfDatasets

Raises exception when there are no more datasets to iterate.

Initialize self. See help(type(self)) for accurate signature.

class bw2io.extractors.simapro_csv.SimaProCSVExtractor[source]#

Bases: object

Extract datasets from SimaPro CSV export files.

The CSV file should be in a specific format, with row 1 containing either the string “SimaPro” or “CSV separator.”

Parameters
  • filepath (str) – The path to the SimaPro CSV export file.

  • delimiter (str, optional) – The delimiter in the CSV file. Default is “;”.

  • name (str, optional) – The name of the project. If the name is not provided, it is extracted from the CSV file.

  • encoding (str, optional) – The character encoding in the SimaPro CSV file. Defaults to “cp1252”.

Returns

  • datasets (list) – The list of extracted datasets from the CSV file.

  • global_parameters (dict) – The dictionary of global parameters for the CSV file.

  • project_metadata (dict) – The dictionary of project metadata.

Raises

AssertionError: – If the CSV file is not a valid Simapro export file.

classmethod create_distribution(amount, kind, field1, field2, field3)[source]#
classmethod extract(filepath, delimiter=';', name=None, encoding='cp1252')[source]#
classmethod get_global_parameters(data, pm)[source]#
classmethod get_next_process_index(data, index)[source]#
classmethod get_project_metadata(data)[source]#
classmethod get_project_name(data)[source]#
classmethod invalid_uncertainty_data(amount, kind, field1, field2, field3)[source]#
classmethod parse_biosphere_flow(line, category, pm)[source]#

Parse biosphere flow line.

  1. name

  2. subcategory

  3. unit

  4. value or formula

  5. uncertainty type

  6. uncert. param.

  7. uncert. param.

  8. uncert. param.

  9. comment

However, sometimes the value is in index 2, and the unit in index 3. Because why not! We assume default ordering unless we find a number in index 2.

classmethod parse_calculated_parameter(line, pm)[source]#

Parse line in Calculated parameters section.

  1. name

  2. formula

  3. comment

Can include multiline comment in TSV.

classmethod parse_final_waste_flow(line, pm)[source]#

Parse final wate flow line.

0: name 1: subcategory? 2: unit 3. value or formula 4. uncertainty type 5. uncert. param. 6. uncert. param. 7. uncert. param.

However, sometimes the value is in index 2, and the unit in index 3. Because why not! We assume default ordering unless we find a number in index 2.

classmethod parse_input_line(line, category, pm)[source]#

Parse technosphere input line.

  1. name

  2. unit

  3. value or formula

  4. uncertainty type

  5. uncert. param.

  6. uncert. param.

  7. uncert. param.

  8. comment

However, sometimes the value is in index 1, and the unit in index 2. Because why not! We assume default ordering unless we find a number in index 1.

classmethod parse_input_parameter(line)[source]#

Parse line in Input parameters section.

  1. name

  2. value (not formula)

  3. uncertainty type

  4. uncert. param.

  5. uncert. param.

  6. uncert. param.

  7. hidden (“Yes” or “No” - we ignore)

  8. comment

classmethod parse_reference_product(line, pm)[source]#

Parse reference product line.

  1. name

  2. unit

  3. value or formula

  4. allocation

  5. waste type

  6. category (separated by )

  7. comment

However, sometimes the value is in index 1, and the unit in index 2. Because why not! We assume default ordering unless we find a number in index 1.

classmethod parse_waste_treatment(line, pm)[source]#

Parse reference product line.

  1. name

  2. unit

  3. value or formula

  4. waste type

  5. category (separated by )

  6. comment

classmethod read_data_set(data, index, db_name, filepath, gp, pm, global_precompiled)[source]#
classmethod read_dataset_metadata(data, index)[source]#
bw2io.extractors.simapro_csv.replace_with_uppercase(string, names, precompiled)[source]#

Replace all occurrences of elements of names in string with their uppercase equivalents.

Parameters
  • string (str) – String to be modified.

  • names (list) – List of variable name strings that should already all be uppercase.

  • precompiled (dict) – Dictionary #TODO.

Return type

The modified string.

bw2io.extractors.simapro_csv.to_number(obj)[source]#

Convert a string to a number.

Parameters

obj (str) – The string to be converted to a number

Returns

converted number as float, or the unchanged string if not successfully converted.

Return type

float or str

bw2io.extractors.simapro_csv.INTRODUCTION = Multiline-String[source]#
Show Value
"""Starting SimaPro import:
        Filepath: %s
        Delimiter: %s
        Name: %s
"""
bw2io.extractors.simapro_csv.SIMAPRO_END_OF_DATASETS[source]#
bw2io.extractors.simapro_csv.SIMAPRO_PRODUCTS[source]#
bw2io.extractors.simapro_csv.SIMAPRO_TECHNOSPHERE[source]#
bw2io.extractors.simapro_csv.strip_whitespace_and_delete[source]#
bw2io.extractors.simapro_csv.uppercase_expression = '(?:^|[^a-zA-Z_])(?P<variable>{})(?:[^a-zA-Z_]|$)'[source]#