Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global parameter #20

Open
Apratiwi opened this issue Oct 18, 2019 · 2 comments
Open

Add global parameter #20

Apratiwi opened this issue Oct 18, 2019 · 2 comments
Labels

Comments

@Apratiwi
Copy link

Hello,
I am a beginner in terms of using Python for OpenLCA.
I have a list of 70 parameters (in excel) that I would like to add as global parameters in my database and I would like to add it using Python code.

As my first approach I followed an example this link:
https://github.com/GreenDelta/openlca-python-tutorial/blob/master/examples.md
`from java.io import File
from org.openlca.core.database.derby import DerbyDatabase
from org.openlca.core.database import ParameterDao

if __name__ == '__main__': db_dir = File('C:/Users/astupratiwi/openLCA-data-1.4/databases/Krigsheim') db = DerbyDatabase(db_dir) dao = ParameterDao(db) param = dao.getForName('k_B')[0] param.value = 42.0 dao.update(param) db.close()

but it failed to create database and there is this report in console 'create new database jdbc:derby:/Applications/openLCA.app/Contents/MacOS/C:/Users/astupratiwi/openLCA-data-1.4/databases/Krigsheim;create=true'

As a second attempt, I tried to add those global parameters to a process by running this code several time

'
process = olca.getProcess("p1")
process.parameters.clear()
param = Parameter()
param.name = "p%s" % I
param.scope=ParameterScope.global
param.isInputParameter = True
param.value = 5
process.parameters.add(param)
olca.updateProcess(process)'

It worked, but as soon as I delete the parameters from the list of input parameter of that process "p1", the parameters are gone from the list of the global parameters.

Does anyone know how to solve this issue?
thank you so much!

Astu

@Apratiwi
Copy link
Author

Hello,
I am a beginner in terms of using Python for OpenLCA.
I have a list of 70 parameters (in excel) that I would like to add as global parameters in my database and I would like to add it using Python code.

As my first approach I followed an example this link:
https://github.com/GreenDelta/openlca-python-tutorial/blob/master/examples.md

from java.io import File
from org.openlca.core.database.derby import DerbyDatabase
from org.openlca.core.database import ParameterDao

if __name__ == '__main__': 
  db_dir = File('C:/Users/astupratiwi/openLCA-data-1.4/databases/Krigsheim') 
  db = DerbyDatabase(db_dir) 
  dao = ParameterDao(db) 
  param = dao.getForName('k_B')[0] 
  param.value = 42.0 dao.update(param) db.close()

but it failed to create database and there is this report in console 'create new database jdbc:derby:/Applications/openLCA.app/Contents/MacOS/C:/Users/astupratiwi/openLCA-data-1.4/databases/Krigsheim;create=true'

As a second attempt, I tried to add those global parameters to a process by running this code several time

process = olca.getProcess("p1")
process.parameters.clear()
param = Parameter()
param.name = "p%s" % I
param.scope=ParameterScope.global
param.isInputParameter = True
param.value = 5
process.parameters.add(param)
olca.updateProcess(process)

It worked, but as soon as I delete the parameters from the list of input parameter of that process "p1", the parameters are gone from the list of the global parameters.

Does anyone know how to solve this issue?
thank you so much!

Astu

@msrocka
Copy link
Member

msrocka commented Oct 21, 2019

As you are on macOS C:/Users... is not a valid path to a folder on your system
(it is a DOS path that works on Windows). This is the reason you get the first error.

Also, you do not attach global parameters to a process. Because when you delete
that process also these parameters are deleted. You can use the ParameterDao
to create stand-alone global parameters like this:

from org.openlca.core.model import Parameter, ParameterScope
from org.openlca.core.database import ParameterDao

# create a global input paramater
param = Parameter()
param.name = "global_p"
param.scope = ParameterScope.GLOBAL
param.isInputParameter = True
param.value = 5

# create the paramater DAO and insert the paramater in
# the database
dao = ParameterDao(db)
dao.insert(param)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants