9.2.6. Utils

General utilities and helpers.

class junifer.utils.ConfigManager(*args, **kwargs)

Manage configuration parameters.

Attributes:
_configdict

Configuration parameters.

Initialize the class.

delete(key)

Delete configuration parameter.

Parameters:
keystr

The configuration key to delete.

get(key, default=None)

Get configuration parameter.

Parameters:
keystr

The configuration key to get.

defaultbool or int or float or None, optional

The default value to return if the key is not found (default None).

Returns:
bool or int or float

The configuration value.

set(key, val)

Set configuration parameter.

Parameters:
keystr

The configuration key to set.

valbool or int or float

The value to set key to.

junifer.utils.check_standardize(value)

Check the value of a standardize parameter.

Booleans were replaced by the strategy names used by nilearn, so they raise an error explaining the change instead of a generic validation error.

Parameters:
valueAny

The value of the parameter.

Returns:
Any

The value of the parameter.

Raises:
ValueError

If value is a boolean.

junifer.utils.configure_logging(level='WARNING', level_datalad=None)

Configure the logging functionality.

Parameters:
levelint or {“DEBUG”, “INFO”, “WARNING”, “ERROR”}

The level of the messages to print. If string, it will be interpreted as elements of logging (default “WARNING”).

level_dataladint or {“DEBUG”, “INFO”, “WARNING”, “ERROR”}, optional

The level of the messages to print for datalad. If string, it will be interpreted as elements of logging. If None, it will be set as the level parameter (default None).

junifer.utils.deep_update(d, u)

Deep update d with u.

From: “https://stackoverflow.com/questions/3232943/update-value-of-a-nested -dictionary-of-varying-depth”

Parameters:
ddict

The dictionary to deep-update.

udict

The dictionary to deep-update d with.

Returns:
dict

The updated dictionary.

junifer.utils.ensure_list(value)

Ensure list.

junifer.utils.ensure_list_or_none(value)

Ensure list or None.

junifer.utils.make_executable(path)

Make path executable.

Parameters:
pathpathlib.Path

The path to make executable.

junifer.utils.raise_error(msg, klass=<class 'ValueError'>, exception=None)

Raise error, but first log it.

Parameters:
msgstr

The message for the exception.

klasssubclass of Exception, optional

The subclass of Exception to raise using (default ValueError).

exceptionException, optional

The original exception to follow up on (default None).

junifer.utils.run_ext_cmd(name, cmd, cwd=None)

Run external command via subprocess.

Parameters:
namestr

The name of the command.

cmdlist of str

The command to run as list of string.

cwdpathlib.Path or None, optional

The directory to run the command in, e.g., for commands that write extra files in the current directory. If None, the current directory is used (default None).

Raises:
RuntimeError

If command fails.

junifer.utils.warn_with_log(msg, category=<class 'RuntimeWarning'>)

Warn, but first log it.

Parameters:
msgstr

Warning message.

categorysubclass of Warning, optional

The warning subclass (default RuntimeWarning).