Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🆕 Add Reading Slide-level info & Simple Plugins for Visualization Tool #789

Draft
wants to merge 45 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9a7de48
add reading slide-level info from provided csv
measty Feb 21, 2024
b811b62
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 21, 2024
a692c59
add documentation entry
measty Feb 21, 2024
79ab016
Merge branch 'add-slide-data' of https://github.com/TissueImageAnalyt…
measty Feb 21, 2024
bcd5131
fix typo
measty Feb 21, 2024
d0995cc
improve test coverage
measty Feb 21, 2024
8b24409
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 21, 2024
ad57393
Merge branch 'develop' into add-slide-data
shaneahmed Mar 1, 2024
2fd714d
Merge branch 'develop' into add-slide-data
shaneahmed Mar 12, 2024
cda3110
Merge branch 'develop' into add-slide-data
shaneahmed Mar 13, 2024
ab711ff
add simple plugins
measty Mar 13, 2024
e45fb3c
Merge branch 'add-slide-data' of https://github.com/TissueImageAnalyt…
measty Mar 13, 2024
8755f27
fix test
measty Mar 13, 2024
b7715f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 14, 2024
4ca17e1
change circle size->radius for bokeh 3.4 compatibility
measty Mar 14, 2024
3cec0aa
Merge branch 'add-slide-data' of https://github.com/TissueImageAnalyt…
measty Mar 14, 2024
1e8df62
remove refs to size
measty Mar 15, 2024
96ccd97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 15, 2024
cd9e3bd
update img size
measty Mar 15, 2024
f52ee5e
Merge branch 'add-slide-data' of https://github.com/TissueImageAnalyt…
measty Mar 15, 2024
d2a6ec4
try dialog
measty Mar 15, 2024
1bec5b6
Merge branch 'develop' into add-slide-data
shaneahmed Mar 19, 2024
7b40965
replace dropdown with select
measty Mar 20, 2024
08fcb59
Merge branch 'develop' into add-slide-data
shaneahmed Mar 22, 2024
646848e
once and per slide options
measty Apr 4, 2024
4a2e48f
update tests for switch to layer select
measty Apr 8, 2024
27a9d1d
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Apr 12, 2024
880e4a6
Merge branch 'add-slide-data' of https://github.com/TissueImageAnalyt…
measty Apr 12, 2024
c8ffd30
add missing docstrings
measty Apr 12, 2024
c5165be
Merge branch 'develop' into add-slide-data
shaneahmed Apr 19, 2024
721ad20
Merge branch 'develop' into add-slide-data
shaneahmed May 10, 2024
f849dee
Merge branch 'develop' into add-slide-data
shaneahmed May 17, 2024
e15f6bb
add tests
measty May 28, 2024
23796bc
Merge branch 'develop' into add-slide-data
shaneahmed Jun 14, 2024
90d69b3
Merge branch 'develop' into add-slide-data
shaneahmed Jun 21, 2024
7768414
Merge branch 'develop' into add-slide-data
shaneahmed Jun 28, 2024
12147da
Merge branch 'add-slide-data' of https://github.com/TissueImageAnalyt…
measty Oct 3, 2024
c9e7ea1
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Oct 3, 2024
0bfb5f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 3, 2024
c39fe41
fix test
measty Oct 4, 2024
43cac84
Merge branch 'add-slide-data' of https://github.com/TissueImageAnalyt…
measty Oct 4, 2024
33a1068
Merge branch 'develop' into add-slide-data
shaneahmed Nov 22, 2024
59b4a2c
Merge branch 'develop' into add-slide-data
shaneahmed Jan 24, 2025
12b4d62
Merge branch 'develop' into add-slide-data
shaneahmed Feb 7, 2025
ab9451e
Merge branch 'develop' into add-slide-data
shaneahmed Feb 21, 2025
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
Prev Previous commit
Next Next commit
update tests for switch to layer select
measty committed Apr 8, 2024
commit 4a2e48f70c7d6a102dd4955783730647c248a8dc
31 changes: 11 additions & 20 deletions tests/test_app_bokeh.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
import requests
from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
from bokeh.events import ButtonClick, DoubleTap, MenuItemClick
from bokeh.events import ButtonClick, DoubleTap
from flask_cors import CORS
from matplotlib import colormaps
from PIL import Image
@@ -262,8 +262,7 @@ def test_add_annotation_layer(doc: Document, data_path: pytest.TempPathFactory)
slide_select.value = [data_path["slide2"].name]
layer_drop = doc.get_model_by_name("layer_drop0")
# trigger an event to select the geojson file
click = MenuItemClick(layer_drop, str(data_path["geojson_anns"]))
layer_drop._trigger_event(click)
layer_drop.value = str(data_path["geojson_anns"])
assert main.UI["vstate"].types == ["annotation"]

# test the name2type function.
@@ -272,11 +271,10 @@ def test_add_annotation_layer(doc: Document, data_path: pytest.TempPathFactory)
# test loading an annotation store
slide_select.value = [data_path["slide1"].name]
layer_drop = doc.get_model_by_name("layer_drop0")
assert len(layer_drop.menu) == 5
assert len(layer_drop.options) == 5
n_renderers = len(doc.get_model_by_name("slide_windows").children[0].renderers)
# trigger an event to select the annotation .db file
click = MenuItemClick(layer_drop, str(data_path["annotations"]))
layer_drop._trigger_event(click)
layer_drop.value = str(data_path["annotations"])
# should be one more renderer now
assert len(doc.get_model_by_name("slide_windows").children[0].renderers) == (
n_renderers + 1
@@ -369,8 +367,7 @@ def test_load_graph(doc: Document, data_path: pytest.TempPathFactory) -> None:
"""Test loading a graph."""
layer_drop = doc.get_model_by_name("layer_drop0")
# trigger an event to select the graph file
click = MenuItemClick(layer_drop, str(data_path["graph"]))
layer_drop._trigger_event(click)
layer_drop.value = str(data_path["graph"])
# we should have 2144 nodes in the node_source now
assert len(main.UI["node_source"].data["x_"]) == 2144

@@ -379,8 +376,7 @@ def test_graph_with_feats(doc: Document, data_path: pytest.TempPathFactory) -> N
"""Test loading a graph with features."""
layer_drop = doc.get_model_by_name("layer_drop0")
# trigger an event to select the graph .json file
click = MenuItemClick(layer_drop, str(data_path["graph_feats"]))
layer_drop._trigger_event(click)
layer_drop.value = str(data_path["graph_feats"])
# we should have keys for the features in node data source now
for i in range(10):
assert f"feat_{i}" in main.UI["node_source"].data
@@ -402,17 +398,15 @@ def test_graph_with_feats(doc: Document, data_path: pytest.TempPathFactory) -> N
)

# test graph overlay option remains on loading new overlay
click = MenuItemClick(layer_drop, str(data_path["annotations"]))
layer_drop._trigger_event(click)
layer_drop.value = str(data_path["annotations"])
assert "graph_overlay" in cmap_select.options


def test_load_img_overlay(doc: Document, data_path: pytest.TempPathFactory) -> None:
"""Test loading an image overlay."""
layer_drop = doc.get_model_by_name("layer_drop0")
# trigger an event to select the image overlay
click = MenuItemClick(layer_drop, str(data_path["img_overlay"]))
layer_drop._trigger_event(click)
layer_drop.value = str(data_path["img_overlay"])
layer_slider = doc.get_model_by_name("layer2_slider")
assert layer_slider is not None

@@ -474,8 +468,7 @@ def test_hovernet_on_box(doc: Document, data_path: pytest.TempPathFactory) -> No
cprop_select = doc.get_model_by_name("cprop0")
cprop_select.value = ["prob"]
layer_drop = doc.get_model_by_name("layer_drop0")
click = MenuItemClick(layer_drop, str(data_path["dat_anns"]))
layer_drop._trigger_event(click)
layer_drop.value = str(data_path["dat_anns"])
assert main.UI["vstate"].types == ["annotation"]
# check the per-type ui controls have been updated
assert len(main.UI["color_column"].children) == 1
@@ -516,8 +509,7 @@ def test_type_select(doc: Document, data_path: pytest.TempPathFactory) -> None:
"""Test selecting/deselecting specific types."""
# load annotation layer
layer_drop = doc.get_model_by_name("layer_drop0")
click = MenuItemClick(layer_drop, str(data_path["annotations"]))
layer_drop._trigger_event(click)
layer_drop.value = str(data_path["annotations"])
time.sleep(1)
im = get_tile("overlay", 4, 8, 4, show=False)
_, num_before = label(np.any(im[:, :, :3], axis=2))
@@ -569,8 +561,7 @@ def test_node_and_edge_alpha(doc: Document, data_path: pytest.TempPathFactory) -
"""Test sliders for adjusting graph node and edge alpha."""
layer_drop = doc.get_model_by_name("layer_drop0")
# trigger an event to select the graph .db file
click = MenuItemClick(layer_drop, str(data_path["graph"]))
layer_drop._trigger_event(click)
layer_drop.value = str(data_path["graph"])

type_column_list = doc.get_model_by_name("type_column0").children
color_column_list = doc.get_model_by_name("color_column0").children
4 changes: 2 additions & 2 deletions tests/test_json_config_bokeh.py
Original file line number Diff line number Diff line change
@@ -87,10 +87,10 @@ def test_slides_available(bk_session: ClientSession) -> None:
assert slide_select.value[0] == "CMU-1-Small-Region.svs"

layer_drop = doc.get_model_by_name("layer_drop0")
assert len(layer_drop.menu) == 2
assert len(layer_drop.options) == 2
# check that the overlays are available.
slide_select.value = ["CMU-1.ndpi"]
assert len(layer_drop.menu) == 2
assert len(layer_drop.options) == 2

# check the metadata wasnt found as the column name was wrong
desc = doc.get_model_by_name("description")
2 changes: 1 addition & 1 deletion tests/test_server_bokeh.py
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ def test_slides_available(bk_session: ClientSession) -> None:
# check that the overlays are available.
slide_select.value = ["CMU-1-Small-region.svs"]
layer_drop = doc.get_model_by_name("layer_drop0")
assert len(layer_drop.menu) == 2
assert len(layer_drop.options) == 2

bk_session.document.clear()
assert len(bk_session.document.roots) == 0
11 changes: 5 additions & 6 deletions tiatoolbox/visualization/bokeh_app/main.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
import pandas as pd
import requests
import torch
from bokeh.events import ButtonClick, DoubleTap, MenuItemClick
from bokeh.events import ButtonClick, DoubleTap
from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models import (
@@ -885,14 +885,13 @@ def slide_select_cb(attr: str, old: str, new: str) -> None: # noqa: ARG001
# Load the overlay and graph automatically if set in config
if doc_config["auto_load"]:
for f in UI["layer_drop"].options:
dummy_attr = DummyAttr(f[0])
layer_drop_cb(dummy_attr)
layer_drop_cb("", "", f[0])


def handle_graph_layer(attr: MenuItemClick) -> None: # skipcq: PY-R1000
def handle_graph_layer(graph_path: str) -> None: # skipcq: PY-R1000
"""Handle adding a graph layer."""
do_feats = False
with Path(attr.item).open("rb") as f:
with Path(graph_path).open("rb") as f:
graph_dict = json.load(f)
# Convert the values to numpy arrays
for k, v in graph_dict.items():
@@ -1002,7 +1001,7 @@ def layer_drop_cb(attr: str, old: str, new: str) -> None: # noqa: ARG001
"""Set up the newly chosen overlay."""
if Path(new).suffix == ".json":
# It's a graph
handle_graph_layer(attr)
handle_graph_layer(new)
return

# Otherwise it's a tile-based overlay of some form