epsproc.util module¶
ePSproc utility functions
Collection of small functions for sorting etc.
14/10/19 Added string replacement function (generic) 11/08/19 Added matEleSelector
-
epsproc.util.
BLMdimList
(sType='stacked')[source]¶ Return standard list of dimensions for calculated BLM.
Parameters: sType (string, optional, default = 'stacked') – Selected ‘stacked’ or ‘unstacked’ dimensions. Set ‘sDict’ to return a dictionary of unstacked <> stacked dims mappings for use with xr.stack({dim mapping}). Returns: list Return type: set of dimension labels.
-
epsproc.util.
dataTypesList
()[source]¶ Return a dict of allowed dataTypes, corresponding to epsproc processed data.
Each dataType lists ‘source’, ‘desc’ and ‘recordType’ fields.
- ‘source’ fields correspond to ePS functions which get or generate the data.
- ‘desc’ brief description of the dataType.
- ‘recordType’ gives the required segment in ePS files (and associated parser). If the segment is not present in the source file, then the dataType will not be available.
TODO: best choice of data structure here? Currently nested dictionary.
-
epsproc.util.
jobSummary
(jobInfo=None, molInfo=None)[source]¶ Print some jobInfo stuff & plot molecular structure. (Currently very basic.)
Parameters: - jobInfo (dict, default = None) – Dictionary of job data, as generated by :py:function:`epsproc.IO.headerFileParse()` from source ePS output file.
- molInfo (dict, default = None) – Dictionary of molecule data, as generated by
epsproc.IO.molInfoParse()
from source ePS output file.
-
epsproc.util.
matEdimList
(sType='stacked')[source]¶ Return standard list of dimensions for matrix elements.
Parameters: sType (string, optional, default = 'stacked') – Selected ‘stacked’ or ‘unstacked’ dimensions. Set ‘sDict’ to return a dictionary of unstacked <> stacked dims mappings for use with xr.stack({dim mapping}). Returns: list Return type: set of dimension labels.
-
epsproc.util.
matEleSelector
(da, thres=None, inds=None, dims=None, sq=False, drop=True)[source]¶ Select & threshold raw matrix elements in an Xarray
Parameters: - da (Xarray) – Set of matrix elements to sub-select
- thres (float, optional, default None) – Threshold value for abs(matElement), keep only elements > thres. This is element-wise.
- inds (dict, optional, default None) – Dicitonary of additional selection criteria, in name:value format. These correspond to parameter dimensions in the Xarray structure. E.g. inds = {‘Type’:’L’,’Cont’:’A2’}
- dims (str or list of strs, dimensions to look for max & threshold, default None) – Set for dimension-wise thresholding. If set, this is used instead of element-wise thresholding. List of dimensions, which will be checked vs. threshold for max value, according to abs(dim.max) > threshold This allows for consistent selection of continuous parameters over a dimension, by a threshold.
- sq (bool, optional, default False) – Squeeze output singleton dimensions.
- drop (bool, optional, default True) – Passed to da.where() for thresholding, drop coord labels for values below threshold.
Returns: Xarray structure of selected matrix elements. Note that Nans are dropped if possible.
Return type: daOut
Example
>>> daOut = matEleSelector(da, inds = {'Type':'L','Cont':'A2'})
-
epsproc.util.
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.