Skip to content

Commit 1a99028

Browse files
committed
Support multiple parameter sets in DBWindow
1 parent dec0b57 commit 1a99028

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/gui/windows/bayesian/DBPresenter.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ async def coro_calculate(self):
5555
if self.mp_handler:
5656
self.mp_handler.stop()
5757

58+
param_sets = self.get_paramsets()
59+
5860
self.mp_handler = MPHandler()
5961
data = await self.mp_handler.coro_bayesian(
60-
self.signals, self.get_paramsets(), self.on_progress_updated
62+
self.signals, param_sets, self.on_progress_updated
6163
)
6264

63-
for d in data:
64-
self.on_bayesian_inference_completed(*d)
65+
for d, p in zip(data, param_sets):
66+
self.on_bayesian_inference_completed(p.to_string(), *d)
6567

6668
if data:
6769
self.update_slider()
@@ -74,6 +76,7 @@ async def coro_calculate(self):
7476

7577
def on_bayesian_inference_completed(
7678
self,
79+
key: str,
7780
signal_name: str,
7881
tm,
7982
p1,
@@ -89,13 +92,21 @@ def on_bayesian_inference_completed(
8992
):
9093
signal = self.signals.get(signal_name)
9194

92-
signal.db_data = DBOutputData(
95+
if not hasattr(signal, "db_data"):
96+
signal.db_data = {}
97+
98+
signal.db_data[key] = DBOutputData(
9399
tm, p1, p2, cpl1, cpl2, cf1, cf2, mcf1, mcf2, surr_cpl1, surr_cpl2
94100
)
95101

96102
def update_slider(self) -> None:
97103
signal, _ = self.get_selected_signal_pair()
98-
data: DBOutputData = signal.db_data
104+
105+
try:
106+
key = self.get_selected_param_set().to_string()
107+
data: DBOutputData = signal.db_data[key]
108+
except (AttributeError, KeyError):
109+
return
99110

100111
cf1 = data.cf1
101112
length = cf1.shape[2]
@@ -117,7 +128,8 @@ def plot_bayesian(self) -> None:
117128

118129
times = signal.times
119130
try:
120-
data: DBOutputData = signal.db_data
131+
key = self.get_selected_param_set().to_string()
132+
data: DBOutputData = signal.db_data.get(key)
121133
except AttributeError:
122134
return
123135

@@ -140,6 +152,9 @@ def plot_bayesian2d(self, times: ndarray, data: DBOutputData) -> None:
140152
for p in (top, middle, bottom):
141153
p.clear()
142154

155+
if not data:
156+
return
157+
143158
for p in (middle, top):
144159
p.axes.xaxis.label.set_visible(False)
145160
p.toolbar.hide()
@@ -173,6 +188,9 @@ def plot_bayesian3d(self, data: DBOutputData) -> None:
173188
for p in (left, right):
174189
p.clear()
175190

191+
if not data:
192+
return
193+
176194
xlabel = r"$\phi_1$"
177195
ylabel = r"$\phi_2$"
178196
zlabel1 = r"$q_1(\phi_1,\phi_2)$"
@@ -247,6 +265,16 @@ def get_paramsets(self) -> List[ParamSet]:
247265
def has_paramset(self, text1, text2):
248266
return self.get_paramset(text1, text2) is not None
249267

268+
def get_selected_param_set(self) -> ParamSet:
269+
param_sets = self.get_paramsets()
270+
271+
try:
272+
index = self.view.listwidget_freq_band1.selectedIndexes()[0].row()
273+
except IndexError:
274+
return 0
275+
276+
return param_sets[index]
277+
250278
def add_paramset(self, params: ParamSet):
251279
self.param_sets[params.to_string()] = params
252280

src/gui/windows/bayesian/DBWindow.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def on_calculate_stopped(self):
125125
self.btn_calculate_single.hide()
126126
self.btn_calculate_all.setText("Calculate")
127127

128-
def get_param_set(self) -> ParamSet:
128+
def create_param_set(self) -> ParamSet:
129129
"""
130130
Creates a parameter set from the current UI elements. This is used when
131131
adding a parameter set to the list.
@@ -166,6 +166,9 @@ def on_paramset_selected(self, widget_index: int, _: QListWidgetItem) -> None:
166166

167167
self.fill_paramset_ui(text1, text2)
168168

169+
self.presenter.update_slider()
170+
self.presenter.plot_bayesian()
171+
169172
def fill_paramset_ui(self, text1, text2) -> None:
170173
"""
171174
Fills the UI with the values from a parameter set.
@@ -189,7 +192,7 @@ def on_add_paramset_clicked(self) -> None:
189192
"""
190193
Called when the user clicks the "add parameter set" button.
191194
"""
192-
params = self.get_param_set()
195+
params = self.create_param_set()
193196
band1, band2 = params.to_string()
194197

195198
if not self.presenter.has_paramset(band1, band2):
@@ -201,6 +204,7 @@ def on_add_paramset_clicked(self) -> None:
201204
self.listwidget_freq_band2.setCurrentRow(lastIndex)
202205

203206
self.presenter.add_paramset(params)
207+
self.presenter.plot_bayesian()
204208

205209
def on_delete_paramset_clicked(self):
206210
"""
@@ -220,6 +224,8 @@ def on_delete_paramset_clicked(self):
220224
for i in (item1, item2):
221225
sip.delete(i)
222226

227+
self.presenter.plot_bayesian()
228+
223229
def setup_radio_preproc(self):
224230
pass
225231

0 commit comments

Comments
 (0)