shared.data_processing_utils
- shared.data_processing_utils.extract_datasets_from_h5_to_csv(h5_filepath, dataset_mapping)[source]
Extract specific datasets from an HDF5 file and save them to CSV files.
Parameters: - h5_filepath: Path to the input HDF5 file. - dataset_mapping: Dictionary where keys are dataset names in the HDF5 file
and values are the output filenames for CSV files.
Note
- it will flatten the data in the dataset to a 2D array if the dataset is a 3D array
3D arrays of shape (x, y, z) → 2D arrays of shape (x*y, z)
4D arrays of shape (w, x, y, z) → 2D arrays of shape (wxy, z)
… and so on.
- shared.data_processing_utils.flatten_ND_to_2D(array)[source]
Flatten a multi-dimensional array keeping the last dimension and format its values.
- shared.data_processing_utils.float_range(start, stop, step)[source]
A generator function that yields a range of floating point numbers.
- Parameters:
start (float) – The start of the range.
stop (float) – The end of the range.
step (float) – The step size.
- Yields:
Each value in the range.
- Return type:
float
- shared.data_processing_utils.get_dipole_values_as_array(filename, string, delimiter)[source]
Reads a file and returns the values of a string in the file as an array.
- Parameters:
filename (str) – The path to the file.
string (str) – The string to search for.
delimiter (str) – The delimiter that separates the string and its values.
- Returns:
The values of the string in the file.
- Return type:
list
- shared.data_processing_utils.natural_sort(iterable, key=None, reverse=False)[source]
Sorts the given iterable in a natural order.
This function is a key-function to the built-in sorted function and can be used as a drop-in replacement for it.
A natural sort, also known as an alphanumeric sort, is a sorting method that orders strings containing numbers in a way that considers the numerical value of the digits rather than treating the entire string as a sequence of characters. In other words, it sorts strings with numbers in a way that reflects their numerical order.
- Parameters:
iterable (iterable) – The iterable to be sorted.
key (callable, optional) – A callable used to extract a comparison key from each element in the iterable.
reverse (bool, optional) – If set to True, the iterable will be sorted in descending order.
- Returns:
A new list containing the sorted elements from the iterable.
- Return type:
list
- Usage::
>>> natural_sort(['2 ft', '10 ft', '1 ft']) ['1 ft', '2 ft', '10 ft']