util module¶
This module contains some small and useful utility functions and classes.
util.resolutionToBinsize (resolution) |
Return the bin size from the resolution unit |
util.binsizeToResolution (binsize) |
Return the resolution unit from the bin size |
util.sorted_nicely (inputList) |
Sorts the given given list in the way that is expected. |
util.locate_significant_digit_after_decimal (value) |
Get location at which significant digit start after decimal |
util.kth_diag_indices (k, a) |
Get diagonal indices of 2D array ‘a’ offset by ‘k’ |
util.detectOutliers1D (points[, thresh]) |
Returns a boolean array with True if points are outliers and False otherwise. |
util.getRandomName ([size, chars]) |
Random name generator |
util.MapNotFoundError (value) |
|
util.ResolutionNotFoundError (value) |
Small utility functions¶
-
exception
MapNotFoundError
(value)
-
exception
ResolutionNotFoundError
(value)
-
binsizeToResolution
(binsize)¶ Return the resolution unit from the bin size
It is a convenient function to convert binsize into resolution unit. It has a support of base (b), kilobase (kb), megabase (mb) and gigabase (gb) unit. It also convert binsize to decimal resolution unit as shown below in examples.
Parameters: binsize (int) – bin size Returns: resolution – resolution unit Return type: str Examples
>>> binsizeToResolution(1) '1b' >>> binsizeToResolution(10) '10b' >>> binsizeToResolution(10000) '10kb' >>> binsizeToResolution(100000) '100kb' >>> binsizeToResolution(125500) '125.5kb' >>> binsizeToResolution(1000000) '1mb' >>> binsizeToResolution(1634300) '1.6343mb'
-
detectOutliers1D
(points, thresh=3.5)¶ Returns a boolean array with
True
if points are outliers and False otherwise.Parameters: - points (numpy.ndarray) – An numobservations by numdimensions array of observations
- thresh (float) – The modified z-score to use as a threshold. Observations with a modified z-score (based on the median absolute deviation) greater than this value will be classified as outliers.
Returns: outBool – A numobservations-length boolean array.
Return type: numpy.ndarray
References
Boris Iglewicz and David Hoaglin (1993), “Volume 16: How to Detect and Handle Outliers”, The ASQC Basic References in Quality Control: Statistical Techniques, Edward F. Mykytka, Ph.D., Editor.
-
detectOutliersMasked1D
(points, thresh=3.5)¶ Returns a masked array where outliers are masked with preserved input mask.
Parameters: - points (numpy.ma.ndarray) – An numobservations by numdimensions array of observations
- thresh (float) – The modified z-score to use as a threshold. Observations with a modified z-score (based on the median absolute deviation) greater than this value will be classified as outliers.
Returns: maskArray – A numobservations-length masked array.
Return type: numpy.ma.ndarray
References
Boris Iglewicz and David Hoaglin (1993), “Volume 16: How to Detect and Handle Outliers”, The ASQC Basic References in Quality Control: Statistical Techniques, Edward F. Mykytka, Ph.D., Editor.
-
getRandomName
(size=10, chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')¶ Random name generator
Parameters: size (int) – Number of alphabets in the name. Returns: name – Randomly generated name. Return type: str
-
kth_diag_indices
(k, a)¶ Get diagonal indices of 2D array ‘a’ offset by ‘k’
Parameters: - k (int) – Diagonal offset
- a (numpy.ndarray) – Input numpy 2D array
Returns: indices – It contain indences of elements that are at the diagonal offset by ‘k’.
Return type: tuple of two numpy.ndarray
-
locate_significant_digit_after_decimal
(value)¶ Get location at which significant digit start after decimal
Parameters: value (float) – Input value Returns: value – Number of zeros after which digit start in a small decimal number. Return type: int
-
resolutionToBinsize
(resolution)¶ Return the bin size from the resolution unit
It is a convenient function to convert resolution unit to binsize. It has a support of base (b), kilobase (kb), megabase (mb) and gigabase (gb) unit. It also convert decimal resolution unit as shown below in examples.
Parameters: resolution (str) – resolution in b, kb, mb or gb. Returns: binsize – bin size Return type: int Examples
>>> resolutionToBinsize('1b') 1 >>> resolutionToBinsize('10b') 10 >>> resolutionToBinsize('1kb') 1000 >>> resolutionToBinsize('16kb') 16000 >>> resolutionToBinsize('1.23kb') 1230 >>> resolutionToBinsize('1.6mb') 1600000 >>> resolutionToBinsize('1.457mb') 1457000