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

Imread: use da.map_blocks instead of da.concatenate #165

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Changes from all 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: 15 additions & 16 deletions dask_image/imread/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,20 @@ def imread(fname, nframes=1, *, arraytype="numpy"):
RuntimeWarning
)

lower_iter, upper_iter = itertools.tee(itertools.chain(
range(0, shape[0], nframes),
[shape[0]]
))
next(upper_iter)

a = []
for i, j in zip(lower_iter, upper_iter):
a.append(dask.array.from_delayed(
dask.delayed(_utils._read_frame)(fname, slice(i, j),
arrayfunc=arrayfunc),
(j - i,) + shape[1:],
dtype,
meta=arrayfunc([])
))
a = dask.array.concatenate(a)
a = dask.array.map_blocks(
_map_read_frame,
chunks=dask.array.core.normalize_chunks(
(nframes,) + shape[1:], shape),
fn=fname,
arrayfunc=arrayfunc,
meta=arrayfunc([]).astype(dtype), # meta overwrites `dtype` argument
)

return a


def _map_read_frame(block_info=None, **kwargs):

i, j = block_info[None]['array-location'][0]
jakirkham marked this conversation as resolved.
Show resolved Hide resolved

return _utils._read_frame(i=slice(i, j), **kwargs)