bw2io.importers#

Submodules#

Classes#

CSVImporter

Generic CSV importer

CSVLCIAImporter

Generic CSV LCIA importer

EcoinventLCIAImporter

Base class for format-specific importers.

Ecospold1LCIAImporter

Ecospold2BiosphereImporter

ExcelImporter

Generic Excel importer.

ExcelLCIAImporter

Generic Excel LCIA importer.

MultiOutputEcospold1Importer

Import and process mutli-output datasets in the ecospold 1 format.

NoIntegerCodesEcospold1Importer

Import and process single-output datasets in the ecospold 1 format.

SimaProCSVImporter

SimaProLCIACSVImporter

SingleOutputEcospold1Importer

Import and process single-output datasets in the ecospold 1 format.

SingleOutputEcospold2Importer

Base class for format-specific importers.

Package Contents#

class bw2io.importers.CSVImporter(filepath)[source]#

Bases: ExcelImporter

Inheritance diagram of bw2io.importers.CSVImporter

Generic CSV importer

extractor#
format = 'CSV'#
class bw2io.importers.CSVLCIAImporter(filepath, name, description, unit, **metadata)[source]#

Bases: ExcelLCIAImporter

Inheritance diagram of bw2io.importers.CSVLCIAImporter

Generic CSV LCIA importer

extractor#
format = 'CSV'#
class bw2io.importers.EcoinventLCIAImporter[source]#

Bases: bw2io.importers.base_lcia.LCIAImporter

Inheritance diagram of bw2io.importers.EcoinventLCIAImporter

Base class for format-specific importers.

Defines workflow for applying strategies.

add_rationalize_method_names_strategy()[source]#
separate_methods()[source]#

Separate the list of CFs into distinct methods

applied_strategies = []#
strategies#
class bw2io.importers.Ecospold1LCIAImporter(filepath, biosphere=None)[source]#

Bases: bw2io.importers.base_lcia.LCIAImporter

Inheritance diagram of bw2io.importers.Ecospold1LCIAImporter
data#
format = 'Ecospold1 LCIA'#
start#
class bw2io.importers.Ecospold2BiosphereImporter(name='biosphere3', version='3.9')[source]#

Bases: bw2io.importers.base_lci.LCIImporter

Inheritance diagram of bw2io.importers.Ecospold2BiosphereImporter
extract(version)[source]#
data#
db_name#
format = 'Ecoinvent XML'#
strategies#
class bw2io.importers.ExcelImporter(filepath)[source]#

Bases: bw2io.importers.base_lci.LCIImporter

Inheritance diagram of bw2io.importers.ExcelImporter

Generic Excel importer.

See the generic Excel example spreadsheet.

Excel spreadsheet should follow the following format:

::

Project parameters <variable>, <formula>, <amount>, metadata

Database, <name of database> <database field name>, <database field value>

Parameters <variable>, <formula>, <amount>, metadata

Activity, <name of activity> <database field name>, <database field value> Exchanges <field name>, <field name>, <field name> <value>, <value>, <value> <value>, <value>, <value>

Neither project parameters, parameters, nor exchanges for each activity are required.

An activity is marked as finished with a blank line.

In general, data is imported without modification. However, the following transformations are applied:

  • Numbers are translated from text into actual numbers.

  • Tuples, separated in the cell by the :: string, are reconstructed.

  • True and False are transformed to boolean values.

  • Fields with the value (Unknown) are dropped.

get_activity(sn, ws)[source]#
get_database(data)[source]#
get_database_parameters(data)[source]#
get_labelled_section(sn, ws, index=0, transform=True)[source]#

Turn a list of rows into a list of dictionaries.

The first line of ws is the column labels. All subsequent rows are the data values. Missing columns are dropped.

transform is a boolean: perform CSV transformation functions like csv_restore_tuples.

get_metadata_section(sn, ws, index=0, transform=True)[source]#
get_project_parameters(data)[source]#

Extract project parameters (variables and formulas).

Project parameters are a section that starts with a line with the string “project parameters” (case-insensitive) in the first cell, and ends with a blank line. There can be multiple project parameter sections.

process_activities(data)[source]#

Take list of (sheet names, raw data) and process it.

write_activity_parameters(data=None, delete_existing=True)[source]#
write_database(**kwargs)[source]#

Same as base write_database method, but activate_parameters is True by default.

write_database_parameters(activate_parameters=True, delete_existing=True)[source]#

Same as base write_database_parameters method, but activate_parameters is True by default.

data#
extractor#
format = 'Excel'#
start#
strategies#
class bw2io.importers.ExcelLCIAImporter(filepath, name, description, unit, **metadata)[source]#

Bases: bw2io.importers.base_lcia.LCIAImporter

Inheritance diagram of bw2io.importers.ExcelLCIAImporter

Generic Excel LCIA importer.

See the documentation.

data#
extractor#
format = 'Excel'#
strategies#
class bw2io.importers.MultiOutputEcospold1Importer(*args, **kwargs)[source]#

Bases: SingleOutputEcospold1Importer

Inheritance diagram of bw2io.importers.MultiOutputEcospold1Importer

Import and process mutli-output datasets in the ecospold 1 format.

Works the same as the single-output importer, but first allocates multioutput datasets.

class bw2io.importers.NoIntegerCodesEcospold1Importer(*args, **kwargs)[source]#

Bases: SingleOutputEcospold1Importer

Inheritance diagram of bw2io.importers.NoIntegerCodesEcospold1Importer

Import and process single-output datasets in the ecospold 1 format.

Applies the following strategies: #. If only one exchange is a production exchange, that is the reference product #. Delete (unreliable) integer codes from extracted data #. Drop unspecified subcategories from biosphere flows #. Normalize biosphere flow categories to ecoinvent 3.1 standard #. Normalize biosphere flow names to ecoinvent 3.1 standard #. Remove locations from biosphere exchanges #. Create a code from the activity hash of the dataset #. Link biosphere exchanges to the default biosphere database #. Link internal technosphere exchanges

Parameters:
  • filepath (*) – Either a file or directory.

  • db_name (*) – Name of database to create.

class bw2io.importers.SimaProCSVImporter(filepath, name=None, delimiter=';', encoding='latin-1', normalize_biosphere=True, biosphere_db=None)[source]#

Bases: bw2io.importers.base_lci.LCIImporter

Inheritance diagram of bw2io.importers.SimaProCSVImporter
get_db_name()[source]#
match_ecoinvent2(db_name)[source]#
write_database(data=None, name=None, *args, **kwargs)[source]#
format = 'SimaPro CSV'#
start#
strategies#
class bw2io.importers.SimaProLCIACSVImporter(filepath, biosphere=None, delimiter=';', encoding='latin-1', normalize_biosphere=True)[source]#

Bases: bw2io.importers.base_lcia.LCIAImporter

Inheritance diagram of bw2io.importers.SimaProLCIACSVImporter
data#
format = 'SimaPro CSV LCIA'#
start#
class bw2io.importers.SingleOutputEcospold1Importer(filepath, db_name, use_mp=True, extractor=Ecospold1DataExtractor)[source]#

Bases: bw2io.importers.base_lci.LCIImporter

Inheritance diagram of bw2io.importers.SingleOutputEcospold1Importer

Import and process single-output datasets in the ecospold 1 format.

Applies the following strategies: #. If only one exchange is a production exchange, that is the reference product #. Delete (unreliable) integer codes from extracted data #. Drop unspecified subcategories from biosphere flows #. Normalize biosphere flow categories to ecoinvent 3.1 standard #. Normalize biosphere flow names to ecoinvent 3.1 standard #. Remove locations from biosphere exchanges #. Create a code from the activity hash of the dataset #. Link biosphere exchanges to the default biosphere database #. Link internal technosphere exchanges

Parameters:
  • filepath (*) – Either a file or directory.

  • db_name (*) – Name of database to create.

db_name#
format = 'Ecospold1'#
start#
strategies#
class bw2io.importers.SingleOutputEcospold2Importer(dirpath, db_name, extractor=Ecospold2DataExtractor, use_mp=True, signal=None, reparametrize_lognormals=False)[source]#

Bases: bw2io.importers.base_lci.LCIImporter

Inheritance diagram of bw2io.importers.SingleOutputEcospold2Importer

Base class for format-specific importers.

Defines workflow for applying strategies.

Takes a database name (string) as initialization parameter.

Initializes the SingleOutputEcospold2Importer class instance.

Parameters:
  • dirpath (str) – Path to the directory containing the ecospold2 file.

  • db_name (str) – Name of the LCI database.

  • extractor (class) – Class for extracting data from the ecospold2 file, by default Ecospold2DataExtractor.

  • use_mp (bool) – Flag to indicate whether to use multiprocessing, by default True.

  • signal (object) – Object to indicate the status of the import process, by default None.

  • reparametrize_lognormals (bool) – Flag to indicate if lognormal distributions for exchanges should be reparametrized such that the mean value of the resulting distribution meets the amount defined for the exchange.

db_name#
dirpath#
format = 'Ecospold2'#
signal#
start#
strategies#