Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
206 commits
Select commit Hold shift + click to select a range
dc34560
initial bokeh app commit
measty Jul 13, 2023
968d658
tests and remote samples
measty Jul 13, 2023
45724e1
hovernet mask
measty Jul 14, 2023
2de2853
demo-name
measty Jul 22, 2023
1c50210
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Jul 22, 2023
b4a8192
update reqs
measty Jul 22, 2023
b5caf1c
add tests
measty Jul 26, 2023
db8d57a
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Aug 3, 2023
feb61b2
add some config tests
measty Aug 4, 2023
e78bbe0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
1a01fdb
remove redundant code
measty Aug 4, 2023
6d5850e
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Aug 4, 2023
cd5909c
Merge branch 'develop' into add-bokeh-app
shaneahmed Aug 4, 2023
3f4ccf6
ruff related changes
measty Aug 4, 2023
2d82060
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Aug 4, 2023
8089521
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
2b76e4c
deepsource/precommit fixes
measty Aug 4, 2023
93827a2
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Aug 4, 2023
06172a7
fix temp paths
measty Aug 4, 2023
d14c5ca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
1eab5fb
deepsource changes
measty Aug 4, 2023
56a9fc7
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Aug 4, 2023
357be17
deepsource fix
measty Aug 4, 2023
4ce161f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
50c3418
add tests
measty Aug 4, 2023
1016da0
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Aug 4, 2023
0cc2dd8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
9a885a3
change graphs to json
measty Aug 4, 2023
15112ef
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Aug 4, 2023
a438307
initial documentation draft
measty Aug 7, 2023
2e9c49d
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Aug 7, 2023
5404fa4
boolean trap stuff
measty Aug 7, 2023
247eb42
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2023
e7840bf
add some annotations
measty Aug 11, 2023
e7313a3
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Aug 11, 2023
a12fea1
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Aug 11, 2023
230eac9
Merge branch 'develop' into add-bokeh-app
shaneahmed Aug 11, 2023
fe74c61
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2023
ea1c2d3
Merge branch 'develop' into add-bokeh-app
shaneahmed Aug 14, 2023
913f9fb
Merge branch 'develop' into add-bokeh-app
shaneahmed Aug 14, 2023
5a170f5
docstring improvements
measty Aug 15, 2023
d680539
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Aug 19, 2023
65e0ad4
additional tests
measty Aug 29, 2023
bb562ef
Merge branch 'develop' into add-bokeh-app
shaneahmed Aug 30, 2023
998af96
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Aug 31, 2023
b4f7914
added tests
measty Sep 1, 2023
b2d89a5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2023
5e6f2dd
precommit fixes
measty Sep 1, 2023
c731ef8
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 7, 2023
eb280b6
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Sep 7, 2023
1744158
make ruff stop complaining
measty Sep 7, 2023
da83e6a
noqa
measty Sep 7, 2023
768d7ef
make ruff stop complaining pt2
measty Sep 7, 2023
4aad61b
make ruff stop complaining pt2
measty Sep 7, 2023
20e56eb
ruff
measty Sep 7, 2023
4c03ae9
ruff..
measty Sep 8, 2023
7249b9d
ruff...
measty Sep 8, 2023
ea924af
:bug: Fix I001 [*] Import block is un-sorted or un-formatted
shaneahmed Sep 8, 2023
691dbf6
add tests
measty Sep 14, 2023
bd897a7
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Sep 14, 2023
40e8232
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 14, 2023
972552c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 14, 2023
84d0a34
more tests
measty Sep 14, 2023
f95ef6a
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 14, 2023
360294b
tests
measty Sep 15, 2023
72d000d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 15, 2023
3d6d246
improve coverage
measty Sep 16, 2023
0978879
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 16, 2023
3adfb8f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2023
3ef12ee
some restructuring + tests
measty Sep 16, 2023
3276163
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 16, 2023
1fd3962
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2023
2a45be6
deepsource fix
measty Sep 16, 2023
c64321b
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 16, 2023
0cf201d
rename tests
measty Sep 16, 2023
08af133
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2023
84de0e1
app hooks
measty Sep 17, 2023
9f011f3
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 17, 2023
b02fc28
add shutdown
measty Sep 17, 2023
a15681f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2023
7b55496
.
measty Sep 17, 2023
7b99b98
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 17, 2023
f75b3ee
.
measty Sep 17, 2023
e6e28b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2023
e863304
add sleep
measty Sep 17, 2023
4174631
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 17, 2023
94d0740
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2023
e5187fa
env
measty Sep 17, 2023
5bc9527
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 17, 2023
e380582
.
measty Sep 18, 2023
e0bbee9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2023
5caae93
.
measty Sep 18, 2023
7ffa7c9
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 18, 2023
65073a4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2023
d79dd0d
make tests work in github actions
measty Sep 18, 2023
698c54f
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 18, 2023
7f44c0b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2023
89ae473
.
measty Sep 18, 2023
1849242
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 18, 2023
fc3c7b4
.
measty Sep 18, 2023
51be263
.
measty Sep 18, 2023
e5238ea
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2023
f45e87f
coverage
measty Sep 18, 2023
c01fb7a
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 18, 2023
4631c87
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2023
95a8e71
coverage
measty Sep 18, 2023
31538a2
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 18, 2023
797d207
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2023
59d9b5f
improve docs
measty Sep 19, 2023
06c0099
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 19, 2023
34b316e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2023
9b56095
doc updates
measty Sep 20, 2023
70ade31
annotation inspection
measty Sep 21, 2023
62ef130
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 21, 2023
cef0505
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 21, 2023
803e4ca
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Sep 21, 2023
096d52e
coverage
measty Sep 22, 2023
149dff6
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Sep 22, 2023
0cb6115
type annotations
measty Sep 29, 2023
6445d9e
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Sep 29, 2023
92380e3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 29, 2023
cd70a97
🚨 Add `flake8-annotations` to `test_app_bokeh`
Oct 2, 2023
372f93d
🚨 Add `flake8-annotations` to more `bokeh` tests
Oct 2, 2023
b47725e
Merge branch 'develop' into add-bokeh-app
shaneahmed Oct 4, 2023
621e6b1
annotations
measty Oct 6, 2023
4539110
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2023
43371eb
annotations again
measty Oct 6, 2023
0267c00
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Oct 6, 2023
28c60c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2023
fdb0839
fix new keyword args
measty Oct 6, 2023
0a0b4b6
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Oct 6, 2023
9b1a9bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2023
29eaea5
fix errors due to some args becoming keyword only
measty Oct 6, 2023
a015934
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2023
6bc76f2
fix test
measty Oct 6, 2023
b4e5b7d
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Oct 6, 2023
ce69405
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Oct 12, 2023
30c7230
annotation and docstring improvements
measty Oct 12, 2023
bd88079
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 12, 2023
1f73712
docstring improvements
measty Oct 13, 2023
96c1bd9
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Oct 13, 2023
6869433
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Oct 13, 2023
482ab28
slide info
measty Oct 17, 2023
dd1bfc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2023
1f3d06f
initial cprop
measty Oct 17, 2023
22024cf
update test
measty Oct 17, 2023
6823a1f
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Oct 17, 2023
a9971b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2023
9378cfb
make template findable by setup.py
measty Oct 19, 2023
482cd45
add template to manifest
measty Oct 19, 2023
3bbf59a
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Oct 19, 2023
7397d1c
address some review commnts
measty Oct 20, 2023
7987648
doc updates
measty Oct 20, 2023
84d1dc8
doc update
measty Oct 20, 2023
74e96cc
re-order doc sections
measty Oct 20, 2023
d381c06
add help tooltips
measty Oct 26, 2023
9e44b10
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Oct 26, 2023
b2883fe
move fixture to conftest
measty Oct 26, 2023
fe97609
doc updates
measty Oct 27, 2023
f122c54
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 27, 2023
8b19b73
capitalize comments
measty Oct 27, 2023
39295ea
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Oct 27, 2023
c61c126
address comments
measty Oct 27, 2023
dac7dd5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 27, 2023
6ab2935
address comments
measty Oct 27, 2023
f9c4555
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Oct 27, 2023
7e4a79c
update add_from_dat to handle newest cerberus output format
measty Oct 27, 2023
9972ff7
small doc corrections
measty Oct 27, 2023
bdf6b0b
add link to cerberus
measty Oct 27, 2023
143be64
doc update
measty Oct 30, 2023
967d420
address feedback
measty Nov 2, 2023
26789ca
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Nov 2, 2023
4e54435
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2023
87fb6e9
improve cli option names
measty Nov 2, 2023
ae029e8
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Nov 2, 2023
59d64b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2023
9e250f0
update docs to new cli
measty Nov 3, 2023
7f44edd
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Nov 3, 2023
8eb8f9d
doc updates
measty Nov 3, 2023
e077cb1
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Nov 3, 2023
566f323
[skip ci] :memo: Fix minor typos
shaneahmed Nov 3, 2023
ccce08e
[skip ci] :memo: Fix minor typos
shaneahmed Nov 3, 2023
ce9e713
[skip ci] :memo: Fix minor typos
shaneahmed Nov 3, 2023
c64bd31
transparency
measty Nov 6, 2023
a443171
add test
measty Nov 8, 2023
d2bbe34
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Nov 8, 2023
eccffe6
Merge branch 'develop' into add-bokeh-app
shaneahmed Nov 22, 2023
d7e798b
Merge branch 'develop' into add-bokeh-app
shaneahmed Nov 30, 2023
fc5b265
address comments
measty Nov 30, 2023
86a6887
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Nov 30, 2023
2e157f7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 30, 2023
0fd25be
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty Nov 30, 2023
d039555
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Nov 30, 2023
ef59755
fix renamed color_dict key
measty Nov 30, 2023
848f0d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 30, 2023
bd8ca1f
multithread
measty Dec 4, 2023
27d3b19
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Dec 4, 2023
5db752b
address comments
measty Dec 4, 2023
e3a0b3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2023
a28b140
remove python 3.7 stuff
measty Dec 4, 2023
283e69d
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty Dec 4, 2023
53fe7f2
add test
measty Dec 5, 2023
7f1f342
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 5, 2023
1c31782
Merge branch 'develop' into add-bokeh-app
shaneahmed Dec 8, 2023
25200b9
Merge branch 'develop' into add-bokeh-app
shaneahmed Dec 12, 2023
94690b7
:pencil2: Fix typos and other minor issues.
shaneahmed Dec 15, 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
2 changes: 2 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# torch installation
--extra-index-url https://download.pytorch.org/whl/cu118; sys_platform != "darwin"
albumentations>=1.3.0
bokeh>=3.1.1
Click>=8.1.3
defusedxml>=0.7.1
filelock>=3.9.0
flask>=2.2.2
flask-cors
glymur>=0.12.1, ~=0.12.6 # 0.12.6 is incompatible due to a private attribute
imagecodecs>=2022.9.26
joblib>=1.1.1
Expand Down
350 changes: 350 additions & 0 deletions tests/test_bokeh_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,350 @@
import io
import time

import matplotlib.pyplot as plt
import numpy as np
import pkg_resources
import pytest
import requests
from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
from bokeh.events import ButtonClick, MenuItemClick
from matplotlib import colormaps
from PIL import Image
from scipy.ndimage import label

from tiatoolbox.data import _fetch_remote_sample
from tiatoolbox.visualization.bokeh_app import main

BOKEH_PATH = pkg_resources.resource_filename("tiatoolbox", "visualization/bokeh_app")


def get_tile(layer, x, y, z, show=False):
"""Get a tile from the server."""
source = main.UI["p"].renderers[main.UI["vstate"].layer_dict[layer]].tile_source
url = source.url
# replace {x}, {y}, {z} with tile coordinates
url = url.replace("{x}", str(x)).replace("{y}", str(y)).replace("{z}", str(z))
im = io.BytesIO(requests.get(url).content)
if show:
plt.imshow(np.array(Image.open(im)))
plt.show()
return np.array(Image.open(im))


def get_renderer_prop(prop):
"""Get a renderer property from the server."""
resp = main.UI["s"].get(f"http://{main.host2}:5000/tileserver/renderer/{prop}")
return resp.json()


@pytest.fixture(scope="module")
def data_path(tmp_path_factory):
"""Set up a temporary data directory."""
tmp_path = tmp_path_factory.mktemp("data")
(tmp_path / "slides").mkdir()
(tmp_path / "overlays").mkdir()
return {"base_path": tmp_path}


@pytest.fixture(scope="module", autouse=True)
def annotation_path(data_path):
data_path["slide1"] = _fetch_remote_sample(
"svs-1-small",
data_path["base_path"] / "slides",
)
data_path["slide2"] = _fetch_remote_sample(
"ndpi-1",
data_path["base_path"] / "slides",
)
data_path["annotations"] = _fetch_remote_sample(
"annotation_store_svs_1",
data_path["base_path"] / "overlays",
)
data_path["graph"] = _fetch_remote_sample(
"graph_svs_1",
data_path["base_path"] / "overlays",
)
return data_path


"""Test visualization tool."""


@pytest.fixture(scope="module")
def doc(data_path):
# make a bokeh app
main.config.set_sys_args(argv=["dummy_str", str(data_path["base_path"])])
handler = FunctionHandler(main.config.setup_doc)
app = Application(handler)
return app.create_document()


def test_roots(doc):
# should be 2 roots, main window and controls
assert len(doc.roots) == 2


def test_slide_select(doc, data_path):
slide_select = doc.get_model_by_name("slide_select0")
# check there are two available slides
assert len(slide_select.options) == 2
assert slide_select.options[0][0] == data_path["slide1"].name

# select a slide and check it is loaded
slide_select.value = ["CMU-1.ndpi"]
assert main.UI["vstate"].slide_path == data_path["slide2"]


def test_dual_window(doc, data_path):
control_tabs = doc.get_model_by_name("ui_layout")
doc.get_model_by_name("slide_windows")
control_tabs.active = 1
slide_select = doc.get_model_by_name("slide_select1")
assert len(slide_select.options) == 2
assert slide_select.options[0][0] == data_path["slide1"].name


def test_remove_dual_window(doc, data_path):
control_tabs = doc.get_model_by_name("ui_layout")
slide_wins = doc.get_model_by_name("slide_windows")
assert len(slide_wins.children) == 2
# remove the second window
control_tabs.tabs.pop()
assert len(slide_wins.children) == 1

slide_select = doc.get_model_by_name("slide_select0")
slide_select.value = [data_path["slide1"].name]
assert main.UI["vstate"].slide_path == data_path["slide1"]


def test_add_annotation_layer(doc, data_path):
layer_drop = doc.get_model_by_name("layer_drop0")
assert len(layer_drop.menu) == 2
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, layer_drop.menu[0][0])
layer_drop._trigger_event(click)
# should be one more renderer now
assert len(doc.get_model_by_name("slide_windows").children[0].renderers) == (
n_renderers + 1
)
# we should have got the types of annotations back from the server too
assert main.UI["vstate"].types == ["0", "1", "2", "3", "4"]


def test_cprop_input(doc):
cprop_input = doc.get_model_by_name("cprop0")
cmap_select = doc.get_model_by_name("cmap0")
cprop_input.value = ["prob"]
# as prob is continuous, cmap should be set to whatever cmap is selected
assert main.UI["vstate"].cprop == "prob"
assert main.UI["color_bar"].color_mapper.palette[0] == main.rgb2hex(
colormaps[cmap_select.value](0),
)

cprop_input.value = ["type"]
# as type is discrete, cmap should be a dict mapping types to colors
assert isinstance(main.UI["vstate"].mapper, dict)
assert list(main.UI["vstate"].mapper.keys()) == list(
main.UI["vstate"].orig_types.values(),
)


def test_type_cmap_select(doc):
cmap_select = doc.get_model_by_name("type_cmap0")
main.UI["vstate"]
main.UI["user"]
cmap_select.value = ["prob", "0"]
# set edge thicknes to 0 so the edges don't add an extra colour
spinner = doc.get_model_by_name("edge_size0")
spinner.value = 0
im = get_tile("overlay", 1, 2, 2)
# check there are more than just num_types unique colors in the image,
# as we have mapped type 0 to a continuous cmap on prob
assert len(np.unique(im.sum(axis=2))) > 10


def test_load_graph(doc, data_path):
layer_drop = doc.get_model_by_name("layer_drop0")
# trigger an event to select the graph .db file
click = MenuItemClick(layer_drop, layer_drop.menu[1][1])
layer_drop._trigger_event(click)
# we should have 2144 nodes in the node_source now
assert len(main.UI["node_source"].data["x_"]) == 2144


def test_hovernet_on_box(doc, data_path):
slide_select = doc.get_model_by_name("slide_select0")
slide_select.value = [data_path["slide2"].name]
go_button = doc.get_model_by_name("to_model0")
assert len(main.UI["color_column"].children) == 0
slide_select.value = [data_path["slide1"].name]
# set up a box selection
main.UI["box_source"].data = {
"x": [1200],
"y": [-2000],
"width": [800],
"height": [800],
}

# select hovernet model and run it on box
model_select = doc.get_model_by_name("model_drop0")
click = MenuItemClick(model_select, model_select.menu[0])
model_select._trigger_event(click)

click = ButtonClick(go_button)
go_button._trigger_event(click)
im = get_tile("overlay", 4, 8, 4)
lab, num = label(np.any(im[:, :, :3], axis=2))
# check there are multiple cells being detected
assert len(main.UI["color_column"].children) > 3
assert num > 10


def test_alpha_sliders(doc):
slide_alpha = doc.get_model_by_name("slide_alpha0")
overlay_alpha = doc.get_model_by_name("overlay_alpha0")

# set alpha to 0.5
slide_alpha.value = 0.5
overlay_alpha.value = 0.5
# check that the alpha values have been set correctly
assert main.UI["p"].renderers[0].alpha == 0.5
assert main.UI["p"].renderers[main.UI["vstate"].layer_dict["overlay"]].alpha == 0.5


def test_alpha_buttons(doc):
slide_toggle = doc.get_model_by_name("slide_toggle0")
overlay_toggle = doc.get_model_by_name("overlay_toggle0")
# clicking the button should set alpha to 0
slide_toggle.active = False
assert main.UI["p"].renderers[0].alpha == 0
overlay_toggle.active = False
assert main.UI["p"].renderers[main.UI["vstate"].layer_dict["overlay"]].alpha == 0

# clicking again should set alpha back to previous value
slide_toggle.active = True
assert main.UI["p"].renderers[0].alpha == 0.5
overlay_toggle.active = True
assert main.UI["p"].renderers[main.UI["vstate"].layer_dict["overlay"]].alpha == 0.5


def test_type_select(doc):
# load annotation layer
layer_drop = doc.get_model_by_name("layer_drop0")
click = MenuItemClick(layer_drop, layer_drop.menu[0][0])
layer_drop._trigger_event(click)
time.sleep(1)
im = get_tile("overlay", 4, 8, 4)
_, num_before = label(np.any(im[:, :, :3], axis=2))
type_column_list = doc.get_model_by_name("type_column0").children
# click on the first and last to deselect them
type_column_list[0].active = False
type_column_list[-1].active = False
# check that the number of cells has decreased
im = get_tile("overlay", 4, 8, 4)
_, num_after = label(np.any(im[:, :, :3], axis=2))
assert num_after < num_before
# reselect them
type_column_list[0].active = True
type_column_list[-1].active = True
# check we are back to original number of cells
im = get_tile("overlay", 4, 8, 4)
_, num_after = label(np.any(im[:, :, :3], axis=2))
assert num_after == num_before


def test_color_boxes(doc):
color_column_list = doc.get_model_by_name("color_column0").children
# set type 0 to red
color_column_list[0].color = "#ff0000"
# set type 1 to blue
color_column_list[1].color = "#0000ff"
# check the mapper matches the new colors
assert main.UI["vstate"].mapper[0] == (1, 0, 0, 1)
assert main.UI["vstate"].mapper[1] == (0, 0, 1, 1)


def test_node_and_edge_alpha(doc, data_path):
layer_drop = doc.get_model_by_name("layer_drop0")
# trigger an event to select the graph .db file
click = MenuItemClick(layer_drop, layer_drop.menu[1][1])
layer_drop._trigger_event(click)

type_column_list = doc.get_model_by_name("type_column0").children
color_column_list = doc.get_model_by_name("color_column0").children
# the last 2 will be edge and node controls
# by default nodes are visible, edges are not
assert not type_column_list[-2].active
assert type_column_list[-1].active
type_column_list[-1].active = False
type_column_list[-2].active = True
# check that the alpha values have been set correctly
assert (
main.UI["p"].renderers[main.UI["vstate"].layer_dict["nodes"]].glyph.fill_alpha
== 0
)
assert main.UI["p"].renderers[main.UI["vstate"].layer_dict["edges"]].visible is True
type_column_list[-1].active = True
color_column_list[-2].value = 0.3
color_column_list[-1].value = 0.4
# check that the alpha values have been set correctly
assert (
main.UI["p"].renderers[main.UI["vstate"].layer_dict["nodes"]].glyph.fill_alpha
== 0.4
)
assert main.UI["p"].renderers[main.UI["vstate"].layer_dict["edges"]].visible is True
assert (
main.UI["p"].renderers[main.UI["vstate"].layer_dict["edges"]].glyph.line_alpha
== 0.3
)


def test_hover_tool(doc):
# how to test this?
pass


def test_filter_box(doc):
filter_input = doc.get_model_by_name("filter0")
im = get_tile("overlay", 4, 8, 4)
_, num_before = label(np.any(im[:, :, :3], axis=2))
# filter for cells of type 0
filter_input.value = "props['type'] == 0"
im = get_tile("overlay", 4, 8, 4)
_, num_after = label(np.any(im[:, :, :3], axis=2))
# should be less than without the filter
assert num_after < num_before
# set no filter
filter_input.value = ""
im = get_tile("overlay", 4, 8, 4)
_, num_after = label(np.any(im[:, :, :3], axis=2))
# should be back to original number
assert num_after == num_before
# set an impossible filter
filter_input.value = "props['prob'] < 0"
im = get_tile("overlay", 4, 8, 4)
_, num_after = label(np.any(im[:, :, :3], axis=2))
# should be no cells
assert num_after == 0


def test_scale_spinner(doc):
scale_spinner = doc.get_model_by_name("scale0")
# set the scale to 0.5
scale_spinner.value = 0.5
# check that the scale has been set correctly
assert get_renderer_prop("max_scale") == 0.5


def test_blur_spinner(doc):
blur_spinner = doc.get_model_by_name("blur0")
# set the blur to 4
blur_spinner.value = 4
# check that the blur has been set correctly
assert get_renderer_prop("blur_radius") == 4


def test_session_end(doc):
doc.clear()
Loading