bw-functional 0b79__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bw_functional/__init__.py +65 -0
- bw_functional/allocation.py +142 -0
- bw_functional/convert.py +143 -0
- bw_functional/database.py +514 -0
- bw_functional/edge_classes.py +166 -0
- bw_functional/node_classes.py +591 -0
- bw_functional-0b79.dist-info/METADATA +216 -0
- bw_functional-0b79.dist-info/RECORD +11 -0
- bw_functional-0b79.dist-info/WHEEL +5 -0
- bw_functional-0b79.dist-info/licenses/LICENSE +12 -0
- bw_functional-0b79.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bw-functional
|
|
3
|
+
Version: 0b79
|
|
4
|
+
Summary: Code for handling multifunctional activities in Brightway
|
|
5
|
+
Author-email: Chris Mutel <cmutel@gmail.com>, Marin Visscher <m.r.visscher@cml.leidenuniv.nl>
|
|
6
|
+
Maintainer-email: Marin Visscher <m.r.visscher@cml.leidenuniv.nl>
|
|
7
|
+
Project-URL: source, https://github.com/brightway-lca/multifunctional
|
|
8
|
+
Project-URL: homepage, https://github.com/brightway-lca/multifunctional
|
|
9
|
+
Project-URL: tracker, https://github.com/brightway-lca/multifunctional/issues
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Natural Language :: English
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: blinker
|
|
23
|
+
Requires-Dist: bw2data>=4.0.1
|
|
24
|
+
Requires-Dist: bw2io>=0.9.1
|
|
25
|
+
Requires-Dist: bw_processing>=0.9.6
|
|
26
|
+
Requires-Dist: numpy<2
|
|
27
|
+
Provides-Extra: testing
|
|
28
|
+
Requires-Dist: bw-functional; extra == "testing"
|
|
29
|
+
Requires-Dist: bw2calc>=2.0.1; extra == "testing"
|
|
30
|
+
Requires-Dist: pytest; extra == "testing"
|
|
31
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
32
|
+
Requires-Dist: pytest-loguru; extra == "testing"
|
|
33
|
+
Requires-Dist: python-coveralls; extra == "testing"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: build; extra == "dev"
|
|
36
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
37
|
+
Requires-Dist: pylint; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
40
|
+
Requires-Dist: pytest-randomly; extra == "dev"
|
|
41
|
+
Requires-Dist: setuptools; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# bw-functional
|
|
45
|
+
|
|
46
|
+
[][pypi status]
|
|
47
|
+
[][pypi status]
|
|
48
|
+
[][pypi status]
|
|
49
|
+
[][license]
|
|
50
|
+
|
|
51
|
+
[][read the docs]
|
|
52
|
+
[][tests]
|
|
53
|
+
[][codecov]
|
|
54
|
+
|
|
55
|
+
[][pre-commit]
|
|
56
|
+
[][black]
|
|
57
|
+
|
|
58
|
+
[pypi status]: https://pypi.org/project/multifunctional/
|
|
59
|
+
[read the docs]: https://multifunctional.readthedocs.io/
|
|
60
|
+
[tests]: https://github.com/brightway-lca/multifunctional/actions?workflow=Tests
|
|
61
|
+
[codecov]: https://app.codecov.io/gh/brightway-lca/multifunctional
|
|
62
|
+
[pre-commit]: https://github.com/pre-commit/pre-commit
|
|
63
|
+
[black]: https://github.com/psf/black
|
|
64
|
+
|
|
65
|
+
Adding functions to Brightway processes
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
You can install _bw-functional_ via [pip] from [PyPI]:
|
|
70
|
+
|
|
71
|
+
```console
|
|
72
|
+
$ pip install bw-functional
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
[//]: # (It is also available on `anaconda` using `mamba` or `conda` at the `cmutel` channel:)
|
|
76
|
+
|
|
77
|
+
[//]: # ()
|
|
78
|
+
[//]: # (```console)
|
|
79
|
+
|
|
80
|
+
[//]: # (mamba install -c conda-forge -c cmutel multifunctional)
|
|
81
|
+
|
|
82
|
+
[//]: # (```)
|
|
83
|
+
|
|
84
|
+
## Usage
|
|
85
|
+
|
|
86
|
+
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.
|
|
87
|
+
|
|
88
|
+
This library is designed around the following workflow:
|
|
89
|
+
|
|
90
|
+
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`.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import bw_functional
|
|
94
|
+
mf_db = bw_functional.FunctionalSQLiteDatabase("emojis FTW")
|
|
95
|
+
mf_db.register()
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
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).
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
mf_data = {
|
|
102
|
+
("emojis FTW", "😼"): {
|
|
103
|
+
"type": "product",
|
|
104
|
+
"name": "meow",
|
|
105
|
+
"unit": "kg",
|
|
106
|
+
"processor": ("emojis FTW", "1"),
|
|
107
|
+
"properties": {
|
|
108
|
+
"price": {'unit': 'EUR', 'amount': 7, 'normalize': True},
|
|
109
|
+
"mass": {'unit': 'kg', 'amount': 1, 'normalize': True},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
("emojis FTW", "🐶"): {
|
|
113
|
+
"type": "product",
|
|
114
|
+
"name": "woof",
|
|
115
|
+
"unit": "kg",
|
|
116
|
+
"processor": ("emojis FTW", "1"),
|
|
117
|
+
"properties": {
|
|
118
|
+
"price": {'unit': 'EUR', 'amount': 12, 'normalize': True},
|
|
119
|
+
"mass": {'unit': 'kg', 'amount': 4, 'normalize': True},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
("emojis FTW", "1"): {
|
|
123
|
+
"name": "process - 1",
|
|
124
|
+
"location": "somewhere",
|
|
125
|
+
"exchanges": [
|
|
126
|
+
{
|
|
127
|
+
"type": "production",
|
|
128
|
+
"input": ("emojis FTW", "😼"),
|
|
129
|
+
"amount": 4,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"type": "production",
|
|
133
|
+
"input": ("emojis FTW", "🐶"),
|
|
134
|
+
"amount": 6,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
LCA calculations can then be done as normal. See `dev/basic_example.ipynb` for a simple example.
|
|
141
|
+
|
|
142
|
+
### Substitution
|
|
143
|
+
|
|
144
|
+
_WORK IN PROGRESS_
|
|
145
|
+
|
|
146
|
+
### Built-in allocation functions
|
|
147
|
+
|
|
148
|
+
`bw-functional` includes the following built-in allocation functions:
|
|
149
|
+
|
|
150
|
+
* `manual_allocation`: Does allocation based on the "allocation" field of the Product. Doesn't normalize by amount of production exchange.
|
|
151
|
+
* `equal`: Splits burdens equally among all functional edges.
|
|
152
|
+
|
|
153
|
+
You can also do property-based allocation by specifying the property label in the `allocation` field of the Process.
|
|
154
|
+
|
|
155
|
+
## Technical notes
|
|
156
|
+
|
|
157
|
+
### Process-specific allocation strategies
|
|
158
|
+
|
|
159
|
+
Individual processes can override the default database allocation by specifying their own `allocation`:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
import bw2data as bd
|
|
163
|
+
node = bd.get_activity(database="emojis FTW", code="1")
|
|
164
|
+
node["allocation"] = "mass"
|
|
165
|
+
node.save()
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## How does it work?
|
|
169
|
+
|
|
170
|
+
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.
|
|
171
|
+
|
|
172
|
+
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.
|
|
173
|
+
|
|
174
|
+
## Contributing
|
|
175
|
+
|
|
176
|
+
Contributions are very welcome.
|
|
177
|
+
To learn more, see the [Contributor Guide][Contributor Guide].
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
Distributed under the terms of the [BSD 3 Clause license][License],
|
|
182
|
+
_multifunctional_ is free and open source software.
|
|
183
|
+
|
|
184
|
+
## Issues
|
|
185
|
+
|
|
186
|
+
If you encounter any problems,
|
|
187
|
+
please [file an issue][Issue Tracker] along with a detailed description.
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
<!-- github-only -->
|
|
191
|
+
|
|
192
|
+
[command-line reference]: https://multifunctional.readthedocs.io/en/latest/usage.html
|
|
193
|
+
[License]: https://github.com/brightway-lca/multifunctional/blob/main/LICENSE
|
|
194
|
+
[Contributor Guide]: https://github.com/brightway-lca/multifunctional/blob/main/CONTRIBUTING.md
|
|
195
|
+
[Issue Tracker]: https://github.com/brightway-lca/multifunctional/issues
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
## Building the Documentation
|
|
199
|
+
|
|
200
|
+
You can build the documentation locally by installing the documentation Conda environment:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
conda env create -f docs/environment.yml
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
activating the environment
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
conda activate sphinx_multifunctional
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
and [running the build command](https://www.sphinx-doc.org/en/master/man/sphinx-build.html#sphinx-build):
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
sphinx-build docs _build/html --builder=html --jobs=auto --write-all; open _build/html/index.html
|
|
216
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
bw_functional/__init__.py,sha256=JvNruLP8_TFRkyFt8r6h0sr3vq2W0XtrlZhrMYK09fg,2240
|
|
2
|
+
bw_functional/allocation.py,sha256=zKHWTxO5kyPkfjAQgvQTa4TU5zMDSlwx8eydCD7x97Y,5545
|
|
3
|
+
bw_functional/convert.py,sha256=pgEqh15K0wHljmhAq7KIol9YducvB7Tft16cCeSf6pM,4840
|
|
4
|
+
bw_functional/database.py,sha256=Tko-R3qIoDfa-BAM3TErttKrNW0FDcqRQU4Ql-zzo9A,22198
|
|
5
|
+
bw_functional/edge_classes.py,sha256=PHCCKM2MK6mEWZWx23UShK7wBBJ_koQBc0UFH-M_uB4,6359
|
|
6
|
+
bw_functional/node_classes.py,sha256=Tuvv2pof4ZvAufdQGjD_hSJxC2EfUYSq-eStev2n6pw,21626
|
|
7
|
+
bw_functional-0b79.dist-info/licenses/LICENSE,sha256=syAySK3ASsB4zegLewsizL0FeLRmtypKPwIaewkDCX4,1489
|
|
8
|
+
bw_functional-0b79.dist-info/METADATA,sha256=NKyeMkKEmX2fwSbrLw4FPatlnlvwKShu4WRWvihQYQQ,8544
|
|
9
|
+
bw_functional-0b79.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
bw_functional-0b79.dist-info/top_level.txt,sha256=WSCJEmC5FgaUciN4RRM9n9MzcXmG6myql2sktGynuA0,14
|
|
11
|
+
bw_functional-0b79.dist-info/RECORD,,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright 2024 Chris Mutel
|
|
2
|
+
Copyright 2025 Leiden University
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
+
|
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
+
|
|
10
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
11
|
+
|
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bw_functional
|