Lcopt development blog #1 - Introducing lcopt-dev

22 Jun 2018

The joy of open-source

One of the best things about using, and particularly writing open-source software is that “you can’t do that”, suddenly becomes “you can’t do that yet”.

Open source developers, particularly in the LCA field, tend to be very responsive to issues posted on GitHub and Bitbucket. And when you’re the developer, you can add all the new features you need as and when you come across them.

I originally wrote lcopt because I needed an easy way to make fully parameterised LCA foreground models for a research projects I was working on. I then found that SimaPro was way too slow to work with while working from home, so I started sending the models to brightway instead. Then I realised that the kinds of visualisations of the result I could create in excel or matplotlib weren’t up to scratch, and the results section of lcopt was born.

At this point lcopt had morphed from a bit of harmless tinkering into something that could potentially be useful to the LCA community, and version 0.4.2 was released and published in the Journal of Open Source Software.

Development paused for a while, but necessity remains the mother of invention. As people started using lcopt great features were requested, and a development branch of lcopt was spawned. I’m now working on a new project and, as a result, I’m coming across new issues and new ideas to extend lcopt. The development branch is moving on apace!

Thanks to the guys at the LCA-ActivityBrowser, particularly @haasad, the lcopt development branch now gets automatically uploaded to conda each time a new feature is added.

There are now enough new features that I thought it would be a good idea to go through them and try and persuade you to install the development version of lcopt - called lcopt-dev to try them out.

How do I get lcopt-dev?

Inspired by activity-browser-dev, there’s now a conda package for lcopt-dev which autoupdates from successful Travis builds on the development branch.

You can get/update this version using

conda install -c conda-forge -c cmutel -c haasad -c pjamesjoyce lcopt-dev

#or 

conda update -c conda-forge -c cmutel -c haasad -c pjamesjoyce lcopt-dev

What’s new in lcopt-dev?

Migration to bw2parameters

Let’s get the technical stuff out of the way first!

lcoptnow uses bw2parameters the parameter engine native to Brightway2 to do its parameter calculations, and the models it exports to Brightway are fully compatible with its way of implementing parameters. More details here

Import existing Brightway2 models

You can now import bw2Package files created in Brightway2 into lcopt to explore/edit your existing foreground models, as requested by @xiaoshir.

It’s as simple as exporting your foreground model as a .bw2package file, and then using create_LcoptModel_from_BW2Package(), like this:

model = create_LcoptModel_from_BW2Package(bw2_package_path)

There’s a notebook going through all the steps here

Define production amounts in your parameter sets

Production exchanges are now exposed to lcopt’s parameters rather than always defaulting to 1 (see this issue).

You can use the production parameters in functions, and you can set them using functions

This means you can set the output of a process to be the sum of the inputs:

output_parameters

And you can use the calculated production parameter to set inputs in other processes. Combining these two things means that by changing the mass of the inputs to the original process, this automatically updates the output of that process AND the input to the final product:

input_parameters

Useful information when you hover over inputs/biosphere flows

You can now see information about what your externally linked flows (technosphere and biosphere) are by hovering over them in the process diagram

hover example

Mass flow diagram

The results now include a mass flow diagram (in the form of a sankey diagram) which looks like this:

mass_flow_example (Note: it’s a mass flow diagram, not an impact flow diagram like the one in the activity browser)

Waterfall chart

Inspired by the charts from CalRecyle’s used oil LCA, a ‘waterfall chart’ is a very cool way of showing the balance between processes in the life cycle that cause an impact, and those which avoid an impact.

Lcopt can now draw these cool charts:

image

Negative impacts

Lcopt’s visualisations weren’t very good at dealing with negative impacts. Implementing the waterfall chart made this very clear!

But not any more.

The tree can now have green branches:

image

And the charts can now go negative:

image

The Parameter Sets table looks a lot nicer

The Parameter Sets quickly table gets really long and unwieldy with big models. You can now expand and collapse each process by clicking on it, making the layout a lot tidier and making your parameters a lot easier to find.

The parameter table now looks like this:

image

Clicking on the process name expands it’s parameters

image

Keyboard Shortcuts

You can now press CTRL+S to save models on the Process Diagram and Parameter Sets screens.

There’s even a nice little ‘toast’ pop up so you know it’s worked:

image

Additions to the lcopt ‘family’

lcopt-cv - Making creating foreground models even easier!

Lcopt makes making LCA foreground models pretty easy, but what if you could just draw a process flow diagram on a piece of paper and use that for your foregroun model instead.

Well now you can - using lcopt-cv.

lcopt-cv is a computer vision driven extension to lcopt which lets you take a photograph of a hand-drawn flow diagram and automatically generate an LCA foreground model in lcopt.

You can see how it works in this video and install it as a conda package (instructions here)

cv-workflow

lcoptview - Share your LCA models transparently with other researchers

A common criticism of LCA publications is that it’s hard to replicate the model and the results. This is usually because the background LCI data is from proprietary databases so you can’t share your models.

Brightway lets you separate the background databases from the foreground ones, and lcopt stores your results in an aggregated form, so your foreground model and your full result sets can be shared with no need to worry about the licensing agreements of the underlying ecoinvent database.

From lcopt you can export your model as an .lcoptview file (click on the ‘Export view file’ button).

You can then share a read-only version of your model with anyone you like, regardless of whether they are ecoinvent licensed. They just need to install lcoptview), instructions for which are here.

This is a lightweight python module (it only depends of Flask) which launches your read-only model in a normal web browser.

Any questions?

That’s it for now! But lcopt is under ongoing development, so if you have any questions or requests for features, just open an issue on the GitHub page.