0

我不知道如何设置 BW2 以在 MC 模拟中为具有对数正态分布的参数获取负值,例如对负排放进行建模。例子:

from brightway2 import *
import numpy as np


mydb = Database('mydb')

mydb.write({
    ('mydb', 'Some activity'): {
        'name': 'Some activity',
        'unit': 'kWh',
        'exchanges': [{
            'input': ('mydb', 'Carbon dioxide'),
            'amount': 20, # positive!
            'unit': 'kg',
            'type': 'biosphere', 
            'uncertainty type' : 2,
            'loc' : np.log(20), 
            'scale' : 1.01 
            }]
    },
    ('mydb', 'Carbon dioxide'): {'name': 'Carbon dioxide', 'unit': 'kg', 'type': 'biosphere'}
    })

exc = list(mydb.get('Some activity').exchanges())[0]
exc.as_dict()
exc.random_sample(n=10)  

这行得通。我得到:

Out[8]: 
array([ 25.20415107,  17.48476344,  16.98842921,   3.79548038,
    12.54165042,  27.93752377,   7.57070571,  43.22285015,
    48.44984804,  13.83083672]) # everything fine

现在让我们假设我想获得相同的值但为负值:array([ -25.20415107, -17.48476344, etc. ...因为我假设我的碳吸收量为 -20 kg 二氧化碳。如果我写'amount': -20,我会得到一个奇怪的结果:

Out[9]: 
array([   0.73060359,   36.69825867,    5.71416558,   10.78119397,
     16.24447705,    2.96507057,    6.73564118,   19.24411117,
      7.23110067,  126.42690714])

我知道对数正态分布不能是负数,但我所期望的是,分布是根据“loc”和“scale”信息根据正值计算的,然后根据“数量”信息进行反转。这是对具有负排放的清单执行 MC 所必需的。有什么线索吗?谢谢

4

1 回答 1

1

有两个问题阻止了预期的行为:

  1. 在字段中给出负值是不够的amount;RNG 代码位于stats_arrays库中,您必须将该字段设置negativeTrue请参阅文档)。
  2. 中有一个错误brightway2-data,在7e3341c和版本2.4.6中已修复,导致无法negativeexchange.uncertainty.

一般来说,当从其他格式导入数据时,该negative字段会自动设置,例如SimaPro CSVEcospold 1。此外,当数据库被处理为参数数组时,该negative字段也总是amount field. 在这种情况下,不同之处在于您是stats_arrays直接调用函数,而不是通过brightway2-calc

negative在最新安装中添加该字段:

from brightway2 import *
import numpy as np
projects.set_current("SO 45935773")
bw2setup()

mydb = Database('mydb')
gwp = ('IPCC 2013', 'climate change', 'GWP 100a')
co2 = get_activity(('biosphere3', '349b29d1-3e58-4c66-98b9-9d1a076efd2e'))

mydb.write({
    ('mydb', 'Some activity'): {
        'name': 'Some activity',
        'unit': 'kWh',
        'exchanges': [{
            'input': co2.key,
            'amount': -20, # negative
            'negative': True,
            'unit': 'kg',
            'type': 'biosphere', 
            'uncertainty type' : 2,
            'loc' : np.log(20), 
            'scale' : 1.01 
        }]
    }
})

exc = list(mydb.get('Some activity').exchanges())[0]
exc.random_sample(n=10)  

产生预期的行为:

array([ -3.24683872,  -5.01873359, -31.54532003, -40.59523805,
       -54.00447092,  -6.11459063, -41.5250442 ,  -8.05295075,
       -31.46077832, -29.8769442 ])
于 2017-08-29T20:15:04.533 回答