0 votes

I am using the olca-ipc package in python to perform automated LCAs in openLCA. For creating product systems I found the possibility to link processes via the exchange class. However doing that for all processes in the supply chain is troublesome. In openLCA there is the option to automatically link processes according to the default provider of each input flow. To my understanding, in the openLCA core API this can be done with the "autoComplete" function. Is there a similar function in the olca-ipc package or a smart workaround how to do it from python (spyder) ?

Thanks in advance !
in openLCA by (150 points)

1 Answer

+1 vote
by (3.4k points)
selected by
Best answer

I know this doesn't get directly at your question, but I thought it might help. This is something I put together to create a bunch of product systems using only the default provider. You have to paste it into the python developer tool within openLCA. Once the product systems are created in openLCA, you can use the IPC to loop through all of your systems. The systems won't show up in the UI until you close and open the database again.

#Most of these imports are probably unnecessary now - leftover from a previous script
import csv
from org.openlca.app import App
from org.openlca.app.components import FileChooser, ModelSelectionDialog
from org.openlca.app.db import Cache
from org.openlca.core.math import CalculationSetup, CalculationType, SystemCalculator
from org.openlca.core.matrix import ProductSystemBuilder
from org.openlca.core.model import ModelType, ProductSystem
from org.openlca.core.model.descriptors import Descriptors
from org.openlca.core.database import ImpactMethodDao, ProcessDao, ProductSystemDao, BaseDao, Daos, ExchangeDao
from org.openlca.core.matrix  import LinkingConfig
from org.openlca.core.database.derby import DerbyDatabase
from org.eclipse.swt.widgets import Display
from java.lang import Long
from java.util import UUID
from java.io import File
from org.openlca.app.util import UI, Dialog
from org.openlca.app import App
from org.openlca.core.matrix.cache import MatrixCache
from org.openlca.core.matrix.LinkingConfig import DefaultProviders
from org.openlca.core.model import ProcessType

#Apparently db is global variable - maybe it comes in with import App above.
processDao = ProcessDao(db)
systemDao = ProductSystemDao(db)
methodDao = ImpactMethodDao(db)

def run(process):
    log.trace("You have entered run")
    log.trace("Building system for " + process.name)
    linkingConfig = LinkingConfig()
    log.trace("Made a new linking config!")
    #I set this up to use default providers only. Options are
    #If you select PREFER or IGNORE you probably need the 
    #next line (options are LCI_RESULT or UNIT_PROCESS):
    #linkingConfig.preferredType = ProcessType.UNIT_PROCESS
    linkingConfig.providerLinking = DefaultProviders.ONLY
    log.trace("Made it default providers only!")
    log.trace("Got MatrixCache")
    builder = ProductSystemBuilder(dasCache,linkingConfig)
    log.trace("Created Builder")
    system = builder.build(process)
    log.trace("Completed auto-building product system")
    log.trace("Inserted system into database!")
def main():
    log.trace("Here we go")
    processes = list(ModelSelectionDialog.multiSelect(ModelType.PROCESS))
    log.trace("You selected some processes, maybe " + str(len(processes)) + "?")
    if processes is None or len(processes) is 0:
        log.trace("No processes selected")
    for descriptor in processes:
      log.trace("You have entered the for loop")
          process = processDao.getForId(descriptor.id)
          log.trace("process was assigned")
          log.trace("Well something went wrong")