pysprint.utils package¶
Submodules¶
pysprint.utils.decorators module¶
-
inplacify
(method)¶ Decorator used to allow a class function to be called as inplace as well. It will invalidate the parent object to have only one reference to it.
-
pprint_disp
(f)¶ Pretty print the dispersion results from returned arrays.
pysprint.utils.exceptions module¶
-
exception
PySprintWarning
¶ Bases:
Warning
Base pysprint warning class.
-
exception
InterpolationWarning
¶ Bases:
pysprint.utils.exceptions.PySprintWarning
This warning is raised when a function applies linear interpolation on the data.
-
exception
FourierWarning
¶ Bases:
pysprint.utils.exceptions.PySprintWarning
This warning is raised when FFT is called first instead of IFFT. Later on it will be improved. For more details see help(pysprint.FFTMethod.calculate)
-
exception
DatasetError
¶ Bases:
Exception
This error is raised when invalid type of data encountered when initializing a dataset or inherited object.
-
exception
NotCalculatedException
¶ Bases:
ValueError
This error is raised when a function is not available yet because something needs to be calculated before.
pysprint.utils.info module¶
This code is mostly adapted from pandas/pandas/util/_print_versions.py. pandas is licensed under the BSD 3-Clause “New” or “Revised” License. See at: pandas.pydata.org
-
print_info
()¶ Print all the relevant information about system and dependecies.
pysprint.utils.meta module¶
-
class
MetaData
(doc='', copy=True)¶ Bases:
object
A class to store additional meta property. This can be set to any valid ~collections.abc.Mapping.
Parameters: - doc (str, optional) – Documentation for the attribute of the class.
Default is
""
. - copy (bool, optional) – If
True
the the value is deepcopied before setting, otherwise it is saved as reference. Default isTrue
.
-
__init__
(doc='', copy=True)¶ Initialize self. See help(type(self)) for accurate signature.
- doc (str, optional) – Documentation for the attribute of the class.
Default is
pysprint.utils.misc module¶
-
pprint_math_or_default
(s)¶
-
run_from_ipython
()¶ Detect if code is run inside Jupyter or maybe Spyder.
-
measurement
(array, confidence=0.95, silent=False)¶ Give the measurement results with condifence interval assuming the standard deviation is unknown.
Parameters: - array (ndarray) – The array containing the measured values
- confidence (float, optional) – The desired confidence level. Must be _between 0 and 1.
- silent (bool, optional) – Whether to print results immediately. Default is False.
Returns: - mean (float) – The mean of the given array
- conf (tuple-like (interval)) – The confidence interval
Examples
>>> import numpy as np >>> from pysprint.utils import measurement >>> a = np.array([123.783, 121.846, 122.248, 125.139, 122.569]) >>> mean, interval = measurement(a, 0.99) 123.117000 ± 2.763022 >>> mean 123.117 >>> interval (120.35397798230359, 125.88002201769642)
Note
The results are printed immediately, because people often don’t use it for further code. Of course, they are also returned if needed.
-
find_nearest
(array, value)¶ Find the nearest element in array to value.
Parameters: - array (np.ndarray-like) – The array to search in.
- value (float) – The value to search.
Returns: - value (float) – The closest value in array.
- idx (int) – The index of the closest element.
-
pad_with_trailing_zeros
(array, shape)¶ Pad an array with trailing zeros to be the desired shape