Search code examples
pythonbrightway

Imported xlsx database loses internal interlinking Brightway


I have two questions concerning the import of databases in Brightway:

  1. How do I import .bw2package files? Maybe it's banal but I couldn't find a dedicated importer function.
  2. Since I couldn't solve point n.1, I exported the database in xlsx format using the Activity Browser. I then imported the file with the ExcelImporter function in a Jupyter Notebook and proceeded to match the database to Ecoinvent. My problem is that in the database I'm working with there are activities that are interlinked (e.g. one is an input for another), but these exchanges result unlinked. While I know how to match a database to another one, I don't know how to restore the matches inside the database itself. I don't have this problem with the same dataset in SimaPro format so it shouldn't be an error in the procedure (unless I'm missing a specific step for xlsx files). I don't know if it might be relevant, but some of the activities have no location.

Has anyone had similar problems or knows how to solve them? Thanks a lot!

I imported the file, did a migration and matched the dataset, used link_iterable_by_fields to link the activities to a new ecoinvent, and there observed that there were many unlinked activities that were those that should link internally to an activity in the same database. When I try to write the database I get an error. for exchange in ds.get('exchanges', []): 155 if 'input' not in exchange or 'amount' not in exchange: --> 156 raise InvalidExchange 157 if 'type' not in exchange: 158 raise UntypedExchange

The same procedure went smoothly when using the same database in SimaPro format


Solution

  • It is indeed not very clear in the documentation

    bw2io.BW2Package.import_file(path_to_file)