Python API#

nviz.image#

Experiment with GFF image stacks to OME-ZARR with display in Napari.

src.nviz.image.image_set_to_arrays(image_dir: str, label_dir: str | None, channel_map: Dict[str, str], ignore: List[str] | None = ['Merge']) Dict[str, Dict[str, ndarray]][source]#

Read a set of images as an array of images. We follow a convention of splitting the following into separate nested dictionaries for use by other functions within this project.

  • “images”: original images

  • “labels”: images which represent objects of interest

    within the original “images”

Parameters:
  • image_dir (str) – Directory containing TIFF image files.

  • label_dir (Optional[str]) – Directory containing label TIFF files.

  • channel_map (Dict[str, str]) – Mapping from filename codes to channel names.

  • ignore (Optional[List[str]]) – List of filename codes to ignore.

Returns:

A dictionary containing two keys: “images” and “labels”. Each key maps to another dictionary where the keys are channel names and the values are numpy arrays of images.

Return type:

Dict[str, Dict[str, np.ndarray]]

src.nviz.image.tiff_to_ometiff(image_dir: str, label_dir: str | None, output_path: str, channel_map: Dict[str, str], scaling_values: List[int] | Tuple[int], ignore: List[str] | None) str[source]#

Convert TIFF files to OME-TIFF format.

Parameters:
  • image_dir (str) – Directory containing TIFF image files.

  • label_dir (Optional[str]) – Directory containing label TIFF files.

  • output_path (str) – Path to save the output OME-TIFF file.

  • channel_map (Dict[str, str]) – Mapping from filename codes to channel names.

  • scaling_values (Union[List[int], Tuple[int]]) – Scaling values for the images.

  • ignore (Optional[List[str]]) – List of filename codes to ignore.

Returns:

Path to the output OME-TIFF file.

Return type:

str

src.nviz.image.tiff_to_zarr(image_dir: str, label_dir: str | None, output_path: str, channel_map: Dict[str, str], scaling_values: List[int] | Tuple[int], ignore: List[str] | None) str[source]#

Convert TIFF files to OME-Zarr format.

Parameters:
  • image_dir (str) – Directory containing TIFF image files.

  • label_dir (Optional[str]) – Directory containing label TIFF files.

  • output_path (str) – Path to save the output OME-Zarr file.

  • channel_map (Dict[str, str]) – Mapping from filename codes to channel names.

  • scaling_values (Union[List[int], Tuple[int]]) – Scaling values for the images.

  • ignore (Optional[List[str]]) – List of filename codes to ignore.

Returns:

Path to the output OME-Zarr file.

Return type:

str

nviz.image_meta#

Viewing utilities for GFF 3D organoid project

src.nviz.image_meta.extract_z_slice_number_from_filename(filename: str) int[source]#

Extracts a z-slice number from a filename. Follows conventions from images which are produced to our knowledge by ZEISS LSM 880 with Airyscan microscope output.

Assumes the z-slice number is a zero-padded number in the filename with the pattern ‘_ZS###_’.

Parameters:

filename (str) – The name of the file from which to extract the z-slice number.

Returns:

The extracted z-slice number. Returns 0 if the pattern is not found.

Return type:

int

src.nviz.image_meta.gather_scaling_info_from_scaninfoxml(xml_file: str) Tuple[float | None, float | None, float | None][source]#

Reads the scan information from an XML file and returns the values of ZStackSpacingMicrons, MicronsPerPixelY, and MicronsPerPixelX.

This function specifically caters to a file named ScanInfo.xml which is included to our knowledge within ZEISS LSM 880 with Airyscan microscope output (and perhaps others).

Parameters:

xml_file (str) – Path to the XML file.

Returns:

A tuple containing the values of ZStackSpacingMicrons, MicronsPerPixelY, and MicronsPerPixelX. If a value is not found, it will be None.

Return type:

Tuple[Optional[float], Optional[float], Optional[float]]

src.nviz.image_meta.generate_ome_xml(metadata: Dict) str[source]#

Generate OME-XML metadata for use within an OME-TIFF file.

Parameters:

metadata (Dict) – Dictionary containing metadata.

Returns:

OME-XML string.

Return type:

str

nviz.view#

Utilities for viewing n-dimensional data

src.nviz.view.view_ometiff_with_napari(ometiff_path: str, scaling_values: tuple, headless: bool = False) Viewer | None[source]#

View a OME-TIFF file created with nviz through napari.

Parameters:
  • ometiff_path (str) – The path to the OME-TIFF file.

  • scaling_values (tuple) – The scaling values for the image.

  • headless (bool) – Whether to run in headless mode (where we don’t run napari and hand back the viewer object instead).

Returns:

The napari viewer object if not headless, otherwise None.

Return type:

Optional[napari.Viewer]]

src.nviz.view.view_zarr_with_napari(zarr_dir: str, scaling_values: tuple, headless: bool = False) Viewer | None[source]#

View a Zarr file created with nviz through napari.

Parameters:
  • zarr_dir (str) – The path to the Zarr file.

  • scaling_values (tuple) – The scaling values for the image.

  • headless (bool) – Whether to run in headless mode (where we don’t run napari and hand back the viewer object instead).

Returns:

The napari viewer object if not headless, otherwise None.

Return type:

Optional[napari.Viewer]]