nabu.resources.utils
source module nabu.resources.utils
Functions
-
get_values_from_file — 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. -
get_memory_per_node — Get the available memory per node in GB.
-
get_threads_per_node — Get the available memory per node in GB.
-
extract_parameters — Extract the named parameters from a string.
-
compact_parameters — Compact the parameters from a dict into a string.
-
get_quantities_and_units — Return a dictionary with quantities as keys, and values in SI.
source get_values_from_file(fname, n_values=None, shape=None, sep=None, any_size=False)
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 : numpy.ndarray — An array containing the values scanned from the text file
Raises
-
ValueError
source get_memory_per_node(max_mem, is_percentage=True)
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.
source get_threads_per_node(max_threads, is_percentage=True)
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.
source extract_parameters(params_str, sep=';')
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'}
source compact_parameters(params_dict, sep=';')
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;"
source is_hdf5_extension(ext)
source get_quantities_and_units(string, sep=';')
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
Raises
-
ValueError