简体   繁体   English

在Brightway2中创建非常简单的LCIA方法

[英]Create very simple LCIA method in brightway2

I am very new to bw2 and I am trying to make a simple LCA without using databases but just using a manually defined inventory and LCIA method. 我是bw2的新手,我尝试不使用数据库而是使用手动定义的清单和LCIA方法来制作简单的LCA。 I used the values from the example in Chapter 11 of "The Computational Structure of Life Cycle Assessment" book. 我使用了《生命周期评估的计算结构》一书第11章中的示例中的值。

I was able to create a inventory and run the LCI calculation: 我能够创建清单并运行LCI计算:

t_db = Database("testdb")

t_db.write({
    ("testdb", "Electricity production"):{
        'name':'Electricity production',
        'unit': 'kWh', 
        'exchanges': [{
                'input': ('testdb', 'Fuel production'),
                'amount': 2,
                'unit': 'kg',
                'type': 'technosphere'
            },{
                'input': ('testdb', 'Carbon dioxide'),
                'amount': 1,
                'unit': 'kg',
                'type': 'biosphere'
            },{
                'input': ('testdb', 'Sulphur dioxide'),
                'amount': 0.1,
                'unit': 'kg',
                'type': 'biosphere'
            },{
                'input': ('testdb', 'Electricity production'), #important to write the same process name in output
                'amount': 10,
                'unit': 'kWh',
                'type': 'production'
            }]
        },
    ('testdb', 'Fuel production'):{
        'name': 'Fuel production',
        'unit': 'kg',
        'exchanges':[{
                'input': ('testdb', 'Carbon dioxide'),
                'amount': 10,
                'unit': 'kg',
                'type': 'biosphere'
            },{
                'input': ('testdb', 'Sulphur dioxide'),
                'amount': 2,
                'unit': 'kg',
                'type': 'biosphere'
            },{
                'input': ('testdb', 'Crude oil'),
                'amount': -50,
                'unit': 'kg',
                'type': 'biosphere'
            },{
                'input': ('testdb', 'Fuel production'),
                'amount': 100,
                'unit': 'kg',
                'type': 'production'
            }]
    },
    ('testdb', 'Carbon dioxide'):{'name': 'Carbon dioxide', 'unit':'kg', 'type': 'biosphere'},
    ('testdb', 'Sulphur dioxide'):{'name': 'Sulphur dioxide', 'unit':'kg', 'type': 'biosphere'},
    ('testdb', 'Crude oil'):{'name': 'Crude oil', 'unit':'kg', 'type': 'biosphere'}

    })

functional_unit = {t_db.get("Electricity production") : 1000}
lca = LCA(functional_unit) 
lca.lci()
print(lca.inventory)

However, the problems start when I create the fictive LCIA method (with all CFs set to 1 for simplicity). 但是,当我创建虚拟LCIA方法时(为简单起见,所有CF都设置为1),问题就开始了。 This is the code I used but clearly it does not work. 这是我使用的代码,但显然不起作用。 The key issue seems to be a failure to link the exchanges from the inventory to the LCIA method. 关键问题似乎是未能将库存中的交换与LCIA方法关联起来。

myLCIAdata = [[('biosphere', 'Carbon dioxide'), 1.0], 
         [('biosphere', 'Sulphur dioxide'), 1.0],
         [('biosphere', 'Crude oil'), 1.0]]

method_key = ('simplemethod', 'imaginaryendpoint', 'imaginarymidpoint')
Method(method_key).validate(myLCIAdata) #returns "TRUE"
Method(method_key).register() 
Method(method_key).write(myLCIAdata)
Method(method_key).load() #check everything works
lca = LCA(functional_unit, method_key) #run LCA calculations again with method
lca.characterized_inventory

The result is <3x2 sparse matrix of type '<class 'numpy.float64'>' with 0 stored elements in Compressed Sparse Row format> So an empty matrix. 结果是<3x2 sparse matrix of type '<class 'numpy.float64'>' with 0 stored elements in Compressed Sparse Row format>因此为空矩阵。 Any idea of what mistake I am making? 对我犯什么错误有任何想法吗? Should I get an unique identifier for each exchange as in the existing databases? 是否应该像现有数据库那样为每个交易所获得唯一的标识符? I have checked the bw2 tutorials, documentation, and previous questions on this site but can't find an answer. 我已经在该网站上查看了bw2教程,文档和以前的问题,但找不到答案。 Thanks in advance. 提前致谢。

You are very close. 你很亲密 In defining your CFs, you do the following: 在定义CF时,请执行以下操作:

myLCIAdata = [[('biosphere', 'Carbon dioxide'), 1.0], 
              [('biosphere', 'Sulphur dioxide'), 1.0],
              [('biosphere', 'Crude oil'), 1.0]]

Taking the first line, this would mean that in the database biosphere , there would be a flow with the code Carbon dioxide . 从第一行开始,这意味着在数据库biosphere ,将出现代码为Carbon dioxide的流程。 But you don't have a biosphere database, you put everything into a database named testdb : 但是您没有biosphere数据库,而是将所有内容都放入名为testdb的数据库中:

    ('testdb', 'Carbon dioxide'):{'name': 'Carbon dioxide', 'unit':'kg', 'type': 'biosphere'},

So either use the right database name in the list of characterization factors, or create a separate biosphere database called biosphere . 因此,要么在表征因子列表中使用正确的数据库名称,要么创建一个单独的名为biosphere生物圈数据库。

Note also that instead of this: 还请注意,除了此以外:

method_key = ('simplemethod', 'imaginaryendpoint', 'imaginarymidpoint')
Method(method_key).validate(myLCIAdata) #returns "TRUE"
Method(method_key).register() 
Method(method_key).write(myLCIAdata)

You should do this: 你应该做这个:

method_key = ('simplemethod', 'imaginaryendpoint', 'imaginarymidpoint')
my_method = Method(method_key)
my_method.validate(myLCIAdata)
my_method.register() 
my_method.write(myLCIAdata)

(Your code isn't broken, but could be more elegant). (您的代码没有损坏,但可能更优雅)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM