【问题标题】:Brightway2 Excel Database Import Problem .write_database() ecoinventBrightway2 Excel 数据库导入问题 .write_database() ecoinvent
【发布时间】:2020-03-09 20:58:41
【问题描述】:

首先,总的来说,我对 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 都是未关联的。

提前谢谢你!

【问题讨论】:

    标签: excel brightway


    【解决方案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 的文档中有一个部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 2018-01-27
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      相关资源
      最近更新 更多