polca / premise

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

Issue with matching IAM model location prevents writing the database to BW25 #147

Closed Michael-ljn closed 5 months ago

Michael-ljn commented 5 months ago

I have started my transition to brightway2.5 and installed premise 1.8.0. No matter what I try, premise does not work. I have installed via pip, then conda. same result. there is an issue with matching the location of the IAM model somehow.

plci2030="remind - SSP2-Base - 2030"

if "plci2030" in bd.databases:
    print(f" databases has already been imported.")
else:
    ndb = NewDatabase(
        scenarios=[
            {"model":"remind", "pathway":"SSP2-Base", "year":2030},],
        source_db= ei_name, # <-- name of the database in the BW25 project.
        source_version="3.9.1", # <-- version of ecoinvent.
        key='xxxxxxxxxxxxxx' )

which runs ok. but when running ndb.update_all(), I get the following:

---------------------------------------------------------------------------
RemoteTraceback                           Traceback (most recent call last)
RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/Users/mickael/anaconda3/envs/bw/lib/python3.11/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/Users/mickael/anaconda3/envs/bw/lib/python3.11/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mickael/anaconda3/envs/bw/lib/python3.11/site-packages/premise/ecoinvent_modification.py", line 437, in _update_all
    scenario, modified_datasets, cache = _update_vehicles(
                                         ^^^^^^^^^^^^^^^^^
  File "/Users/mickael/anaconda3/envs/bw/lib/python3.11/site-packages/premise/transport.py", line 42, in _update_vehicles
    trspt = Transport(
            ^^^^^^^^^^
  File "/Users/mickael/anaconda3/envs/bw/lib/python3.11/site-packages/premise/transport.py", line 475, in __init__
    super().__init__(
  File "/Users/mickael/anaconda3/envs/bw/lib/python3.11/site-packages/premise/transformation.py", line 288, in __init__
    self.ecoinvent_to_iam_loc: Dict[str, str] = {
                                                ^
  File "/Users/mickael/anaconda3/envs/bw/lib/python3.11/site-packages/premise/transformation.py", line 289, in <dictcomp>
    loc: self.geo.ecoinvent_to_iam_location(loc)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mickael/anaconda3/envs/bw/lib/python3.11/site-packages/premise/geomap.py", line 166, in ecoinvent_to_iam_location
    raise ValueError(f"Could not find equivalent for {location}.")
ValueError: Could not find equivalent for IAI Area, EU27 & EFTA.
"""

if I skip ndb.update_all() and proceed to writing the database, it's something similar.

Write new database(s) to Brightway.
Cannot find the IAM location for IN-AS from IAM model remind.
Cannot find the IAM location for US-WECC from IAM model remind.
Cannot find the IAM location for BR-Southern grid from IAM model remind.
Cannot find the IAM location for BR-AM from IAM model remind.
Cannot find the IAM location for CN-GX from IAM model remind.
Cannot find the IAM location for BR-AC from IAM model remind.
Cannot find the IAM location for SS from IAM model remind.
Cannot find the IAM location for TG from IAM model remind.
Cannot find the IAM location for TH from IAM model remind.
{
    "name": "ValueError",
    "message": "Could not find equivalent for CN-NECG.",
    "stack": "---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[11], line 3
      1 # ndb.update_all()
      2 # ndb.write_superstructure_db_to_brightway()
----> 3 ndb.write_db_to_brightway(plci2030)

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/premise/ecoinvent_modification.py:1451, in NewDatabase.write_db_to_brightway(self, name)
   1448 cache = {}
   1450 for scenario in self.scenarios:
-> 1451     scenario, cache = _prepare_database(
   1452         scenario=scenario,
   1453         scenario_cache=cache,
   1454         version=self.version,
   1455         system_model=self.system_model,
   1456         modified_datasets=self.modified_datasets,
   1457     )
   1459 for scen, scenario in enumerate(self.scenarios):
   1460     write_brightway_database(
   1461         scenario[\"database\"],
   1462         name[scen],
   1463     )

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/premise/export.py:1068, in _prepare_database(scenario, scenario_cache, version, system_model, modified_datasets)
   1065 def _prepare_database(
   1066     scenario, scenario_cache, version, system_model, modified_datasets
   1067 ):
-> 1068     scenario[\"database\"], scenario_cache = prepare_db_for_export(
   1069         scenario,
   1070         cache=scenario_cache,
   1071         name=\"database\",
   1072         version=version,
   1073         system_model=system_model,
   1074         modified_datasets=modified_datasets,
   1075     )
   1077     return scenario, scenario_cache

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/premise/export.py:982, in prepare_db_for_export(scenario, cache, name, version, system_model, modified_datasets)
    979 def prepare_db_for_export(
    980     scenario, cache, name, version, system_model, modified_datasets
    981 ):
--> 982     base = BaseTransformation(
    983         database=scenario[\"database\"],
    984         iam_data=scenario[\"iam data\"],
    985         model=scenario[\"model\"],
    986         pathway=scenario[\"pathway\"],
    987         year=scenario[\"year\"],
    988         version=version,
    989         system_model=system_model,
    990         cache=cache,
    991         modified_datasets=modified_datasets,
    992     )
    994     # we ensure the absence of duplicate datasets
    995     # print(\"- check for duplicates...\")
    996     base.database = check_for_duplicates(base.database)

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/premise/transformation.py:288, in BaseTransformation.__init__(self, database, iam_data, model, pathway, year, version, system_model, modified_datasets, cache)
    285         self.fuel_map_reverse[v] = key
    287 self.material_map: Dict[str, Set] = mapping.generate_material_map()
--> 288 self.ecoinvent_to_iam_loc: Dict[str, str] = {
    289     loc: self.geo.ecoinvent_to_iam_location(loc)
    290     for loc in self.get_ecoinvent_locs()
    291 }

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/premise/transformation.py:289, in <dictcomp>(.0)
    285         self.fuel_map_reverse[v] = key
    287 self.material_map: Dict[str, Set] = mapping.generate_material_map()
    288 self.ecoinvent_to_iam_loc: Dict[str, str] = {
--> 289     loc: self.geo.ecoinvent_to_iam_location(loc)
    290     for loc in self.get_ecoinvent_locs()
    291 }

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/premise/geomap.py:166, in Geomap.ecoinvent_to_iam_location(self, location)
    163         return self.additional_mappings[location][self.model]
    165     # likely a case of missing \"EUR\" region
--> 166     raise ValueError(f\"Could not find equivalent for {location}.\")
    168 # If not, then we look for IAM regions that contain it
    169 try:

ValueError: Could not find equivalent for CN-NECG."
}

Is there a stable version for BW25 available?

romainsacchi commented 5 months ago

Hi @Michael-ljn you should try upgrading premise to 1.2.8.dev7 (pip install premise==1.8.2.dev7). It's still in development, but I will release a stable version very soon.

Michael-ljn commented 5 months ago

Hi @romainsacchi, thanks for this, and sorry for replying this late. I upgraded to 1.2.8.dev7 and I confirm that the issue is resolved.