8.4.13. pymodaq_utils.utils module

class pymodaq_utils.utils.JsonConverter[source]

Bases: object

Methods

istrusted

json2object

object2json

trusted_types

classmethod istrusted(type_name)[source]
classmethod json2object(jsonstring)[source]
classmethod object2json(obj)[source]
classmethod trusted_types()[source]
class pymodaq_utils.utils.PlotColors(colors=[[255, 255, 255], [255, 0, 0], [0, 255, 0], [0, 0, 255], [14, 207, 189], [207, 14, 166], [207, 204, 14]])[source]

Bases: object

Methods

check_color

check_colors

copy

remove

static check_color(color)[source]
check_colors(colors)[source]
copy()[source]
remove(item)[source]
class pymodaq_utils.utils.ThreadCommand(command, attribute=None, attributes=None, args=(), kwargs=None)[source]

Bases: SerializableBase

Generic object to pass info (command) and data (attribute) between thread or objects using signals

Parameters:
  • command (str) – The command to be analysed for further action

  • attribute (any type) – the attribute related to the command. The actual type and value depend on the command and the situation

  • attributes (deprecated, attribute should be used instead)

command

The command to be analysed for further action

Type:

str

attribute

the attribute related to the command. The actual type and value depend on the command and the situation

Type:

any type

args
Type:

some variables in a list

kwargs
Type:

some variables in a dict

Methods

deserialize(bytes_str)

serialize(obj)

static deserialize(bytes_str)[source]
Return type:

Tuple[ThreadCommand, bytes]

static serialize(obj)[source]
Return type:

bytes

args: list
attribute: Any
command: str
kwargs: dict
pymodaq_utils.utils.caller_name(skip=2)[source]

Get a name of a caller in the format module.class.method

skip specifies how many levels of stack to skip while getting caller name. skip=1 means “who calls me”, skip=2 “who calls my caller” etc.

An empty string is returned if skipped levels exceed stack height

pymodaq_utils.utils.capitalize(string, Nfirst=1)[source]

Returns same string but with first Nfirst letters upper :type string: (str) :param string: :type string: (str) :type Nfirst: (int) :param Nfirst: :type Nfirst: (int)

Return type:

str

pymodaq_utils.utils.check_vals_in_iterable(iterable1, iterable2)[source]
pymodaq_utils.utils.count_lines(ini_path, count=0, filters=['lextab', 'yacctab', 'pycache', 'pyc'])[source]
pymodaq_utils.utils.elt_as_first_element(elt_list, match_word='Mock')[source]
pymodaq_utils.utils.elt_as_first_element_dicts(elt_list, match_word='Mock', key='name')[source]
pymodaq_utils.utils.ensure_ndarray(data)[source]

Make sure data is returned as a numpy array :type data: :param data:

Return type:

ndarray

pymodaq_utils.utils.find_dict_if_matched_key_val(dict_tmp, key, value)[source]

check if a key/value pair match in a given dictionary :type dict_tmp: (dict) the dictionary to be tested :param dict_tmp: :type dict_tmp: (dict) the dictionary to be tested :type key: (str) a key string to look for in dict_tmp :param key: :type key: (str) a key string to look for in dict_tmp :type value: (object) any python object :param value: :type value: (object) any python object

Returns:

bool

Return type:

True if the key/value pair has been found in dict_tmp

pymodaq_utils.utils.find_dict_in_list_from_key_val(dicts, key, value, return_index=False)[source]

lookup within a list of dicts. Look for the dict within the list which has the correct key, value pair

Parameters:
  • dicts ((list) list of dictionnaries)

  • key ((str) specific key to look for in each dict)

  • value (value to match)

Returns:

dict

Return type:

if found otherwise returns None

pymodaq_utils.utils.find_dicts_in_list_from_key_val(dicts, key, value)[source]

lookup within a list of dicts. Look for the dicts within the list which have the correct key, value pair

Parameters:
  • dicts ((list) list of dictionnaries)

  • key ((str) specific key to look for in each dict)

  • value (value to match)

Returns:

dict

Return type:

if found otherwise returns None

pymodaq_utils.utils.find_keys_from_val(dict_tmp, val)[source]

Returns the keys from a dict if its value is matching val

pymodaq_utils.utils.find_object_if_matched_attr_name_val(obj, attr_name, attr_value)[source]

check if an attribute key/value pair match in a given object

Parameters:
  • obj (object)

  • attr_name (str) – attribute name to look for in the object

  • attr_value (object) – value to match

Returns:

bool

Return type:

True if the key/value pair has been found in dict_tmp

pymodaq_utils.utils.find_objects_in_list_from_attr_name_val(objects, attr_name, attr_value, return_first=True)[source]

lookup within a list of objects. Look for the objects within the list which has the correct attribute name, value pair

Parameters:
  • objects (List[object]) – list of objects

  • attr_name (str) – attribute name to look for in the object

  • attr_value (object) – value to match

  • return_first (bool) – if True return the first objects found in the list else all the objects matching

Returns:

list of tuple(object, int)

Return type:

object and index or list of object and indexes

pymodaq_utils.utils.getLineInfo()[source]

get information about where the Exception has been triggered

pymodaq_utils.utils.get_entrypoints(group='pymodaq.plugins')[source]

Get the list of modules defined from a group entry point

Because of evolution in the package, one or another of the forms below may be deprecated. We start from the newer way down to the older

Parameters:

group (str) – the name of the group

Return type:

List[EntryPoint]

pymodaq_utils.utils.get_new_file_name(base_path=PosixPath('C:\\Data'), base_name='tttr_data')[source]
pymodaq_utils.utils.get_version(package_name='pymodaq')[source]

Obtain the package version using the importlib metadata module

pymodaq_utils.utils.is_64bits()[source]
pymodaq_utils.utils.recursive_find_expr_in_files(ini_path, exp='make_enum', paths=[], filters=['.git', '.idea', '__pycache__', 'build', 'egg', 'documentation', '.tox'], replace=False, replace_str='')[source]
pymodaq_utils.utils.recursive_find_files(ini_path, exp='make_enum', paths=[], filters=['build'])[source]
pymodaq_utils.utils.recursive_find_files_extension(ini_path, ext, paths=[])[source]
pymodaq_utils.utils.remove_spaces(string)[source]

return a string without any white spaces in it :type string: :param string:

pymodaq_utils.utils.rint(x)[source]

almost same as numpy rint function but return an integer :type x: (float or integer) :param x: :type x: (float or integer)

Return type:

nearest integer

pymodaq_utils.utils.timer(func)[source]

Print the runtime of the decorated function

pymodaq_utils.utils.uncapitalize(string, Nfirst=1)[source]
pymodaq_utils.utils.zeros_aligned(n, align, dtype=<class 'numpy.uint32'>)[source]

Get aligned memory array wih alignment align. :type n: (int) length in dtype bytes of memory :param n: :type n: (int) length in dtype bytes of memory :type align: (int) memory alignment :param align: :type align: (int) memory alignment :type dtype: (numpy.dtype) type of the stored memory elements :param dtype: :type dtype: (numpy.dtype) type of the stored memory elements