Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (63 sloc) 1.95 KB
# -*- coding: utf-8 -*-
__author__ = """John Kirkham"""
__email__ = ""
import itertools
import numbers
import warnings
import dask
import dask.array
import dask.delayed
import numpy
import pims
from . import _utils
def imread(fname, nframes=1):
Read image data into a Dask Array.
Provides a simple, fast mechanism to ingest image data into a
Dask Array.
fname : str
A glob like string that may match one or multiple filenames.
nframes : int, optional
Number of the frames to include in each chunk (default: 1).
array : dask.array.Array
A Dask Array representing the contents of all image files.
if not isinstance(nframes, numbers.Integral):
raise ValueError("`nframes` must be an integer.")
if (nframes != -1) and not (nframes > 0):
raise ValueError("`nframes` must be greater than zero.")
with as imgs:
shape = (len(imgs),) + imgs.frame_shape
dtype = numpy.dtype(imgs.pixel_type)
if nframes == -1:
nframes = shape[0]
if nframes > shape[0]:
"`nframes` larger than number of frames in file."
" Will truncate to number of frames in file.",
elif shape[0] % nframes != 0:
"`nframes` does not nicely divide number of frames in file."
" Last chunk will contain the remainder.",
lower_iter, upper_iter = itertools.tee(itertools.chain(
range(0, shape[0], nframes),
a = []
for i, j in zip(lower_iter, upper_iter):
dask.delayed(_utils._read_frame)(fname, slice(i, j)),
(j - i,) + shape[1:],
a = dask.array.concatenate(a)
return a
You can’t perform that action at this time.