Skip to content
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
214e637
storage updates
measty Jun 23, 2023
5952ca0
byte geom decoding
measty Jun 23, 2023
e634918
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Jul 3, 2023
362bc0a
add wkb decoding via numpy
measty Jul 3, 2023
65aaffa
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Jul 4, 2023
7414195
deepsource fixes
measty Jul 4, 2023
1e5b7ef
add tests
measty Jul 6, 2023
faf4450
further tests
measty Jul 7, 2023
502025c
min area test
measty Jul 7, 2023
d2c1c87
warnings test
measty Jul 7, 2023
7bbce45
:memo: Minor docstring changes
shaneahmed Jul 11, 2023
e39d46b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 11, 2023
6d145da
Merge branch 'develop' into wkb-decoding
shaneahmed Jul 12, 2023
5c62547
🎨 Change to_wkb_geometry to to_wkb For Consistency
John-P Jul 14, 2023
fe1c809
🐛 Correct Return Type for to_wkb
John-P Jul 14, 2023
4b8006c
✨ Extend Annotation To Support Creation From Coords
John-P Jul 14, 2023
638a057
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 14, 2023
35de8ac
🐛 Require coords or geometry in init
John-P Jul 14, 2023
2fefa27
🎨 Remove Redundant Conditional
John-P Jul 14, 2023
4e02aab
Merge branch 'develop' into wkb-decoding
shaneahmed Jul 14, 2023
948d650
Merge branch 'wkb-decoding' into wkb-decoding-annotation-ext
shaneahmed Jul 14, 2023
b3c8920
Update tests/test_visualization.py
shaneahmed Jul 14, 2023
7dc0e30
Merge branch 'wkb-decoding' into wkb-decoding-annotation-ext
shaneahmed Jul 14, 2023
56ca0f6
address comments
measty Jul 21, 2023
2cb1921
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Jul 21, 2023
9ac9119
Merge branch 'wkb-decoding' into wkb-decoding-annotation-ext
John-P Jul 22, 2023
127f012
🚨 Fix Flake8 & Ruff Errors
John-P Jul 23, 2023
fd75373
🚨 Fix Ruff Errors
John-P Jul 23, 2023
6e70fdc
🏷️ Add Future Annotations Import
John-P Jul 23, 2023
4dcece8
🔀 Merge branch 'develop' into wkb-decoding-annotation-ext
John-P Jul 23, 2023
e03f825
✏️ Spelling
John-P Jul 23, 2023
c81c3af
Merge branch 'develop' into wkb-decoding-annotation-ext
John-P Jul 24, 2023
d37f7e1
🐛 Fix Create Frozen Annotation from Coordinates
John-P Jul 24, 2023
3a9cf6c
✅ Change Expected Exception
John-P Jul 24, 2023
8b47fdc
Merge branch 'wkb-decoding-annotation-ext' of https://github.com/TIA-…
John-P Jul 24, 2023
1b91b8d
📝 Fix Quotes In Example
John-P Jul 24, 2023
ddae270
🎨 Change Imports to Avoid Shadowing wkt/wkb
John-P Jul 24, 2023
f60f93c
✅ Fix decode_wkb Test
John-P Jul 24, 2023
714acf3
Merge branch 'develop' into wkb-decoding-annotation-ext
shaneahmed Jul 24, 2023
64a2352
Merge branch 'develop' into wkb-decoding-annotation-ext
John-P Jul 24, 2023
5706505
✅ Add Anotation Init Tests
John-P Jul 24, 2023
e0a1538
✨ Use Enum For Geometry Type
John-P Jul 24, 2023
9e48b68
🎨 Rename geom_type -> geometry_type
John-P Jul 24, 2023
cabac1b
🎨 Rename geometry_type -> geom_type
John-P Jul 24, 2023
a8f439e
🎨 Rename GEOMTYPES -> GEOM_TYPES
John-P Jul 24, 2023
81ddc5f
♻️ Integrate With Upstream Changes
John-P Jul 25, 2023
397c9d4
🎨 Tidy Typing
John-P Jul 25, 2023
89dca3d
🔀 Merge branch 'develop' into wkb-decoding-annotation-ext
John-P Jul 25, 2023
5dd9ff4
🐛 Remove TypeAlias for Python<3.10
John-P Jul 25, 2023
58107d0
Merge branch 'develop' into wkb-decoding-annotation-ext
John-P Jul 25, 2023
2051334
🔥 Remove Unused Method
John-P Jul 25, 2023
c8beb3b
✅ Add No Cover
John-P Jul 25, 2023
39c82c7
✅ Add Annotation Tests
John-P Jul 25, 2023
9e21622
🔀 Merge branch 'develop' into wkb-decoding-annotation-ext
John-P Jul 25, 2023
46e002e
✅ Add Annotation Tests
John-P Jul 25, 2023
128b9df
✅ Add Annotation Tests
John-P Jul 25, 2023
62ec8fb
✅ Add Equality Test
John-P Jul 26, 2023
29038c1
📝 Docstring Update
John-P Jul 26, 2023
81ed136
✅ Update Test for Appending Invalid Geometry Type
John-P Jul 26, 2023
e2c0b84
✅ Update Tests for Rendering Unknown Geometry
John-P Jul 26, 2023
06bfd89
✅ Update MultiPolygon Rendering
John-P Jul 26, 2023
fd5afe3
📝 Missing Newline
John-P Jul 26, 2023
c8e63d8
🔀 Merge branch 'develop' into wkb-decoding-annotation-ext
John-P Jul 27, 2023
505010c
✅ Add Tests for WKB to Coords
John-P Jul 27, 2023
2de247e
🔥 Remove MultiPolygon from render_by_type Cases
John-P Jul 27, 2023
9d2b160
🐛 Fix Annotation WKB to Coords Tests
John-P Jul 28, 2023
9d8a1ef
🐛 Test Fixes
John-P Jul 28, 2023
83750ce
⏪ Add Removed Imports
John-P Jul 28, 2023
e874ff4
⏪ Restore Removed Imports
John-P Jul 28, 2023
699d667
🐛 Ensure Consistency Between WKB & Shapely Coords
John-P Jul 28, 2023
85c8588
✅ Add MultiPoint Tests
John-P Jul 28, 2023
abff97f
✅ Add Test For Unknown Geomertry
John-P Jul 28, 2023
0a1e03c
🔀 Merge branch 'develop' into wkb-decoding-annotation-ext
John-P Jul 28, 2023
e70eda0
Merge branch 'develop' into wkb-decoding-annotation-ext
John-P Jul 31, 2023
84dc5e0
:rotating_light: Fix linter errors in tests/test_annotation_stores.py
shaneahmed Aug 3, 2023
914a6c8
:rotating_light: Fix linter errors in tests/test_enums.py and tests/t…
shaneahmed Aug 3, 2023
6b8a845
Merge remote-tracking branch 'origin/develop' into wkb-decoding-annot…
shaneahmed Aug 4, 2023
447828e
Merge branch 'develop' into wkb-decoding-annotation-ext
shaneahmed Aug 8, 2023
9ca4ec6
:bug: Fix merge errors
shaneahmed Aug 8, 2023
416cbda
Merge branch 'develop' into wkb-decoding-annotation-ext
shaneahmed Aug 9, 2023
2041513
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
674a409
Merge remote-tracking branch 'origin/develop' into wkb-decoding-annot…
shaneahmed Aug 11, 2023
90997c8
:bug: Fix unused tests
shaneahmed Aug 11, 2023
ca57db7
Merge branch 'develop' into wkb-decoding-annotation-ext
shaneahmed Aug 14, 2023
c56acc5
Merge branch 'develop' into wkb-decoding-annotation-ext
shaneahmed Aug 14, 2023
ae4a806
✏️ Fix Typos + WKT Refactor Test
John-P Aug 16, 2023
181a0b9
🚨 Add noqa Comments
John-P Aug 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
329 changes: 308 additions & 21 deletions tests/test_annotation_stores.py

Large diffs are not rendered by default.

34 changes: 15 additions & 19 deletions tests/test_annotation_tilerendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,17 @@ def sub_tile_level_count(self):


def test_unknown_geometry(
fill_store,
tmp_path: Path,
fill_store, # noqa: ARG001
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test warning when unknown geometries cannot be rendered."""
array = np.ones((1024, 1024))
wsi = wsireader.VirtualWSIReader(array)
_, store = fill_store(SQLiteStore, tmp_path / "test.db")
store.append(
Annotation(geometry=MultiPoint([(5.0, 5.0), (10.0, 10.0)]), properties={}),
)
store.commit()
renderer = AnnotationRenderer(max_scale=8, edge_thickness=0)
tg = AnnotationTileGenerator(wsi.info, store, renderer, tile_size=256)
tg.get_tile(0, 0, 0)
renderer.render_by_type(
tile=np.zeros((256, 256, 3), dtype=np.uint8),
annotation=Annotation(MultiPoint([(5.0, 5.0), (10.0, 10.0)])),
top_left=(0, 0),
scale=1,
)
assert "Unknown geometry" in caplog.text


Expand Down Expand Up @@ -431,16 +427,16 @@ def test_unfilled_polys(fill_store, tmp_path: Path) -> None:
assert np.sum(tile_filled) > 2 * np.sum(tile_outline)


def test_multipolygon_render(cell_grid, tmp_path: Path) -> None:
def test_multipolygon_render(cell_grid) -> None:
"""Test multipolygon rendering."""
array = np.ones((1024, 1024))
wsi = wsireader.VirtualWSIReader(array, mpp=(1, 1))
store = SQLiteStore(tmp_path / "test.db")
# add a multi-polygon
store.append(Annotation(MultiPolygon(cell_grid), {"color": (1, 0, 0)}))
renderer = AnnotationRenderer(score_prop="color", edge_thickness=0)
tg = AnnotationTileGenerator(wsi.info, store, renderer, tile_size=256)
tile = np.array(tg.get_tile(1, 0, 0))
tile = np.zeros((1024, 1024, 3), dtype=np.uint8)
renderer.render_multipoly(
tile=tile,
annotation=Annotation(MultiPolygon(cell_grid), {"color": (1, 0, 0)}),
top_left=(0, 0),
scale=1,
)
_, num = label(np.array(tile)[:, :, 0])
assert num == 25 # expect 25 red objects

Expand Down
40 changes: 40 additions & 0 deletions tests/test_enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Tests for the enumerated types used by TIAToolbox."""
import pytest

from tiatoolbox.enums import GeometryType


def test_geometrytype_missing() -> None:
"""Test that GeometryType.MISSING is returned when given None."""
with pytest.raises(ValueError, match="not a valid GeometryType"):
GeometryType(None)


def test_geometrytype_point_from_string() -> None:
"""Init GeometryType.POINT from string."""
assert GeometryType("Point") == GeometryType.POINT


def test_geometrytype_linestring_from_string() -> None:
"""Init GeometryType.LINE_STRING from string."""
assert GeometryType("LineString") == GeometryType.LINE_STRING


def test_geometrytype_polygon_from_string() -> None:
"""Init GeometryType.POLYGON from string."""
assert GeometryType("Polygon") == GeometryType.POLYGON


def test_geometrytype_multipoint_from_string() -> None:
"""Init GeometryType.MULTI_POINT from string."""
assert GeometryType("MultiPoint") == GeometryType.MULTI_POINT


def test_geometrytype_multilinestring_from_string() -> None:
"""Init GeometryType.MULTI_LINE_STRING from string."""
assert GeometryType("MultiLineString") == GeometryType.MULTI_LINE_STRING


def test_geometrytype_multipolygon_from_string() -> None:
"""Init GeometryType.MULTI_POLYGON from string."""
assert GeometryType("MultiPolygon") == GeometryType.MULTI_POLYGON
35 changes: 22 additions & 13 deletions tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
Polygon,
)

from tiatoolbox.annotation.storage import Annotation
from tiatoolbox.enums import GeometryType
from tiatoolbox.utils.visualization import (
AnnotationRenderer,
overlay_prediction_contours,
overlay_prediction_mask,
overlay_probability_map,
Expand All @@ -27,7 +28,7 @@
from tiatoolbox.wsicore.wsireader import WSIReader


def test_overlay_prediction_mask(sample_wsi_dict) -> None:
def test_overlay_prediction_mask(sample_wsi_dict: dict) -> None:
"""Test for overlaying merged patch prediction of wsi."""
mini_wsi_svs = Path(sample_wsi_dict["wsi2_4k_4k_svs"])
mini_wsi_pred = Path(sample_wsi_dict["wsi2_4k_4k_pred"])
Expand Down Expand Up @@ -127,7 +128,7 @@ def test_overlay_prediction_mask(sample_wsi_dict) -> None:
_ = overlay_prediction_mask(thumb_float, merged, min_val=0.5, return_ax=False)


def test_overlay_probability_map(sample_wsi_dict) -> None:
def test_overlay_probability_map(sample_wsi_dict: dict) -> None:
"""Test functional run for overlaying merged patch prediction of wsi."""
mini_wsi_svs = Path(sample_wsi_dict["wsi2_4k_4k_svs"])
reader = WSIReader.open(mini_wsi_svs)
Expand Down Expand Up @@ -216,8 +217,9 @@ def test_overlay_instance_prediction() -> None:
type_colours=type_colours,
line_thickness=1,
)
ref_value = -12
assert np.sum(canvas[..., 0].astype(np.int32) - inst_map) == 0
assert np.sum(canvas[..., 1].astype(np.int32) - inst_map) == -12
assert np.sum(canvas[..., 1].astype(np.int32) - inst_map) == ref_value
assert np.sum(canvas[..., 2].astype(np.int32) - inst_map) == 0
canvas = overlay_prediction_contours(
canvas,
Expand Down Expand Up @@ -276,8 +278,6 @@ def test_plot_graph() -> None:

def test_decode_wkb() -> None:
"""Test decoding of WKB geometries."""
renderer = AnnotationRenderer()

# Create some Shapely geometries of supported types
point = Point(0, 0)
line = LineString([(0, 0), (1, 1), (2, 0)])
Expand All @@ -289,9 +289,18 @@ def test_decode_wkb() -> None:
polygon_wkb = polygon.wkb

# Decode the WKB geometries
point_contours = renderer.decode_wkb(point_wkb, 1).reshape(-1, 2)
line_contours = renderer.decode_wkb(line_wkb, 2).reshape(-1, 2)
polygon_contours = renderer.decode_wkb(polygon_wkb, 3).reshape(-1, 2)
point_contours = Annotation.decode_wkb(
point_wkb,
GeometryType.POINT,
)
line_contours = Annotation.decode_wkb(
line_wkb,
GeometryType.LINE_STRING,
)
polygon_contours = Annotation.decode_wkb(
polygon_wkb,
GeometryType.POLYGON,
)

# Check that the decoded contours are as expected
assert np.all(point_contours == np.array([[0, 0]]))
Expand All @@ -314,9 +323,9 @@ def test_decode_wkb() -> None:
multiline_wkb = multiline.wkb
multipolygon_wkb = multipolygon.wkb

multipoint_contours = renderer.decode_wkb(multipoint_wkb, 4).reshape(3, -1, 2)
multiline_contours = renderer.decode_wkb(multiline_wkb, 5).reshape(2, -1, 2)
multipolygon_contours = renderer.decode_wkb(multipolygon_wkb, 6).reshape(2, -1, 2)
multipoint_contours = Annotation.decode_wkb(multipoint_wkb, 4)
multiline_contours = Annotation.decode_wkb(multiline_wkb, 5)
multipolygon_contours = Annotation.decode_wkb(multipolygon_wkb, 6)

assert np.all(multipoint_contours == np.array([[[0, 0]], [[1, 1]], [[2, 0]]]))
assert np.all(
Expand All @@ -335,4 +344,4 @@ def test_decode_wkb() -> None:

# test unknown geometry type
with pytest.raises(ValueError, match=r"Unknown geometry type"):
renderer.decode_wkb(multipolygon_wkb, 7)
Annotation.decode_wkb(multipolygon_wkb, 7)
Loading