问题描述
我在运行蒙特卡洛时遇到问题,我不确定问题出在哪里或什么地方。正常的LCA计算运行良好,我检查了交易所是否增加了不确定性。我也尝试用两种不同的方式编写代码,但是问题是一样的,结果是:[nan,nan,nan]
下面是我正在使用的代码
mymethod1 = ('ReCiPe Midpoint (H) V1.13 no LT','climate change','GWP100')
mymethod1
el = t_db.get("chemical1 production")
functional_unit = {el: 1}
lca = bw.LCA(functional_unit,mymethod1)
lca.lci()
lca.lcia()
print(lca.score)
mc = bw.MonteCarloLCA({el: 1},mymethod1)
mc_results = [next(mc) for x in range(5)]
mc_results
#also tried doing like this
mc = bw.MonteCarloLCA({bw.Database('exldb').get('chemical1 production'):1},mymethod1)
next(mc)
mc_results = [next(mc) for x in range(5)]
mc_results
解决方法
我怀疑问题出在库存中,而不是影响评估方法中。我将确保您具有定义正确定义的概率分布所需的所有参数。在表here中,您可以看到需要根据所使用的概率分布类型定义哪些参数。
您可以写:
import math as math
for Input,Output,Row,Col,Type,Uncertainty_Type,Amount,Loc,Scale,Shape,Min,Max,Negative in lca.tech_params:
if Uncertainty_Type in [0,1]:
assert math.isnan(Loc) is False
assert math.isnan(Scale) or (Scale is None)
assert math.isnan(Shape) or (Shape is None)
assert math.isnan(Min) or (Min is None)
assert math.isnan(Max) or (Max is None)
elif Uncertainty_Type in [2,3]:
# lognormal and normal
assert math.isnan(Loc) is False
assert math.isnan(Scale) is False
assert math.isnan(Shape) or (Shape is None)
elif Uncertainty_Type == 4:
# uniform
assert math.isnan(Max) is False
assert math.isnan(Loc) or (Scale is None),f" loc {Loc}"
assert math.isnan(Scale) or (Scale is None)
assert math.isnan(Shape) or (Shape is None)
elif Uncertainty_Type in [5,7]:
# triangular and discrete uniform
assert math.isnan(Max) is False
elif Uncertainty_Type in [8,9]:
# weibull and Gamma
assert math.isnan(Scale) is False
assert math.isnan(Shape) is False
elif Uncertainty_Type in [10,11]:
# beta,generalized extreme value
assert math.isnan(Loc) is False
assert math.isnan(Shape) is False
elif Uncertainty_Type == 12:
# student
assert math.isnan(Shape) is False
检查是否已定义所有不确定性参数。
更新:stat-arrays存储库针对值不同于np.nan的可选列发出警告。我添加了一些断言来检查这一点..并意识到对于ecoinvent(3.6结果)不是这种情况