bw2io.extractors.simapro_csv
#
Module Contents#
Classes#
Extract datasets from SimaPro CSV export files. |
Functions#
|
Replace all occurrences of elements of |
|
Convert a string to a number. |
Attributes#
- exception bw2io.extractors.simapro_csv.EndOfDatasets[source]#
Bases:
Exception
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 parse_biosphere_flow(line, category, pm)[source]#
Parse biosphere flow line.
name
subcategory
unit
value or formula
uncertainty type
uncert. param.
uncert. param.
uncert. param.
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.
name
formula
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.
name
unit
value or formula
uncertainty type
uncert. param.
uncert. param.
uncert. param.
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.
name
value (not formula)
uncertainty type
uncert. param.
uncert. param.
uncert. param.
hidden (“Yes” or “No” - we ignore)
comment
- classmethod parse_reference_product(line, pm)[source]#
Parse reference product line.
name
unit
value or formula
allocation
waste type
category (separated by )
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.
- bw2io.extractors.simapro_csv.replace_with_uppercase(string, names, precompiled)[source]#
Replace all occurrences of elements of
names
instring
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