spatiomic.data

Expose i/o functions from the data submodule.

Classes

read

A class to read in microscopy files.

subsample

A class to subsample image data.

Functions

anndata_from_array(data, channel_names[, clusters, ...])

Create an AnnData object from an image data array.

subset(data, channel_names_data, channel_names_subset)

Subset the data with the given channel names to the subset channel names in the given order.

Package Contents

spatiomic.data.anndata_from_array(data, channel_names, clusters=None, cluster_key='clusters', spatial_weights=None)

Create an AnnData object from an image data array.

Parameters:
  • data (NDArray) – The image data array.

  • channel_names (List[str]) – The channel names.

  • clusters (Optional[NDArray], optional) – The clusters. Defaults to None.

  • cluster_key (str, optional) – The cluster key. Defaults to “clusters”.

  • spatial_weights (Optional[W], optional) – The spatial weights. Defaults to None.

Returns:

The AnnData object

Return type:

AnnData

class spatiomic.data.read

A class to read in microscopy files.

static get_czi_image_channels(image, image_shape, ubyte=True)

Get the channels of an .czi image.

Parameters:
  • image (NDArray) – The read CziFile of an image.

  • image_shape (List[Tuple[str, int]]) – The shape of the CziFile. Example format of the image shape: [(‘B’, 1), (‘H’, 1), (‘T’, 1), (‘C’, 3), (‘Z’, 1), (‘Y’, 2048), (‘X’, 2048)]

  • ubyte (bool, optional) – Whether to interpret the data as np.uint8.. Defaults to True.

Returns:

An array containing the channels of the .czi file

Return type:

NDArray

classmethod read_czi(file_path, input_dimension_order='XYC')

Read a single czi file on a given path and returns it.

Parameters:
  • file_path (str) – Location of the file to be read.

  • input_dimension_order (str)

Returns:

An array containing the channels of the .czi file

Return type:

NDArray

static read_lif(file_path, image_idx=0)

Read a single lif file on a given path and returns it.

Parameters:
  • file_path (str) – Location of the file to be read.

  • image_idx (int)

Returns:

An array containing the channels of the .lif file

Return type:

NDArray

static read_tiff(file_path, input_dimension_order='XYC', precision='float32')

Read a single tiff file on a given path and returns it.

Parameters:
  • file_path (str) – Location of the file to be read.

  • input_dimension_order (str, optional) – The dimension order of the channels in the tiff file. Defaults to “XYC”.

  • precision (Literal["float32", "float64"], optional) – The precision of the data in the tiff file. Defaults to “float32”.

Returns:

An array containing the channels of the .tiff file in XYC dimension order.

Return type:

NDArray

static split_multi_image_lif(file_path, save_folder, save_prefix)

Read a lif file with multiple images and save every image in a defined folder.

Parameters:
  • file_path (str) – [description]

  • save_folder (str) – [description]

  • save_prefix (str) – [description]

Return type:

None

class spatiomic.data.subsample

A class to subsample image data.

static fit_transform(data, method='fraction', fraction=0.1, count=100000, *args, **kwargs)

Create a random subsample of some image data pixels, preserving channel dimensionality.

Parameters:
  • data (NDArray) – Image data to take the subsample from.

  • method (Literal["fraction", "count"], optional) – The method to use. Defaults to “fraction”.

  • fraction (float, optional) – The fraction of pixels to take when using the “fraction” method. When this results in a non-integer number of pixels, the number of pixels is rounded down. Defaults to 0.1.

  • count (int, optional) – The number of pixels to take. Defaults to 10000 when using the “count” method. Defaults to 100,000.

  • seed (Optional[int], optional) – The seed to use for random number generation. Defaults to None.

  • args (Any)

  • kwargs (dict)

Returns:

A flattened, random subsample of the pixels in the provided image data.

Return type:

NDArray

spatiomic.data.subset(data, channel_names_data, channel_names_subset)

Subset the data with the given channel names to the subset channel names in the given order.

Parameters:
  • data (NDArray) – The image data, channel-last.

  • channel_names_data (List[str]) – The channel names of the data.

  • channel_names_subset (List[str]) – The channel names to include in the subset.

Returns:

The subsetted data, with channel ordered according to the subset channel names.

Return type:

NDArray