首页 > 解决方案 > 如何使用 Brightway 参数化现有的交换

问题描述

我想参数化现有的 Brightway 活动的交换。在示例中,我发现公式是为 new_exchange 定义的,我们可以对现有的进行吗?

一个实际的例子可能是将燃料消耗重新定义为更高热值和效率的函数。

ex=[act for act in bw.Database('ei_34con') if 'natural gas' in act['name']
                                  and 'condensing' in act['name']
                                  and 'CH' in act['location']][0].copy()

ng_flow=[f for f in ex.technosphere() if ('natural gas' in f['name'])][0]


act_data=[{'name':'eff',
       'database':ex['database'],
       'code':ex['code'],
       'amount':0.95,
       'unit':''},
       {'name':'HHV',
       'database':ex['database'],
       'code':ex['code'],
       'amount':37,
       'unit':'MJ/m3'}]

bw.parameters.new_activity_parameters(act_data, "my group")

我天真地尝试过

ng_flow['formula']='1/eff/HHV'

bw.parameters.add_exchanges_to_group("my group", ex)
ActivityParameter.recalculate_exchanges("my group")

但参数并没有更新交换量。

标签: brightway

解决方案


你非常接近。

我重新运行了您的代码和行

bw.parameters.add_exchanges_to_group("my group", ex)

返回 0。这意味着没有添加任何参数。

但是,如果我先保存交换:

 ng_flow.save()
 bw.parameters.add_exchanges_to_group("my group", ex)

返回 1,并且

for exc in ex.technosphere():
    if "natural gas" in exc['name']:
        print(exc.amount, exc.input, exc.output)

印刷

0.028449502133712657 'market for natural gas, low pressure' (cubic meter, CH, None) 'heat production, natural gas, at boiler condensing modulating <100kW' (megajoule, CH, None)

请注意,ng_flow.as_dict()显示更新的值。


推荐阅读