bw2io.importers.base#
Classes#
Base class for format-specific importers. |
Module Contents#
- 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.
- _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_name (str) – The name of the migration function to apply to the importer’s datasets.
- Returns:
Modifies the importer’s data in place.
- Return type:
None
- 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_name (str) – The name of the migration function to apply to the importer’s exchanges.
- Returns:
Modifies the importer’s data in place.
- Return type:
None
- 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:
strategies (list, optional) – List of strategies to apply. Defaults to self.strategies.
verbose (bool, optional) – If True, print a message indicating which strategy is being applied. Defaults to True.
- Returns:
Modifies the importer’s data in place.
- Return type:
None
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:
strategy (callable) – The strategy function to apply to the importer’s data.
verbose (bool, optional) – If True, print a message indicating which strategy is being applied. Defaults to True.
- Returns:
Modifies the importer’s data in place.
- Return type:
None
- 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:
name (str) – The name of the UnlinkedData data store to be written.