Skip to content

Commit

Permalink
Refactor utility module for imread (#53)
Browse files Browse the repository at this point in the history
Refactor utility module for imread
  • Loading branch information
jakirkham committed Sep 2, 2018
1 parent 6705a11 commit 57c5653
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 2 additions & 5 deletions dask_image/imread/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pims

from .. import _pycompat
from . import _utils


def imread(fname, nframes=1):
Expand Down Expand Up @@ -63,10 +64,6 @@ def imread(fname, nframes=1):
RuntimeWarning
)

def _read_frame(fn, i):
with pims.open(fn) as imgs:
return numpy.asanyarray(imgs[i])

lower_iter, upper_iter = itertools.tee(itertools.chain(
_pycompat.irange(0, shape[0], nframes),
[shape[0]]
Expand All @@ -76,7 +73,7 @@ def _read_frame(fn, i):
a = []
for i, j in _pycompat.izip(lower_iter, upper_iter):
a.append(dask.array.from_delayed(
dask.delayed(_read_frame)(fname, slice(i, j)),
dask.delayed(_utils._read_frame)(fname, slice(i, j)),
(j - i,) + shape[1:],
dtype
))
Expand Down
14 changes: 14 additions & 0 deletions dask_image/imread/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-


__author__ = """John Kirkham"""
__email__ = "kirkhamj@janelia.hhmi.org"


import numpy
import pims


def _read_frame(fn, i):
with pims.open(fn) as imgs:
return numpy.asanyarray(imgs[i])

0 comments on commit 57c5653

Please sign in to comment.