-
Notifications
You must be signed in to change notification settings - Fork 42
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
SimaPro CSV importer doesn't fix broken uncertainty values #236
Comments
@SamiraHuber Thanks for the bug report. I am moving this issue to the correct repo. The SimaPro CSV importer should check the lognormal values and fix them where needed. We already do this in other importers. In the meantime, you could do: from numbers import Number
for ds in bw2data.Database("my database"):
for exc in ds.exchanges():
if (
"uncertainty type" in exc
and exc["uncertainty type"] in (2, 3)
and (not isinstance(exc.get("scale"), Number) or exc["scale"] <= 0)
):
print(f"Fixing exchange: {exc}")
exc["previous uncertainty type"] = exc["uncertainty type"]
exc["uncertainty type"] = 0
exc["fixed nonpositive (log)normal scale"] = True
exc["previous (log)normal scale value"] = exc.get("scale")
exc["previous (log)normal loc value"] = exc.get("loc")
exc["loc"] = exc["amount"]
exc.save() |
@cmutel Thanks a lot for the fast reply and moving it in the correct repo! Sadly I get another error after the fixing of the values:
Do you have an idea how I can handle this? And the long log:
|
Can you please give me an idea of the number of exchanges fixed by the previous code? We aren't seeing the kind of distribution here, just the fact that it supplies a min and max value, and that these are incorrect. Try this: from numbers import Number
for ds in bw2data.Database("my database"):
for exc in ds.exchanges():
if (isinstance(exc.get("minimum"), Number)
and isinstance(exc.get("maximum"), Number)
and exc["maximum"] <= exc["minimum"]):
print(f"Fixing exchange min/max: {exc}")
if exc.get("uncertainty type") is None:
pass
elif exc["uncertainty type"] in (4, 5):
# Uniform and triangular
exc["previous invalid uncertainty type"] = exc["uncertainty type"]
exc["uncertainty type"] = 0
exc["previous maximum value"] = exc.get("maximum")
exc["previous minimum value"] = exc.get("minimum")
exc["loc"] = exc["amount"]
else:
exc["previous maximum value"] = exc.get("maximum")
exc["previous minimum value"] = exc.get("minimum")
del exc["minimum"]
del exc["maximum"]
exc.save() |
@cmutel
|
@SamiraHuber Great, thanks. Please don't close this, I need to add a fix to the generic importer so no one else needs to deal with this :) |
I don't know what I am doing wrong but after running the second code snippet, with updating the maximum and minimum, I again get the error I got in the beginning. Also when I run the first code you provided again, it still stays with the error. The full error-log:
The activities that it fixed:
|
@SamiraHuber pretty sure we can figure out what is happening. First, let's look at the error message:
We made adjustments for the following uncertainty distributions: 2, 4, and 5 (Lognormal, Uniform, and Triangular). But we didn't fix normal distributions, and it's not surprising that they also have problems in this data. The code snippet above has been updated to fix normal distributions as well. |
Thanks a lot (also for helping out on a Sunday!), it is working! |
I tried to do the Monte Carlo analysis with the Agribalyse3.1 database, based on this notebook:
https://github.com/brightway-lca/brightway2/blob/master/notebooks/Monte%20Carlo%20from%20Excel%20import.ipynb
The second line fails with the error: "Real, positive scale (sigma) values are required for lognormal uncertainties."
The same happens in the acitivity browser. It works when using the Ecoinvent database.
I appreciate your help on how to fix it. Thanks a lot! Here are some more information:
My Agribalyse-Version:
https://sustaincertcom-my.sharepoint.com/:x:/g/personal/gustave_coste_sustain-cert_com/ESwnbkR0VpRGrozFdZersVsBePolrNLmnVuCTeJbObSU4g?e=cTFO7Z&download=1
I took this from here:
https://github.com/sc-gcoste/brightway-agribalyse3.1
My brightway versions:
brightway2==2.4.2
bw-migrations==0.2
bw2analyzer==0.10
bw2data==1.8.1
bw2data==3.6.5
bw2io==0.8.8
bw2parameters==0.7
The text was updated successfully, but these errors were encountered: