Skip to content

Commit ffa5ad8

Browse files
mrvisschermarc-vdm
andauthored
Fixed EF & Process contribution tables not switching scenarios (#1237)
* Fixed EF & Process contribution tables not switching scenarios * Fix pythonic 'if' formatting --------- Co-authored-by: marc-vdm <m.t.van.der.meide@cml.leidenuniv.nl>
1 parent 7710770 commit ffa5ad8

3 files changed

Lines changed: 27 additions & 12 deletions

File tree

activity_browser/bwutils/multilca.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def _build_contributions(data: np.ndarray, index: int, axis: int) -> np.ndarray:
592592
return data.take(index, axis=axis)
593593

594594
def get_contributions(self, contribution, functional_unit=None,
595-
method=None) -> np.ndarray:
595+
method=None, **kwargs) -> np.ndarray:
596596
"""Return a contribution matrix given the type and fu / method."""
597597
if all([functional_unit, method]) or not any([functional_unit, method]):
598598
raise ValueError(
@@ -703,7 +703,7 @@ def top_elementary_flow_contributions(self, functional_unit: Optional[tuple] = N
703703
Annotated top-contribution dataframe
704704
705705
"""
706-
contributions = self.get_contributions(self.EF, functional_unit, method)
706+
contributions = self.get_contributions(self.EF, functional_unit, method, **kwargs)
707707

708708
x_fields = self._contribution_rows(self.EF, aggregator)
709709
index, y_fields = self._contribution_index_cols(
@@ -746,7 +746,7 @@ def top_process_contributions(self, functional_unit: Optional[tuple] = None, met
746746
Annotated top-contribution dataframe
747747
748748
"""
749-
contributions = self.get_contributions(self.ACT, functional_unit, method)
749+
contributions = self.get_contributions(self.ACT, functional_unit, method, **kwargs)
750750

751751
x_fields = self._contribution_rows(self.ACT, aggregator)
752752
index, y_fields = self._contribution_index_cols(

activity_browser/bwutils/superstructure/mlca.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def _build_scenario_contributions(data: np.ndarray, fu_index: int, m_index: int)
286286
return data[fu_index, m_index, :]
287287

288288
def get_contributions(self, contribution, functional_unit=None,
289-
method=None) -> np.ndarray:
289+
method=None, scenario=0) -> np.ndarray:
290290
"""Return a contribution matrix given the type and fu / method
291291
292292
Allow for both fu and method to exist.
@@ -305,6 +305,7 @@ def get_contributions(self, contribution, functional_unit=None,
305305
dataset[contribution], self.mlca.func_key_dict[functional_unit],
306306
self.mlca.method_index[method]
307307
)
308+
self.mlca.current = scenario
308309
return super().get_contributions(contribution, functional_unit, method)
309310

310311
def _contribution_index_cols(self, **kwargs) -> (dict, Optional[Iterable]):

activity_browser/layouts/tabs/LCA_results_tabs.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -873,24 +873,37 @@ def set_combobox_changes(self):
873873
combobox objects to be read out (which comparison, drop-down indexes,
874874
etc.) and fed into update calls.
875875
"""
876-
if self.combobox_menu.agg.currentText() != 'none':
877-
compare_fields = {"aggregator": self.combobox_menu.agg.currentText()}
878-
else:
879-
compare_fields = {"aggregator": None}
876+
# gather the combobox values
877+
method = self.parent.method_dict[self.combobox_menu.method.currentText()]
878+
functional_unit = self.combobox_menu.func.currentText()
879+
scenario = self.combobox_menu.scenario.currentIndex()
880+
aggregator = self.combobox_menu.agg.currentText()
881+
882+
# catch uninitiated scenario combobox
883+
if scenario < 0:
884+
scenario = 0
885+
# set aggregator to None if unwanted
886+
if aggregator == 'none':
887+
aggregator = None
888+
889+
# initiate dict with the field we want to compare
890+
compare_fields = {"aggregator": aggregator}
880891

881892
# Determine which comparison is active and update the comparison.
882893
if self.switches.currentIndex() == self.switches.indexes.func:
883894
compare_fields.update({
884-
"method": self.parent.method_dict[self.combobox_menu.method.currentText()],
895+
"method": method,
896+
"scenario": scenario
885897
})
886898
elif self.switches.currentIndex() == self.switches.indexes.method:
887899
compare_fields.update({
888-
"functional_unit": self.combobox_menu.func.currentText(),
900+
"functional_unit": functional_unit,
901+
"scenario": scenario
889902
})
890903
elif self.switches.currentIndex() == self.switches.indexes.scenario:
891904
compare_fields.update({
892-
"method": self.parent.method_dict[self.combobox_menu.method.currentText()],
893-
"functional_unit": self.combobox_menu.func.currentText(),
905+
"method": method,
906+
"functional_unit": functional_unit,
894907
})
895908

896909
# Determine the unit for the figure, update the filenames and the
@@ -906,6 +919,7 @@ def connect_signals(self):
906919
self.combobox_menu.method.currentIndexChanged.connect(self.update_tab)
907920
self.combobox_menu.func.currentIndexChanged.connect(self.update_tab)
908921
self.combobox_menu.agg.currentIndexChanged.connect(self.update_tab)
922+
self.combobox_menu.scenario.currentIndexChanged.connect(self.update_tab)
909923

910924
def update_tab(self):
911925
"""Update the tab."""

0 commit comments

Comments
 (0)