我构建LCI活动和交流。但是当我尝试将时态数据集加载到新的数据集中时,它将显示错误。。。我的时态数据集格式错误吗?(这是一个简短的版本,我的项目中有更多的数据集。)我对Python不是很在行,但我的专业Python朋友说,编码没有错误。希望有人能帮我解决这个问题。多谢各位
# activities and exchanges
CarbonateProduction_ionadsorp=eidb_apos.new_activity(code='Carbonate_production_ionadsorp', name="Carbonate Production from Ion Adsorption", unit="kilogram", location="CN")
# exchange 1
electricity_carbonate_ionadsorp = [act for act in eidb_apos if 'market for electricity, medium voltage' in act['name'] and 'CN-CSG' in act['location']][0]
CarbonateProduction_ionadsorp.new_exchange(name='electricity_carbonate_ionadsorp', input=electricity_carbonate_ionadsorp.key,amount=13.4,unit="kilowatt hour",type='technosphere', formula=0).save()
CarbonateProduction_ionadsorp.save()
# exchange 2
AmmoniumSulfate_carbonate_ionadsorp = [act for act in eidb_apos if 'market for ammonium sulfate' in act['name'] and 'RoW' in act['location']][0]
CarbonateProduction_ionadsorp.new_exchange(name='Ammonium sulfate_carbonate_ionadsorp',input=AmmoniumSulfate_carbonate_ionadsorp.key,amount=26.5916, unit="kilogram",type='technosphere', formula=0).save()
CarbonateProduction_ionadsorp.save()
将exchange数据集转移到临时状态
# Electricity
new_elec_carb_code='elec_carb_ionad'
new_elec_carb=copy.deepcopy(CarbonateProduction_ionadsorp.as_dict())
new_elec_carb['database']=new_db_name
new_elec_carb['code']=new_elec_carb_code
new_elec_carb['name']=new_elec_carb_code
new_elec_carb['exchanges']=[] #empty list of exchanges to add add with for loop below
new_elec_carb_key=(new_db_name,new_elec_carb['code']) #we jsut keep same code and change db for simplicity
to_replace=(new_db_name,'6b31477f9f9f9715dd6eb0d3693f15a2')
for exc in CarbonateProduction_ionadsorp.exchanges():
data = copy.deepcopy(exc._data)
data['output'] = new_elec_carb_key
# Change `input` for production exchanges
if exc['input'] == exc['output']:
data['input'] = new_elec_carb_key
new_elec_carb['exchanges'].append(data)
new_db[new_elec_carb_key]=new_elec_carb
new_elec_carb['exchanges']
# Ammonium sulfate
new_AmmoniumSulfate_carb_code='AmmoniumSulfate_carb_ionad'
new_AmmoniumSulfate_carb=copy.deepcopy(CarbonateProduction_ionadsorp.as_dict())
new_AmmoniumSulfate_carb['database']=new_db_name
new_AmmoniumSulfate_carb['code']=new_AmmoniumSulfate_carb_code
new_AmmoniumSulfate_carb['name']=new_AmmoniumSulfate_carb_code
new_AmmoniumSulfate_carb['exchanges']=[] #empty list of exchanges to add add with for loop below
new_AmmoniumSulfate_carb_key=(new_db_name,new_AmmoniumSulfate_carb['code']) #we jsut keep same code and change db for simplicity
to_replace=(new_db_name,'79734430dfbaa0742c1a32215834759e')
for exc in CarbonateProduction_ionadsorp.exchanges():
data = copy.deepcopy(exc._data)
data['output'] = new_AmmoniumSulfate_carb_key
# Change `input` for production exchanges
if exc['input'] == exc['output']:
data['input'] = new_AmmoniumSulfate_carb_key
new_AmmoniumSulfate_carb['exchanges'].append(data)
new_db[new_AmmoniumSulfate_carb_key]=new_AmmoniumSulfate_carb
new_AmmoniumSulfate_carb['exchanges']
这是我希望加载到系统上的最后一个数据集
new_db_name='Ion_adsorption_tempo'
new_db={}
code_carb='CarbonateProduction_ionadsorp_ionad'
# temporal dataset writing
data={
('Ion_adsorption_tempo', code_carb):{
'database':new_db_name,
'name':'CarbonateProduction_ionadsorp',
'code':code_carb,
'type':'process',
'exchanges':
[
# Dynamic Part
{ 'amount': 13.4,
'input': (new_db_name, new_elec_carb_code),
'name': new_elec_carb_code,
'temporal distribution':[(10, 3), (20, 5), (30, 5.4)],
'type': 'technosphere',
'unit': 'MJ'
},{
'amount': 26.5916,
'input': (new_db_name, new_AmmoniumSulfate_carb_code),
'name': new_AmmoniumSulfate_carb_code,
'temporal distribution': [(10, 8.0337),(20, 8.8371), (30, 9.7208)],
'type': 'technosphere',
'unit': 'kilogram'
}]
}
}
Tempo= bw.Database("Ion_adsorption_tempo")
Tempo.write(data)
结果总是显示“在('Ion_Absorption_tempo','elec_carb_ionad')和('Ion_Absorption_tempo','CarbonedProduction_ionadsorp_ionad')之间的交换无效-其中一个对象是未知的(即不作为流程数据集存在)。”
目前没有回答
相关问题 更多 >
编程相关推荐