Closed aleksandra-kim closed 3 years ago
Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).
Thanks for the bug report!
It looks like this parameter distribution is incorrect. In the triangular distribution, the "left" (minimum) must be less than or equal to the mode, which must be less or equal to the maximum ("right"). See https://en.wikipedia.org/wiki/Triangular_distribution.
What database are you working with? Or can you say which tutorial, specifically?
Thanks, Chris
Original comment by Caroline Nadel (Bitbucket: cazcazn, ).
Like I say, it happened with both tutorials 2 and 3 after following them from 1. In order to import the US-LCI database I had to fix a few things in the code, as when checking if a category is in the biosphere, it crashed. In addition, the database folder structure has changed so it makes sense to update the tutorial.
I would make a pull request, but it entailed forcing the checker to accept some database values that might not have been correct. Import failed with "Incorrect category for biosphere flow". The changes I made to get around this were in bw2data/io/import_ecospold.py
:
21:BIOSPHERE = ("air", "water", "soil", "resource", "final-waste-flow", "raw", "others", "non-material")
431: assert exc[u"matching"][u"categories"][0].lower() in BIOSPHERE, \
Specifically, "Air" was rejected so I added a .lower
, and "others" and "non-material" were rejected so I added those to the biosphere list. This may have messed up the database in some unknown way.
Perhaps you could try running through the tutorials from scratch with the latest US-LCI and see what fixes need to be made? Then once I understand the code a bit more I'm more than happy to contribute!
Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).
Hi Cazcazn-
Thanks again, sorry for the delay.
I can't import the US LCI cleanly, due partly to the reasons you have noticed, but also because there are some internal inconsistencies, partly due it looks like to some entries being manually typed in (with the resulting typos), but also due to some pollution from SimaPro. I have also added the SimaPro biosphere categories (https://bitbucket.org/cmutel/brightway2-io/src/b7dca26debaaae2df834ed51df154e3192ac838f/bw2io/compatibility.py?at=default&fileviewer=file-view-default). However, I still have a number of issues with the import, as seen here: http://nbviewer.ipython.org/urls/bitbucket.org/cmutel/brightway2/raw/2.0/notebooks/IO%20-%20Importing%20US%20LCI%20database.ipynb
I would love to have an example database that could be used in the tutorials, but haven't found a good one yet. Maybe you have some ideas?
BTW, you can fix the MC problem with something like this (adapt as needed):
#!python
from brightway2 import *
from stats_arrays import *
import numpy as np
db = Database("whatever")
data = db.load()
for ds in data.values():
for exc in ds.get('exchanges'):
if exc['uncertainty type'] == TriangularUncertainty.id and \
(exc['minimum'] >= exc['loc'] or exc['maximum'] <= exc['loc']):
# Invalid triangular, switch to no uncertainty
exc['uncertainty type'] = NoUncertainty.id
exc['minimum'] = exc['maximum'] = np.nan
db.write(data)
In the development version (see http://brightwaylca.org/dev-docs/), it would be:
#!python
from brightway2 import *
from stats_arrays import *
import numpy as np
for ds in Database("whatever"):
for exc in ds.exchanges():
if exc['uncertainty type'] == TriangularUncertainty.id and \
(exc['minimum'] >= exc['loc'] or exc['maximum'] <= exc['loc']):
# Invalid triangular, switch to no uncertainty
exc['uncertainty type'] = NoUncertainty.id
exc['minimum'] = exc['maximum'] = np.nan
exc.save()
Original report by Caroline Nadel (Bitbucket: cazcazn, ).
Following the tutorials. Everytime I try to do a Monte Carlo as documented, an exception
ValueError: left > mode
is thrown. This happens with both tutorials 2 and 3 so far.Stack trace:
ValueError Traceback (most recent call last)