【问题标题】:Create very simple LCIA method in brightway2在 Brightway2 中创建非常简单的 LCIA 方法
【发布时间】:2017-01-05 00:40:37
【问题描述】:

我对 bw2 非常陌生,我正在尝试在不使用数据库的情况下制作一个简单的 LCA,而只是使用手动定义的库存和 LCIA 方法。我使用了“生命周期评估的计算结构”一书第 11 章中示例中的值。

我能够创建库存并运行 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)

但是,当我创建虚构的 LCIA 方法时问题就开始了(为简单起见,所有 CF 都设置为 1)。这是我使用的代码,但显然它不起作用。关键问题似乎是未能将清单中的交换与 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

结果是<3x2 sparse matrix of type '<class 'numpy.float64'>' with 0 stored elements in Compressed Sparse Row format> 所以是一个空矩阵。知道我犯了什么错误吗?我是否应该像在现有数据库中一样为每个交易所获取一个唯一标识符?我检查了本网站上的 bw2 教程、文档和以前的问题,但找不到答案。提前致谢。

【问题讨论】:

    标签: python brightway


    【解决方案1】:

    你很亲密。在定义 CF 时,请执行以下操作:

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

    取第一行,这意味着在数据库biosphere 中,将有一个代码为Carbon dioxide 的流。但是您没有biosphere 数据库,您将所有内容放入名为testdb 的数据库中:

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

    因此,要么在表征因素列表中使用正确的数据库名称,要么创建一个名为 biosphere 的单独生物圈数据库。

    还要注意,而不是这个:

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

    你应该这样做:

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

    (您的代码没有损坏,但可以更优雅)。

    【讨论】:

    • 谢谢。我看到了错误,我对 LCIA 方法定义中的“生物圈”部分感到困惑,我认为这是流的类型,而不是指数据库。我将代码修改为:myLCIAdata = [[('testdb', 'Carbon dioxide'), 1.0] ... ,添加了lca.lcia(),它工作了。 (得到优雅点,感谢您的建议)。
    猜你喜欢
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2017-10-10
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    相关资源
    最近更新 更多