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

field equality strategy and default location strategy #167

Closed BenPortner closed 1 year ago

BenPortner commented 1 year ago

This PR adds two new generic strategies:

1) bw2io.strategies.generic.overwrite_exchange_field_values: The new ExchangeLinker class introduced in f5c9d28 allows "soft-matches", i.e. an exchange field exchange["categories"] = "(air,)" will be identified as matching an activity activity["categories"] = ("air",). However, this means that the exchange data in the database contains a string instead of a tuple. This might be undesirable in some use cases. The new strategy fixes this by going through all exchanges and overwriting their fields with values from the linked activities.

2) bw2io.strategies.generic.assign_default_location: Brightway allows defining activities without a location field. However, tools like the Activity Browser Sankey Diagram expect a location field and will break if there isn't any. This strategy goes through all activities and applies a default_loc where locations are missing.

BenPortner commented 1 year ago

This should be good to merge. Requesting review @cmutel

cmutel commented 1 year ago

Will be in DEV20 release. Would be lovely if this was followed up with even basic tests.