Skip to content

Commit

Permalink
fix tests from new GSF coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
markotoplak committed Oct 4, 2024
1 parent 1395e70 commit edddbca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
30 changes: 17 additions & 13 deletions orangecontrib/spectroscopy/tests/test_owhyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,41 +234,43 @@ def test_select_all(self):
self.assertIsNone(out, None)

# select specific points
self.widget.imageplot.select_square(QPointF(9.4, 9.4), QPointF(11.6, 10.6))
self.widget.imageplot.select_square(QPointF(53.20, 30.0), QPointF(53.21, 30.03))
out = self.get_output("Selection")
np.testing.assert_equal(out.metas, [[10, 10], [11, 10]])
np.testing.assert_almost_equal(out.metas,
[[53.2043, 30.0185], [53.2043, 30.0085]],
decimal=3)
np.testing.assert_equal([o[out.domain["Group"]].value for o in out],
["G1", "G1"])

def test_select_polygon_as_rectangle(self):
# rectangle and a polygon need to give the same results
self.send_signal("Data", self.whitelight)
wait_for_image(self.widget)
self.widget.imageplot.select_square(QPointF(5, 5), QPointF(15, 10))
self.widget.imageplot.select_square(QPointF(53, 30), QPointF(54, 31))
out = self.get_output("Selection")
self.widget.imageplot.select_polygon([QPointF(5, 5), QPointF(15, 5), QPointF(15, 10),
QPointF(5, 10), QPointF(5, 5)])
self.widget.imageplot.select_polygon([QPointF(53, 30), QPointF(53, 31), QPointF(54, 31),
QPointF(54, 30), QPointF(53, 30)])
outpoly = self.get_output("Selection")
self.assertEqual(list(out), list(outpoly))

def test_select_click(self):
self.send_signal("Data", self.whitelight)
wait_for_image(self.widget)
self.widget.imageplot.select_by_click(QPointF(1, 2))
self.widget.imageplot.select_by_click(QPointF(53.2443, 30.6984))
out = self.get_output("Selection")
np.testing.assert_equal(out.metas, [[1, 2]])
np.testing.assert_almost_equal(out.metas, [[53.2443, 30.6984]], decimal=3)

def test_select_click_multiple_groups(self):
data = self.whitelight
self.send_signal("Data", data)
wait_for_image(self.widget)
self.widget.imageplot.select_by_click(QPointF(1, 2))
self.widget.imageplot.select_by_click(QPointF(53.2, 30))
with hold_modifiers(self.widget, Qt.ShiftModifier):
self.widget.imageplot.select_by_click(QPointF(2, 2))
self.widget.imageplot.select_by_click(QPointF(53.4, 30))
with hold_modifiers(self.widget, Qt.ShiftModifier):
self.widget.imageplot.select_by_click(QPointF(3, 2))
self.widget.imageplot.select_by_click(QPointF(53.6, 30))
with hold_modifiers(self.widget, Qt.ControlModifier):
self.widget.imageplot.select_by_click(QPointF(4, 2))
self.widget.imageplot.select_by_click(QPointF(53.8, 30))
out = self.get_output(self.widget.Outputs.annotated_data)
self.assertEqual(len(out), 20000) # have a data table at the output
newvars = out.domain.variables + out.domain.metas
Expand All @@ -278,15 +280,17 @@ def test_select_click_multiple_groups(self):
out = out[np.asarray(np.flatnonzero(
out.transform(Orange.data.Domain([group_at])).X != unselected))]
self.assertEqual(len(out), 4)
np.testing.assert_equal([o["map_x"].value for o in out], [1, 2, 3, 4])
np.testing.assert_almost_equal([o["map_x"].value for o in out],
[53.1993, 53.3993, 53.5993, 53.7993],
decimal=3)
np.testing.assert_equal([o[group_at].value for o in out], ["G1", "G2", "G3", "G3"])
out = self.get_output(self.widget.Outputs.selected_data)
np.testing.assert_equal([o[out.domain["Group"]].value for o in out],
["G1", "G2", "G3", "G3"])

# remove one element
with hold_modifiers(self.widget, Qt.AltModifier):
self.widget.imageplot.select_by_click(QPointF(1, 2))
self.widget.imageplot.select_by_click(QPointF(53.2, 30))
out = self.get_output(self.widget.Outputs.selected_data)
np.testing.assert_equal(len(out), 3)
np.testing.assert_equal([o[out.domain["Group"]].value for o in out],
Expand Down
13 changes: 7 additions & 6 deletions orangecontrib/spectroscopy/tests/test_owspectralseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,20 @@ def test_unknown(self):

def test_select_click(self):
self.send_signal("Data", self.whitelight)
self.widget.imageplot.select_by_click(QPointF(1, 2))
self.widget.imageplot.select_by_click(QPointF(0, 1))
# work by indices
out = self.get_output("Selection")
np.testing.assert_equal(out.metas[:, 0], 1)
np.testing.assert_equal(out.metas[:, 1], 99)
np.testing.assert_almost_equal(out.metas[:, 0], 53.0693, decimal=3)
np.testing.assert_almost_equal(out.metas[:, 1], 30.7085, decimal=3)
np.testing.assert_equal(out.Y, 0) # selection group
# select a feature
self.widget.imageplot.attr_x = "map_x"
self.widget.imageplot.update_attr()
self.widget.imageplot.select_by_click(QPointF(1, 2))
self.widget.imageplot.select_by_click(QPointF(53.1, 1))
out = self.get_output("Selection")
np.testing.assert_equal(out.metas[:, 0], 1)
np.testing.assert_equal(out.metas[:, 1], list(reversed(np.arange(100))))
np.testing.assert_almost_equal(out.metas[:, 0], 53.099327, decimal=3)
np.testing.assert_almost_equal(out.metas[:, 1],
self.whitelight[::200].metas[:, 1], decimal=3)
np.testing.assert_equal(out.Y, 0) # selection group

def test_single_update_view(self):
Expand Down
9 changes: 6 additions & 3 deletions orangecontrib/spectroscopy/tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,16 @@ def test_open_2d(self):
self.assertEqual(data.X.shape, (20000, 1))
# check some pixel vaules
self.assertAlmostEqual(data.X[235,0], 1.2788502, 7)
np.testing.assert_array_equal(data.metas[235], [35, 98])
np.testing.assert_almost_equal(data.metas[235],
[53.2443, 30.6984], decimal=3)

self.assertAlmostEqual(data.X[1235,0], 1.2770579, 7)
np.testing.assert_array_equal(data.metas[1235], [35, 93])
np.testing.assert_almost_equal(data.metas[1235],
[53.2443, 30.6484], decimal=3)

self.assertAlmostEqual(data.X[11235,0], 1.2476133, 7)
np.testing.assert_array_equal(data.metas[11235], [35, 43])
np.testing.assert_almost_equal(data.metas[11235],
[53.2443, 30.1484], decimal=3)


class TestNea(unittest.TestCase):
Expand Down

0 comments on commit edddbca

Please sign in to comment.