Skip to main content

bw-functional

PyPI Status Python Version License

Read the documentation at https://multifunctional.readthedocs.io/ Tests Codecov

pre-commit Black

Adding functions to Brightway processes

Installation

You can install bw-functional via [pip] from [PyPI]:

$ pip install bw-functional

The intended conda install is from conda-forge (pending acceptance of the feedstock PR):

$ conda install -c conda-forge bw-functional

The package remains available for now on the private LCA Anaconda channel, but that channel is deprecated in favor of conda-forge. Prefer conda-forge once the package appears there.

Usage

Multifunctional activities can lead to linear algebra problems which don't have exactly one solution. Therefore, we commonly need to apply a handling function to either partition such activities, or otherwise manipulate their data such that they allow for the creation of a square and non-singular technosphere matrix.

This library is designed around the following workflow:

Users create and register a bw_functional.FunctionalSQLiteDatabase. Registering this database must include the database metadata key default_allocation, which refers to an allocation strategy function present in bw_functional.allocation_strategies.

import bw_functional
mf_db = bw_functional.FunctionalSQLiteDatabase("emojis FTW")
mf_db.register()

Multifunctional process(es) are created and written to the FunctionalSQLiteDatabase. A multifunctional process is any process with multiple "functions", either outputs (products) and/or input (reducts).

mf_data = {
    ("emojis FTW", "😼"): {
        "type": "product",
        "name": "meow",
        "unit": "kg",
        "processor": ("emojis FTW", "1"),
        "properties": {
            "price": {'unit': 'EUR', 'amount': 7, 'normalize': True},
            "mass": {'unit': 'kg', 'amount': 1, 'normalize': True},
        },
    },
    ("emojis FTW", "🐶"): {
        "type": "product",
        "name": "woof",
        "unit": "kg",
        "processor": ("emojis FTW", "1"),
        "properties": {
            "price": {'unit': 'EUR', 'amount': 12, 'normalize': True},
            "mass": {'unit': 'kg', 'amount': 4, 'normalize': True},
        },
    },
    ("emojis FTW", "1"): {
        "name": "process - 1",
        "location": "somewhere",
        "exchanges": [
            {
                "type": "production",
                "input": ("emojis FTW", "😼"),
                "amount": 4,
            },
            {
                "type": "production",
                "input": ("emojis FTW", "🐶"),
                "amount": 6,
            },
        ],
    }
}

LCA calculations can then be done as normal. See dev/basic_example.ipynb for a simple example.

Substitution

WORK IN PROGRESS

Built-in allocation functions

bw-functional includes the following built-in allocation functions:

  • manual_allocation: Does allocation based on the "allocation" field of the Product. Doesn't normalize by amount of production exchange.
  • equal: Splits burdens equally among all functional edges.

You can also do property-based allocation by specifying the property label in the allocation field of the Process.

Technical notes

Process-specific allocation strategies

Individual processes can override the default database allocation by specifying their own allocation:

import bw2data as bd
node = bd.get_activity(database="emojis FTW", code="1")
node["allocation"] = "mass"
node.save()

How does it work?

Recent Brightway versions allow users to specify which graph nodes types should be used when building matrices, and which types can be ignored. We create a multifunctional process node with the type multifunctional, which will be ignored when creating processed datapackages. However, in our database class FunctionalSQLiteDatabase we change the function which creates these processed datapackages to load the multifunctional processes, perform whatever strategy is needed to handle multifunctionality, and then use the results of those handling strategies (e.g. monofunctional processes) in the processed datapackage.

We also tell MultifunctionalDatabase to load a new ReadOnlyProcess process class instead of the standard Activity class when interacting with the database. This new class is read only because the data is generated from the multifunctional process itself - if updates are needed, either that input process or the allocation function should be modified.

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the BSD 3 Clause license, multifunctional is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Building the Documentation

You can build the documentation locally by installing the documentation Conda environment:

conda env create -f docs/environment.yml

activating the environment

conda activate sphinx_multifunctional

and running the build command:

sphinx-build docs _build/html --builder=html --jobs=auto --write-all; open _build/html/index.html

Metadata

Release files for bw-functional 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bw-functional 0.1.1
File Size Uploaded Provenance Actions
bw_functional-0.1.1.tar.gz 27.7 kB Without provenance Details for bw_functional-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bw-functional 0.1.1
File Interpreter ABI Platform Actions
bw_functional-0.1.1-py3-none-any.whl Python 3 none any Details for bw_functional-0.1.1-py3-none-any.whl

Total release size: 50.8 kB

Release files / bw_functional-0.1.1.tar.gz

Download URL bw_functional-0.1.1.tar.gz
Size 27.7 kB
Tags Source
SHA-256 checksum
How to use checksums
85414350d36765ac2f50503f5921261d2007e41b1cbaebfe74aa26f1fccd21ad
BLAKE2b-256 checksum
How to use checksums
8ff7a73e17b475736268afa3e33e3c01d703c9a25c765228b5f71a8cdb2aaead
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / bw_functional-0.1.1-py3-none-any.whl

Download URL bw_functional-0.1.1-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af670b879d950e44fe986e80825cbbe2f2bb652041c35a69d252ab46738bf9d2
BLAKE2b-256 checksum
How to use checksums
cc2e1458771ba6bc3977098c6e5c0adc6f4a22d025b075baa576b3b670539918
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Security for bw-functional 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page