You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法计算生物圈流影响:Brightway2 OutsideTechnosphere错误求助

手动计算清单交换项贡献时触发OutsideTechnosphere错误

我正在对某产品的交换项做贡献分析,已将Excel格式的清单数据库导入Activity Browser,使用自定义代码计算各流的贡献值。没有使用bw2analyzer.contribution类函数,因为它会展示供应链下游流程,而我只需要计算导入数据库清单内交换项的贡献。

目标清单截图:
目标清单截图

使用的代码如下:

contributions_for_activity = {'Activity': act['name']}
print(f"\nContribution Analysis for activity: {act['name']}")

for method in selected_impact_methods:
    method_contributions = {}
    
    # Perform LCA for each activity with the chosen impact method
    lca = bw.LCA({act: 1}, method)
    lca.lci()
    lca.lcia()
    
    total_impact_score = lca.score
    print(f"Total impact score for {act['name']} using {method}: {total_impact_score}")


    for exc in act.exchanges():
        lca.redo_lcia({exc.input: exc['amount']})
        contribution_value = lca.score
        method_contributions[exc.input['name']] = contribution_value
        print(f" - {exc.input['name']}: {contribution_value}")

    contributions_for_activity[str(method)] = method_contributions

contributions.append(contributions_for_activity)

运行代码后出现以下错误:

KeyError                                  Traceback (most recent call last)
File ~\miniconda3\envs\LCALab2023\lib\site-packages\bw2calc\lca.py:143, in LCA.build_demand_array(self, demand)
    142 try:
--> 143     self.demand_array[self.product_dict[key]] = demand[key]
    144 except KeyError:

KeyError: 'Carbon dioxide, non-fossil' (kilogram, None, ('air',))

During handling of the above exception, another exception occurred:

OutsideTechnosphere                       Traceback (most recent call last)
Cell In[41], line 22
     18 print(f"Total impact score for {act['name']} using {method}: {total_impact_score}")
     21 for exc in act.exchanges():
---> 22     lca.redo_lcia({exc.input: exc['amount']})
     23     contribution_value = lca.score
     24     method_contributions[exc.input['name']] = contribution_value

File ~\miniconda3\envs\LCALab2023\lib\site-packages\bw2calc\lca.py:529, in LCA.redo_lcia(self, demand)
    527 assert hasattr(self, "characterized_inventory"), "Must do LCIA first"
    528 if demand is not None:
--> 529     self.redo_lci(demand)
    530     self.demand = demand
    531 self.lcia_calculation()

File ~\miniconda3\envs\LCALab2023\lib\site-packages\bw2calc\lca.py:513, in LCA.redo_lci(self, demand)
    511 assert hasattr(self, "inventory"), "Must do lci first"
    512 if demand is not None:
--> 513     self.build_demand_array(demand)
    514     self.demand = demand
    515 self.lci_calculation()

File ~\miniconda3\envs\LCALab2023\lib\site-packages\bw2calc\lca.py:151, in LCA.build_demand_array(self, demand)
    146     raise ValueError((u"LCA can only be performed on products,"
    147         u" not activities ({} is the wrong dimension)"
    148         ).format(key)
    149     )
    150 else:
--> 151     raise OutsideTechnosphere("Can't find key {} in product dictionary".format(key))

OutsideTechnosphere: Can't find key 'Carbon dioxide, non-fossil' (kilogram, None, ('air',)) in product dictionary

恳请相关帮助或指导。

内容的提问来源于stack exchange,提问作者Nizaanth Raja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 20:13:09