-
Notifications
You must be signed in to change notification settings - Fork 67
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
PERF ND reader flexibility #227
Conversation
A subclass of FramesSequenceND now should only define 1 (or more) reader method that can return any axes (even single pixels), given by the `@reads_frames('yx')` decorator. The reader then figures out how to iterate over the reader methods to return the desired axes.
Register a get_frame method in the initialization using `self._register_get_frame(method, axes)`
Mainly for backwards compatibility
Does anybody have time to look into this PR? The performance increase is great for my purposes and I would like to see it in master. |
That's very exciting and in line with some things @tacaswell and I are interested in here as well. @vivekthampy might also be excited about this. I gave this a quick read -- looks fine to me. Merge? |
Merge is fine by me! I am happy to collaborate on extensions or generalizations on this, let me know. I leave the merge to you or @tacaswell |
def _register_get_frame(self, method, axes): | ||
axes = tuple([a for a in axes]) | ||
if not hasattr(self, '_get_frame_dict'): | ||
self._get_frame_dict = dict() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest putting this initialization in FrameSequenceND.__init__
and requrining sub-classes to call super()
before doing anything else. Likely will have to do this test + warn for awhile to maintain back-compat.
Just one picky comment |
@tacaswell I pushed the changes that you suggested, ready to go |
See soft-matter/pims#227 . Wait with merge for release of this PR (probably pims v0.4)
This enables FramesSequenceND readers to use the frame dimensions of the underlying reader in a smart way. For instance: currently when an RGB frame is loaded from a movie, the frame is actually read 3 times, each time only using 1 channel.
Subclassed FramesSequenceND readers have to register their
get_frame
methods, using the axes names:When
bundle_axes
is set, the reader wraps theget_frame_2D
method with atranspose
,iterate
ordrop
operation so that the correct axes are returned. It always tries to minimize IO traffic: several calls toget_frame_2D
is referred over reading too much data.Any combination between
get_frame
axes andbundle_axes
is possible (and tested).This enhancement paves the way to make the readers actually lazy in all dimensions. Cropping could be pushed down to reader level, when the underlying reader supports reading pixel lines or single pixels.