pjamesjoyce / lcopt

Create foreground LCA models via an intuitive user interface and analyse them using Brightway2
BSD 3-Clause "New" or "Revised" License
22 stars 6 forks source link

compatibility with bw2data (i.e. databases) and bw2parameters #13

Closed cardosan closed 7 years ago

cardosan commented 7 years ago

Hi P, I have checked a bit the documentation and it is not completely clear to me how much lcopt is integrated with bw2 and if it uses it only for running LCA.

I am in a situation where have databases installed in bw2 that contained parameters (handled by bw2parameters. Is it possible to work on and modify these dbs and the relative parameters from lcopt or not?

If not, is there the possibility perhaps to import a simparo.csv file and the relative parameters (or maybe also a bw2 compatible format like BW2Package), modify them on lcopt and then export back to bw2 and perform all the analysis with it?

Thanks ahead and congrat, very nice work!!!

pjamesjoyce commented 7 years ago

Hi @cardosan!

At the moment the integration with bw2 is one way I'm afraid.

Lcopt creates the model, uses it to write a bw2 database, then it writes its own parameters rather than using bw2parameters (as recommended in the bw2parameters example notebook).

bw2 then sends the results back to Lcopt for the visualisations.

Lcopt doesn't have an import function at the minute - it started life as a simple way to create LCA models alongside non-LCA experts. I'll tag this as a feature request though, as it's likely to be useful for the LCA community. It should be possible, at least from bw2 into Lcopt. I'll keep you posted on here.

Cheers

James

cardosan commented 7 years ago

Thanks Peter, would be very nice, how do you see also the possibility to export to bw2? This is actually what I would need the most since I would need to run dynamicLCA with bw2temporalis.

pjamesjoyce commented 7 years ago

Lcopt exports to brightway every time you run an analysis.

The best thing to do would be to:

  1. Launch lcopt from a jupyter notebook using model.launch_interact()
  2. Create an Lcopt model with one parameter set
  3. Run an analysis on the model
  4. Quit the GUI
  5. Import brightway2 in the same notebook
  6. Use sorted(projects) to list your projects - one of them will have the same name as your lcopt model.
  7. Use projects.set_current('Your project') to switch to it
  8. (Optionally) Use projects.copy_project(new_name, switch=True) to create a new copy so lcopt won't overwrite any changes you make
  9. Run the dynamic LCAs in bw2

I'll try and upload some example notebooks in the next couple of days that go through some of the mre involved stuff

cardosan commented 7 years ago

Cool thanks!!!

pjamesjoyce commented 7 years ago

I've just pushed an experimental branch /import which contains a function to import a bw2package file containing a single database into lcopt.

It's not incorporated into the GUI, but you can use if from a jupyter notebook or python shell.

To use it, create a new lcopt conda environment (with a different name) as in the installation instructions to get all the necessary dependencies sorted. Then uninstall that version of lcopt and install the version from the import branch using

pip install https://github.com/pjamesjoyce/lcopt/archive/import.zip

To use it first export your database from bw2 using

from brightway2 import *
from bw2io.package import BW2Package

projects.set_current('my project')
export_db = Database('my database')
filename = 'my_filename'
filepath = 'path\to\export\folder'

BW2Package.export_obj(export_db, filename, filepath)

Check the real filename of the bw2package file. bw2 adds a hash string after the name you choose e.g. Sample_Db.1499a346648778a2d15b5c7e7e9d82d2.bw2package

Then try and import it to Lcopt using

from lcopt import *

model = create_LcoptModel_from_BW2Package('real_bw2package_path')

model.launch_interact()

It works for a simple model I've created with a couple of processes, inputs from ecoinvent 3.3 and direct emissions to air.

FWIW I created the model by exporting from SimaPro as .csv, importing to bw2 following these instructions and then exporting it as a bw2package using the code above.

If you have problems, reopen this issue or raise a new one. Hope it helps!