导入ecoinvent 3.2/3.3后果导向版本时未关联交换错误咨询
It sounds like you're hitting a common compatibility gap between older ecoinvent consequential databases and Brightway2's default biosphere setup. Let's break down why this happens and how to fix it:
Why the Problem Occurs
- ecoinvent 3.2/3.3 consequential versions have biosphere flows that don't perfectly align with Brightway's default
biosphere3database (which is optimized for newer ecoinvent releases). - The
bw.add_ecoinvent_33_biosphere_flows()function often fails to properly load the 3.3-specific biosphere flows, leaving gaps for consequential-exclusive exchanges. - Cutoff versions (like 3.3 cutoff) use a more standardized set of flows that match
biosphere3better, hence no issues. ecoinvent 3.4+ also updated its flow naming/categorization to align with Brightway's defaults.
Step-by-Step Solutions
1. Manually Import the ecoinvent 3.3 Biosphere Database
Skip the unreliable add_ecoinvent_33_biosphere_flows() function and load the 3.3 biosphere directly from your ecoinvent files:
# Replace with your actual path to the ecoinvent 3.3 biosphere folder biosphere_33_path = "/path/to/ecoinvent-3.3/biosphere" # Create and write the 3.3 biosphere database biosphere_importer = bw.BiosphereImporter(biosphere_33_path, "biosphere33") biosphere_importer.apply_strategies() biosphere_importer.write_database()
This ensures you have the exact biosphere flows needed for 3.3 consequential imports.
2. Adjust Import Strategies to Link Unmatched Exchanges
After applying default strategies, manually target the unlinked exchanges using field-based matching with the new biosphere33 database:
# First run default strategies as before ei33consequential = bw.SingleOutputEcospold2Importer(path, "ei_33con") ei33consequential.apply_strategies() # Import the matching strategy from bw2io.strategies import link_iterable_by_fields # Link unlinked exchanges to the 3.3 biosphere ei33consequential.apply_strategy(link_iterable_by_fields( ei33consequential.unlinked, bw.Database("biosphere33"), fields=("name", "categories", "unit") # Match on core identifiers )) # Check if unlinked exchanges are resolved ei33consequential.statistics()
3. Rename Mislabeled Exchanges (If Needed)
Some flows like residual wood, dry or venting of nitrogen, liquid might have naming discrepancies between the consequential database and biosphere. Fix this with a rename strategy:
from bw2io.strategies import rename_exchanges # Map problematic names to their exact matches in biosphere33 rename_mapping = { "residual wood, dry": "residual wood, dry, in ground", # Adjust to match your biosphere33 entry "venting of nitrogen, liquid": "nitrogen, liquid, vented" } # Apply the rename before relinking ei33consequential.apply_strategy(rename_exchanges(rename_mapping)) ei33consequential.apply_strategy(link_iterable_by_fields( ei33consequential.unlinked, bw.Database("biosphere33"), fields=("name", "categories", "unit") ))
4. Verify and Write the Database
Once ei33consequential.statistics() shows 0 unlinked exchanges, you can safely write the database:
ei33consequential.write_database()
For ecoinvent 3.2 consequential, repeat the same process but use the 3.2 biosphere database instead of 3.3.
内容的提问来源于stack exchange,提问作者mfastudillo

