FastSurferCNN.utils.common

class FastSurferCNN.utils.common.SubjectDirectory(subject_dir=None, **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)

Construct a full absolute path from the subject directory and the passed filepath.

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]

Construct a full absolute path from the subject directory and the passed filepath.

Parameters:
filepathstr, Path

Absolute to the file or name of the file.

Returns:
Path

The path to the file in the subject folder.

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, default_cuda_device='cuda')[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, default=”auto”

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

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).

default_cuda_devicestr, torch.device, default=”cuda”

Default cuda device to use, if cuda is available and device is “auto”.

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.suppress_stderr()[source]

Contextmanager that suppresses all output on stderr.

Notes

This Context Manager does not work with multiple threads, as sys.stderr is shared between threads.

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

Contextmanager that suppresses all output on stdout.

Notes

This Context Manager does not work with multiple threads, as sys.stdout is shared between threads.

FastSurferCNN.utils.common.update_docstring(**kwargs)[source]

Make custom replacements in the docstring.