Skip to content

add thumbnail_size property #34

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 7 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
31 changes: 27 additions & 4 deletions dash_slicer/slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class VolumeSlicer:
scene_id (str): the scene that this slicer is part of. Slicers
that have the same scene-id show each-other's positions with
line indicators. By default this is derived from ``id(volume)``.
thumbnail_size (int or None): linear size of low-resolution data to be
uploaded to the client. If ``None``, the full-resolution data are
uploaded client-side.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feeling a bit uncomfortable about the None which is often used to denote a default value. What about just thumbnail, which can be set to True/False, but also allowing an int with the size? Once we've fixed the anisotropy thing, the default size should be fine in nearly all cases.

Let's also mention the default size here.


This is a placeholder object, not a Dash component. The components
that make up the slicer can be accessed as attributes. These must all
Expand Down Expand Up @@ -73,6 +76,7 @@ def __init__(
axis=0,
reverse_y=True,
scene_id=None,
thumbnail_size=32,
):

if not isinstance(app, Dash):
Expand All @@ -97,6 +101,11 @@ def __init__(
self._other_axii = [0, 1, 2]
self._other_axii.pop(self._axis)

# Check and store thumbnail size
if thumbnail_size is not None and not (isinstance(thumbnail_size, int)):
raise ValueError("thumbnail_size must be an integer, or None.")
self._thumbnail_size = thumbnail_size

# Check and store scene id, and generate
if scene_id is None:
n = len(_assigned_scene_ids)
Expand All @@ -120,7 +129,8 @@ def __init__(

# Build the slicer
self._create_dash_components()
self._create_server_callbacks()
if thumbnail_size is not None:
self._create_server_callbacks()
self._create_client_callbacks()

# Note(AK): we could make some stores public, but let's do this only when actual use-cases arise?
Expand All @@ -137,6 +147,11 @@ def axis(self):
"""The axis at which the slicer is slicing."""
return self._axis

@property
def thumbnail_size(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need a public prop for this. Or do you have a use-case in mind?

"""Linear size of low-resolution data."""
return self._thumbnail_size

@property
def nslices(self):
"""The number of slices for this slicer."""
Expand Down Expand Up @@ -260,12 +275,18 @@ def _create_dash_components(self):
info = self._slice_info

# Prep low-res slices
thumbnail_size = get_thumbnail_size(info["size"][:2], (32, 32))
if self._thumbnail_size is None:
thumbnail_size = None
info["lowres_size"] = info["size"]
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a check here to make thumbnail_size None when the given size is larger than the image size?

thumbnail_size = get_thumbnail_size(
info["size"][:2], (self._thumbnail_size, self._thumbnail_size)
)
info["lowres_size"] = thumbnail_size
thumbnails = [
img_array_to_uri(self._slice(i), thumbnail_size)
for i in range(info["size"][2])
]
info["lowres_size"] = thumbnail_size

# Create the figure object - can be accessed by user via slicer.graph.figure
self._fig = fig = Figure(data=[])
Expand Down Expand Up @@ -324,7 +345,9 @@ def _create_dash_components(self):
self._overlay_data = Store(id=self._subid("overlay"), data=[])

# Slice data provided by the server
self._server_data = Store(id=self._subid("server-data"), data="")
self._server_data = Store(
id=self._subid("server-data"), data={"index": -1, "slice": None}
)

# Store image traces for the slicer.
self._img_traces = Store(id=self._subid("img-traces"), data=[])
Expand Down
4 changes: 4 additions & 0 deletions tests/test_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def test_slicer_init():
with raises(ValueError):
VolumeSlicer(app, vol, axis=4)

# Need a valide thumbnail_size
with raises(ValueError):
VolumeSlicer(app, vol, thumbnail_size=20.2)

# This works
s = VolumeSlicer(app, vol)

Expand Down