9. Math utilities¶

The module provides the following classes and functions:

smo.math.util.formatNumber(n, sig=6)[source]

Converts a floating point number to a string using the given number of significant digits. :param sig: number of significant digits

class smo.math.util.Interpolator1D(xValues, yValues, outOfRange='value')[source]

1D interpolator using numpy.interp. Allows the values to be set only once in the constructor, and then called as a function.

class smo.math.util.SectionCalculator[source]

Perform calculations over a sectioned array object, using different callable objects for each section

Parameters: sectionIndices – a tuple (x1, x2) where x1 is the first index of the section and x2 is the last index calculator – a callable fn(x) accepting a single argument that will be use used to calculate z = fn(y) over this section
class smo.math.util.NamedStateVector(stateList)[source]

A data structure which has two different views. On one hand it is a vector of values (of the same type), on the other hand each value can be accessed by name, as though it is a member variable of the class.

set(values, copy=False)[source]

Sets variable values from a numpy vector

get(copy=False)[source]

Sets numpy array’s values from the internal storage

Example usage:

>>> a = NamedStateVector(['T', 'p', 'h'])
>>> n1 = np.array([3, 7, 4])
>>> a.set(n1)
>>> print('T = {}, p = {}, h = {}'.format(a.T, a.p, a.h))
T = 3, p = 7, h = 4
>>> a.T = 56
>>> a.h = -20
>>> print('T = {}, p = {}, h = {}'.format(a.T, a.p, a.h))
T = 56, p = 7, h = -20
>>> print (a.get())
[ 56   7 -20]