FileSequence

class tifffile.FileSequence(imread, files, *, container=None, sort=None, parse=None, **kwargs)

Sequence of files containing compatible array data.

Parameters:
  • imread (Callable[..., NDArray[Any]]) – Function to read image array from single file.

  • files (str | os.PathLike[Any] | Sequence[str | os.PathLike[Any]] | None) – Glob filename pattern or sequence of file names. If None, use ‘*’. All files must contain array data of same shape and dtype. Binary streams are not supported.

  • container (str | os.PathLike[Any] | None) – Name or open instance of ZIP file in which files are stored.

  • sort (Callable[..., Any] | bool | None) – Function to sort file names if files is a pattern. The default is natural_sorted(). If False, disable sorting.

  • parse (Callable[..., Any] | None) – Function to parse sequence of sorted file names to dims, shape, chunk indices, and filtered file names. The default is parse_filenames() if kwargs contains ‘pattern’.

  • **kwargs (Any) – Additional arguments passed to parse function.

Examples

>>> filenames = ['temp_C001T002.tif', 'temp_C001T001.tif']
>>> ims = TiffSequence(filenames, pattern=r'_(C)(\d+)(T)(\d+)')
>>> ims[0]
'temp_C001T002.tif'
>>> ims.shape
(1, 2)
>>> ims.axes
'CT'
imread: Callable[..., NDArray[Any]]

Function to read image array from single file.

axes: str

Character codes for dimensions in shape.

dims: tuple[str, ...]

Names of dimensions in shape.

shape: tuple[int, ...]

Shape of file series. Excludes shape of chunks in files.

indices: tuple[tuple[int, ...]]

Indices of files in shape.

asarray(*, imreadargs=None, chunkshape=None, chunkdtype=None, dtype=None, axestiled=None, out_inplace=None, ioworkers=1, out=None, **kwargs)

Return images from files as NumPy array.

Parameters:
  • imreadargs (dict[str, Any] | None) – Arguments passed to FileSequence.imread.

  • chunkshape (tuple[int, ...] | None) – Shape of chunk in each file. Must match FileSequence.imread(file, **imreadargs).shape. By default, this is determined by reading the first file.

  • chunkdtype (DTypeLike | None) – Data type of chunk in each file. Must match FileSequence.imread(file, **imreadargs).dtype. By default, this is determined by reading the first file.

  • axestiled (dict[int, int] | Sequence[tuple[int, int]] | None) – Axes to be tiled. Map stacked sequence axis to chunk axis.

  • ioworkers (int | None) – Maximum number of threads to execute FileSequence.imread asynchronously. If 0, use up to _TIFF.MAXIOWORKERS threads. Using threads can significantly improve runtime when reading many small files from a network share.

  • out_inplace (bool | None) – FileSequence.imread decodes directly to the output instead of returning an array, which is copied to the output. Not all imread functions support this, especially in non-contiguous cases.

  • out (OutputType) – Specifies how image array is returned. By default, create a new array. If a numpy.ndarray, a writable array to which the images are copied. If ‘memmap’, create a memory-mapped array in a temporary file. If a string or open file, the file used to create a memory-mapped array.

  • **kwargs (Any) – Arguments passed to FileSequence.imread in addition to imreadargs.

  • dtype (DTypeLike | None)

Raises:

IndexError, ValueError – Array shapes do not match.

Return type:

NDArray[Any]

aszarr(**kwargs)

Return images from files as Zarr store.

Parameters:

**kwargs (Any) – Arguments passed to ZarrFileSequenceStore.

Return type:

ZarrFileSequenceStore

close()

Close open files.

Return type:

None

commonpath()

Return longest common sub-path of each file in sequence.

Return type:

str

property files_missing: int

Number of empty chunks.