-
Notifications
You must be signed in to change notification settings - Fork 101
✨ Add bokeh Visualization
#684
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
Merged
Merged
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 968d658
tests and remote samples
measty 45724e1
hovernet mask
measty 2de2853
demo-name
measty 1c50210
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty b4a8192
update reqs
measty b5caf1c
add tests
measty db8d57a
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty feb61b2
add some config tests
measty e78bbe0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1a01fdb
remove redundant code
measty 6d5850e
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty cd5909c
Merge branch 'develop' into add-bokeh-app
shaneahmed 3f4ccf6
ruff related changes
measty 2d82060
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 8089521
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2b76e4c
deepsource/precommit fixes
measty 93827a2
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 06172a7
fix temp paths
measty d14c5ca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1eab5fb
deepsource changes
measty 56a9fc7
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 357be17
deepsource fix
measty 4ce161f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 50c3418
add tests
measty 1016da0
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 0cc2dd8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9a885a3
change graphs to json
measty 15112ef
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty a438307
initial documentation draft
measty 2e9c49d
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 5404fa4
boolean trap stuff
measty 247eb42
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e7840bf
add some annotations
measty e7313a3
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty a12fea1
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 230eac9
Merge branch 'develop' into add-bokeh-app
shaneahmed fe74c61
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ea1c2d3
Merge branch 'develop' into add-bokeh-app
shaneahmed 913f9fb
Merge branch 'develop' into add-bokeh-app
shaneahmed 5a170f5
docstring improvements
measty d680539
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 65e0ad4
additional tests
measty bb562ef
Merge branch 'develop' into add-bokeh-app
shaneahmed 998af96
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty b4f7914
added tests
measty b2d89a5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5e6f2dd
precommit fixes
measty c731ef8
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty eb280b6
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 1744158
make ruff stop complaining
measty da83e6a
noqa
measty 768d7ef
make ruff stop complaining pt2
measty 4aad61b
make ruff stop complaining pt2
measty 20e56eb
ruff
measty 4c03ae9
ruff..
measty 7249b9d
ruff...
measty ea924af
:bug: Fix I001 [*] Import block is un-sorted or un-formatted
shaneahmed 691dbf6
add tests
measty bd897a7
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 40e8232
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 972552c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 84d0a34
more tests
measty f95ef6a
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 360294b
tests
measty 72d000d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3d6d246
improve coverage
measty 0978879
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 3adfb8f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3ef12ee
some restructuring + tests
measty 3276163
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 1fd3962
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2a45be6
deepsource fix
measty c64321b
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 0cf201d
rename tests
measty 08af133
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 84de0e1
app hooks
measty 9f011f3
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty b02fc28
add shutdown
measty a15681f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7b55496
.
measty 7b99b98
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty f75b3ee
.
measty e6e28b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e863304
add sleep
measty 4174631
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 94d0740
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e5187fa
env
measty 5bc9527
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty e380582
.
measty e0bbee9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5caae93
.
measty 7ffa7c9
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 65073a4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d79dd0d
make tests work in github actions
measty 698c54f
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 7f44c0b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 89ae473
.
measty 1849242
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty fc3c7b4
.
measty 51be263
.
measty e5238ea
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f45e87f
coverage
measty c01fb7a
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 4631c87
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 95a8e71
coverage
measty 31538a2
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 797d207
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 59d9b5f
improve docs
measty 06c0099
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 34b316e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9b56095
doc updates
measty 70ade31
annotation inspection
measty 62ef130
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty cef0505
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 803e4ca
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 096d52e
coverage
measty 149dff6
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 0cb6115
type annotations
measty 6445d9e
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 92380e3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cd70a97
🚨 Add `flake8-annotations` to `test_app_bokeh`
372f93d
🚨 Add `flake8-annotations` to more `bokeh` tests
b47725e
Merge branch 'develop' into add-bokeh-app
shaneahmed 621e6b1
annotations
measty 4539110
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 43371eb
annotations again
measty 0267c00
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 28c60c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fdb0839
fix new keyword args
measty 0a0b4b6
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 9b1a9bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 29eaea5
fix errors due to some args becoming keyword only
measty a015934
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6bc76f2
fix test
measty b4e5b7d
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty ce69405
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 30c7230
annotation and docstring improvements
measty bd88079
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1f73712
docstring improvements
measty 96c1bd9
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 6869433
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 482ab28
slide info
measty dd1bfc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1f3d06f
initial cprop
measty 22024cf
update test
measty 6823a1f
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty a9971b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9378cfb
make template findable by setup.py
measty 482cd45
add template to manifest
measty 3bbf59a
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 7397d1c
address some review commnts
measty 7987648
doc updates
measty 84d1dc8
doc update
measty 74e96cc
re-order doc sections
measty d381c06
add help tooltips
measty 9e44b10
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty b2883fe
move fixture to conftest
measty fe97609
doc updates
measty f122c54
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8b19b73
capitalize comments
measty 39295ea
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty c61c126
address comments
measty dac7dd5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6ab2935
address comments
measty f9c4555
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 7e4a79c
update add_from_dat to handle newest cerberus output format
measty 9972ff7
small doc corrections
measty bdf6b0b
add link to cerberus
measty 143be64
doc update
measty 967d420
address feedback
measty 26789ca
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 4e54435
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 87fb6e9
improve cli option names
measty ae029e8
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 59d64b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9e250f0
update docs to new cli
measty 7f44edd
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 8eb8f9d
doc updates
measty e077cb1
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty 566f323
[skip ci] :memo: Fix minor typos
shaneahmed ccce08e
[skip ci] :memo: Fix minor typos
shaneahmed ce9e713
[skip ci] :memo: Fix minor typos
shaneahmed c64bd31
transparency
measty a443171
add test
measty d2bbe34
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty eccffe6
Merge branch 'develop' into add-bokeh-app
shaneahmed d7e798b
Merge branch 'develop' into add-bokeh-app
shaneahmed fc5b265
address comments
measty 86a6887
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 2e157f7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0fd25be
Merge branch 'develop' of https://github.com/TissueImageAnalytics/tia…
measty d039555
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty ef59755
fix renamed color_dict key
measty 848f0d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bd8ca1f
multithread
measty 27d3b19
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 5db752b
address comments
measty e3a0b3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a28b140
remove python 3.7 stuff
measty 283e69d
Merge branch 'add-bokeh-app' of https://github.com/TissueImageAnalyti…
measty 53fe7f2
add test
measty 7f1f342
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1c31782
Merge branch 'develop' into add-bokeh-app
shaneahmed 25200b9
Merge branch 'develop' into add-bokeh-app
shaneahmed 94690b7
:pencil2: Fix typos and other minor issues.
shaneahmed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): | ||
measty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # 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() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.