GreenDelta/openlca-python-tutorial

Create Database in Python and Dump into openLCA

RunshengSong opened this issue · 1 comments

Hi,

Thanks for your tutorial. I found openLCA is very friendly to developers with python embedded. Thanks for making this.

I want to use the python interface to create a database with about 1,000 processes. I have walked through your tutorial but not sure I can dump this database to openLCA for further analysis (e.g, connect unlinked processes with US LCI data).

Is it possible to create XML format database in this developer tool and dump it into openLCA later? My environment is Ubuntu 16.04 + Eclipse + Jython, as you suggested in the tutorial.

Thank you


Yes, this should be possible. In the setup with Eclipse you are just using the openLCA libraries as normal Java libraries and you can pull in other libraries if you want. Jython is a general purpose language that runs on the Java Virtual Machine (so in principle, you can do anything that can be done with Java + Python 2.7; I have just learned that there is even progress going on to bring CPython extensions like NumPy to Jython).

Regarding the XML data sets: I assume they are in EcoSpold 1. In the openLCA core package there is a library for processing EcoSpold 1 files. It is maybe a bit complicated and you have to study the Java API in order to understand how to use it, but it should be possible to do what you want:

# an example for reading an EcoSpold 1 file
from org.openlca.ecospold.io import DataSetType, EcoSpoldIO
import java.io.File as File

xml_file = File("C:/Users/ms/Downloads/spold1.xml")
processes = EcoSpoldIO.readFrom(xml_file, DataSetType.PROCESS)
for ds in processes.dataset:
  print(ds.metaInformation.processInformation.referenceFunction.name)