nanshe.io.xtiff module

The module xtiff provides support for conversion from TIFF to HDF5.

Overview

The module xtiff implements a relatively simplistic form of conversion from TIFF to HDF5. Preserves the description fields from the metadata if found as a list under the attribute descriptions. Additionally, keeps track of the TIFF filenames stitched together and the offsets of each TIFF file as the attributes filenames and offsets, respectively.

Todo

Currently, this only keeps one channel and works on one Z-plane. It would be nice to relax these constraints and these features in the future.

API

nanshe.io.xtiff.convert_tiffs(*args, **kwargs)[source]

Convert a stack of tiffs to an HDF5 file.

Parameters:
  • new_tiff_filenames (list or str) – takes a str for a single file or a list of strs for filenames to combine (allows regex).
  • new_hdf5_pathname (str) – the HDF5 file and location to store the dataset.
  • axis (int) – which axis to concatenate along.
  • channel (int) – which channel to select for the HDF5 (can only keep one).
  • z_index (int) – which z value to take (the algorithm is not setup for 3D data yet)
  • pages_to_channel (int) – if channels are not normally stored in the channel variable, but are stored as pages, then this will split neighboring pages into separate channels.
  • memmap (bool) – allows one to load the array using a memory mapped file as opposed to reading it directly. (by default is False)
nanshe.io.xtiff.get_multipage_tiff_shape_dtype(*args, **kwargs)[source]

Gets the info about the shape (including page number as time) and dtype.

Parameters:new_tiff_filename (str) – the TIFF file to get info about
Returns:
an ordered dictionary with
”shape” first and “dtype” (type) second.
Return type:(collections.OrderedDict)
nanshe.io.xtiff.get_multipage_tiff_shape_dtype_transformed(*args, **kwargs)[source]

Gets the info about the shape and dtype after some transformations have been performed.

Parameters:
  • new_tiff_filename (str) – the TIFF file to get info about
  • axis_order (str) – the desired axis order when reshaped
  • pages_to_channel (int) – number of channels to divide from the pages
Returns:

an ordered dictionary with

”shape” first and “dtype” (type) second.

Return type:

(collections.OrderedDict)

nanshe.io.xtiff.get_standard_tiff_array(*args, **kwargs)[source]

Reads a tiff file and returns a standard 5D array.

Parameters:
  • new_tiff_filename (str) – the TIFF file to read in
  • axis_order (int) – how to order the axes (by default returns “tzyxc”).
  • pages_to_channel (int) – if channels are not normally stored in the channel variable, but are stored as pages (or as a mixture), then this will split neighboring pages into separate channels. (by default is 1 so changes nothing)
  • memmap (bool) – allows one to load the array using a memory mapped file as opposed to reading it directly. (by default is False)
Returns:

an array with the axis order

specified.

Return type:

(numpy.ndarray or numpy.memmap)

nanshe.io.xtiff.get_standard_tiff_data(*args, **kwargs)[source]

Reads a tiff file and returns a standard 5D array and the metadata.

Parameters:
  • new_tiff_filename (str) – the TIFF file to read in
  • axis_order (int) – how to order the axes (by default returns “tzyxc”).
  • pages_to_channel (int) – if channels are not normally stored in the channel variable, but are stored as pages (or as a mixture), then this will split neighboring pages into separate channels. (by default is 1 so changes nothing)
  • memmap (bool) – allows one to load the array using a memory mapped file as opposed to reading it directly. (by default is False)
Returns:

an array with the axis order

specified and description metadata.

Return type:

(ndarray/memmap, ndarray)