brightway - 导入方法 EF 3.0 - 结果有问题
问题描述
我编写了一个脚本来导入 Brightway 上的 LCIA 方法 EF 3.0(已改编)的表征因素。我认为它工作正常,因为我在活动浏览器上看到了正确的特征因素(例如气候变化方法:但是当我使用该方法运行计算时,结果与 Simapro 上的不同(我得到了 CSV 导入文件) from) :例如,气候变化方法的结果为 0。你知道可能是什么问题吗?单位似乎不同,但 Brightway 上可用的其他方法是相同的。
此外,我在另一个问题上看到将实施一种方法来导入 EF 3.0 方法,它是否可用?非常感谢您的帮助。
导入脚本的代码:
import brightway2 as bw
import csv
import uuid
from bw2data import mapping
from bw2data.utils import recursive_str_to_unicode
class import_method_EF:
'''Class for importing the EF method from Simapro export CSV file to Brightway. '''
def __init__(
self,
project_name,
name_file,
):
self.project_name = project_name
self.name_file = name_file
self.db_biosphere = bw.Database('biosphere3')
#Definition of the dictionnary for the correspondance between the Simapro and the ecoinvent categories
self.dict_categories = {'high. pop.' : 'urban air close to ground',
'low. pop.' : 'low population density, long-term',
'river' : 'surface water',
'in water' : 'in water',
'(unspecified)' : '',
'ocean' : 'ocean',
'indoor' : 'indoor',
'stratosphere + troposphere' : 'lower stratosphere + upper troposphere',
'low. pop., long-term' : 'low population density, long-term',
'groundwater, long-term' : 'ground-, long-term',
'agricultural' : 'agricultural',
'industrial' : 'industrial',
}
#Definition of the dictionnary of the ecoinvent units abreviations
self.dict_units = {'kg' : 'kilogram',
'kWh' : 'kilowatt hour',
'MJ' : 'megajoule',
'p':'p',
'unit':'unit',
'km':'kilometer',
'my' : 'meter-year',
'tkm' : 'ton kilometer',
'm3' : 'cubic meter',
'm2' :'square meter',
'kBq' : 'kilo Becquerel',
'm2a' : 'm2a', #à modifier
}
def importation(self) :
"""
Makes the importation from the Simapro CSV file to Brightway.
"""
#Set the current project
bw.projects.set_current(self.project_name)
self.data = self.open_CSV(self.name_file, [])
list_methods = []
new_flows = []
for i in range(len(self.data)) :
#print(self.data[i])
if self.data[i] == ['Name'] :
name_method = self.data[i+1][0]
if self.data[i] == ['Impact category'] :
list_flows = []
j = 4
while len(self.data[i+j])>1 :
biosphere_code = self.get_biosphere_code(self.data[i+j][2],self.data[i+j][1],self.data[i+j][0].lower())
if biosphere_code == 0 :
if self.find_if_already_new_flow(i+j, new_flows)[0] :
code = self.find_if_already_new_flow(i+j, new_flows)[1]
list_flows.append((('biosphere3', code),float(self.data[i+j][4].replace(',','.'))))
else :
code = str(uuid.uuid4())
while (self.db_biosphere.name, code) in mapping:
code = str(uuid.uuid4())
new_flows.append({'amount' : float(self.data[i+j][4].replace(',','.')),
'CAS number' : self.data[i+j][3],
'categories' : (self.data[i+j][0].lower(), self.dict_categories[self.data[i+j][1]]),
'name' : self.data[i+j][2],
'unit' : self.dict_units[self.data[i+j][5]],
'type' : 'biosphere',
'code' : code})
list_flows.append((('biosphere3', code),float(self.data[i+j][4].replace(',','.'))))
else :
list_flows.append((('biosphere3', biosphere_code),float(self.data[i+j][4].replace(',','.'))))
j+=1
list_methods.append({'name' : self.data[i+1][0],
'unit' : self.data[i+1][1],
'flows' : list_flows})
new_flows = recursive_str_to_unicode(dict([self._format_flow(flow) for flow in new_flows]))
if new_flows :
print('new flows :',len(new_flows))
self.new_flows = new_flows
biosphere = bw.Database(self.db_biosphere.name)
biosphere_data = biosphere.load()
biosphere_data.update(new_flows)
biosphere.write(biosphere_data)
print('biosphere_data :',len(biosphere_data))
for i in range(len(list_methods)) :
method = bw.Method((name_method,list_methods[i]['name']))
method.register(**{'unit':list_methods[i]['unit'],
'description':''})
method.write(list_methods[i]['flows'])
print(method.metadata)
method.load()
def open_CSV(self, CSV_file_name, list_rows):
'''
Opens a CSV file and gets a list of the rows.
: param : CSV_file_name = str, name of the CSV file (must be in the working directory)
: param : list_rows = list, list to get the rows
: return : list_rows = list, list of the rows
'''
#Open the CSV file and read it
with open(CSV_file_name, 'rt') as csvfile:
data = csv.reader(csvfile, delimiter = ';')
#Write every row in the list
for row in data:
list_rows.append(row)
return list_rows
def get_biosphere_code(self, simapro_name, simapro_cat, type_biosphere):
"""
Gets the Brightway code of a biosphere process given in a Simapro format.
: param : simapro_name = str, name of the biosphere process in a Simapro format.
: param : simapro_cat = str, category of the biosphere process (ex : high. pop., river, etc)
: param : type_biosphere = str, type of the biosphere process (ex : Emissions to water, etc)
: return : 0 if the process is not found in biosphere, the code otherwise
"""
if 'GLO' in simapro_name or 'RER' in simapro_name :
simapro_name = simapro_name[:-5]
if '/m3' in simapro_name :
simapro_name = simapro_name[:-3]
#Search in the biosphere database, depending on the category
if simapro_cat == '' :
act_biosphere = self.db_biosphere.search(simapro_name, filter={'categories' : (type_biosphere,)})
else :
act_biosphere = self.db_biosphere.search(simapro_name, filter={'categories' : (type_biosphere, self.dict_categories[simapro_cat])})
#Pourquoi j'ai fait ça ? ...
for act in act_biosphere :
if simapro_cat == '' :
if act['categories'] == (type_biosphere, ):
return act['code']
else :
if act['categories'] == (type_biosphere, self.dict_categories[simapro_cat]):
return act['code']
return 0
def _format_flow(self, cf):
# TODO
return (self.db_biosphere.name, cf['code']), {
'exchanges': [],
'categories': cf['categories'],
'name': cf['name'],
'type': ("resource" if cf["categories"][0] == "resource"
else "emission"),
'unit': cf['unit'],
}
def find_if_already_new_flow(self, n, new_flows) :
"""
"""
for k in range(len(new_flows)) :
if new_flows[k]['name'] == self.data[n][2] :
return True, new_flows[k]['code']
return False, 0
编辑:我对 get_biosphere_code 方法进行了修改,效果更好(它没有找到一些生物圈流),但我在 Brightway 上获得的结果与在 Simapro 上获得的结果之间仍然存在重要差异。我的调查使我得出以下观察结果:
- ecoinvent 活动存在一些差异,特别是在生物圈流量列表中(应该是结果差异的汇),Brightway 和用于导入的 ecoSpold 数据中缺少一些与 Simapro 中的数据相比
- 似乎 LCA 计算与子类别的工作方式不同:例如,生物圈流量二氧化碳、化石(空气)在气候变化方法的特征化因素列表中,并且在查看清单时在 Simapro LCA 结果中,似乎所有二氧化碳、化石流到空气中都参与了气候变化影响,无论它们的子类别是什么。但是 Brightway 不是这样工作的,它只考虑完全相同的流量,因此会导致结果的重要差异。
解决方案
在 LCA 中,没有就基本流量和典型排放情景/背景达成一致(https://doi.org/10.1007/s11367-017-1354-3),影响评估方法的实施也不同(https://www.lifecycleinitiative .org/portfolio_category/lcia/)。
相同的活动和相同的影响评估方法在不同的软件中返回不同的结果并不罕见。有一些改进当前实践的尝试(参见例如,https ://github.com/USEPA/LCIAformatter )。
推荐阅读
- php - Symfony 3.4 资产:通过 SSH 安装失败
- javascript - Angular:仅在授权的情况下从服务器加载延迟加载的模块(使用 JWT)
- php - 检测 laravel 输入预填充值的变化
- sql - 如何通过使用 VBA 代码将查询结果分配给文本框来填充表单中的数据
- python - Pandas 在使用 .loc 过滤的数据帧上使用 .str
- python - 旋转多列 - Python
- javascript - 验证:单选按钮组
- assembly - MIPS 程序集:如何将答案存储在内存“单词”变量中?
- git - 运行 git clean -X 时保留一些 gitignored 文件
- database-design - 如何解耦并行 ping 处理系统