从python调用openlca函数的python包。

olca-ipc的Python项目详细描述


openlca提供了一个implementation 基于JSON-RPC的协议 进程间通信(IPC)。这样,就可以调用函数 在openlca中并在openlca之外处理它们的结果。那olca-ipc 包提供了一个方便的api,用于使用来自标准 python(cpython v3.6+),因此可以使用openlca作为数据存储 以及计算引擎,并将其与python中的库相结合 生态系统(努比、熊猫和朋友)。

OpenLCA IPC协议基于OpenLCA数据交换格式,即 在olca-schema中指定 储存库。olca-ipc包提供了 openlca数据交换格式和与openlca通信的api IPC服务器通过这些类的实例。

当前稳定版本的olca-ipc可通过 Python Package Index。因此,为了 使用它,您只需使用pip:

pip install -U olca-ipc

为了与openlca通信,首先需要启动openlca ipc 服务器。您可以通过openlca中的用户界面在 Window > Developer Tools > IPC Server。IPC服务器在特定的 端口,例如8080,从IPC客户端连接到该端口:

importolcaclient=olca.Client(8080)

因此,olca.Client类的实例是 调用openlca函数并处理其结果。以下 示例显示了一些典型的用例(注意,这些只是示例 没有输入检查、错误处理、代码结构和所有 通常会这样)。

运行计算

OpenLCA提供不同类型的计算,可以通过 calculation_typecalculation setup。 在下面的示例中,使用产品系统和影响的计算设置 评估方法被创建、计算并最终导出到excel中:

importolcaclient=olca.Client(8080)# create the calculation setupsetup=olca.CalculationSetup()# define the calculation type here# see http://greendelta.github.io/olca-schema/html/CalculationType.htmlsetup.calculation_type=olca.CalculationType.CONTRIBUTION_ANALYSIS# select the product system and LCIA methodsetup.impact_method=client.find(olca.ImpactMethod,'TRACI 2.1')setup.product_system=client.find(olca.ProductSystem,'compost plant, open')# amount is the amount of the functional unit (fu) of the system that# should be used in the calculation; unit, flow property, etc. of the fu# can be also defined; by default openLCA will take the settings of the# reference flow of the product systemsetup.amount=1.0# calculate the result and export it to an Excel fileresult=client.calculate(setup)client.excel_export(result,'result.xlsx')# the result remains accessible (for exports etc.) until# you dispose it, which you should always do when you do# not need it anymoreclient.dispose(result)

参数化计算设置

为了计算具有不同参数集的产品系统,可以 使用计算设置直接将一组参数重新定义传递到 计算。这样,您就不需要修改产品系统或 数据库中的参数,以便用不同的参数计算 值:

# ... same steps as abovesetup=olca.CalculationSetup()# ...forsomethinginyour.parameter_data:redef=olca.ParameterRedef()redef.name=the_parameter_nameredef.value=the_parameter_value# redef.context = ... you can also redefine process and LCIA method#                     parameters by providing a parameter context which#                     is a Ref (reference) to the respective process or#                     LCIA method; with no context a global parameter is#                     redefinedsetup.parameter_redefs.append(redef)

如名称所述,参数重新定义重新定义现有的值。 全局、进程或LCIA方法参数。

蒙特卡罗模拟

运行蒙特卡罗模拟与正常计算类似,但是 在calculate中,调用将返回引用的simulator方法 然后用于运行计算的模拟器(在每个计算中 模拟器为中的不确定度分布生成新值。 系统)。您可以获得每次迭代的结果,还可以导出 以后所有迭代都将显示为excel。对于正常计算的结果, 当模拟器不再使用时,应进行处理:

importolcaclient=olca.Client(8080)# creating the calculation setupsetup=olca.CalculationSetup()setup.calculation_type=olca.CalculationType.MONTE_CARLO_SIMULATIONsetup.impact_method=client.find(olca.ImpactMethod,'TRACI 2.1')setup.product_system=client.find(olca.ProductSystem,'compost plant')setup.amount=1.0# create the simulatorsimulator=client.simulator(setup)foriinrange(0,10):result=client.next_simulation(simulator)first_impact=result.impact_results[0]print('iteration %i: result for %s = %4.4f'%(i,first_impact.impact_category.name,first_impact.value))# we do not have to dispose the result here (it is not cached# in openLCA); but we need to dispose the simulator later (see below)# export the complete result of all simulationsclient.excel_export(simulator,'simulation_result.xlsx')# the result remains accessible (for exports etc.) until# you dispose it, which you should always do when you do# not need it anymoreclient.dispose(simulator)

有关更多信息和示例,请参见 package documentation

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
写入远程文件java   在java中尝试播放音频时出现音频流错误。wav文件   用户界面如何在Java中禁用GUI按钮   在java中如何使用条件拆分字符串   java从一个方法在数组中设置,从另一个方法获取   java如何忽略“”而不是“”   java证书。木卫一。IOException:密钥库被篡改,或密码不正确   java Android onCreate不调用   在play framework(i18n)中未正确显示德语Umlautes的java显示   使用java从eclipse运行MacOSX命令的macos   java是检查数组中备用项的最有效方法   如何使用java流编写包含循环、if/else和返回语句的代码   为什么在Java中,循环内的声明似乎比循环外的声明更快?   java软件包不存在mvn clean install