qudi.util.helpers

Functions

csv_2_list(csv_string[, str_2_val])

Parse a list literal (with or without square brackets) given as a string containing comma-separated int or float values to a Python list.

in_range(value, lower_limit, upper_limit)

Check if a value is in a given range an return closest possible value in range.

is_complex(test_value)

Check all available complex representations

is_complex_type(test_obj)

Check if passed object is a complex type

is_float(test_value)

Check all available float representations

is_float_type(test_obj)

Check if passed object is a float type

is_integer(test_value)

Check all available integer representations

is_integer_type(test_obj)

Check if passed object is an integer type

is_number(test_value)

Check whether passed value is a number

is_number_type(test_obj)

Check whether passed object is a number type

is_string(test_value)

Check all available string representations

is_string_type(test_obj)

Check if passed object is a string type

iter_modules_recursive(paths[, prefix])

Has the same signature as pkgutil.iter_modules() but extends the functionality by walking through the entire directory tree and concatenating the return values of pkgutil.iter_modules() for each directory.

natural_sort(iterable)

Sort an iterable of strings in an intuitive, natural way (human/natural sort).

str_to_number(str_value[, return_failed])

Parse a string into either int, float or complex (in that order)

qudi.util.helpers.csv_2_list(csv_string: str, str_2_val: Callable[[str], Any] | None = None) List[Any][source]

Parse a list literal (with or without square brackets) given as a string containing comma-separated int or float values to a Python list.

Blanks before and after commas are handled.

Parameters:
csv_stringstr

Scalar number literals as strings separated by a single comma and any number of blanks. Brackets are ignored. Example: ‘[1e-6,2.5e6, 42]’ or ‘1e-6, 2e-6, 42’.

str_2_valfunction, optional

Function to use for casting substrings into single values.

Returns:
list

List of float values. If str_2_val is provided, type is invoked by this function.

qudi.util.helpers.in_range(value: int | float, lower_limit: int | float, upper_limit: int | float) Tuple[bool, int | float][source]

Check if a value is in a given range an return closest possible value in range. Also check the range. Return value is clipped to range.

qudi.util.helpers.is_complex(test_value: Any) bool[source]

Check all available complex representations

qudi.util.helpers.is_complex_type(test_obj: Type) bool[source]

Check if passed object is a complex type

qudi.util.helpers.is_float(test_value: Any) bool[source]

Check all available float representations

qudi.util.helpers.is_float_type(test_obj: Type) bool[source]

Check if passed object is a float type

qudi.util.helpers.is_integer(test_value: Any) bool[source]

Check all available integer representations

qudi.util.helpers.is_integer_type(test_obj: Type) bool[source]

Check if passed object is an integer type

qudi.util.helpers.is_number(test_value: Any) bool[source]

Check whether passed value is a number

qudi.util.helpers.is_number_type(test_obj: Type) bool[source]

Check whether passed object is a number type

qudi.util.helpers.is_string(test_value: Any) bool[source]

Check all available string representations

qudi.util.helpers.is_string_type(test_obj: Type) bool[source]

Check if passed object is a string type

qudi.util.helpers.iter_modules_recursive(paths: str | Iterable[str], prefix: str | None = '') List[ModuleInfo][source]

Has the same signature as pkgutil.iter_modules() but extends the functionality by walking through the entire directory tree and concatenating the return values of pkgutil.iter_modules() for each directory.

Additional modifications include: - Directories starting with “_” or “.” are ignored (including their sub-directories). - Python modules starting with a double-underscore (“__”) are excluded from the result.

Parameters:
pathsiterable

Iterable of root directories to start the search for modules.

prefixstr, optional

Prefix to prepend to all module names.

Returns:
iterable

Concatenated return values of pkgutil.iter_modules() for all directories in the tree.

qudi.util.helpers.natural_sort(iterable: Iterable[Any]) List[Any][source]

Sort an iterable of strings in an intuitive, natural way (human/natural sort). This is useful for sorting alphanumeric strings that contain integers.

Parameters:
iterablelist of str

Iterable with string items to sort.

Returns:
list

Sorted list of strings.

qudi.util.helpers.str_to_number(str_value: str, return_failed: bool | None = False) int | float | complex | str[source]

Parse a string into either int, float or complex (in that order)