Skip to content

InconsistentGlobalIndex error when trying to modify the characterization matrix via interfaces #70

@mfastudillo

Description

@mfastudillo

From this stackoverflow post. If I try to modify the characterization matrix via an interface I get an IconsistentGlobalIndex error when I try to calculate the lca score.

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.

## 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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions