pysprint.utils package


pysprint.utils.decorators module


Decorator that allows a class function to be called as inplace. It will invalidate the parent object to have only one reference to the Dataset.


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. module

This code is mostly adapted from pandas/pandas/util/ pandas is licensed under the BSD 3-Clause “New” or “Revised” License. See at:


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

  • 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 is True.
__init__(doc='', copy=True)

Initialize self. See help(type(self)) for accurate signature.

pysprint.utils.misc module


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.

  • 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.

  • mean (float) – The mean of the given array
  • conf (tuple-like (interval)) – The confidence interval


>>> 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
>>> interval
(120.35397798230359, 125.88002201769642)


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.

  • array (np.ndarray-like) – The array to search in.
  • value (float) – The value to search.

  • 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