FastSurferCNN.utils.common

class FastSurferCNN.utils.common.SerialExecutor[source]

Represent a serial executor.

Methods

map(fn, *iterables[, timeout, chunksize])

The map function.

shutdown([wait, cancel_futures])

Clean-up the resources associated with the Executor.

submit(_SerialExecutor__fn, *args, **kwargs)

A callable function that returns a Future representing the result.

map(fn, *iterables, timeout=None, chunksize=-1)[source]

The map function.

Parameters:
fnCallable[…, _T]

A callable function to be applied to the items in the iterables.

*iterablesIterable[Any]

One or more iterable objects.

timeoutOptional[float]

Maximum number of seconds to wait for a result. Default is None.

chunksizeint

The size of the chunks, default value is -1.

Returns:
Iterator[_T]

An iterator that yields the results of applying ‘fn’ to the items of ‘iterables’.

submit(_SerialExecutor__fn, *args, **kwargs)[source]

A callable function that returns a Future representing the result.

Parameters:
__fnCallable[…, _T]

A callable function to be executed.

*args

Potential arguments to be passed to the callable function.

**kwargs

Keyword arguments to be passed to the callable function.

Returns:
“Future[_T]”

A Future object representing the execution result of the callable function.

class FastSurferCNN.utils.common.SubjectDirectory(**kwargs)[source]

Represent a subject directory.

Attributes

asegdkt_segfile

Try to return absolute path.

conf_name

Try to return absolute path.

copy_orig_name

Try to return absolute path.

id

Get the id.

main_segfile

Try to return absolute path.

orig_name

Try to return absolute path.

segfile

Try to return absolute path.

subject_dir

Gets the subject directory name.

Methods

can_resolve_attribute(attr_name)

Check whether we can resolve the attribute.

can_resolve_filename(filename)

Check whether we can resolve the file name.

fileexists_by_attribute(attr_name)

Check if a file exists based on the provided attribute name.

fileexists_in_subject_folder(filepath)

Check if file exists in the subject folder.

filename_by_attribute(attr_name)

Retrieve a filename based on the provided attribute name.

filename_in_subject_folder(filepath)

Return the full path to the file.

get_attribute(attr_name)

Give the requested attribute.

has_attribute(attr_name)

Check if the attribute is set.

can_resolve_attribute(attr_name)[source]

Check whether we can resolve the attribute.

Parameters:
attr_namestr

Name of the attribute to check.

Returns:
bool

Whether we can resolve the attribute.

can_resolve_filename(filename)[source]

Check whether we can resolve the file name.

Parameters:
filenamestr

Name of the filename to check.

Returns:
bool

Whether we can resolve the file name.

fileexists_by_attribute(attr_name)[source]

Check if a file exists based on the provided attribute name.

Parameters:
attr_namestr

The name of the attribute associated with the file existence check.

Returns:
bool

Whether the file exists or not.

fileexists_in_subject_folder(filepath)[source]

Check if file exists in the subject folder.

Parameters:
filepathPath, str

Path to the file.

Returns:
bool

Whether the file exists or not.

filename_by_attribute(attr_name)[source]

Retrieve a filename based on the provided attribute name.

Parameters:
attr_namestr

The name of the attribute associated with the desired filename.

Returns:
Path

The filename corresponding to the provided attribute name.

filename_in_subject_folder(filepath)[source]

Return the full path to the file.

Parameters:
filepathstr, Path

Absolute to the file or name of the file.

Returns:
Path

Path to the file.

get_attribute(attr_name)[source]

Give the requested attribute.

Parameters:
attr_namestr

Name of the attribute to return.

Returns:
str, Path

The value of the requested attribute.

Raises:
AttributeError

If the subject has no attribute with the given name.

has_attribute(attr_name)[source]

Check if the attribute is set.

Parameters:
attr_namestr

Name of the attribute to check.

Returns:
bool

Whether the attribute exists or not.

property asegdkt_segfile

Try to return absolute path.

If the asegdkt_segfile is a relative path, it will be interpreted as relative to folder.

Returns:
Path

Path to segmentation file.

property conf_name

Try to return absolute path.

If the conformed_t1_file is a relative path, it will be interpreted as relative to folder.

Returns:
Path

The path to the conformed image file.

property copy_orig_name

Try to return absolute path.

If the copy_orig_t1_file is a relative path, it will be interpreted as relative to folder.

Returns:
Path

The copy of orig name.

property id

Get the id.

Returns:
str

The id.

property main_segfile

Try to return absolute path.

If the main_segfile is a relative path, it will be interpreted as relative to folder.

Returns:
Path

Path to the main segfile.

property orig_name

Try to return absolute path.

If the native_t1_file is a relative path, it will be interpreted as relative to folder.

Returns:
str

The orig name.

property segfile

Try to return absolute path.

If the segfile is a relative path, it will be interpreted as relative to folder.

Returns:
Path

Path to the segfile.

property subject_dir

Gets the subject directory name.

Returns:
Path

The set subject directory.

class FastSurferCNN.utils.common.SubjectList(args, flags=None, **assign)[source]

Represent a list of subjects.

Attributes

flags

Give the flags.

Methods

are_all_subject_files()

Check if all entries in subjects are actually files.

get_common_suffix()

Find common suffix, if all entries in the subject list share a common suffix.

make_subjects_dir()

Try to create the subject directory.

are_all_subject_files()[source]

Check if all entries in subjects are actually files.

This is performed asynchronously internally.

get_common_suffix()[source]

Find common suffix, if all entries in the subject list share a common suffix.

Returns:
str

The suffix the entries share.

make_subjects_dir()[source]

Try to create the subject directory.

property flags

Give the flags.

Returns:
dict[str, dict]

Flags.

FastSurferCNN.utils.common.assert_no_root()[source]

Check whether the user is the root user and raises an error message is so.

Returns:
bool

Whether the user is root or not.

FastSurferCNN.utils.common.find_device(device='auto', flag_name='device', min_memory=0)[source]

Create a device object from the device string passed.

Includes detection of devices if device is not defined or “auto”.

Parameters:
devicetorch.device, str

The device to search for and test following pytorch device naming conventions, e.g. ‘cuda:0’, ‘cpu’, etc. (default: ‘auto’).

flag_namestr

Name of the corresponding flag for error messages (default: ‘device’).

min_memoryint

The minimum memory in bytes required for cuda-devices to be valid (default: 0, works always).

Returns:
device: torch.device

The torch.device object.

FastSurferCNN.utils.common.handle_cuda_memory_exception(exception)[source]

Handle CUDA out of memory exception and print a help text.

Parameters:
exceptionbuiltins.BaseException

Received exception.

Returns:
bool

Whether the exception was a RuntimeError caused by Cuda out memory.

FastSurferCNN.utils.common.iterate(pool, func, iterable)[source]

Iterate over iterable, yield pairs of elements and func(element).

Parameters:
poolExecutor

The Executor object (dummy object to have a common API with pipeline).

funccallable()

Function to use.

iterableIterable

Iterable to draw objects to process with func from.

Yields:
element_Ti

Elements

_T

Results of func corresponding to element: func(element).

FastSurferCNN.utils.common.pipeline(pool, func, iterable, *, pipeline_size=1)[source]

Pipeline a function to be executed in the pool.

Analogous to iterate, but run func in a different thread for the next element while the current element is returned.

Parameters:
poolExecutor

Thread pool executor for parallel execution.

funccallable()

Function to use.

iterableIterable

Iterable containing input elements.

pipeline_sizeint, default=1

Size of the processing pipeline.

Yields:
element_Ti

Elements

_T

Results of func corresponding to element: func(element).