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

Missmatch between chemical formula and parameter formula #44

Closed
inrDL opened this issue Feb 26, 2024 · 3 comments
Closed

Missmatch between chemical formula and parameter formula #44

inrDL opened this issue Feb 26, 2024 · 3 comments

Comments

@inrDL
Copy link

inrDL commented Feb 26, 2024

Hello,

In ecoinvent, some emissions have an attribute 'formula', which gives the chemical formula of the molecule emitted, such as 'CO2' for carbon dioxide.
When freezing a foreground database, that has some ecoinvent activities in it with such emissions, I get the error :
'TypeError: Cannot convert expression to float'
followed by
'Exception: Context : CO2'

From what I understand, freezing convert all the parameters formulas into float. But when it come accros a chemical formula, it raises an error because the parameter CO2 does not exists. So it seems that the same attribute name 'formula' is given to two distinct fields.
It is correct ? How could this be corrected ? (except renaming in ecoinvent all 'formula' field into 'chemical formula', which takes ~2 hour)

Thank you !

@raphaeljolivet
Copy link
Contributor

Hi,

That's a known bug of Brightway that they have fixed in DEV/beta release but not on older versions yet.
Until it is fixed, you can simply cleanup all "formula" attribute of your ecoinvent database with a sample code like :

db = bw.Database("name_of_eco_db")
for act in db:
    for ex in act.exchanges():
        if "formula" in ex: 
            print(ex, ex["formula"])
            del ex["formula"]
            ex.save()

It takes a couple of minutes, not two hours.

@raphaeljolivet
Copy link
Contributor

BTW : the problem only happens if you have copied a background ecoinvent activity, containg chemical formulas, in your foreground and then try to freeze it :
You are not supposed to "freeze" your background database, which is static / not parametrized.

@inrDL
Copy link
Author

inrDL commented Feb 26, 2024

Hello,

Thank you very much. Okay for the cleaning, I had done something similar that took too long, I will use your code !

I understand we are not supposed to freeze background database, but indeed it happen if you copy an ecoinvent activity to your foreground database and modify it but keeping old exchanges, which was my case.

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

No branches or pull requests

2 participants