bw-processing 1.4__tar.gz → 1.6__tar.gz

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.
Files changed (56) hide show
  1. {bw_processing-1.4/src/bw_processing.egg-info → bw_processing-1.6}/PKG-INFO +34 -7
  2. {bw_processing-1.4 → bw_processing-1.6}/README.md +33 -6
  3. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/__init__.py +1 -1
  4. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/datapackage.py +191 -101
  5. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/matrix_entry.py +28 -8
  6. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/merging.py +1 -1
  7. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/utils.py +12 -1
  8. {bw_processing-1.4 → bw_processing-1.6/src/bw_processing.egg-info}/PKG-INFO +34 -7
  9. {bw_processing-1.4 → bw_processing-1.6}/tests/test_datapackage.py +209 -51
  10. {bw_processing-1.4 → bw_processing-1.6}/tests/test_matrix_entry.py +197 -0
  11. {bw_processing-1.4 → bw_processing-1.6}/tests/test_utils.py +27 -3
  12. {bw_processing-1.4 → bw_processing-1.6}/LICENSE +0 -0
  13. {bw_processing-1.4 → bw_processing-1.6}/MANIFEST.in +0 -0
  14. {bw_processing-1.4 → bw_processing-1.6}/pyproject.toml +0 -0
  15. {bw_processing-1.4 → bw_processing-1.6}/setup.cfg +0 -0
  16. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/array_creation.py +0 -0
  17. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/constants.py +0 -0
  18. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/errors.py +0 -0
  19. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/__init__.py +0 -0
  20. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/datapackage_1/another name.indices.parquet +0 -0
  21. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/datapackage_1/sa-data-vector-from-dict.data.parquet +0 -0
  22. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/datapackage_1/sa-data-vector-from-dict.distributions.parquet +0 -0
  23. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/datapackage_1/sa-data-vector-from-dict.flip.parquet +0 -0
  24. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/datapackage_1/sa-data-vector-from-dict.indices.parquet +0 -0
  25. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/datapackage_1/some name.data.parquet +0 -0
  26. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/datapackage_1/some name.flip.parquet +0 -0
  27. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/datapackage_1/some name.indices.parquet +0 -0
  28. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/datapackage_2.zip +0 -0
  29. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/interfaces.py +0 -0
  30. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/parquet_files.py +0 -0
  31. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/examples/simple.zip +0 -0
  32. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/filesystem.py +0 -0
  33. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/indexing.py +0 -0
  34. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/io_helpers.py +0 -0
  35. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/io_parquet_helpers.py +0 -0
  36. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/io_pyarrow_helpers.py +0 -0
  37. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/param_labels.py +0 -0
  38. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/proxies.py +0 -0
  39. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing/unique_fields.py +0 -0
  40. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing.egg-info/SOURCES.txt +0 -0
  41. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing.egg-info/dependency_links.txt +0 -0
  42. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing.egg-info/requires.txt +0 -0
  43. {bw_processing-1.4 → bw_processing-1.6}/src/bw_processing.egg-info/top_level.txt +0 -0
  44. {bw_processing-1.4 → bw_processing-1.6}/tests/test_array_creation.py +0 -0
  45. {bw_processing-1.4 → bw_processing-1.6}/tests/test_filesystem.py +0 -0
  46. {bw_processing-1.4 → bw_processing-1.6}/tests/test_filtered_datapackage.py +0 -0
  47. {bw_processing-1.4 → bw_processing-1.6}/tests/test_indexing.py +0 -0
  48. {bw_processing-1.4 → bw_processing-1.6}/tests/test_integration.py +0 -0
  49. {bw_processing-1.4 → bw_processing-1.6}/tests/test_interfaces.py +0 -0
  50. {bw_processing-1.4 → bw_processing-1.6}/tests/test_io_parquet_helpers.py +0 -0
  51. {bw_processing-1.4 → bw_processing-1.6}/tests/test_io_pyarrow_helpers.py +0 -0
  52. {bw_processing-1.4 → bw_processing-1.6}/tests/test_loading.py +0 -0
  53. {bw_processing-1.4 → bw_processing-1.6}/tests/test_merging.py +0 -0
  54. {bw_processing-1.4 → bw_processing-1.6}/tests/test_params.py +0 -0
  55. {bw_processing-1.4 → bw_processing-1.6}/tests/test_proxies.py +0 -0
  56. {bw_processing-1.4 → bw_processing-1.6}/tests/test_unique_fields.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bw_processing
3
- Version: 1.4
3
+ Version: 1.6
4
4
  Summary: Foo
5
5
  Author-email: Chris Mutel <cmutel@gmail.com>
6
6
  Maintainer-email: Chris Mutel <cmutel@gmail.com>
@@ -211,12 +211,12 @@ print(data_obj.url)
211
211
 
212
212
  ### Scale arrays
213
213
 
214
- Any resource group (persistent or dynamic, vector or array) can carry an optional `scale_array`: a one-dimensional float array of the same length as `indices_array`. Each element is a multiplicative factor applied to the corresponding data value before it is inserted into the matrix. The factor is applied to both static and stochastically-sampled values. A value of `1.0` leaves the data unchanged.
214
+ Any resource group (persistent or dynamic, vector or array) can carry an optional `rescale_array`: a one-dimensional float array of the same length as `indices_array`. Each element is a multiplicative factor applied to the corresponding data value before it is inserted into the matrix. The factor is applied to both static and stochastically-sampled values. A value of `1.0` leaves the data unchanged.
215
215
 
216
216
  Typical use cases:
217
217
 
218
- * **Allocation factors** — when a process produces multiple products, the exchange amounts must be partitioned between them. Storing the allocation coefficients as a `scale_array` keeps them alongside the data they modify without requiring a separate processing step.
219
- * **Unit conversions** — when source data is expressed in a unit that differs from the matrix convention, a constant conversion factor can be stored as a `scale_array` rather than baked into every data value.
218
+ * **Allocation factors** — when a process produces multiple products, the exchange amounts must be partitioned between them. Storing the allocation coefficients as a `rescale_array` keeps them alongside the data they modify without requiring a separate processing step.
219
+ * **Unit conversions** — when source data is expressed in a unit that differs from the matrix convention, a constant conversion factor can be stored as a `rescale_array` rather than baked into every data value.
220
220
 
221
221
  ```python
222
222
  import numpy as np
@@ -226,18 +226,45 @@ from bw_processing.constants import INDICES_DTYPE
226
226
  dp = create_datapackage()
227
227
  indices_array = np.array([(1, 4), (2, 5), (3, 6)], dtype=INDICES_DTYPE)
228
228
  data_array = np.array([100.0, 200.0, 300.0])
229
- scale_array = np.array([0.6, 1.0, 0.4]) # e.g. allocation factors
229
+ rescale_array = np.array([0.6, 1.0, 0.4]) # e.g. allocation factors
230
230
 
231
231
  dp.add_persistent_vector(
232
232
  matrix="technosphere",
233
233
  name="my-process",
234
234
  indices_array=indices_array,
235
235
  data_array=data_array,
236
- scale_array=scale_array,
236
+ rescale_array=rescale_array,
237
237
  )
238
238
  ```
239
239
 
240
- The stored resource has `kind="scale"` and can be retrieved via `dp.get_resource("my-process.scale")`. The `scale_array` must be a float dtype (`float32` or `float64`); passing an integer array raises `WrongDatatype`.
240
+ The stored resource has `kind="rescale"` and can be retrieved via `dp.get_resource("my-process.rescale")`. The `rescale_array` must be a float dtype (`float32` or `float64`); passing an integer array raises `WrongDatatype`.
241
+
242
+ ### Reference (production) exchanges
243
+
244
+ Any resource group can also carry an optional `reference_array`: a one-dimensional boolean array of the same length as `indices_array`. Where an element is `True`, that exchange is the **reference (production) exchange** for its activity/column.
245
+
246
+ The five structural heuristics in `bw_graph_tools` (matching ids, single non-flipped entry, single positive, single negative, unique product) cannot always identify the reference exchange — whenever an activity has more than one same-sign exchange and the products also appear in other columns, the choice is genuinely ambiguous. Only the modeller knows the answer. `reference_array` records it directly so downstream tools can read it instead of guessing.
247
+
248
+ ```python
249
+ import numpy as np
250
+ from bw_processing import create_datapackage
251
+ from bw_processing.constants import INDICES_DTYPE
252
+
253
+ dp = create_datapackage()
254
+ indices_array = np.array([(1, 4), (2, 5), (3, 6)], dtype=INDICES_DTYPE)
255
+ data_array = np.array([1.0, 0.5, 2.0])
256
+ reference_array = np.array([True, False, False]) # first exchange is the reference
257
+
258
+ dp.add_persistent_vector(
259
+ matrix="technosphere",
260
+ name="my-process",
261
+ indices_array=indices_array,
262
+ data_array=data_array,
263
+ reference_array=reference_array,
264
+ )
265
+ ```
266
+
267
+ The stored resource has `kind="reference"` and can be retrieved via `dp.get_resource("my-process.reference")`. It must be a boolean array; passing a non-boolean array raises `WrongDatatype`. To keep the common case cheap, the resource is written only when at least one entry is `True` — a group with no reference flags carries no `reference` resource. Using the high-level `MatrixEntry`/`ArrayEntry` API, set `reference=True` (or a boolean `reference` array) on the entries you want flagged.
241
268
 
242
269
  ### Parameter arrays for sensitivity analysis
243
270
 
@@ -168,12 +168,12 @@ print(data_obj.url)
168
168
 
169
169
  ### Scale arrays
170
170
 
171
- Any resource group (persistent or dynamic, vector or array) can carry an optional `scale_array`: a one-dimensional float array of the same length as `indices_array`. Each element is a multiplicative factor applied to the corresponding data value before it is inserted into the matrix. The factor is applied to both static and stochastically-sampled values. A value of `1.0` leaves the data unchanged.
171
+ Any resource group (persistent or dynamic, vector or array) can carry an optional `rescale_array`: a one-dimensional float array of the same length as `indices_array`. Each element is a multiplicative factor applied to the corresponding data value before it is inserted into the matrix. The factor is applied to both static and stochastically-sampled values. A value of `1.0` leaves the data unchanged.
172
172
 
173
173
  Typical use cases:
174
174
 
175
- * **Allocation factors** — when a process produces multiple products, the exchange amounts must be partitioned between them. Storing the allocation coefficients as a `scale_array` keeps them alongside the data they modify without requiring a separate processing step.
176
- * **Unit conversions** — when source data is expressed in a unit that differs from the matrix convention, a constant conversion factor can be stored as a `scale_array` rather than baked into every data value.
175
+ * **Allocation factors** — when a process produces multiple products, the exchange amounts must be partitioned between them. Storing the allocation coefficients as a `rescale_array` keeps them alongside the data they modify without requiring a separate processing step.
176
+ * **Unit conversions** — when source data is expressed in a unit that differs from the matrix convention, a constant conversion factor can be stored as a `rescale_array` rather than baked into every data value.
177
177
 
178
178
  ```python
179
179
  import numpy as np
@@ -183,18 +183,45 @@ from bw_processing.constants import INDICES_DTYPE
183
183
  dp = create_datapackage()
184
184
  indices_array = np.array([(1, 4), (2, 5), (3, 6)], dtype=INDICES_DTYPE)
185
185
  data_array = np.array([100.0, 200.0, 300.0])
186
- scale_array = np.array([0.6, 1.0, 0.4]) # e.g. allocation factors
186
+ rescale_array = np.array([0.6, 1.0, 0.4]) # e.g. allocation factors
187
187
 
188
188
  dp.add_persistent_vector(
189
189
  matrix="technosphere",
190
190
  name="my-process",
191
191
  indices_array=indices_array,
192
192
  data_array=data_array,
193
- scale_array=scale_array,
193
+ rescale_array=rescale_array,
194
194
  )
195
195
  ```
196
196
 
197
- The stored resource has `kind="scale"` and can be retrieved via `dp.get_resource("my-process.scale")`. The `scale_array` must be a float dtype (`float32` or `float64`); passing an integer array raises `WrongDatatype`.
197
+ The stored resource has `kind="rescale"` and can be retrieved via `dp.get_resource("my-process.rescale")`. The `rescale_array` must be a float dtype (`float32` or `float64`); passing an integer array raises `WrongDatatype`.
198
+
199
+ ### Reference (production) exchanges
200
+
201
+ Any resource group can also carry an optional `reference_array`: a one-dimensional boolean array of the same length as `indices_array`. Where an element is `True`, that exchange is the **reference (production) exchange** for its activity/column.
202
+
203
+ The five structural heuristics in `bw_graph_tools` (matching ids, single non-flipped entry, single positive, single negative, unique product) cannot always identify the reference exchange — whenever an activity has more than one same-sign exchange and the products also appear in other columns, the choice is genuinely ambiguous. Only the modeller knows the answer. `reference_array` records it directly so downstream tools can read it instead of guessing.
204
+
205
+ ```python
206
+ import numpy as np
207
+ from bw_processing import create_datapackage
208
+ from bw_processing.constants import INDICES_DTYPE
209
+
210
+ dp = create_datapackage()
211
+ indices_array = np.array([(1, 4), (2, 5), (3, 6)], dtype=INDICES_DTYPE)
212
+ data_array = np.array([1.0, 0.5, 2.0])
213
+ reference_array = np.array([True, False, False]) # first exchange is the reference
214
+
215
+ dp.add_persistent_vector(
216
+ matrix="technosphere",
217
+ name="my-process",
218
+ indices_array=indices_array,
219
+ data_array=data_array,
220
+ reference_array=reference_array,
221
+ )
222
+ ```
223
+
224
+ The stored resource has `kind="reference"` and can be retrieved via `dp.get_resource("my-process.reference")`. It must be a boolean array; passing a non-boolean array raises `WrongDatatype`. To keep the common case cheap, the resource is written only when at least one entry is `True` — a group with no reference flags carries no `reference` resource. Using the high-level `MatrixEntry`/`ArrayEntry` API, set `reference=True` (or a boolean `reference` array) on the entries you want flagged.
198
225
 
199
226
  ### Parameter arrays for sensitivity analysis
200
227
 
@@ -35,7 +35,7 @@ __all__ = (
35
35
  "UndefinedInterface",
36
36
  )
37
37
 
38
- __version__ = "1.4"
38
+ __version__ = "1.6"
39
39
 
40
40
 
41
41
  from bw_processing.array_creation import create_array, create_structured_array