Skip to content

Utils

Source

Utils module.

BaseEnum

Bases: Enum

Base Enum class, allowing checking if a value is in the enum.

Example

from careamics.utils.base_enum import BaseEnum

Define a new enum

class BaseEnumExtension(BaseEnum): ... VALUE = "value"

Check if value is in the enum

"value" in BaseEnumExtension True

check_path_exists(path)

Check if a path exists. If not, raise an error.

Note that it returns path as a Path object.

Parameters:

Name Type Description Default
path Union[str, Path]

Path to check.

required

Returns:

Type Description
Path

Path as a Path object.

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:

Name Type Description Default
path Union[str, Path]

New working directory path.

required

Returns:

Type Description
Iterator[None]

None values.

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:

Type Description
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 Type Description Default
name str

Name of the logger.

required
log_level int

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

INFO
log_path Optional[Union[str, Path]]

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

None

Returns:

Type Description
Logger

Logger.

get_ram_size()

Get RAM size in mbytes.

Returns:

Type Description
int

RAM size in mbytes.