Brightway25创建活动后production()返回空列表的原因咨询
问题原因
在Brightway25中,reference product和production amount只是活动的属性标记,用来定义该活动的核心产出是什么,但它们不会自动生成对应的生产交换流。act.production()方法返回的是活动的交换对象集合,只有显式添加的交换才会被包含在内。
解决方案
有两种正确的方式创建包含生产输出的活动:
方法1:创建活动时直接定义交换流
在new_activity的参数中加入exchanges列表,明确声明生产交换:
act = db.new_activity( **{ 'code': 'test', 'location': 'GLO', 'name': 'activity name', 'reference product': 'output product', 'unit': 'kg', 'exchanges': [ { 'amount': 1, 'input': ('你的数据库名称', 'test'), # 替换为实际数据库名 'type': 'production', 'name': 'output product', 'unit': 'kg' } ] } ) act.save()
方法2:创建活动后手动添加生产交换
先创建活动,再通过act.new_exchange()添加生产流:
act = db.new_activity( **{ 'code': 'test', 'location': 'GLO', 'name': 'activity name', 'reference product': 'output product', 'unit': 'kg', } ) # 添加生产交换 prod_exchange = act.new_exchange( amount=1, input=(db.name, act['code']), type='production', name='output product', unit='kg' ) prod_exchange.save() act.save()
验证:执行上述任一方法后,运行len([i for i in act.production()])会返回1,说明生产交换已成功创建。
内容的提问来源于stack exchange,提问作者Stücke
相关产品推荐
相关产品推荐

