polca / premise

Coupling Integrated Assessment Models output with Life Cycle Assessment.
BSD 3-Clause "New" or "Revised" License
100 stars 45 forks source link

An Issue related to "write_db_to" function #168

Closed MMahdi97 closed 2 weeks ago

MMahdi97 commented 1 month ago

Hello everyone,

I have used ecoinvent database version 3.9 cut off and remind SSP2-Base scenario to creat a database, but when I want to use ndb.write_db_to_simapro() there is an error that I cannot understand what I should do. Here is the error: image

This code worked several days ago, but it does not work now. Could someone please help me to solve it?

romainsacchi commented 1 month ago

I will look into this, thx.

B-Maes commented 1 month ago

I get a similar issue for the consequential version if I do not update electricity. If I do update electricity, I get the following error:

Schermafbeelding 2024-06-03 083122
MMahdi97 commented 1 month ago

I think it is related to the premise version. I think the last version which is 2.1 has some bugs. I have installed an older version and it works.

lolow commented 1 month ago

I have the same bug with 2.1. Which version did you use @MMahdi97 :question: Thanks!

lolow commented 1 month ago

I have the same bug with 2.1. Which version did you use @MMahdi97 ❓ Thanks!

I managed to use write_db_to_brightway using version 2.0.0

romainsacchi commented 1 month ago

I’ll have a look and provide a fix shortly.Can someone paste the script used to generate this error?On 4 Jun 2024, at 10:28, Laurent Drouet @.***> wrote:

I have the same bug with 2.1. Which version did you use @MMahdi97 ❓ Thanks!

I managed to use write_db_to_brightway using version 2.0.0

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

lolow commented 1 month ago

Here is the script (based on the example one)

import brightway2 as bw
bw.projects.set_current("iamc_db_test")
bw.bw2setup()
if 'ecoinvent 3.9.1_cutoff_ecoSpold02' in bw.databases:
    print("Database has already been imported.")
else:
    # The ecoinvent file must be unzipped; then: path to the datasets subfolder
    dir_ei391cut = r"datasets"
    ei391cut = bw.SingleOutputEcospold2Importer(dir_ei391cut, 'ecoinvent 3.9.1_cutoff_ecoSpold02')
    ei391cut
    ei391cut.apply_strategies()
    ei391cut.statistics()
    ei391cut.write_database()
from premise import *

ndb = NewDatabase(
    scenarios=[
        {"model":"image", "pathway":"SSP2-RCP19", "year":2050},
        {"model":"remind", "pathway":"SSP2-PkBudg500", "year":2050},
    ],
    source_db="ecoinvent 3.9.1_cutoff_ecoSpold02", # <-- name of the database in the BW2 project. Must be a string.
    source_version="3.9.1", # <-- version of ecoinvent. Can be "3.5", "3.6", "3.7" or "3.8". Must be a string.
    key='xx', # <-- decryption key
    # to be requested from the library maintainers if you want ot use default scenarios included in `premise`
    #use_multiprocessing=True, # True by default, set to False if multiprocessing is causing troubles
    keep_uncertainty_data=False, # False by default, set to True if you want to keep ecoinvent's uncertainty data
    use_absolute_efficiency=True, # False by default, set to True if you want to use the IAM's absolute efficiency for power plants
)
ndb.write_db_to_brightway()
MMahdi97 commented 1 month ago

@lolow I am using premise 2.0.2

@romainsacchi Before I was using 2.1 and I had the problem.

romainsacchi commented 1 month ago

Here is the script (based on the example one)

import brightway2 as bw
bw.projects.set_current("iamc_db_test")
bw.bw2setup()
if 'ecoinvent 3.9.1_cutoff_ecoSpold02' in bw.databases:
    print("Database has already been imported.")
else:
    # The ecoinvent file must be unzipped; then: path to the datasets subfolder
    dir_ei391cut = r"datasets"
    ei391cut = bw.SingleOutputEcospold2Importer(dir_ei391cut, 'ecoinvent 3.9.1_cutoff_ecoSpold02')
    ei391cut
    ei391cut.apply_strategies()
    ei391cut.statistics()
    ei391cut.write_database()
from premise import *

ndb = NewDatabase(
    scenarios=[
        {"model":"image", "pathway":"SSP2-RCP19", "year":2050},
        {"model":"remind", "pathway":"SSP2-PkBudg500", "year":2050},
    ],
    source_db="ecoinvent 3.9.1_cutoff_ecoSpold02", # <-- name of the database in the BW2 project. Must be a string.
    source_version="3.9.1", # <-- version of ecoinvent. Can be "3.5", "3.6", "3.7" or "3.8". Must be a string.
    key='xx', # <-- decryption key
    # to be requested from the library maintainers if you want ot use default scenarios included in `premise`
    #use_multiprocessing=True, # True by default, set to False if multiprocessing is causing troubles
    keep_uncertainty_data=False, # False by default, set to True if you want to keep ecoinvent's uncertainty data
    use_absolute_efficiency=True, # False by default, set to True if you want to use the IAM's absolute efficiency for power plants
)
ndb.write_db_to_brightway()

Hi @lolow , here the issue is that you do not apply any scenario integration (ndb.update()) before writing the database to the brightway project. So, there is not, at this point in your script, an existing database yet. If you did not have this error, the database you would export back would anyway not be "prospective" since it would be a mere copy of the original LCA database. I will provide a more informative error message.

romainsacchi commented 1 month ago

I have the same bug with 2.1. Which version did you use @MMahdi97 ❓ Thanks!

I managed to use write_db_to_brightway using version 2.0.0

And the reason it worked with an earlier version is because of how we store databases (so you are able to write the database in v.2.0 but that database is not transformed yet based on the IAM scenario. But in summary, you can use the latest version, and add a "transformation" step before writing the database (e.g., ndb.update()).

romainsacchi commented 1 month ago

Hello everyone,

I have used ecoinvent database version 3.9 cut off and remind SSP2-Base scenario to creat a database, but when I want to use ndb.write_db_to_simapro() there is an error that I cannot understand what I should do. Here is the error: image

This code worked several days ago, but it does not work now. Could someone please help me to solve it?

Hi @MMahdi97, similar to @lolow : could it be you did not run the transformation step (ndb.update()) before writing the database?

lolow commented 1 month ago

I confirm that doing ndb.update() before ndb.write_db_to_brightway() is solving the issue.

romainsacchi commented 1 month ago

Hello @B-Maes @MMahdi97, I believe v.2.1.1.dev0 should fix these issues now. Please let me know.