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

`export_to_brightway2` throws error `AssertionError` #11

Closed michaelweinold closed 2 years ago

michaelweinold commented 2 years ago

Attempting to write to brightway2 using

analysis_object.export_to_brightway2(
    bw2_project_name = 'apples',
    created_database_name = 'bananas',
    path_to_ecoinvent_ecospold_datasets = path_dir_ecoinvent_input,
    aggregated = True
)

and the hybridized database ~/hybridization_data/databases_hybrid/hybrid_ecoinvent_3_5_exiobase_monetary_pxp_2012.pickle throws the error:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/home/weinold/github/Autumn-School-2022/tutorials/hybridization/0_1_pylcaio_debugging.ipynb Cell 11 in <cell line: 1>()
----> [1](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/Autumn-School-2022/tutorials/hybridization/0_1_pylcaio_debugging.ipynb#X13sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0) analysis_object.export_to_brightway2(
      [2](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/Autumn-School-2022/tutorials/hybridization/0_1_pylcaio_debugging.ipynb#X13sdnNjb2RlLXJlbW90ZQ%3D%3D?line=1)     bw2_project_name = 'apples',
      [3](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/Autumn-School-2022/tutorials/hybridization/0_1_pylcaio_debugging.ipynb#X13sdnNjb2RlLXJlbW90ZQ%3D%3D?line=2)     created_database_name = 'hybrid-ecoinvent',
      [4](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/Autumn-School-2022/tutorials/hybridization/0_1_pylcaio_debugging.ipynb#X13sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3)     path_to_ecoinvent_ecospold_datasets = path_dir_ecoinvent_input,
      [5](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/Autumn-School-2022/tutorials/hybridization/0_1_pylcaio_debugging.ipynb#X13sdnNjb2RlLXJlbW90ZQ%3D%3D?line=4)     aggregated = True
      [6](vscode-notebook-cell://ssh-remote%2Bhetzner/home/weinold/github/Autumn-School-2022/tutorials/hybridization/0_1_pylcaio_debugging.ipynb#X13sdnNjb2RlLXJlbW90ZQ%3D%3D?line=5) )

File ~/pylcaio/src/pylcaio.py:2177, in Analysis.export_to_brightway2(self, bw2_project_name, created_database_name, path_to_ecoinvent_ecospold_datasets, aggregated)
   2172 BW2Package.import_file(pkg_resources.resource_stream(__name__, '/Data/for_export_in_brightway2/'
   2173                                                                'laurepatou-IMPACT-World-in-Brightway-d949b33/'
   2174                                                                'Brightway_IW_damage_1_46_and_midpoint_1_28.bw2package'))
   2176 # importing hybrid-ecoinvent into the project
-> 2177 eco_importer = SingleOutputEcospold2Importer(path_to_ecoinvent_ecospold_datasets, 'hybrid-ecoinvent')
   2178 eco_importer.apply_strategies()
   2179 eco_importer.write_database()

File ~/miniconda3/envs/hybridization/lib/python3.8/site-packages/bw2io/importers/ecospold2.py:71, in SingleOutputEcospold2Importer.__init__(self, dirpath, db_name, extractor, use_mp, signal)
     69 start = time()
     70 try:
---> 71     self.data = extractor.extract(dirpath, db_name, use_mp=use_mp)
     72 except RuntimeError as e:
     73     raise MultiprocessingError(
     74         "Multiprocessing error; re-run using `use_mp=False`"
     75     ).with_traceback(e.__traceback__)

File ~/miniconda3/envs/hybridization/lib/python3.8/site-packages/bw2io/extractors/ecospold2.py:61, in Ecospold2DataExtractor.extract(cls, dirpath, db_name, use_mp)
     59 @classmethod
     60 def extract(cls, dirpath, db_name, use_mp=True):
---> 61     assert os.path.exists(dirpath)
     62     if os.path.isdir(dirpath):
     63         filelist = [
     64             filename
     65             for filename in os.listdir(dirpath)
     66             if os.path.isfile(os.path.join(dirpath, filename))
     67             and filename.split(".")[-1].lower() == "spold"
     68         ]

AssertionError:
michaelweinold commented 2 years ago

This is caused by path_to_ecoinvent_ecospold_datasets leading to a nonexistent directory.