Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty characterization matrix arrays for MultiLCA #100

Closed
TimoDiepers opened this issue Jul 8, 2024 · 7 comments
Closed

Empty characterization matrix arrays for MultiLCA #100

TimoDiepers opened this issue Jul 8, 2024 · 7 comments

Comments

@TimoDiepers
Copy link
Member

TimoDiepers commented Jul 8, 2024

I'm not sure if this is an actual issue of bw2calc or even an issue at all (maybe I just don't fully understand how the new MultiLCA implementation works, sorry in that case), but I tried using the new MultiLCA calculation and keep getting an AllArraysEmpty Error - for the characterization matrix as it seems. What I did:

functional_units = {
    "wind": {10905: 1},
    "coal": {21943: 1}, 
    "pv": {10305: 1}.
}

config = {
    "impact_categories": [
        ('EF v3.1', 'climate change', 'global warming potential (GWP100)'), 
    ],
}

data_objs = bd.get_multilca_data_objs(functional_units=functional_units, method_config=config)

mlca = bc.MultiLCA(demands=functional_units, method_config=config, data_objs=data_objs)
mlca.lci()
mlca.lcia()

If I do a normal LCA with this same data it works just fine.

I tried to look into this but couldn't figure out why this part here in MultiLCA.load_lcia_data returned no values in the arrays:
https://github.com/brightway-lca/brightway2-calc/blob/ef9bac1565488290ccaf5c02e0d09798a9345725/bw2calc/multi_lca.py#L254C1-L260C15

Also, here's the complete error message I get when calling MultiLCA.lcia():

---------------------------------------------------------------------------
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/utils.py:38, in safe_concatenate_indices(arrays, empty_ok)
     [37](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/utils.py:37) try:
---> [38](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/utils.py:38)     return np.hstack(arrays)
     [39](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/utils.py:39) except ValueError:

File ~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/numpy/core/shape_base.py:359, in hstack(tup, dtype, casting)
    [358](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/numpy/core/shape_base.py:358) else:
--> [359](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/numpy/core/shape_base.py:359)     return _nx.concatenate(arrs, 1, dtype=dtype, casting=casting)

ValueError: need at least one array to concatenate

During handling of the above exception, another exception occurred:

AllArraysEmpty                            Traceback (most recent call last)
Cell In[36], [line 1](vscode-notebook-cell:?execution_count=36&line=1)
----> [1](vscode-notebook-cell:?execution_count=36&line=1) mlca.lcia()

File ~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:139, in MultiLCA.lcia(self)
    [138](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:138) def lcia(self) -> None:
--> [139](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:139)     return super().lcia()

File ~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/lca_base.py:203, in LCABase.lcia(self, demand)
    [198](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/lca_base.py:198)     raise EmptyBiosphere
    [200](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/lca_base.py:200) if not (
    [201](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/lca_base.py:201)     hasattr(self, "characterization_matrix") or hasattr(self, "characterization_matrices")
    [202](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/lca_base.py:202) ):
--> [203](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/lca_base.py:203)     self.load_lcia_data()
    [204](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/lca_base.py:204) if demand is not None:
    [205](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/lca_base.py:205)     self.check_demand(demand)

File ~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:254, in MultiLCA.load_lcia_data(self, data_objs)
    [250](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:250) fltr = (lambda x: x["col"] == global_index) if global_index is not None else None
    [252](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:252) use_arrays, use_distributions = self.check_selective_use("characterization_matrix")
--> [254](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:254) self.characterization_mm_dict = mu.MappedMatrixDict(
    [255](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:255)     packages={
    [256](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:256)         ic: self.filter_package_by_identifier(
    [257](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:257)             data_objs=data_objs or self.packages, identifier=list(ic)
    [258](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:258)         )
    [259](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:259)         for ic in self.config["impact_categories"]
    [260](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:260)     },
    [261](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:261)     matrix="characterization_matrix",
    [262](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:262)     use_arrays=use_arrays,
    [263](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:263)     use_distributions=use_distributions,
    [264](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:264)     seed_override=self.seed_override,
    [265](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:265)     row_mapper=self.biosphere_mm.row_mapper,
    [266](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:266)     col_mapper=None,
    [267](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:267)     diagonal=True,
    [268](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:268)     custom_filter=fltr,
    [269](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:269) )
    [270](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:270) for key, value in self.characterization_mm_dict.items():
    [271](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/bw2calc/multi_lca.py:271)     if len(value.matrix.data) == 0:

File ~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:132, in MappedMatrixDict.__init__(self, packages, matrix, row_mapper, col_mapper, use_vectors, use_arrays, use_distributions, seed_override, indexer_override, diagonal, transpose, custom_filter, empty_ok, sequential, matrix_class, **kwargs)
    [129](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:129) if not isinstance(packages, Mapping):
    [130](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:130)     raise ValueError("`packages` must be a dictionary")
--> [132](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:132) self.matrices = {
    [133](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:133)     key: matrix_class(
    [134](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:134)         packages=packages,
    [135](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:135)         matrix=matrix,
    [136](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:136)         use_vectors=use_vectors,
    [137](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:137)         use_arrays=use_arrays,
    [138](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:138)         use_distributions=use_distributions,
    [139](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:139)         row_mapper=row_mapper,
    [140](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:140)         col_mapper=col_mapper,
    [141](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:141)         seed_override=seed_override,
    [142](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:142)         indexer_override=self.global_indexer,
    [143](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:143)         diagonal=diagonal,
    [144](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:144)         transpose=transpose,
    [145](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:145)         custom_filter=custom_filter,
    [146](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:146)         empty_ok=empty_ok,
    [147](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:147)         **kwargs,
    [148](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:148)     )
    [149](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:149)     for key, packages in packages.items()
    [150](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:150) }

File ~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:133, in <dictcomp>(.0)
    [129](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:129) if not isinstance(packages, Mapping):
    [130](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:130)     raise ValueError("`packages` must be a dictionary")
    [132](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:132) self.matrices = {
--> [133](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:133)     key: matrix_class(
    [134](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:134)         packages=packages,
    [135](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:135)         matrix=matrix,
    [136](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:136)         use_vectors=use_vectors,
    [137](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:137)         use_arrays=use_arrays,
    [138](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:138)         use_distributions=use_distributions,
    [139](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:139)         row_mapper=row_mapper,
    [140](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:140)         col_mapper=col_mapper,
    [141](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:141)         seed_override=seed_override,
    [142](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:142)         indexer_override=self.global_indexer,
    [143](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:143)         diagonal=diagonal,
    [144](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:144)         transpose=transpose,
    [145](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:145)         custom_filter=custom_filter,
    [146](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:146)         empty_ok=empty_ok,
    [147](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:147)         **kwargs,
    [148](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:148)     )
    [149](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:149)     for key, packages in packages.items()
    [150](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix_dict.py:150) }

File ~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix.py:136, in MappedMatrix.__init__(self, packages, matrix, use_vectors, use_arrays, use_distributions, row_mapper, col_mapper, seed_override, indexer_override, diagonal, transpose, custom_filter, empty_ok)
    [133](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix.py:133)     self.add_mappers(axis=1, mapper=self.col_mapper)
    [134](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix.py:134) self.map_indices()
--> [136](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix.py:136) row_indices = safe_concatenate_indices([obj.row_matrix for obj in self.groups], empty_ok)
    [137](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix.py:137) col_indices = safe_concatenate_indices([obj.col_matrix for obj in self.groups], empty_ok)
    [139](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/mapped_matrix.py:139) if diagonal:

File ~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/utils.py:43, in safe_concatenate_indices(arrays, empty_ok)
     [41](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/utils.py:41)     return np.array([], dtype=int)
     [42](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/utils.py:42) else:
---> [43](https://file+.vscode-resource.vscode-cdn.net/Users/timodiepers/Documents/Coding/lca-epe/Exercises/~/anaconda3/envs/lcaepe/lib/python3.11/site-packages/matrix_utils/utils.py:43)     raise AllArraysEmpty

AllArraysEmpty:
@transfluxus
Copy link

Hi Timo,

I would be interested in the solution to this, since I am facing the same problem.
I assume you are using
bw2calc==2.0.dev17
May I ask which version of bw2data you are using, since I dont find the function "get_multilca_data_objs" in
bw2data==4.0.dev33

@TimoDiepers
Copy link
Member Author

@transfluxus I'm on bw2data=4.0.dev45, which is currently the latest version. get_multilca_data_objs seems to have been added with 4.0dev40 and wasn't changed since then -> https://github.com/brightway-lca/brightway2-data/blob/main/CHANGES.md#40dev40-2024-06-05

@transfluxus
Copy link

@TimoDiepers
thanks, I can confirm the error :)

@cmutel
Copy link
Member

cmutel commented Jul 22, 2024

@TimoDiepers @transfluxus Sorry about this.

To support multiple method impact categories with a single list of data objects, we needed to filter the data objects per impact category (and normalization and weighting), which in turn meant that we needed to include the necessary information to apply filtering in the datapackage.

I just ran into the same problem, as I hadn't changed my database, so the older datapackage was still being used, but this was missing the needed "name" attribute. Long story short, do this:

import bw2data
for method in bw2data.methods:
    bw2data.Method(method).process()

@transfluxus
Copy link

transfluxus commented Jul 23, 2024

Thanks @cmutel , nice. It runs for me now. However, MultiLCA often results in 0 results:

# normal LCA

heat_and_power_act = db.get("b9d74efa4fd670b1977a3471ec010737")
print(heat_and_power_act)
# > 'heat and power co-generation, wood chips, 6667 kW, state-of-the-art 2014' (kilowatt hour, DK, None)

method = ('EF v3.1', 'climate change', 'global warming potential (GWP100)')
lca = LCA({heat_and_power_act: 1.0},method)
lca.lci()
lca.lcia()
print(lca.score)
# > 0.0540628976277506

# MultiLCA

demand = {"energy": {heat_and_power_act.id: 1.0}}

method_config = {
    "impact_categories": [method]
}

for method in method_config["impact_categories"]:
    bw2data.Method(method).process()

data_objs = bw2data.get_multilca_data_objs(functional_units=demand, method_config=method_config)
mlca = MultiLCA(demands=demand, method_config=method_config, data_objs=data_objs)
mlca.lci()
mlca.lcia()
print(mlca.scores)
# > {(('EF v3.1', 'climate change', 'global warming potential (GWP100)'), 'energy'): 0.0}

@TimoDiepers
Copy link
Member Author

TimoDiepers commented Jul 23, 2024

@transfluxus @cmutel My original example works now, but I could also reproduce the zero value above. However, I've come to notice that this only occurs if only one entry is in functional units. If there are two, it seems to work:

heat_and_power_act = bd.get_node(database="ecoinvent-3.10-cutoff", name="heat and power co-generation, wood chips, 6667 kW, state-of-the-art 2014", location="DK", unit="kilowatt hour")

functional_units = {
    "one": {heat_and_power_act.id: 1},
    "two": {heat_and_power_act.id: 1}, # leaving this out results in a score of 0
}

config = {
    "impact_categories": [
        ("EF v3.1", "climate change", "global warming potential (GWP100)"),
    ],
}

data_objs = bd.get_multilca_data_objs(
    functional_units=functional_units, method_config=config
)

mlca = bc.MultiLCA(demands=functional_units, method_config=config, data_objs=data_objs)
mlca.lci()
mlca.lcia()
mlca.scores

# > {(('EF v3.1', 'climate change', 'global warming potential (GWP100)'),
# >  'one'): 0.05507812866658305,
# > (('EF v3.1', 'climate change', 'global warming potential (GWP100)'),
# >  'two'): 0.05507812866658305}

@TimoDiepers
Copy link
Member Author

TimoDiepers commented Jul 23, 2024

And I think the problem lies here:

solutions = spsolve(
self.technosphere_matrix, np.vstack([arr for arr in self.demand_arrays.values()]).T
)
self.supply_arrays = {name: arr for name, arr in zip(self.demands, solutions.T)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants