0 votes


We're trying to get the Contribution Tree results into Excel. As they are not exported, I was thinking that I could perhaps access them with python and save them in a format that I can use.

But it seems that IPC only has methods for the SimpleResults, even when I use CalculationType.UPSTREAM_ANALYSIS.

Is there any way to get the contribution tree, either through export or through a script?


in openLCA by (160 points)

1 Answer

0 votes
by (160 points)

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)
    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)
by (160 points)
Thank you for the reply. This is what I thought with IPC, that's why I tried executing the above script directly inside openLCA to have access to SystemCalculator. Are you saying that even with the above script accessing the "native" openLCA methods, I don't have access to the FullResult?