Skip to content

Commit 477e7f2

Browse files
committed
fix: deselecting curves of a qmap resulted in ValueError if QMap tab was selected
1 parent bf91ff8 commit 477e7f2

File tree

8 files changed

+112
-27
lines changed

8 files changed

+112
-27
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
- fix: info tab did not display QMap metadata
33
- fix: do not fit the entire dataset when applying a rating threshold
44
but take the values from previous ratings
5+
- fix: deselecting curves of a qmap resulted in ValueError if QMap tab
6+
was selected
57
- fix: set correct display range for residuals
68
- docs: UI section for basics FD analysis
79
- build: Windows build broken since 0.5.6

docs/scrots/make_scrots_ui_fd.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def cleanup_autosave(jpkfile):
6767
war.tabs.grab().save("_ui_fd_tab_info.png")
6868

6969
war.tabs.setCurrentIndex(5)
70+
war.sp_rating_thresh.setValue(0)
71+
war.btn_rating_filter.clicked.emit()
7072
QApplication.processEvents()
7173
war.tabs.grab().save("_ui_fd_tab_qmap.png")
7274

pyjibe/fd/main.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def selected_curves(self):
106106
for ar in self.data_set:
107107
idx = self.data_set.index(ar)
108108
item = self.list_curves.topLevelItem(idx)
109-
if item.checkState(3) == 2:
109+
if item.checkState(3) == QtCore.Qt.Checked:
110110
curves.append(ar)
111111
return curves
112112

@@ -163,7 +163,7 @@ def callback(partial):
163163

164164
def autosave(self, fdist):
165165
"""Performs autosaving for all files"""
166-
if (self.cb_autosave.checkState() == 2 and
166+
if (self.cb_autosave.checkState() == QtCore.Qt.Checked and
167167
fdist.fit_properties and
168168
fdist.fit_properties["success"]):
169169
# Determine the directory of the current curve
@@ -183,7 +183,7 @@ def autosave(self, fdist):
183183
# fdist was fitted with same model
184184
ar.fit_properties["model_key"] == model_key and
185185
# user selected curve for export ("use")
186-
it.checkState(3) == 2
186+
it.checkState(3) == QtCore.Qt.Checked
187187
):
188188
exp_curv.append(ar)
189189
# The file to export
@@ -449,14 +449,17 @@ def on_params_init(self):
449449
def on_rating_threshold(self):
450450
"""(De)select curves according to threshold rating"""
451451
thresh = self.sp_rating_thresh.value()
452+
self.list_curves.blockSignals(True)
452453
for ii, fdist in enumerate(self.data_set):
453454
rtd = fdist.get_rating_parameters()
454455
rating = rtd["Rating"]
455456
it = self.list_curves.topLevelItem(ii)
456-
if not np.isnan(rating) and rating >= thresh:
457-
it.setCheckState(3, 2)
458-
else:
459-
it.setCheckState(3, 0)
457+
if not np.isnan(rating):
458+
if rating >= thresh:
459+
it.setCheckState(3, QtCore.Qt.Checked)
460+
else:
461+
it.setCheckState(3, QtCore.Qt.Unhecked)
462+
self.list_curves.blockSignals(False)
460463
# TODO:
461464
# - make this more efficient. There is a lot written to disk here.
462465
for fdist in self.data_set:

pyjibe/fd/main.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@
466466
<property name="decimals">
467467
<number>1</number>
468468
</property>
469+
<property name="minimum">
470+
<double>0.000000000000000</double>
471+
</property>
469472
<property name="maximum">
470473
<double>10.000000000000000</double>
471474
</property>

pyjibe/fd/mpl_qmap.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,15 @@ def set_selection_by_index(self, index):
174174
cx = self.qmap_coords[:, 0]
175175
cy = self.qmap_coords[:, 1]
176176
newxy = (cx[index]-self.dx/2, cy[index]-self.dy/2)
177-
self.select_rect.set_visible(True)
178177
self.select_rect.set_xy(newxy)
178+
self.show_selection(True)
179+
180+
def show_selection(self, b):
181+
self.select_rect.set_visible(b)
182+
if b:
179183
self.select_rect.set_width(self.dx)
180184
self.select_rect.set_height(self.dy)
181-
self.canvas.draw()
185+
self.canvas.draw()
182186

183187
def update(self, qmap, feature, cmap="viridis", vmin=None, vmax=None):
184188
"""Update the map tab plot data
@@ -221,6 +225,10 @@ def update(self, qmap, feature, cmap="viridis", vmin=None, vmax=None):
221225

222226
self.plot.set_cmap(cmap)
223227

228+
# explicitly set x/y limits
229+
self.axis_main.set_xlim(extent[0], extent[1])
230+
self.axis_main.set_ylim(extent[2], extent[3])
231+
224232
if (prev_data is None
225233
or not np.allclose(qmap_data, prev_data, equal_nan=True)):
226234
# visibility of plot elements
@@ -238,15 +246,19 @@ def update(self, qmap, feature, cmap="viridis", vmin=None, vmax=None):
238246
self.reset_lines()
239247
xm, ym = np.meshgrid(range(shape[0]),
240248
range(shape[1]))
249+
241250
for xi, yi in zip(xm.flat, ym.flat):
242251
if np.isnan(qmap_data[yi, xi]):
243-
xv = qmap_coords[0][0] + xi * dx
244-
yv = qmap_coords[0][1] + yi * dy
245-
if (np.sum(np.all(np.array([xi, yi]) == p)
246-
for p in qmap_coords_px)):
247-
color = "#14571A"
252+
xv = extent[0] + (xi+.5) * dx
253+
yv = extent[2] + (yi+.5) * dy
254+
for p in qmap_coords_px:
255+
if np.allclose([xi, yi], p):
256+
# data available, but not computed
257+
color = "#14571A" # green
258+
break
248259
else:
249-
color = "#571714"
260+
# curve not available
261+
color = "#571714" # red
250262
self.lines.append(
251263
self.axis_main.plot([xv-dx*.4, xv+dx*.4],
252264
[yv-dy*.4, yv+dy*.4],

pyjibe/fd/tab_qmap.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs):
2121
# set colormaps
2222
cmaps = ["viridis", "plasma", "afmhot", "seismic"]
2323
for cm in cmaps:
24-
self.qmpa_cmap_cb.addItem(cm)
24+
self.qmpa_cmap_cb.addItem(cm, cm)
2525
self.qmpa_cmap_cb.setCurrentIndex(0)
2626
self.qmap_data_cb.currentIndexChanged.connect(
2727
self.on_qmap_data_changed)
@@ -44,8 +44,9 @@ def mpl_qmap_update(self):
4444
if self.fd.tabs.currentWidget() == self:
4545
fdist = self.current_curve
4646
# Get all selected curves with the same path
47-
fdist_map = self.fd.selected_curves.subgroup_with_path(fdist.path)
48-
self.update_qmap(fdist_map, fdist_map.index(fdist))
47+
fdist_group = self.fd.selected_curves.subgroup_with_path(
48+
fdist.path)
49+
self.update_qmap(fdist_group, fdist)
4950

5051
def on_qmap_cmap_changed(self):
5152
"""colormap selection changed"""
@@ -57,7 +58,7 @@ def on_qmap_data_changed(self):
5758
self.qmap_sp_range1.blockSignals(True)
5859
self.qmap_sp_range2.blockSignals(True)
5960
if hasattr(self, "_cache_qmap_spin_ctl"):
60-
data = self.qmap_data_cb.currentIndex()
61+
data = self.qmap_data_cb.currentData()
6162
if data in self._cache_qmap_spin_ctl:
6263
vmin, vmax = self._cache_qmap_spin_ctl[data]
6364
else:
@@ -73,7 +74,7 @@ def on_qmap_min_max_changed(self):
7374
# store spin control values for data column
7475
vmin = self.qmap_sp_range1.value()
7576
vmax = self.qmap_sp_range2.value()
76-
data = self.qmap_data_cb.currentIndex()
77+
data = self.qmap_data_cb.currentData()
7778
if not hasattr(self, "_cache_qmap_spin_ctl"):
7879
self._cache_qmap_spin_ctl = {}
7980
self._cache_qmap_spin_ctl[data] = (vmin, vmax)
@@ -92,12 +93,29 @@ def on_qmap_selection(self, idx):
9293
item = fd.list_curves.topLevelItem(idcurve)
9394
fd.list_curves.setCurrentItem(item)
9495

95-
def update_qmap(self, fdist_map, index):
96+
def update_qmap(self, fdist_group, fdist):
97+
"""Update the QMap plotting data
98+
99+
Parameters
100+
----------
101+
fdist_group: nanite.IndentationGroup
102+
Indentation group containing all curves that will be
103+
part of the map
104+
fdist: nanite.Indentation
105+
Indentation curve that is currently selected. If `fdist`
106+
is not in `fdist_group`, then the red selection square
107+
is hidden.
108+
"""
109+
if fdist in fdist_group:
110+
index = fdist_group.index(fdist)
111+
else:
112+
index = None
113+
96114
# Build list of possible selections
97115
selist = nanite.qmap.available_features
98116

99117
# Get plotting parameter and check if it makes sense
100-
feature = self.qmap_data_cb.currentText()
118+
feature = self.qmap_data_cb.currentData()
101119
if not feature or feature not in selist:
102120
# Use a default plotting map
103121
feature = "data min height"
@@ -113,19 +131,22 @@ def update_qmap(self, fdist_map, index):
113131
self.qmap_data_cb.removeItem(0)
114132
# add new items
115133
for item in selist:
116-
self.qmap_data_cb.addItem(item)
134+
self.qmap_data_cb.addItem(item, item)
117135
self.qmap_data_cb.setCurrentIndex(selist.index(feature))
118136
self.qmap_data_cb.blockSignals(False)
119137

120-
if len(fdist_map) > 1:
138+
if len(fdist_group) > 1:
121139
# Get map data
122-
qmap = nanite.QMap(fdist_map)
140+
qmap = nanite.QMap(fdist_group)
123141
# update plot
124142
self.mpl_qmap.update(qmap=qmap,
125143
feature=feature,
126-
cmap=self.qmpa_cmap_cb.currentText(),
144+
cmap=self.qmpa_cmap_cb.currentData(),
127145
vmin=self.qmap_sp_range1.value(),
128146
vmax=self.qmap_sp_range2.value())
129-
self.mpl_qmap.set_selection_by_index(index)
147+
if index is not None:
148+
self.mpl_qmap.set_selection_by_index(index)
149+
else:
150+
self.mpl_qmap.show_selection(False)
130151
else:
131152
self.mpl_qmap.reset()
931 KB
Binary file not shown.

tests/test_fd_qmap.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Test of data set functionalities"""
2+
import pathlib
3+
4+
from PyQt5 import QtWidgets, QtCore
5+
import pytest
6+
7+
8+
import pyjibe.head
9+
10+
11+
here = pathlib.Path(__file__).parent
12+
jpkfile = here / "data" / "map2x2_extracted.jpk-force-map"
13+
14+
15+
def cleanup_autosave(jpkfile):
16+
"""Remove autosave files"""
17+
path = jpkfile.parent
18+
files = path.glob("*.tsv")
19+
files = [f for f in files if f.name.startswith("pyjibe_")]
20+
[f.unlink() for f in files]
21+
22+
23+
@pytest.fixture(autouse=True)
24+
def run_around_tests():
25+
# Code that will run before your test, for example:
26+
cleanup_autosave(jpkfile)
27+
# A test function will be run at this point
28+
yield
29+
# Code that will run after your test, for example:
30+
cleanup_autosave(jpkfile)
31+
32+
33+
def test_qmap_with_unused_curves(qtbot):
34+
"""Uncheck "use" in the curve list and switch to the qmap tab"""
35+
main_window = pyjibe.head.PyJibe()
36+
main_window.load_data(files=[jpkfile])
37+
war = main_window.subwindows[0].widget()
38+
# uncheck first curve
39+
cl1 = war.list_curves.currentItem()
40+
cl1.setCheckState(3, QtCore.Qt.Unchecked)
41+
war.tabs.setCurrentIndex(5)
42+
QtWidgets.QApplication.processEvents()

0 commit comments

Comments
 (0)