Skip to content

Commit

Permalink
TST: first tests for RectangularROI, EllipticalROI with theta
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed Sep 25, 2021
1 parent cecf0b7 commit 312e566
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion glue/core/tests/test_roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,18 @@ class TestEllipse(object):
def setup_method(self, method):
self.roi_empty = EllipticalROI()
self.roi = EllipticalROI(1, 2, 3, 4)
self.roi_rotated = EllipticalROI(1, 2, 3, 0.4, theta=np.pi / 6)

def test_undefined_on_creation(self):
assert not self.roi_empty.defined()
assert self.roi.defined()
assert self.roi_rotated.defined()

def test_contains_on_undefined_contains_raises(self):
with pytest.raises(UndefinedROI):
self.roi_empty.contains(1, 1)
self.roi.contains(1, 1)
self.roi.contains(1, 1)

def test_set_center(self):
assert self.roi.contains(0, 0)
Expand Down Expand Up @@ -366,6 +369,11 @@ def test_poly(self):
assert poly.contains(0, 0)
assert not poly.contains(10, 0)

x, y = self.roi_rotated.to_polygon()
poly = PolygonalROI(vx=x, vy=y)
assert poly.contains(0, 2.5)
assert not poly.contains(0, 0)

def test_poly_undefined(self):
x, y = self.roi_empty.to_polygon()
assert x == []
Expand Down Expand Up @@ -931,7 +939,7 @@ def test_circular_roi_representation():

# Case 2: linear-linear axes with non-square aspect ratio

ax.set_xlim(-40, 100)
ax.set_xlim(10, 100)
ax.set_ylim(-2, 5)
ax.set_xscale('linear')
ax.set_yscale('linear')
Expand Down
16 changes: 15 additions & 1 deletion glue/core/tests/test_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ def test_roi_subset_state(self):
roi = RectangularROI(xmin=0, xmax=3, ymin=1.1, ymax=1.4)

subset = self.data.new_subset()
subset.subset_state = RoiSubsetState(xatt=self.data.id['a'], yatt=self.data.id['c'], roi=roi)
subset.subset_state = RoiSubsetState(xatt=self.data.id['a'], yatt=self.data.id['c'],
roi=roi)
assert_equal(self.data.subsets[0].to_mask(), [0, 1, 0, 0])

data_clone = clone(self.data)
Expand All @@ -871,6 +872,19 @@ def test_roi_subset_state_with_pretransform(self):

assert_equal(data_clone.subsets[0].to_mask(), [0, 1, 0, 0])

def test_roi_subset_state_rotated(self):

roi = RectangularROI(xmin=0, xmax=3, ymin=1.1, ymax=1.4, theta=np.pi / 3)

subset = self.data.new_subset()
subset.subset_state = RoiSubsetState(xatt=self.data.id['a'], yatt=self.data.id['c'],
roi=roi)
assert_equal(self.data.subsets[0].to_mask(), [0, 0, 0, 1])

data_clone = clone(self.data)

assert_equal(data_clone.subsets[0].to_mask(), [0, 1, 0, 0])


@requires_scipy
def test_floodfill_subset_state():
Expand Down

0 comments on commit 312e566

Please # to comment.