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

PERF ND reader flexibility #227

Merged
merged 9 commits into from
Apr 14, 2016
Merged

Conversation

caspervdw
Copy link
Member

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:

self._register_get_frame(self.get_frame_2D, 'yxc')

When bundle_axes is set, the reader wraps the get_frame_2D method with a transpose, iterate or drop operation so that the correct axes are returned. It always tries to minimize IO traffic: several calls to get_frame_2D is referred over reading too much data.

Any combination between get_frame axes and bundle_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.

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
@caspervdw
Copy link
Member Author

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.

@danielballan
Copy link
Member

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.

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?

@caspervdw
Copy link
Member Author

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()
Copy link
Member

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.

@tacaswell
Copy link
Member

Just one picky comment

@caspervdw
Copy link
Member Author

@tacaswell I pushed the changes that you suggested, ready to go

@danielballan danielballan merged commit c034829 into soft-matter:master Apr 14, 2016
caspervdw added a commit to caspervdw/pims_nd2 that referenced this pull request Jun 22, 2016
See soft-matter/pims#227 . Wait with merge for
release of this PR (probably pims v0.4)
@caspervdw caspervdw mentioned this pull request Feb 17, 2017
5 tasks
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.

3 participants