brightway-lca / brightway2-io

Importing and exporting for the Brightway LCA framework
BSD 3-Clause "New" or "Revised" License
26 stars 40 forks source link

WrongDatabase: Activity database must be ecoinvent_3_8, but set() was also found #261

Open pymusa-09 opened 1 month ago

pymusa-09 commented 1 month ago

I have ecoinvent_38_cutoff_3011_with_methods.zolca, which I can open in OpenLCA without any issues. My code integrates Brightway2 and therefore I exported all the processes and impact methods to EcoSpold and successfully exported all the data. The data files are XML format.

Now when I am trying to create a database..for example;

import brightway2 as bw import bw2io from bw2io import strategies

Set the current project

bw.projects.set_current('ecoinvent_38_import')

Ensure biosphere database is set up

if 'biosphere3' not in bw.databases: bw.bw2setup()

Path to the extracted ecoinvent files

ecoinvent_path = r'D:/LCAmodel/EcoSpold01'

Verify if the path exists and is a directory

import os if not os.path.isdir(ecoinvent_path): raise ValueError(f"dirpath value was not a directory: {ecoinvent_path}")

Initialize the importer

importer = bw2io.SingleOutputEcospold2Importer(ecoinvent_path, 'ecoinvent_3_8')

Apply strategies

importer.apply_strategies()

Check statistics

print("Initial import statistics:", importer.statistics())

Apply additional linking strategies

strategies.link_biosphere_by_flow_uuid(importer) strategies.link_internal_technosphere_by_composite_code(importer)

Check statistics again

print("Post-linking import statistics:", importer.statistics())

expected_db_name = 'ecoinvent_3_8' if importer.db_name != expected_db_name: raise ValueError(f"Database name mismatch: expected {expected_db_name}, found {importer.db_name}")

Write the database

importer.write_database()

Debug unlinked exchanges if they exist

unlinked = importer.unlinked if unlinked: print("Unlinked exchanges found:", unlinked)

The database is not created and it says; 0 datasets 0 exchanges 0 unlinked exchanges

Initial import statistics: (0, 0, 0) 0 datasets 0 exchanges 0 unlinked exchanges

Post-linking import statistics: (0, 0, 0) Traceback (most recent call last):WrongDatabase: Activity database must be ecoinvent_3_8, but set() was also found

Please guide me on where is the issue coming from. Thank you in advance

cmutel commented 1 month ago

Can you please add:

pymusa-09 commented 1 month ago

bw2data 3.6.6 bw2io 0.8.12 I have ecoinvent databases from my university in .zolca format. That is why I am converted to ecospold from openLCA...Can you please guide me accordingly. Thank you 1 2ecospold

pymusa-09 commented 1 month ago

Any idea how to solve this issue?

pymusa-09 commented 1 month ago

dataset dataset2