bw2io.importers.base_lci#

Module Contents#

Classes#

LCIImporter

Base class for format-specific importers.

class bw2io.importers.base_lci.LCIImporter(db_name)[source]#

Bases: bw2io.importers.base.ImportBase

Inheritance diagram of bw2io.importers.base_lci.LCIImporter

Base class for format-specific importers.

Defines workflow for applying strategies.

Takes a database name (string) as initialization parameter.

property all_linked[source]#
database_parameters[source]#
format = 'Generic LCIImporter'[source]#
metadata[source]#
project_parameters[source]#
_prepare_activity_parameters(data=None, delete_existing=True)[source]#
_write_activity_parameters(activity_parameters)[source]#
add_unlinked_activities()[source]#

Add technosphere flows to self.data.

add_unlinked_flows_to_biosphere_database(biosphere_name=None)[source]#
create_new_biosphere(biosphere_name, relink=True)[source]#

Create new biosphere database from biosphere flows in self.data.

Links all biosphere flows to new bio database if relink.

drop_unlinked(i_am_reckless=False)[source]#
match_database(db_name=None, fields=None, ignore_categories=False, relink=False, kind=None)[source]#

Match current database against itself or another database.

If db_name is None, match against current data. Otherwise, db_name should be the name of an existing Database.

fields is a list of fields to use for matching. Field values are case-insensitive, but otherwise must match exactly for a link to be valid. If fields is None, use the default fields of ‘name’, ‘categories’, ‘unit’, ‘reference product’, and ‘location’.

If ignore_categories, link based only on name, unit and location. ignore_categories conflicts with fields.

If relink, relink exchanges even if a link is already present.

kind can be a string or a list of strings. Common values are “technosphere”, “biosphere”, “production”, and “substitution”.

Nothing is returned, but self.data is changed.

migrate(migration_name)[source]#
statistics(print_stats=True)[source]#
write_database(data=None, delete_existing=True, backend=None, activate_parameters=False, db_name=None, searchable=True, **kwargs)[source]#

Write data to a Database.

All arguments are optional, and are normally not specified.

delete_existing effects both the existing database (it will be emptied prior to writing if True, which is the default), and, if activate_parameters is True, existing database and activity parameters. Database parameters will only be deleted if the import data specifies a new set of database parameters (i.e. database_parameters is not None) - the same is true for activity parameters. If you need finer-grained control, please use the DatabaseParameter, etc. objects directly.

Args:
  • data (dict, optional): The data to write to the Database. Default is self.data.

  • delete_existing (bool, default True): See above.

  • activate_parameters (bool, default False). Instead of storing parameters in Activity and other proxy objects, create ActivityParameter and other parameter objects, and evaluate all variables and formulas.

  • backend (string, optional): Storage backend to use when creating Database. Default is the default backend.

Returns:

Database instance.

write_database_parameters(activate_parameters=False, delete_existing=True)[source]#
write_excel(only_unlinked=False, only_names=False)[source]#

Write database information to a spreadsheet.

If only_unlinked, then only write unlinked exchanges.

If only_names, then write only activity names, no exchange data.

Returns the filepath to the spreadsheet file.

write_project_parameters(data=None, delete_existing=True)[source]#

Write global parameters to ProjectParameter database table.

delete_existing controls whether new parameters will delete_existing existing parameters, or just update values. The name field is used to determine if a parameter exists.

data should be a list of dictionaries (self.project_parameters is used by default):

[{
    'name': name of variable (unique),
    'amount': numeric value of variable (optional),
    'formula': formula in Python as string (optional),
    optional keys like uncertainty, etc. (no limitations)
}]