Skip to content

Commit 25fcaf1

Browse files
committed
fix: ValueError wehn filtering all events in Quick View (close #37)
1 parent 50e2482 commit 25fcaf1

File tree

6 files changed

+104
-14
lines changed

6 files changed

+104
-14
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.0.2
22
- fix: IndexError when removing a plot (#36)
3+
- fix: ValueError wehn filtering all events in Quick View (#37)
34
2.0.1
45
- fix: correctly distinguish prereleases when checking for new versions
56
- enh: allow loading data via drag&drop

shapeout2/gui/matrix/block_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def get_widget(self, slot_id=None, filt_plot_id=None):
117117
return wi
118118
else:
119119
raise ValueError(
120-
"One of `slot_id` or `filt_plot_id` must be specified!")
120+
"At least one of `slot_id`, `filt_plot_id` must be specified!")
121121

122122
def invalidate_elements(self, invalid_dm, invalid_pm):
123123
for slot_id, filt_id in invalid_dm:

shapeout2/gui/matrix/data_matrix.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ def get_quickview_ids(self):
360360
me = self.get_matrix_element(slot_id, filt_id)
361361
if current == me:
362362
return slot_id, filt_id
363+
else:
364+
# no valid QuickView selection (issue #38)
365+
return None, None
363366
else:
364367
return None, None
365368

shapeout2/gui/quick_view/qv_scatter.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ def plot_data(self, rtdc_ds, slot, xax="area_um", yax="deform",
105105
cmap = pg.ColorMap(*zip(*Gradients["viridis"]["ticks"]))
106106
for k in kde:
107107
brush.append(cmap.mapToQColor(k))
108-
# set viewbox
109-
pipeline_plot.set_viewbox(plot=self,
110-
range_x=(x.min(), x.max()),
111-
range_y=(y.min(), y.max()),
112-
scale_x=self.xscale,
113-
scale_y=self.yscale,
114-
padding=0.05)
108+
if x.size: # test for empty x/y (#37)
109+
# set viewbox
110+
pipeline_plot.set_viewbox(plot=self,
111+
range_x=(x.min(), x.max()),
112+
range_y=(y.min(), y.max()),
113+
scale_x=self.xscale,
114+
scale_y=self.yscale,
115+
padding=0.05)
115116
# set data
116117
self.setData(x, y, brush=brush)
117118
# set axes labels (replace with user-defined flourescence names)

tests/test_gui_quickview.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Test of data set functionalities"""
1+
"""Test of Quick View set functionalities"""
22
import pathlib
33

44
from PyQt5 import QtCore
@@ -51,23 +51,30 @@ def test_clear_session_issue_25(qtbot):
5151

5252

5353
def test_update_polygon_filter_issue_26(qtbot):
54-
"""https://github.com/ZELLMECHANIK-DRESDEN/ShapeOut2/issues/26"""
54+
"""https://github.com/ZELLMECHANIK-DRESDEN/ShapeOut2/issues/26
55+
56+
The recomputation of the filter ray was not triggered for some
57+
reason.
58+
"""
5559
mw = ShapeOut2()
5660
qtbot.addWidget(mw)
5761

5862
# add a dataslot
5963
path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
60-
mw.add_dataslot(paths=[path])
64+
filt_id = mw.add_filter()
65+
slot_ids = mw.add_dataslot(paths=[path])
6166

6267
assert len(mw.pipeline.slot_ids) == 1, "we added that"
6368
assert len(mw.pipeline.filter_ids) == 1, "automatically added"
6469

6570
# activate a dataslot
66-
slot_id = mw.pipeline.slot_ids[0]
67-
filt_id = mw.pipeline.filter_ids[0]
71+
slot_id = slot_ids[0]
6872
em = mw.block_matrix.get_widget(slot_id, filt_id)
69-
qtbot.mouseClick(em, QtCore.Qt.LeftButton) # activate
7073
qtbot.mouseClick(em, QtCore.Qt.LeftButton, QtCore.Qt.ShiftModifier)
74+
75+
em = mw.block_matrix.get_widget(slot_id, filt_id)
76+
qtbot.mouseClick(em, QtCore.Qt.LeftButton)
77+
7178
# did that work?
7279
assert mw.toolButton_quick_view.isChecked()
7380

tests/test_gui_quickview2.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""Test of Quick View functionalities
2+
3+
Created a new test file because putting "test_no_events_issue_37" and
4+
"test_update_polygon_filter_issue_26" in one file raised an error
5+
"RuntimeError: wrapped C/C++ object of type MatrixElement has been
6+
deleted" (similar to issue #38).
7+
"""
8+
import pathlib
9+
10+
from PyQt5 import QtCore
11+
12+
import numpy as np
13+
from shapeout2.gui.main import ShapeOut2
14+
from shapeout2 import session
15+
import pytest
16+
17+
18+
@pytest.fixture(autouse=True)
19+
def run_around_tests():
20+
# Code that will run before your test, for example:
21+
session.clear_session()
22+
# A test function will be run at this point
23+
yield
24+
# Code that will run after your test, for example:
25+
session.clear_session()
26+
27+
28+
def test_no_events_issue_37(qtbot):
29+
"""https://github.com/ZELLMECHANIK-DRESDEN/ShapeOut2/issues/37
30+
31+
"ValueError: zero-size array to reduction operation minimum
32+
which has no identity" when all events are filtered out.
33+
"""
34+
mw = ShapeOut2()
35+
qtbot.addWidget(mw)
36+
37+
# add a dataslot
38+
path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
39+
mw.add_dataslot(paths=[path, path])
40+
41+
assert len(mw.pipeline.slot_ids) == 2, "we added those"
42+
assert len(mw.pipeline.filter_ids) == 1, "automatically added"
43+
44+
# activate a dataslot
45+
slot_id = mw.pipeline.slot_ids[0]
46+
filt_id = mw.pipeline.filter_ids[0]
47+
em = mw.block_matrix.get_widget(slot_id, filt_id)
48+
qtbot.mouseClick(em, QtCore.Qt.LeftButton) # activate
49+
# did that work?
50+
assert mw.pipeline.is_element_active(slot_id, filt_id)
51+
52+
# filter away all events
53+
fe = mw.block_matrix.get_widget(filt_plot_id=filt_id)
54+
qtbot.mouseClick(fe.toolButton_modify, QtCore.Qt.LeftButton)
55+
fv = mw.widget_ana_view.widget_filter
56+
qtbot.mouseClick(fv.toolButton_moreless, QtCore.Qt.LeftButton)
57+
rc = fv._box_range_controls["area_um"]
58+
qtbot.mouseClick(rc.checkBox, QtCore.Qt.LeftButton)
59+
# did that work?
60+
assert rc.checkBox.isChecked()
61+
qtbot.mouseClick(fv.toolButton_moreless, QtCore.Qt.LeftButton)
62+
# set range
63+
rc.doubleSpinBox_min.setValue(0)
64+
rc.doubleSpinBox_max.setValue(1)
65+
qtbot.mouseClick(fv.pushButton_apply, QtCore.Qt.LeftButton)
66+
# did that work?
67+
ds = mw.pipeline.get_dataset(slot_index=0, filt_index=0,
68+
apply_filter=True)
69+
assert np.sum(ds.filter.all) == 0
70+
71+
# open QuickView
72+
slot_id = mw.pipeline.slot_ids[0]
73+
filt_id = mw.pipeline.filter_ids[0]
74+
em = mw.block_matrix.get_widget(slot_id, filt_id)
75+
76+
# this raised the error
77+
qtbot.mouseClick(em, QtCore.Qt.LeftButton, QtCore.Qt.ShiftModifier)
78+
mw.close()

0 commit comments

Comments
 (0)