michaelweinold / pylcaio

A Python class that structures, manipulates and facilitates the hybridization of life cycle assessment and environmentally extended input output at the process or database level.
GNU General Public License v2.0
0 stars 0 forks source link

`calc_lifecycle` throws error `WrongDatabase` #9

Open michaelweinold opened 2 years ago

michaelweinold commented 2 years ago

When trying to run the calc_lifecycle() method of the pylcaio.Analysis class on a hybridized database based on Ecoinvent 3.5:

analysis_object = pylcaio.Analysis(path_file_hybrid)
analysis_object.calc_lifecycle()

the following error is thrown:

---------------------------------------------------------------------------
WrongDatabase                             Traceback (most recent call last)
File <timed eval>:1

File ~/pylcaio/src/pylcaio.py:2174, in Analysis.export_to_brightway2(self, bw2_project_name, created_database_name, path_to_ecoinvent_ecospold_datasets, aggregated)
   2172 eco_importer = SingleOutputEcospold2Importer(path_to_ecoinvent_ecospold_datasets, 'hybrid-ecoinvent')
   2173 eco_importer.apply_strategies()
-> 2174 eco_importer.write_database()
   2176 if not aggregated:
   2177     # importing exiobase into the project
   2178     self.import_exiobase_into_brightway2()

File ~/miniconda3/envs/hybridization/lib/python3.10/site-packages/bw2io/importers/base_lci.py:237, in LCIImporter.write_database(self, data, delete_existing, backend, activate_parameters, **kwargs)
    233 if {o["database"] for o in data} != {self.db_name}:
    234     error = "Activity database must be {}, but {} was also found".format(
    235         self.db_name, {o["database"] for o in data}.difference({self.db_name})
    236     )
--> 237     raise WrongDatabase(error)
    238 if len({o["code"] for o in data}) < len(data):
    239     seen, duplicates = set(), []

WrongDatabase: Activity database must be hybrid-ecoinvent, but set() was also found
cmutel commented 2 years ago

So, when writing the database there is an activity dictionary with the key "database" and the value set(). This is an error at some other point where the database key was set. I wonder if it is the same for all activities?

michaelweinold commented 2 years ago

calc_lifecycle() works fine for a hybridized databased based on Ecoinvent 3.8.