Skip to content

Commit

Permalink
Fixed EF & Process contribution tables not switching scenarios (#1237)
Browse files Browse the repository at this point in the history
* Fixed EF & Process contribution tables not switching scenarios

* Fix pythonic 'if' formatting

---------

Co-authored-by: marc-vdm <[email protected]>
  • Loading branch information
mrvisscher and marc-vdm authored Feb 19, 2024
1 parent 7710770 commit ffa5ad8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
6 changes: 3 additions & 3 deletions activity_browser/bwutils/multilca.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def _build_contributions(data: np.ndarray, index: int, axis: int) -> np.ndarray:
return data.take(index, axis=axis)

def get_contributions(self, contribution, functional_unit=None,
method=None) -> np.ndarray:
method=None, **kwargs) -> np.ndarray:
"""Return a contribution matrix given the type and fu / method."""
if all([functional_unit, method]) or not any([functional_unit, method]):
raise ValueError(
Expand Down Expand Up @@ -703,7 +703,7 @@ def top_elementary_flow_contributions(self, functional_unit: Optional[tuple] = N
Annotated top-contribution dataframe
"""
contributions = self.get_contributions(self.EF, functional_unit, method)
contributions = self.get_contributions(self.EF, functional_unit, method, **kwargs)

x_fields = self._contribution_rows(self.EF, aggregator)
index, y_fields = self._contribution_index_cols(
Expand Down Expand Up @@ -746,7 +746,7 @@ def top_process_contributions(self, functional_unit: Optional[tuple] = None, met
Annotated top-contribution dataframe
"""
contributions = self.get_contributions(self.ACT, functional_unit, method)
contributions = self.get_contributions(self.ACT, functional_unit, method, **kwargs)

x_fields = self._contribution_rows(self.ACT, aggregator)
index, y_fields = self._contribution_index_cols(
Expand Down
3 changes: 2 additions & 1 deletion activity_browser/bwutils/superstructure/mlca.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _build_scenario_contributions(data: np.ndarray, fu_index: int, m_index: int)
return data[fu_index, m_index, :]

def get_contributions(self, contribution, functional_unit=None,
method=None) -> np.ndarray:
method=None, scenario=0) -> np.ndarray:
"""Return a contribution matrix given the type and fu / method
Allow for both fu and method to exist.
Expand All @@ -305,6 +305,7 @@ def get_contributions(self, contribution, functional_unit=None,
dataset[contribution], self.mlca.func_key_dict[functional_unit],
self.mlca.method_index[method]
)
self.mlca.current = scenario
return super().get_contributions(contribution, functional_unit, method)

def _contribution_index_cols(self, **kwargs) -> (dict, Optional[Iterable]):
Expand Down
30 changes: 22 additions & 8 deletions activity_browser/layouts/tabs/LCA_results_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,24 +873,37 @@ def set_combobox_changes(self):
combobox objects to be read out (which comparison, drop-down indexes,
etc.) and fed into update calls.
"""
if self.combobox_menu.agg.currentText() != 'none':
compare_fields = {"aggregator": self.combobox_menu.agg.currentText()}
else:
compare_fields = {"aggregator": None}
# gather the combobox values
method = self.parent.method_dict[self.combobox_menu.method.currentText()]
functional_unit = self.combobox_menu.func.currentText()
scenario = self.combobox_menu.scenario.currentIndex()
aggregator = self.combobox_menu.agg.currentText()

# catch uninitiated scenario combobox
if scenario < 0:
scenario = 0
# set aggregator to None if unwanted
if aggregator == 'none':
aggregator = None

# initiate dict with the field we want to compare
compare_fields = {"aggregator": aggregator}

# Determine which comparison is active and update the comparison.
if self.switches.currentIndex() == self.switches.indexes.func:
compare_fields.update({
"method": self.parent.method_dict[self.combobox_menu.method.currentText()],
"method": method,
"scenario": scenario
})
elif self.switches.currentIndex() == self.switches.indexes.method:
compare_fields.update({
"functional_unit": self.combobox_menu.func.currentText(),
"functional_unit": functional_unit,
"scenario": scenario
})
elif self.switches.currentIndex() == self.switches.indexes.scenario:
compare_fields.update({
"method": self.parent.method_dict[self.combobox_menu.method.currentText()],
"functional_unit": self.combobox_menu.func.currentText(),
"method": method,
"functional_unit": functional_unit,
})

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

def update_tab(self):
"""Update the tab."""
Expand Down

0 comments on commit ffa5ad8

Please sign in to comment.