Using python inside openLCA 1.10, this works for the full result. But then it fails when I try to get the UpstreamTree. Any ideas why?
from java.io import File
from org.openlca.core.database.derby import DerbyDatabase
from org.openlca.core.database import ProductSystemDao, EntityCache, ImpactMethodDao, ImpactCategoryDao
from org.openlca.core.matrix.cache import MatrixCache
from org.openlca.eigen import NativeLibrary
from org.openlca.julia import JuliaSolver
from org.openlca.core.math import CalculationSetup, SystemCalculator, CalculationType
if __name__ == '__main__':
# load the product system
db_dir = File('C:/xxxxxxxxxxx')
db = DerbyDatabase(db_dir)
dao = ProductSystemDao(db)
system = dao.getForName('my product system')[0]
# caches, native lib., solver
m_cache = MatrixCache.createLazy(db)
e_cache = EntityCache.create(db)
NativeLibrary.loadFromDir(File('../native'))
solver = JuliaSolver()
# calculation
setup = CalculationSetup(CalculationType.UPSTREAM_ANALYSIS, system)
# impact method
impact_dao = ImpactMethodDao(db)
impactMethod = impact_dao.getForName('my impact method')[0]
# get the right impact category from the method and dao
impactCategories = impactMethod.impactCategories
impactCategory = None
for ic in impactCategories:
if ic.referenceUnit == "kg CO2 eq":
impactCategory = ic
# get the descriptor
ic_dao = ImpactCategoryDao(db)
icDesc = ic_dao.getDescriptor(impactCategory.id)
# run calculation
calculator = SystemCalculator(m_cache, solver)
result = calculator.calculateFull(setup)
# this one fails with a java.lang.NullPointerException:
# File "<string>", line 84, in <module>
# at org.openlca.core.results.FullResult.getTree(FullResult.java:238)
tree = result.getTree(icDesc)