我想将现有的Brightway活动的交换参数化。在example中,我发现公式是为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")
但是参数没有更新交换量。
答案 0 :(得分:0)
你很近。
我重新运行了您的代码和该行
import subprocess as sbp
with open('conf_15000.xyz','w') as fo:
p1 =sbp.Popen(['head','-n', '300000','nnp-pos-1.xyz'],stdout=sbp.PIPE)
p2 = sbp.Popen(['tail','-n', '198'],stdin=p1.stdout,stdout=fo)
p2.wait()
with open('conf_15000.xyz','r') as fp:
fp.seek(0)
flines = fp.readlines()
print flines
返回0。这意味着未添加任何参数。
但是,如果我保存先进行交换:
bw.parameters.add_exchanges_to_group("my group", ex)
返回1,然后
ng_flow.save()
bw.parameters.add_exchanges_to_group("my group", ex)
打印
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)
不会不显示。