USEPA / ElectricityLCI

Creative Commons Zero v1.0 Universal
24 stars 10 forks source link

ELCI_3 gen mix dictionary not writing ... #60

Closed WesIngwersen closed 5 years ago

WesIngwersen commented 5 years ago

Using the model config that recreates the old EPA ELCI_3, it works except the generation_mix dictionary is not being written. The attached script shows the errors.

Changes were made to the olcaschema_genmix function including a matching_dict check which looks up processes in the process dictionaries matching by name. It finds processes but those processes do not have a uuid field. I guess that there was a change at some point to add the uuid field to the generation process dictionaries before JSON-LD creation? Previously, the process UUIDs were not created until the JSON-LD files were created in olca_jsonld_writer.

WesIngwersen commented 5 years ago

import electricitylci

Select model ELCI_3

from electricitylci.utils import fill_default_provider_uuids

all_generation_db = electricitylci.get_generation_process_df()

all_gen_dict = electricitylci.write_generation_process_database_to_dict(all_generation_db)

all_gen_mix_db = electricitylci.get_generation_mix_process_df() all_gen_mix_dict = electricitylci.write_generation_mix_database_to_dict(all_gen_mix_db,all_gen_dict)

Fails

Traceback (most recent call last):

File "C:\Users\wesle\AppData\Local\Programs\Python\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code

exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 1, in

all_gen_mix_dict = electricitylci.write_generation_mix_database_to_dict(all_gen_mix_db,all_gen_dict)

File "C:\Users\wesle\ElectricityLCI\electricitylci__init__.py", line 229, in write_generation_mix_database_to_dict

genmix_database, gen_dict, subregion=regions

File "C:\Users\wesle\ElectricityLCI\electricitylci\generation_mix.py", line 337, in olcaschema_genmix

"@id": matching_dict["uuid"],

KeyError: 'uuid'

Try to use the util function to fill default providers

all_gen_dict = fill_default_provider_uuids(all_gen_dict)

Fails with same error

Traceback (most recent call last):

File "C:\Users\wesle\AppData\Local\Programs\Python\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code

exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 1, in

all_gen_mix_dict = electricitylci.write_generation_mix_database_to_dict(all_gen_mix_db,all_gen_dict)

File "C:\Users\wesle\ElectricityLCI\electricitylci__init__.py", line 229, in write_generation_mix_database_to_dict

genmix_database, gen_dict, subregion=regions

File "C:\Users\wesle\ElectricityLCI\electricitylci\generation_mix.py", line 337, in olcaschema_genmix

"@id": matching_dict["uuid"],

KeyError: 'uuid'

WesIngwersen commented 5 years ago

Actually I found, using your modified build_model.py example, that adding the code all_gen_dict=electricitylci.write_process_dicts_to_jsonld(all_gen_dict) before all_gen_mix_dict = electricitylci.write_generation_mix_database_to_dict(all_gen_mix_db,all_gen_dict) modifies the dict to add the uuid field, so then it no longer causes the error. Closing the issue