brightway-lca / brightway2-data

Tools for the management of inventory databases and impact assessment methods. Part of the Brightway LCA framework.
https://docs.brightway.dev/
BSD 3-Clause "New" or "Revised" License
11 stars 24 forks source link

Set node types when writing a `Database` #193

Closed cmutel closed 1 month ago

cmutel commented 1 month ago

This PR adds a utility function set_correct_process_type and applies it when writing Database data. This means that every node written to the datastore will have a type attribute (before this could be missing or None). We also differentiate process and processwithreferenceproduct nodes, and fix nodes with the type process which should be processwithreferenceproduct.

This PR allows for GUIs to cleanly differentiate LCI node types in their data tables. Only nodes with types product and processwithreferenceproduct can be used as functional units (but please don't hard-code these values, use bw2data.labels.product_node_types and bw2data.labels.chimaera_node_default).

A processwithreferenceproduct node is one which consumes or produces its own product - i.e. this node exists as both a row and column in the technosphere matrix. Contrast this with process, which is only a column in the matrix, and consumes and produces products, which are rows.

Eventually we should phase out processwithreferenceproduct as this makes the code more complicated and prone to errors. It is much cleaner and simpler to have explicit process and product nodes.

This is a big change and could break some code:

cmutel commented 1 month ago

FYI @mrvisscher @jsvgoncalves @marc-vdm @tngTUDOR

cmutel commented 1 month ago

See utils.py function definition and especially the new tests to see under what conditions we add or change the type attribute.

mrvisscher commented 1 month ago

I totally love that we're making this more explicit and that there is a strong intention to make the distinction between products and processes even more clear in the future.

What is the implementation path? Do users need to apply this manually for their existing databases, or will you enforce it through an update or something similar?

cmutel commented 1 month ago

What is the implementation path? Do users need to apply this manually for their existing databases, or will you enforce it through an update or something similar?

I think the easiest is to add something to updates so that this is applied automatically. Please let me know if you have any strong disagreements.