REGISTER NOW: DdS Autumn School! 🇨🇭 Grosshöchstetten (Switzerland) 🗓️ 6.-11. October 2024

bw2io.importers.base#

Module Contents#

Classes#

ImportBase

Base class for format-specific importers.

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

Bases: object

Base class for format-specific importers. Defines workflow for applying strategies.

Initialize the ImportBase object.

Parameters#

*args :

Variable length argument list.

**kwargs :

Arbitrary keyword arguments.

Raises#

NotImplemented :

This class should be subclassed.

property unlinked[source]#

Iterate through unique unlinked exchanges.

Uniqueness is determined by activity_hash.

Yields#
exc :

The unlinked exchange that is currently being iterated over.

_migrate_datasets(migration_name)[source]#

Apply a migration function to the importer’s datasets.

This method applies a given migration function to the importer’s datasets, using migrate_datasets. The migration function must be specified by name in the migrations dictionary.

Parameters#
migration_namestr

The name of the migration function to apply to the importer’s datasets.

Returns#
None

Modifies the importer’s data in place.

Raises#
AssertionError

If the specified migration function is not in the migrations dictionary.

_migrate_exchanges(migration_name)[source]#

Apply a migration function to the importer’s exchanges.

This method applies a given migration function to the importer’s exchanges, using migrate_exchanges. The migration function must be specified by name in the migrations dictionary.

Parameters#
migration_namestr

The name of the migration function to apply to the importer’s exchanges.

Returns#
None

Modifies the importer’s data in place.

Raises#
AssertionError

If the specified migration function is not in the migrations dictionary.

apply_strategies(strategies=None, verbose=True)[source]#

Apply a list of strategies to the importer’s data.

This method applies a list of given strategies to the importer’s data and logs the applied strategies’ names to self.applied_strategies. If no list of strategies is provided, it uses self.strategies.

Parameters#
strategieslist, optional

List of strategies to apply. Defaults to self.strategies.

verbosebool, optional

If True, print a message indicating which strategy is being applied. Defaults to True.

Returns#
None

Modifies the importer’s data in place.

Notes#

The method apply_strategy is called to apply each individual strategy to the importer’s data. Strategies that partially modify data before raising a StrategyError should be avoided.

apply_strategy(strategy, verbose=True)[source]#

Apply the specified strategy transform to the importer’s data.

This method applies a given strategy to the importer’s data and logs the applied strategy’s name to self.applied_strategies. If the strategy raises a StrategyError, the error message is printed but not raised.

Parameters#
strategycallable

The strategy function to apply to the importer’s data.

verbosebool, optional

If True, print a message indicating which strategy is being applied. Defaults to True.

Returns#
None

Modifies the importer’s data in place.

Raises#
None

If the strategy raises a StrategyError, the error message is printed but not raised.

Notes#

Strategies should not partially modify data before raising a StrategyError.

write_unlinked(name)[source]#

Write all data to an UnlinkedData data store.

This method writes all of the importer’s data to an UnlinkedData data store with the specified name. The UnlinkedData object is created with the importer’s class name appended to the name. The applied strategies are logged to the unlinked_data dictionary.

Parameters#
namestr

The name of the UnlinkedData data store to be written.