Skip to content

Use of presamples in LCA and index advancement could be improved #67

@PascalLesage

Description

@PascalLesage

Suppose a presamples package containing matrix data with the following properties:

  • with ncols>1, say 5
  • seed='sequential'
  • presamples package dirpath= pp_dirpath.

If used in MonteCarloLCA, the indices start at 0 (thanks to the reset of the indexers here). For each iteration (i.e. each time next(mc_object) is called), the matrix data indexer goes up by 1.
All this is sane and easy to use.

For LCA, however, things are more complicated.

Suppose the data in the presamples package is some time series, and we want to generate LCA results for each time step by calling LCA n times. If we just use the LCA.lci() method, things don't work:

>>> import brightway2 as bw
>>> import presamples as ps
>>> lca = bw.LCA({some_act:1}, presamples=[pp_dirpath])
>>> print("iteration\tindex")
>>> for i in range(5):
...     lca.lci()
...     print(i, "\t", lca.presamples.matrix_indexer[0].index)

iteration	index
0 		 0
1 		 0
2 		 0
3 		 0
4 		 0

We need to actively update indices to get the indices moving up. If we naively use update_matrices, we don't get the first column.

>>> lca = bw.LCA({some_act:1}, presamples=[pp_dirpath])
>>> print("iteration\tindex")
>>> for i in range(5):
...     lca.presamples.update_matrices()
...     lca.lci()
...     print(i, "\t", lca.presamples.matrix_indexer[0].index)

iteration	index
0 		 1
1 		 2
2 		 3
3 		 4
4 		 5

Resetting sequential indices, like for MonteCarloLCA, gives the expected behaviour to the problem described above:

>>> lca = bw.LCA({some_act:1}, presamples=[pp_dirpath])
>>> lca.presamples.reset_sequential_indices()
>>> print("iteration\tindex")
>>> for i in range(5):
...     lca.presamples.update_matrices()
...     lca.lci()
...     print(i, "\t", lca.presamples.matrix_indexer[0].index)

iteration	index
0 		 0
1 		 1
2 		 2
3 		 3
4 		 4

This resetting could simply be added here
Tried it, no presamples tests fail.

We may want to consider moving indices directly when the lci method is invoked.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions