FastSurferCNN.utils.arg_types

FastSurferCNN.utils.arg_types.float_gt_zero_and_le_one(a)[source]

Check whether a parameters are a float between 0 and one.

Parameters:
astr

String of a number or none, infinity.

Returns:
float or None

If a is a valid float between 0 and 1, return the float value. If a is ‘none’ or ‘infinity’, return None.

Raises:
argparse.ArgumentTypeError

If a is neither a float between 0 and 1.

FastSurferCNN.utils.arg_types.img_size(a)[source]

Convert the img_size argument to ‘fov’, ‘auto’ or int as a valid image size.

Parameters:
astr

Image size type. Can be auto, fov or an integer greater than 0.

Returns:
str or int

If ‘auto’ or ‘fov’ is provided, it returns a string(‘auto’ or ‘fov’). If a valid image size (greater than 0) is provided, it returns an int. If ‘any’, it returns None.

Raises:
argparse.ArgumentTypeError

If the argument is not “fov”, “auto” or convertible to an int greater than 0.

FastSurferCNN.utils.arg_types.int_ge_zero(value)[source]

Convert to integers greater 0.

Parameters:
valuestr

String to convert to int.

Returns:
valint

Given value if bigger or equal to zero.

Raises:
argparse

ArgumentTypeError: Invalid value, must be greater than 0.

FastSurferCNN.utils.arg_types.int_gt_zero(value)[source]

Convert to positive integers.

Parameters:
valueUnion[str, int]

Integer to convert.

Returns:
valint

Converted integer.

Raises:
argparse

ArgumentTypeError: Invalid value, must not be negative.

FastSurferCNN.utils.arg_types.orientation(a)[source]

Convert the orientation argument to a valid orientation from ‘native’, ‘soft[-_ ]<orientation/i>’, and ‘<orientation/i>’, where <orientation/i> is any valid orientation (case-insensitive).

Parameters:
astr

Target orientation type, handles cases.

Returns:
str

One of ‘native’, ‘soft <orientation>’, or ‘<orientation>’.

Raises:
argparse.ArgumentTypeError

If the argument is not a valid choice.

FastSurferCNN.utils.arg_types.string_to_bool(a)[source]

Convert a string to a boolean value.

Parameters:
astr

String to convert.

Returns:
bool

If a is “on”, “true”, “yes”, “y”, “1” (case-insensitive).

FastSurferCNN.utils.arg_types.target_dtype(a)[source]

Check for valid dtypes.

Parameters:
astr

Datatype descriptor.

Returns:
str

The validated data type.

Raises:
argparse.ArgumentTypeError

Invalid dtype.

See also

numpy.dtype

For more information on numpy data types and their properties.

FastSurferCNN.utils.arg_types.unquote_str(value)[source]

Unquote a (single quoted) string, i.e. remove one level of single-quotes.

Parameters:
valuestr

String to be unquoted.

Returns:
valstr

A string of the value without leading and trailing single-quotes.

FastSurferCNN.utils.arg_types.vox_size(a)[source]

Convert the vox_size argument to ‘min’ or a valid voxel size.

Parameters:
astr

Vox size type. Can be auto, min or a number between 1 an 0.

Returns:
str or float or None

If ‘auto’ or ‘min’ is provided, it returns a string(‘auto’ or ‘min’). If a valid voxel size (between 0 and 1) is provided, it returns a float. If ‘any’, it returns None.

Raises:
argparse.ArgumentTypeError

If the argument is not “min”, “auto” or convertible to a float between 0 and 1.