Brightway2 Excel数据库导入问题.write_database()ecoinvent

时间:2020-03-07 14:22:55

标签: excel brightway

首先,我对bw2和LCA总体来说还很陌生,所以请谅解。

我目前正在开发一种工具,该工具可以将生态发明活动的交流导出到Excel工作表。 在excel工作表中,我想更改金额并添加新交易或删除交易。之后,我的计划是将此Excel工作表用作LCA的数据库。

我有两个问题:

1)目前,一个具有活动的excel工作表及其交换准备好加载到jupyter笔记本中。我使用了maxkoslowski的“ Brightway2_Intro”的“ excel_importer_example”结构。在我必须使用“ .write_database()”之前,它可以正常工作。不知何故它不起作用。我收到一条错误消息,对我完全没有帮助:

*InvalidExchange                           Traceback (most recent call last)
<ipython-input-149-0d0d7c5cd566> in <module>
----> 1 imp.write_database() #hier das Problem: Database wird nicht gespeichert, obwohl Datei in Zeile drüber gefunden wird
~\Miniconda3\envs\tomaten\lib\site-packages\bw2io\importers\excel.py in write_database(self, **kwargs)
    257         """Same as base ``write_database`` method, but ``activate_parameters`` is True by default."""
    258         kwargs['activate_parameters'] = kwargs.get('activate_parameters', True)
--> 259         super(ExcelImporter, self).write_database(**kwargs)
    260 
    261     def get_activity(self, sn, ws):
~\Miniconda3\envs\tomaten\lib\site-packages\bw2io\importers\base_lci.py in write_database(self, data, delete_existing, backend, activate_parameters, **kwargs)
    238 
    239         existing.update(data)
--> 240         db.write(existing)
    241 
    242         if activate_parameters:
~\Miniconda3\envs\tomaten\lib\site-packages\wrapt\wrappers.py in __call__(self, *args, **kwargs)
    604                 return self._self_wrapper(wrapped, instance, args, kwargs)
    605 
--> 606             return self._self_wrapper(self.__wrapped__, self._self_instance,
    607                     args, kwargs)
    608 
~\Miniconda3\envs\tomaten\lib\site-packages\bw2data\project.py in writable_project(wrapped, instance, args, kwargs)
    354     if projects.read_only:
    355         raise ReadOnlyProject(READ_ONLY_PROJECT)
--> 356     return wrapped(*args, **kwargs)
~\Miniconda3\envs\tomaten\lib\site-packages\bw2data\backends\peewee\database.py in write(self, data, process)
    258         if data:
    259             try:
--> 260                 self._efficient_write_many_data(data)
    261             except:
    262                 # Purge all data from database, then reraise
~\Miniconda3\envs\tomaten\lib\site-packages\bw2data\backends\peewee\database.py in _efficient_write_many_data(self, data, indices)
    202 
    203             for index, (key, ds) in enumerate(data.items()):
--> 204                 exchanges, activities = self._efficient_write_dataset(
    205                     index, key, ds, exchanges, activities
    206                 )
~\Miniconda3\envs\tomaten\lib\site-packages\bw2data\backends\peewee\database.py in _efficient_write_dataset(self, index, key, ds, exchanges, activities)
    154         for exchange in ds.get('exchanges', []):
    155             if 'input' not in exchange or 'amount' not in exchange:
--> 156                 raise InvalidExchange
    157             if 'type' not in exchange:
    158                 raise UntypedExchange
InvalidExchange:

有人知道这个问题可能是什么吗?

2)我的计划是否有可能制定?我所读到的下一个问题是,无联系的交换似乎是一个大问题,而我的全部都是无联系的atm。

提前谢谢!

1 个答案:

答案 0 :(得分:1)

如果您有未关联的交易所,则无法导入数据库

Brightway基本上是用于进行基于矩阵的计算的框架。为了正确地构建矩阵,对于每个数据点,我们需要了解三件事:行,列和要插入的数字。

在您提供的错误的最后,您看到以下内容:

    155             if 'input' not in exchange or 'amount' not in exchange:
--> 156                 raise InvalidExchange

这不是非常有用的信息,但是您可以在此处看到input(将是行;列是output)或amount(将是数字)是失踪。正如您稍后在“我的所有事物都未链接”中所说的那样,我的猜测是input是罪魁祸首。

如果您的交易所未链接,那么我们的数据点带有数字,并且我们知道列索引,但不知道行。我们不能使用它们来构建矩阵,因此会引发错误。要解决此问题,我们需要告诉软件如何找到正确的行。

Brightway库bw2io使用“策略”进行此链接。因为我们支持多种文件格式和思维模型,所以没有单一的处理方法。 Brightway中的数据IO是一个很大的主题,但是在文档中涉及。 example notebooks中有许多关于如何链接数据的信息,importing and exporting中的文档中有一节。