Shell and process utilities

library.utilities.utilities_process.convert(img, target_type_min, target_type_max, target_type)

Converts an image from one type to another and also resizes

Parameters:
  • img – numpy array

  • target_type_min – min size

  • target_type_max – max size

  • target_type – dtype of array

Returns:

library.utilities.utilities_process.convert_size(size_bytes: int) str

Function takes unformatted bytes, calculates human-readable format [with units] and returns string

Parameters:

size_bytes (int)

Returns:

str:

library.utilities.utilities_process.create_downsample(file_key)

takes a big tif and scales it down to a manageable size. This method is used in PrepCreator For 16bit images, this is a good number near the high end.

library.utilities.utilities_process.delete_in_background(path: str) Future
library.utilities.utilities_process.get_cpus()

Helper method to return the number of CPUs to use

library.utilities.utilities_process.get_directory_size(directory)
library.utilities.utilities_process.get_hostname() str

Returns hostname of server where code is processed

Returns:

string of the current workstation

library.utilities.utilities_process.get_image_size(filepath: str) tuple[int, int]

Returns the width and height of a single image using Pillow.

Parameters:

filepath – Path of the input file.

Returns:

Tuple containing the width and height as integers.

library.utilities.utilities_process.get_scratch_dir()

Helper method to return the scratch dir Ratto can’t use /scratch as it is not big enough

library.utilities.utilities_process.random_string()
library.utilities.utilities_process.read_image(file_path: str)

Reads an image from the filesystem with exceptions

library.utilities.utilities_process.test_dir(animal: str, directory: str, section_count: int, downsample: bool = True, same_size: bool = False) tuple[list[str], int, int, int]

Tests the directory for image files, checks their sizes, and validates the number of files. Args: :param animal (str): The name of the animal. :param directory (str): The path to the directory containing the image files. :param section_count (int): The expected number of sections (files) in the directory. :param downsample (bool, optional): Whether to downsample the images. Defaults to True. :param same_size (bool, optional): Whether all images should be of the same size. Defaults to False. :return: tuple[list[str], int, int, int]: A tuple containing: - A list of filenames in the directory. - The number of files in the directory. - The maximum width of the images. - The maximum height of the images. :raise: SystemExit: If there are errors in processing the files or if the number of files is incorrect.

library.utilities.utilities_process.use_scratch_dir(directory: str) bool

Determines if there is enough free space in the /scratch directory to accommodate the specified directory with a buffer factor applied. Args: :param directory (str): The path to the directory whose size needs to be checked. :return: bool: True if there is enough free space in the /scratch directory, False otherwise.

library.utilities.utilities_process.write_image(file_path: str, data, message: str = 'Error') None

Writes an TIFF image to the filesystem