IO Module

SCOUT’s IO module is for reading and writing different volumetric image formats and preparing chunked arrays for processing. SCOUT makes use of TIFF and Zarr file formats throughout the analysis pipeline, and the this module is meant to consolidate these side-effecting IO operations.

scout.io.imread(path)

Reads TIFF file into a numpy array in memory.

Parameters

path (str) – Path to TIFF image to open

Returns

image – Image array

Return type

ndarray

scout.io.imread_folder(path, nb_workers)

Finds all TIFF images in a folder and loads them into a single array.

Note: all images must be the same shape to be able to stack them.

Parameters
  • path (str) – Path to directory with TIFF images in alphabetical order

  • nb_workers (int) – Number of parallel processes to use in reading images

Returns

data – Image array

Return type

ndarray

scout.io.imread_parallel(paths, nb_workers)

Reads TIFF files into a numpy array in memory.

Parameters
  • paths (list) – A list of TIFF paths to read (order is preserved)

  • nb_workers (int) – Number of parallel processes to use in reading images

Returns

data – Image data

Return type

ndarray

scout.io.imsave(path, data, compress=1)

Saves numpy array as a TIFF image.

Parameters
  • path (str) – Path to TIFF image to create / overwrite

  • data (ndarray) – Image data array

  • compress (int) – Level of lossless TIFF compression (0-9)

scout.io.new_zarr(path, shape, chunks, dtype, in_memory=False, **kwargs)

Create new Zarr NestedDirectoryStore at path.

NOTE: Persistent Zarr arrays are stored on disk. To avoid data loss, be careful when calling new_zarr on a path with an existing array.

Parameters
  • path (str) – Path to new zarr array

  • shape (tuple) – Overall shape of the zarr array

  • chunks (tuple) – Shape of each chunk for the zarr array

  • dtype (str) – Data type of for the zarr array

  • kwargs (dict) – Keyword args to passs to zarr.open()

Returns

arr – Reference to open zarr array

Return type

zarr Array

scout.io.new_zarr_like(path, arr, **kwargs)

Creates a new zarr array like arr.

Parameters
  • path (str) – Path to new zarr array

  • arr (zarr Array) – Reference to template zarr array

  • kwargs (dict) – Keyword args to passs to zarr.open()

Returns

new_arr – Reference to new zarr array

Return type

zarr Array

scout.io.open(path, nested=True, mode='a')

Opens a persistent Zarr array or NestedDirectoryStore located at path.

Parameters
  • path (str) – Path to Zarr array or NestedDirectoryStore

  • nested (bool) – Flag to indicate if path is for flat Zarr array or NestedDirectoryStore

  • mode (str) – Read / write permissions mode

Returns

arr – Reference to open Zarr array

Return type

zarr Array