pyms.Utils
¶
Utility functions for PyMassSpec wide use.
pyms.Utils.IO
¶
General I/O functions.
Functions:
|
Dumps an object to a file through |
|
Returns lines from a file, as a list. |
|
Loads an object previously dumped with |
|
Convert string filename into pathlib.Path object and create parent directories if required. |
|
Saves a list of numbers or a list of lists of numbers to a file with specific formatting. |
-
dump_object
(obj, file_name)[source]¶ Dumps an object to a file through
pickle.dump()
.
-
file_lines
(file_name, strip=False)[source]¶ Returns lines from a file, as a list.
- Parameters:
- Return type:
- Returns:
A list of lines
- Authors:
Vladimir Likic, Dominic Davis-Foster (pathlib support)
-
load_object
(file_name)[source]¶ Loads an object previously dumped with
dump_object()
.
-
prepare_filepath
(file_name, mkdirs=True)[source]¶ Convert string filename into pathlib.Path object and create parent directories if required.
-
save_data
(file_name, data, format_str='%.6f', prepend='', sep=' ', compressed=False)[source]¶ Saves a list of numbers or a list of lists of numbers to a file with specific formatting.
- Parameters:
data (
Union
[List
[float
],List
[List
[float
]]]) – A list of numbers, or a list of listsformat_str (
str
) – A format string for individual entries. Default'%.6f'
.prepend (
str
) – A string, printed before each row. Default''
.sep (
str
) – A string, printed after each number. Default'␣'
.compressed (
bool
) – IfTrue
, the output will be gzipped. DefaultFalse
.
- Authors:
Vladimir Likic, Dominic Davis-Foster (pathlib support)
pyms.Utils.Math
¶
Provides mathematical functions.
Functions:
|
Median absolute deviation. |
|
Test if a string, or list of strings, contains a numeric value(s). |
|
Identify outliers using the median absolute deviation (MAD). |
|
Return the sample arithmetic mean of data. |
|
Return the median (middle value) of numeric data. |
|
Identify outliers using the median value. |
|
Identify outliers using a percentile. |
|
Calculates RMSD for the 2 lists. |
|
Return the square root of the sample variance. |
|
Generates a list by using start, stop, and step values. |
-
is_float
(s)[source]¶ Test if a string, or list of strings, contains a numeric value(s).
-
mad_based_outlier
(data, thresh=3.5)[source]¶ Identify outliers using the median absolute deviation (MAD).
- Parameters:
- Author:
David Kainer
- Url:
-
mean
(data)[source]¶ Return the sample arithmetic mean of data.
>>> mean([1, 2, 3, 4, 4]) 2.8
>>> from fractions import Fraction as F >>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)]) Fraction(13, 21)
>>> from decimal import Decimal as D >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")]) Decimal('0.5625')
If
data
is empty, StatisticsError will be raised.
-
median
(data)[source]¶ Return the median (middle value) of numeric data.
When the number of data points is odd, return the middle data point. When the number of data points is even, the median is interpolated by taking the average of the two middle values:
>>> median([1, 3, 5]) 3 >>> median([1, 3, 5, 7]) 4.0
-
median_outliers
(data, m=2.5)[source]¶ Identify outliers using the median value.
- Parameters:
data
m (
float
) – Default2.5
.
- Author:
David Kainer
- Author:
- Author:
Benjamin Bannier (https://stackoverflow.com/users/176922/benjamin-bannier)
- Url:
http://stackoverflow.com/questions/11686720/is-there-a-numpy-builtin-to-reject-outliers-from-a-list
-
percentile_based_outlier
(data, threshold=95)[source]¶ Identify outliers using a percentile.
- Parameters:
- Author:
David Kainer
- Url:
-
std
(data, xbar=None)¶ Return the square root of the sample variance.
See
variance
for arguments and other details.>>> stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]) 1.0810874155219827
pyms.Utils.Time
¶
Time conversion and related functions.
Functions:
|
Returns whether the argument is a string in the format of a number. |
|
Resolves time string of the form |
|
Converts window selection parameter into points based on the time step in an ion chromatogram |
-
is_str_num
(arg)[source]¶ Returns whether the argument is a string in the format of a number.
The number can be an integer, or alternatively a floating point number in scientific or engineering format.
-
time_str_secs
(time_str)[source]¶ Resolves time string of the form
'<NUMBER>s'
or'<NUMBER>m'
and returns the time in seconds.
-
window_sele_points
(ic, window_sele, half_window=False)[source]¶ Converts window selection parameter into points based on the time step in an ion chromatogram
- Parameters:
ic (
IonChromatogram
) – ion chromatogram object relevant for the conversionwindow_sele (
Union
[int
,str
]) – The window selection parameter. This can be an integer or time string. If an integer, taken as the number of points. If a string, must of the form'<NUMBER>s'
or'<NUMBER>m'
, specifying a time in seconds or minutes, respectivelyhalf_window (
bool
) – Specifies whether to return half-window. DefaultFalse
.
- Return type:
- Returns:
The number of points in the window
- Author:
Vladimir Likic
pyms.Utils.Utils
¶
General utility functions.
Functions:
|
Returns whether |
|
Returns whether the object represents a filesystem path. |
|
Returns whether the object is a |
|
Returns whether the object is a |
-
is_sequence_of
(obj, of)[source]¶ Returns whether the object is a
Sequence
, and not a string, of the given type.
-
pyms.Utils.Utils.
signedinteger
¶ numpy.signedinteger
at runtime;int
when type checking.