Skip to content

Utils

Source

Utils module.

autocorrelation_stack(image, axes, average_z=True)

Compute the autocorrelation of an image stack, averaged over samples.

The input is normalized to SC(Z)YX using axes, autocorrelation is computed per image, and the results are averaged over the sample dimension. Channels are kept separate.

Parameters:

  • image (NDArray) –

    Input image stack.

  • axes (str) –

    Axes of the input stack, a subset of STCZYX containing Y and X.

  • average_z (bool, default: True ) –

    If True, compute a 2D (YX) autocorrelation averaged over the sample and Z dimensions. If False, compute a 3D (ZYX) autocorrelation averaged over the sample dimension only. Ignored when the data has no Z axis.

Returns:

  • ndarray –

    Averaged autocorrelation, C(Z)YX with the channel dimension dropped when there is a single channel.

cwd(path)

Change the current working directory to the given path.

This method can be used to generate files in a specific directory, once out of the context, the working directory is set back to the original one.

Parameters:

Returns:

Examples:

The context is whcnaged within the block and then restored to the original one.

>>> with cwd(my_path):
...     pass # do something

get_careamics_home()

Return the CAREamics home directory.

CAREamics home directory is a hidden folder in home.

Returns:

  • Path –

    CAREamics home directory path.

get_logger(name, log_level=logging.INFO, log_path=None)

Create a python logger instance with configured handlers.

Parameters:

  • name (str) –

    Name of the logger.

  • log_level (int, default: INFO ) –

    Log level (info, error etc.), by default logging.INFO.

  • log_path (Optional[Union[str, Path]], default: None ) –

    Path in which to save the log, by default None.

Returns:

get_ram_size()

Get RAM size in mbytes.

Returns:

  • int –

    RAM size in mbytes.

get_run_version(root_folder, folder_name)

Get the version run based on experiment folder name.

Versioned folder starts at <folder_name>_0 and is incremented based on the content of the root folder. This method is intended to be used for creating checkpoint folders for each training run, without mixing up checkpoints. It should mimick the csv logger.

Parameters:

  • root_folder (str | Path) –

    The root folder where the versioned folders are located.

  • folder_name (str) –

    The name of the versioned folder.

Returns:

  • int –

    The version number for the new run, which is one higher than the highest existing version number. If no versioned folders exist, it returns 0.