Error in writing superstructure
I was trying to write the scenarios created from ecoinvent 3.7.1 based on the inbuilt scenarios using: ndb.write_superstructure_db_to_brightway(name="test_superstructure"),
It gave me an error of: UnknownObject: Exchange between ('biosphere3', 'e030108f-2125-4bcb-a73b-ad72130fcca3') and ('test_superstructure', '00110620-4d86-4fd5-82d3-3cf415a4b941') is invalid - one of these objects is unknown (i.e. doesn't exist as a process dataset)
Does anyone know what unknown object it is referring to and how to solve this problem? Thanks
Hi @OliverLyon, can you paste the script you used?
@OliverLyon can you check that you have a flow called:
Nickel, ion with the compartment water, ground in your biosphere database in the project to which you are trying to expert the superstructure database?
Hi @OliverLyon, can you paste the script you used?
Hi @romainsacchi, the script is pasted below:
from bw2data import databases print(databases) from bw2data import Database import bw2data as bw bw.databases import bw2calc as bc import bw2io as bi from premise import * clear_inventory_cache()
ndb = NewDatabase(
scenarios = [
{"model": "REMIND", "pathway": "SSP1-NPi", "year": 2020},
{"model": "REMIND", "pathway": "SSP1-NPi", "year": 2030},
{"model": "REMIND", "pathway": "SSP1-NPi", "year": 2040},
{"model": "REMIND", "pathway": "SSP1-NPi", "year": 2050},
],
source_type="ecospold",
source_file_path=r"C:\Users\EcoInvent\ecoinvent 3.7.1_cutoff_ecoSpold02\datasets",
source_version="3.7.1",
key='tUePmX_S5B8ieZkkM7WUU2CnO8SmShwmAeWK9x2rTFo=',
use_cached_inventories=True, # This will use any cached inventories
keep_source_db_uncertainty=False, # False by default, set to True if you want to keep ecoinvent's uncertainty data
keep_imports_uncertainty=False, # False by default, set to True if you want to keep the uncertainty data of the additional inventories
use_absolute_efficiency=False, # False by default, set to True if you want to use the IAM's absolute efficiencies
)
ndb.write_superstructure_db_to_brightway(name="test_superstructure"),
cx
@OliverLyon can you check that you have a flow called:
Nickel, ionwith the compartmentwater, groundin yourbiospheredatabase in the project to which you are trying to expert the superstructure database?
I used the following code to check the flow Nickel, ion:
import bw2data as bd import bw2io
bd.projects.set_current('yourProject')
importer = SingleOutputEcospold2Importer( r"C:\Users\Desktop\EcoInvent\ecoinvent 3.7.1_cutoff_ecoSpold02\datasets", "ecoinvent_ecospold" ) importer.apply_strategies() importer.statistics()
importer.drop_unlinked(True)
importer.write_database()
bio = bd.Database(db_name)
nickel_ion_flows = bio.search('Nickel, ion')
filtered_flows = [flow for flow in nickel_ion_flows if 'water, ground' in flow['categories']]
if filtered_flows: for flow in filtered_flows: print(f"Flow code: {flow['code']}") print(f"Flow details: {flow.dict}") else: print("No flows found for 'Nickel, ion' in 'water, ground'.")
I gave me an output of 'No flows found for 'Nickel, ion' in 'water, ground'.
Is it the correct way to check the flow?
Not exactly. This flow should be found in your biosphere3 database, not the ecoinvent one. Your brightway project yourProject should contain a biosphere3 database listing all environmental flows.
@OliverLyon, has your brightway project been created using an old activity-browser version? In activity-browser <2.9, biosphere databases were incorrectly created. I suggest ensuring you have the latest activity-browser version (2.10.3) and then create a new project to ensure you have a correct biosphere database. Alternatively, you can use bw2io 0.8.12 to create such project.
@OliverLyon, has your
brightwayproject been created using an oldactivity-browserversion? Inactivity-browser <2.9,biospheredatabases were incorrectly created. I suggest ensuring you have the latestactivity-browserversion (2.10.3) and then create a new project to ensure you have a correctbiospheredatabase. Alternatively, you can usebw2io 0.8.12to create such project.
No, did not use activity browser for the project, right now I'm just trying to import the database file and output the superstructure with scenarios.
Hello! im having a very similar problem. (Exchange between ('biosphere3', 'ed9d969e-f77b-5f66-aa23-1b43ec0e9fa1') and ('ei_cutoff_3.10_remind_SSP2-Base_2030 2024-12-20', '0098430e52a85232e41363ad5a2d33b2') is invalid - one of these objects is unknown (i.e. doesn't exist as a process dataset)")
This is the script that im using: import brightway25 as bw import premise import getpass from bw2data import projects, Database, databases
Set up Brightway project
BW_PROJECT = 'premise_project' # name your project EI_DATABASE = 'ecoinvent-3.10-cutoff' # Select a database
bw.projects.set_current(BW_PROJECT)
Validate biosphere3 database
if "biosphere3" not in databases: print("Registering biosphere3...") from bw2io import create_default_biosphere3 create_default_biosphere3()
Check if ecoinvent database is already imported; if not, proceed with import
if EI_DATABASE in bw.databases: print('Ecoinvent database already installed') else: # Prompt for ecoinvent credentials EI_USERNAME = input("Enter your ecoinvent username: ") EI_PASS = getpass.getpass("Enter your ecoinvent password: ")
# Import ecoinvent database with cutoff system model
bw.import_ecoinvent_release(
version="3.10",
system_model='cutoff',
username=EI_USERNAME,
password=EI_PASS
)
print(f"Ecoinvent {EI_DATABASE} database imported successfully.")
and:
from premise import * import bw2data
Step 3: Migrate the Project to Brightway 2.5 Format
#print("Migrating the project to Brightway 2.5 format if necessary...") #bw2data.projects.migrate_project_25() #print("Project migration completed.")
Activate the Brightway project
bw2data.projects.set_current("premise_project") # Select the project where you want the database to be created #If you are using Activity Browser, this is the same project you access thorugh the interface
List currently installed databases
print("Databases in the project:", bw2data.databases)
Define the IAM scenarios for 2030, 2040, and 2050
scenarios = [ {"model": "remind", "pathway": "SSP2-Base", "year": 2030}, {"model": "remind", "pathway": "SSP2-Base", "year": 2040}, {"model": "remind", "pathway": "SSP2-Base", "year": 2050}, ]
Create the Premise NewDatabase object
ndb = NewDatabase( scenarios=scenarios, # Scenarios to process source_db="ecoinvent-3.10-cutoff", # Source database name source_version="3.10", # Version of ecoinvent key='XXXXXXXXXXXXXX', # An actual decryption key keep_source_db_uncertainty=True, # Keep ecoinvent uncertainty data keep_imports_uncertainty=True, # Keep uncertainty in additional inventories use_absolute_efficiency=True, # Use IAM's absolute efficiencies quiet=False # Show detailed logs )
Update all sectors with IAM data
print("Updating database with IAM scenarios...") ndb.update() # Apply transformations to electricity, transport, fuels, etc.
Step 1: Rename Databases for Simplicity
simple_names = { "ei_cutoff_3.10_remind_SSP2-Base_2030": "premise_2030", "ei_cutoff_3.10_remind_SSP2-Base_2040": "premise_2040", "ei_cutoff_3.10_remind_SSP2-Base_2050": "premise_2050", }
Step 2: Register Databases with Simple Names
for original_name, simple_name in simple_names.items(): print(f"Renaming {original_name} to {simple_name}...") db = Database(original_name) db.name = simple_name db.register() print(f"Database {original_name} renamed to {simple_name} and registered.")
Optional: Superstructure Database
This step is skipped if simple naming is only needed for individual databases
ndb.write_superstructure_db_to_brightway()
print("Premise scenarios for 2030, 2040, and 2050 successfully created, renamed, and registered!")
Write individual databases
ndb.write_db_to_brightway()
Thanks a lot,
Hi @33nickels , you do not need to run the biosphere function.
Create a project, and run the bw.import_ecoinvent_release() function directly.