首页 > 解决方案 > 导入方法 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 上获得的结果之间仍然存在重要差异。我的调查使我得出以下观察结果:

标签: brightway

解决方案


在 LCA 中,没有就基本流量和典型排放情景/背景达成一致(https://doi.org/10.1007/s11367-017-1354-3),影响评估方法的实施也不同(https://www.lifecycleinitiative .org/portfolio_category/lcia/)。

相同的活动和相同的影响评估方法在不同的软件中返回不同的结果并不罕见。有一些改进当前实践的尝试(参见例如,https ://github.com/USEPA/LCIAformatter )。


推荐阅读