此处描述的 brightway2 Excel 导入器似乎假定参考产品名称和活动名称相同,但情况并非总是如此。
将参考产品部分添加到活动元数据没有帮助:链接无法将production
交换链接到生成它的活动。
是否有使用 Excel 导入器导入活动的解决方法,其中production
交换不一定与活动完全命名?
链接由“策略”功能完成。在这种情况下,您似乎只需要一个自定义函数来获取您想要的字段。我还没有测试过,但是类似下面的东西应该没问题:
def match_by_reference_product(database):
"""Match using reference product instead of 'name' field."""
def get_product_exchange(dataset):
lst = [e for e in dataset if e['type'] == 'production']
if len(lst) != 1:
raise ValueError("Can't find one production exchange: {}".format(dataset))
return lst[0]
def get_fields(exc):
return (
exc['reference product'],
exc['unit'],
exc['location']
)
possibles = {
get_fields(get_product_exchange(dataset)): (dataset['database'], dataset['code'])
for dataset in database
}
for dataset in database:
for exc in dataset['exchanges']:
if exc['input']:
continue
if exc['type'] != 'technosphere':
continue
try:
exc['input'] = possibles[(exc['name'], exc['unit'], exc['location'])]
except KeyError:
pass
return database
使用my_importer.apply_stragtegy(match_by_reference_product)
.