nabu.resources.utils module

nabu.resources.utils.get_values_from_file(fname, n_values=None, shape=None, sep=None, any_size=False)[source]

Read a text file and scan the values inside. This function expects one value per line, or values separated with a separator defined with the sep parameter.

Parameters:
  • fname (str) – Path of the text file

  • n_values (int, optional) – If set to a value, this function will check that it scans exactly this number of values. Ignored if shape is provided

  • shape (tuple, optional) – Generalization of n_values for higher dimensions.

  • sep (str, optional) – Separator between values. Default is white space

  • any_size (bool, optional) – If set to True, then the parameters ‘n_values’ and ‘shape’ are ignored.

Returns:

arr – An array containing the values scanned from the text file

Return type:

numpy.ndarray

nabu.resources.utils.get_memory_per_node(max_mem, is_percentage=True)[source]

Get the available memory per node in GB.

Parameters:
  • max_mem (float) – If is_percentage is False, then number is interpreted as an absolute number in GigaBytes. Otherwise, it should be a number between 0 and 100 and is interpreted as a percentage.

  • is_percentage (bool) – A boolean indicating whether the parameter max_mem is to be interpreted as a percentage of available system memory.

nabu.resources.utils.get_threads_per_node(max_threads, is_percentage=True)[source]

Get the available memory per node in GB.

Parameters:
  • max_threads (float) – If is_percentage is False, then number is interpreted as an absolute number of threads. Otherwise, it should be a number between 0 and 100 and is interpreted as a percentage.

  • is_percentage (bool) – A boolean indicating whether the parameter max_threads is to be interpreted as a percentage of available system memory.

nabu.resources.utils.extract_parameters(params_str, sep=';')[source]

Extract the named parameters from a string.

Example

The function can be used as follows:

>>> extract_parameters("window_width=None; median_filt_shape=(3,3); padding_mode='wrap'")
... {'window_width': None, 'median_filt_shape': (3, 3), 'padding_mode': 'wrap'}
nabu.resources.utils.compact_parameters(params_dict, sep=';')[source]

Compact the parameters from a dict into a string.

This is the inverse of extract_parameters. It can be used for example in tomwer to convert parameters into a string, for example for cor_options, prior to calling a nabu method which is expecting an argument to be in the form of a string containing options.

Example

The function can be used as follows:

>>> compact_parameters( {"side":"near", "near_pos":300 } )
... "side=near; nearpos= 300;"
nabu.resources.utils.is_hdf5_extension(ext)[source]
nabu.resources.utils.get_quantities_and_units(string, sep=';')[source]

Return a dictionary with quantities as keys, and values in SI.

Example

get_quantities_and_units(“pixel_size = 1.2 um ; distance = 1 m”) Will return {“pixel_size”: 1.2e-6, “distance”: 1}