memmap

tifffile.memmap(filename, /, *, shape=None, dtype=None, page=None, series=0, level=0, mode='r+', **kwargs)

Return memory-mapped NumPy array of image data stored in TIFF file.

Memory-mapping requires the image data stored in native byte order, without tiling, compression, predictors, etc. If shape and dtype are provided, existing files are overwritten or appended to depending on the append argument. Else, the image data of a specified page or series in an existing file are memory-mapped. By default, the image data of the first series are memory-mapped. Call flush to write any changes in the array to the file.

Parameters:
  • filename (str | os.PathLike[Any]) – Name of TIFF file which stores array.

  • shape (Sequence[int] | None) – Shape of empty array.

  • dtype (DTypeLike | None) – Datatype of empty array.

  • page (int | None) – Index of page which image data to memory-map.

  • series (int) – Index of page series which image data to memory-map.

  • level (int) – Index of pyramid level which image data to memory-map.

  • mode (Literal['r+', 'r', 'c']) – Memory-map file open mode. The default is ‘r+’, which opens existing file for reading and writing.

  • **kwargs (Any) – Additional arguments passed to imwrite() or TiffFile.

Returns:

Image in TIFF file as memory-mapped NumPy array.

Raises:

ValueError – Image data in TIFF file are not memory-mappable.

Return type:

numpy.memmap[Any, Any]