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

Reuse current image #24

Merged
merged 6 commits into from
Dec 7, 2017
Merged

Reuse current image #24

merged 6 commits into from
Dec 7, 2017

Conversation

jakirkham
Copy link
Owner

Tries to reuse the current image displayed in get_image calls. Should speed up operations like inspecting intensities at coordinates within a frame.

The extra slicing step exists to handle converting some internal Lazy
objects from the workflow into NumPy arrays. The `asarray` call exists
to convert Dask Arrays to NumPy arrays. Hence it makes sense to roll
these into the same step to guarantee an array is provided for `cur_img`
before doing type conversion. Previously Dask would have handled the
type conversion as well. However the type conversion is trivially
performed locally. Plus it is easier to reason about if a NumPy array is
guaranteed at this step.
Instead of waiting until the retrieval of the 2-D/3-D data slice, check
to determine what the selected frame is at the beginning of `get_image`.
There really isn't time for the 2-D case. However it can effectively be
treated as having a single time slice at 0. Hence we fill in the default
`i` for that case. Though it is not actually use in any later code.
When working with large data on a slow filesystem, re-reading the
current displayed image is unnecessarily slow. This happens when
checking the intensity of different coordinates for instance (via
mouseover events). To improve performance, we can store the currently
displayed frame and simply access it if the user has not selected a
different frame.

We accomplish this here by storing the frame number (time) and the
current frame's data. These are both initialized to be `None` so that
they will fail cache hits the first time.  Within `get_image`, checks
are added to see if the current frame number (time) and requested one
are the same. If not, the new frame is loaded and the cache values
updated once loading completes. This ensures that some raised exception
doesn't create an incorrectly determined cached state. Whether or not
the frame is current or new, the frame is returned.
Add some checks to make sure that if the same frame is retrieved again
(pulled from cache) that it still retrieves the image correctly.
@jakirkham jakirkham merged commit 44948db into master Dec 7, 2017
@jakirkham jakirkham deleted the reuse_cur_img branch December 7, 2017 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant