brightway-lca / brightway-lca/bw_processing

InconsistentGlobalIndex error when trying to modify the characterization matrix via interfaces

Open
#70 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
8
Forks
6
PR merge metrics
No merged PRs in 30d

Description

From this stackoverflow [post](https://stackoverflow.com/questions/78886889/use-an-iterface-to-replace-characterization-factors-of-an-lca-object-with-bright). If I try to modify the characterization matrix via an interface I get an IconsistentGlobalIndex error when I try to calculate the lca score.

```python

import bw2data as bd
import bw_processing as bwp
import numpy as np
import bw2calc as bc

bd.projects.set_current("bw25")

mobility_db = bd.Database('Mobility example')
combustion_car_driving = mobility_db.get(name='Driving an combustion car')
co2 = mobility_db.get(name='CO2')

# create datapackage with alternative values for the GWP of CO2
indices_array = np.array([(co2.id,
bd.geomapping[bd.config.global_location])],
dtype=bwp.INDICES_DTYPE)

values_array = np.array([list(range(1,10))])
dp_c = bwp.create_datapackage(sequential=True)
dp_c.add_dynamic_array(
matrix='characterization_matrix',
indices_array=indices_array,
interface=values_array,
)

```

If I set the `global_index` using the default global_location then it works. But this is not very intuitive. I guess this should be done by default. I am not sure where it the right place.

```python
## hack
r = dp_c.filter_by_attribute('matrix',
'characterization_matrix').filter_by_attribute("kind","indices").resources[0]
r["global_index"] = bd.geomapping[bd.config.global_location]
##
fu, data_objs , _ = bd.prepare_lca_inputs({combustion_car_driving:1},
method=('IPCC','simple'))
lca = bc.LCA(demand=fu,
method=('IPCC','simple'),
data_objs=data_objs+[dp_c],
use_arrays=True)
lca.lci()
lca.lcia()
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.