You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将数据库中LCI输入从旧版ecoinvent升级至新版?

旧版ecoinvent数据库迁移至新版的Brightway操作指南

一、批量更新LCI的核心操作步骤

  • 第一步:导入新版ecoinvent数据库到当前Brightway项目
    先确保新版ecoinvent数据集已下载,再通过bw2io工具导入,示例代码:

    from bw2io import SingleOutputEcospold2Importer
    # 替换为你的新版数据集路径和自定义数据库名称
    ei_importer = SingleOutputEcospold2Importer("/path/to/new/ecoinvent/dataset", "ecoinvent 3.9 cutoff")
    ei_importer.apply_strategies()
    ei_importer.statistics()
    ei_importer.write_database()
    
  • 第二步:加载并应用ecoinvent官方迁移文件
    ecoinvent每个版本更新都会提供对应迁移文件(如migrations-3.8-to-3.9.json),从ecoinvent官网下载对应版本的迁移包后,用Brightway的Migration类映射旧活动到新活动:

    from bw2data import Migration, Database
    # 加载迁移规则
    Migration("ecoinvent 3.8 to 3.9").write("/path/to/migrations-3.8-to-3.9.json")
    # 对旧数据库执行迁移
    old_ei_db = Database("your-old-ecoinvent-db-name")
    old_ei_db.migrate("ecoinvent 3.8 to 3.9")
    
  • 第三步:更新自定义数据库的输入链接
    遍历你的自定义数据库,将引用旧版ecoinvent的输入替换为新版链接:

    custom_db = Database("your-custom-db-name")
    new_ei_db = Database("ecoinvent 3.9 cutoff")
    
    for act in custom_db:
        updated_exchanges = []
        for exc in act.exchanges():
            if exc.input[0] == old_ei_db.name:
                # 优先用迁移后的代码匹配新版活动
                new_code = exc.input.get("migrated_code", exc.input.code)
                new_input = (new_ei_db.name, new_code)
                if new_input in new_ei_db:
                    exc.input = new_input
                    updated_exchanges.append(exc)
                else:
                    # 暂存未匹配项,后续手动处理
                    updated_exchanges.append(exc)
            else:
                updated_exchanges.append(exc)
        act.exchanges = updated_exchanges
        act.save()
    

二、处理活动删除/名称变更的方案

  • 针对活动被删除的情况

    1. 查看ecoinvent版本更新日志,确认活动删除原因(是被合并到其他活动,还是完全废弃)
    2. 找到功能匹配的替代活动,手动更新自定义数据库中的输入链接;若无合适替代,评估该活动在你的数据库中的必要性,考虑删除或重新构建
  • 针对名称/代码变更未被迁移文件覆盖的情况
    用Brightway搜索功能定位新版数据库中的相似活动:

    # 替换为旧活动名称关键词
    target_name = "old-activity-name-keyword"
    for act in new_ei_db:
        if target_name in act["name"]:
            print(f"匹配到新版活动:{act['name']} | 代码:{act.code}")
    

    确认匹配后,手动修改自定义数据库中对应的输入链接

  • 批量验证未匹配项
    完成迁移后,运行完整性检查找出无效链接:

    from bw2data.utils import check_database_integrity
    check_database_integrity(custom_db.name)
    

    根据输出结果逐个处理未匹配的输入链接

内容的提问来源于stack exchange,提问作者Daina

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 00:20:30