mpylab.tools.interpol module

This is mpylab.tools.interpol.

Provides interpolation routines

author:

Hans Georg Krauthäuser (main author)

license:

GPL-3 or higher

mpylab.tools.interpol.InterpolateMResults(y, x, interpolation=None)

Create interpolation function with optional log-axis transforms.

mpylab.tools.interpol.MResult_Interpol(dct, interpolation)

Create interpolation function from mapping of x->y values.

class mpylab.tools.interpol.UQ_interpol(dct, typ=None, frequency_scale='LINEAR', value_scale='LINEAR', complex_mode='POLAR', db_factor=None)

Bases: object

Interpolation routine for a dct with uncertain quantities as values. type is not yet used. cplx_interpol() is used to interpolate complex values.

Example:

from mpylab.tools.interpol import *
import numpy
import scuq

freqs=[p*1e6 for p in range(16)]
phis=[p*math.pi/16 for p in range(16)]
vals=[complex(math.cos(p),math.sin(p)) for p in phis]
dct=dict((v for v in zip(freqs,vals)))
cinter=cplx_interpol(dct)
print "Complex interpolation:"
print cinter(5e5)
print

uqvals=[scuq.quantities.Quantity(scuq.si.VOLT,v) for v in vals]
dct2=dict((v for v in zip(freqs,uqvals)))
uqinter=UQ_interpol(dct2)
print "SCUQ interpolation:"
print uqinter(5e5)
class mpylab.tools.interpol.cartesian_interpol(dct, frequency_scale='LINEAR')

Bases: object

Interpolate complex values through real and imaginary components.

class mpylab.tools.interpol.cplx_interpol(dct, typ=None, frequency_scale='LINEAR', magnitude_scale='LINEAR', db_factor=20.0)

Bases: object

Interpolation routine for a dct with complex values. type is not yet used. Phase is unwrapped using unwrap()

Example:

In [1]: from interpol import *
You should use UTF-8 instead of mac-roman as encoding, or the SI units won't display correctly

In [2]: freqs=[p*1e6 for p in range(16)]

In [3]: phis=[p*math.pi/16 for p in range(16)]

In [4]: vals=[complex(math.cos(p),math.sin(p)) for p in phis]

In [5]: dct=dict((v for v in zip(freqs,vals)))

In [6]: cinter=cplx_interpol(dct)

In [7]: abs(cinter(5e5))
Out[8]: 1.0

In [9]: math.atan2(cinter(5e5).imag, cinter(5e5).real)
Out[9]: 0.098174770424681035
mpylab.tools.interpol.extrap1d(interpolator)

Return a vectorized interpolation function with linear extrapolation.

mpylab.tools.interpol.unwrap(dct, arg=None)

Phase unwrapping of values in dictionary dct.

dct is a dict with keys that can be sorted (frequencies). The values are typically complex values representing e.g. S-parameters.

If arg is given, it is expected to be a callable with a signature like math.atan2() that returns the argument (phase) of the objects in dct.

The function returns a 3-tuple of lists with the sorted keys, the magnitude, and the phase of the values.