epsproc.util.misc module¶
ePSproc convenience functions
Collection of small functions for sorting etc.
-
epsproc.util.misc.
arraySort2D
(a, col)[source]¶ Sort np.array a by specified column col. From https://thispointer.com/sorting-2d-numpy-array-by-column-or-row-in-python/
-
epsproc.util.misc.
checkDims
(data, refDims=[])[source]¶ Check dimensions for a data array (Xarray) vs. a reference list (or dict).
Returns dictionary of dims, intersection and differences.
TODO: check and order dims by size? Otherwise set return is alphebetical
11/05/21 Added handling for stacked dims.
-
epsproc.util.misc.
fileListSort
(fList, groupByPrefix=True, prefixStr=None, verbose=1)[source]¶ Sort a list of file names, and group by prefix.
Note: this currently assumes a file name schema whereby split(‘_’)[0] picks the grouping string.
Note: os.path.commonprefix() is used for determining prefix, this may fail in some cases (e.g. for cases where a single file is passed, or files from different dirs). Pass prefix manaully in these cases.
Returns: Return type: fListSorted, groupedList, prefixStr
-
epsproc.util.misc.
stringRepMap
(string, replacements, ignore_case=False)[source]¶ Given a string and a replacement map, it returns the replaced string. :param str string: string to execute replacements on :param dict replacements: replacement dictionary {value to find: value to replace} :param bool ignore_case: whether the match should be case insensitive :rtype: str
CODE from: https://gist.github.com/bgusach/a967e0587d6e01e889fd1d776c5f3729 https://stackoverflow.com/questions/6116978/how-to-replace-multiple-substrings-of-a-string … more or less verbatim.
Thanks to bgusach for the Gist.