brightway25 并导入 ecoinvent v3.10 的本地副本

问题描述 投票:0回答:1

我知道我们现在有ecoinvent_interface可以直接从Ecoinvent API下载,但我有ecoinvent v3.10的本地副本,并且系统中无法访问互联网。在这种情况下如何使用brightway25导入ecoinvent v3.10?如果我尝试“ei.statistics()”,我会得到 60 个未链接的交换

python-3.10 brightway
1个回答
0
投票

https://github.com/Haitham-ghida/Premise_BW_recipes/blob/main/lca_recipes.ipynb

尝试此功能

我建议您输入新的项目名称以避免出现问题。

import bw2data as bd
import bw2io as bi
# from premise_gwp import add_premise_gwp  # only add if you want to use the premise

def base_setup_with_ecoinvent(
    project_name: str,
    db_name: str,
    db_loc: str,
    reparametrize_lognormals: bool = False,
    # setup_premise_gwp: bool = True, # only add if you want to use the premise
):
    """
    This method sets up a Brightway project with the ecoinvent database.

    Parameters
    ----------
    db_name : str
        The name of the database to import
    db_loc : str
        The location of the database to import (e.g. "C:/Users/.../ecoinvent 3.7.1_cutoff_ecoSpold02/datasets"))
    reparametrize_lognormals : bool, optional
        Whether or not to reparametrize lognormal distributions, by default True (recommended)
        This sets the mean of the lognormal distribution to static value of the LCA calculation.
        This is recommended because the default behavior of Brightway is to set the mean of the lognormal distribution to the value of the LCA calculation.
        This can lead to problems when performing Monte Carlo LCA calculations, because the mean of the lognormal distribution will change with each iteration.
        This can lead to a large number of iterations being required to reach convergence.
    setup_premise_gwp : bool, optional
        Whether or not to setup the premise_gwp method, by default True
        This method provides characterization factors for biogenic CO2 flows and hydrogen emissions to air.
    """

    # set the project, it will create a new project if it does not exist
    bd.projects.set_current(project_name)

    # imports biosphere flows, it will skip if already done
    bi.bw2setup()

    # get the path to the datasets folder
    db_dir = db_loc
    # give a name to the database
    data_base_name = db_name
    # check if the database is already in the project, and skip if yes
    if data_base_name in bd.databases:
        print("Database has already been imported")

    else:
        # import database
        db = bi.SingleOutputEcospold2Importer(
            db_dir,
            data_base_name,
            reparametrize_lognormals=reparametrize_lognormals,
        )

        db.apply_strategies()

        db.statistics()

        # db.drop_unlinked(True)
        # writes database into sql
        db.write_database()
        # Because some of the scenarios can yield LCI databases
        # containing net negative emission technologies (NET),
        # it is advised to account for biogenic CO2 flows when calculating
        # Global Warming potential indicators.
        # `premise_gwp` provides characterization factors for such flows.
        # It also provides factors for hydrogen emissions to air.
        # if setup_premise_gwp: # only add if you want to use the premise
        #     add_premise_gwp()

像这样使用它:

base_setup_with_ecoinvent('newProject', 'nameOfDataBase', 'full/path/to/your/db/where/you/saved/it')

请注意,当您下载 ecoinvent 时,它是压缩的,因此请将其解压,路径应指向数据集文件夹,例如“C:/Users/.../ecoinvent 3.7.1_cutoff_ecoSpold02/datasets”

© www.soinside.com 2019 - 2024. All rights reserved.