在Brightway2 Excel导入器中区分参考产品和活动名称

在Brightway2 Excel导入器中区分参考产品和活动名称,brightway,Brightway,如上所述,brightway2 Excel导入器似乎假定参考产品名称和活动名称相同,但情况并非总是如此 向活动元数据添加参考产品部分没有帮助:链接无法将生产交换链接到生成它的活动 如果生产交换不一定与活动名称完全相同,那么使用Excel导入器导入活动是否有解决方法 链接由“策略”功能完成。在这种情况下,您似乎只需要一个自定义函数来获取所需的字段。我还没有测试过它,但类似于以下的东西应该可以: def match_by_reference_product(database): """Mat

如上所述,brightway2 Excel导入器似乎假定参考产品名称和活动名称相同,但情况并非总是如此

向活动元数据添加参考产品部分没有帮助:链接无法将
生产
交换链接到生成它的活动

如果
生产
交换不一定与活动名称完全相同,那么使用Excel导入器导入活动是否有解决方法

链接由“策略”功能完成。在这种情况下,您似乎只需要一个自定义函数来获取所需的字段。我还没有测试过它,但类似于以下的东西应该可以:

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\u导入器应用。应用策略(按参考产品匹配)

链接通过“策略”功能完成。在这种情况下,您似乎只需要一个自定义函数来获取所需的字段。我还没有测试过它,但类似于以下的东西应该可以:

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\u导入器应用。应用策略(按参考产品匹配)

这是一个使用自定义策略的好教程。这是一个使用自定义策略的好教程。