Skip to content

Commit

Permalink
Add quantiles quantification
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Mar 28, 2024
1 parent b70e800 commit a57156a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
4 changes: 1 addition & 3 deletions pathways/lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ def load_matrix_and_index(
dtype=bwp.UNCERTAINTY_DTYPE,
)

print(distributions_array[:5])

return data_array, indices_array, flip_array, distributions_array


Expand Down Expand Up @@ -144,7 +142,7 @@ def get_lca_matrices(
matrix="biosphere_matrix",
indices_array=b_indices,
data_array=b_data,
# flip_array=b_sign,
flip_array=b_sign,
distributions_array=b_distributions,
)

Expand Down
20 changes: 5 additions & 15 deletions pathways/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int
"demand": demand.values * float(unit_vector),
}

lca.lci(demand={idx: demand.values * float(unit_vector)})

if use_distributions == 0:
lca.lci(demand={idx: demand.values * float(unit_vector)})
characterized_inventory = (
characterization_matrix @ lca.inventory
).toarray()
Expand All @@ -322,29 +323,18 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int
# Use distributions for LCA calculations
# next(lca) is a generator that yields the inventory matrix

for _ in range(use_distributions):
next(lca)
lca.lci(demand={idx: demand.values * float(unit_vector)})
print(lca.inventory.shape)
print(lca.inventory.sum())

results = np.array(
[
(
characterization_matrix
@ lca.lci(
demand={idx: demand.values * float(unit_vector)}
).inventory
@ lca.inventory
).toarray()
for _ in zip(range(use_distributions), lca)
]
)

print(results.shape)
for result in results:
print(result.sum(axis=-1))

characterized_inventory = np.empty_like(lca.inventory)
# calculate quantiles along the first dimension
characterized_inventory = np.quantile(results, [0.05, 0.5, 0.95], axis=0)

# vars_info = fetch_indices(mapping, regions, variables, A_index, Geomap(model))
# characterized_inventory = remove_double_counting(characterized_inventory=characterized_inventory,
Expand Down

0 comments on commit a57156a

Please sign in to comment.