lightlab.util.data.two_dim module

Two dimensional measured objects where the second abscissa variable is either

Summary

Classes:

FunctionBundle A bundle of MeasuredFunction’s: “z” vs.
FunctionalBasis A FunctionBundle that supports additional linear algebra methods
MeasuredErrorField A field that hold two abscissa arrays and two ordinate matrices
MeasuredSurface Basically a two dimensional measured function: “z” vs.
Spectrogram
param absc:same meaning as measured function

Reference

class FunctionBundle(measFunList=None)[source]

Bases: lightlab.laboratory.Hashable

A bundle of MeasuredFunction’s: “z” vs. “x”, “i”

The key is that they have the same abscissa base. This class will take care of resampling in a common abscissa base.

The bundle can be:
  • iterated to get the individual :class`~lightlab.util.data.one_dim.MeasuredFunction`’s
  • operated on with other FunctionBundles
  • plotted with :meth`simplePlot` and multiAxisPlot()

Feeds through callable signal processing methods to its members (type MeasuredFunction), If the method is not found in the FunctionBundle, and it is in it’s member, it will be mapped to every function in the bundle, returning a new bundle.

Distinct from a MeasuredSurface because the additional axis does not represent a continuous thing. It is discrete and sometimes unordered.

Distinct from a FunctionalBasis because it does not support most linear algebra-like stuff (e.g. decomposision, matrix multiplication, etc.). This is not a strict rule.

Can be initialized fully, or initialized with None to be built interactively.

Parameters:measFunList (list[MeasuredFunction] or None) – list of MeasuredFunctions that must have the same abscissa.
addDim(newMeasFun)[source]
copy()[source]
extend(otherFunctionBund)[source]
max()[source]

Returns a single MeasuredFunction(subclass) that is the maximum of all in this bundle

min()[source]

Returns a single MeasuredFunction(subclass) that is the minimum of all in this bundle

mean()[source]

Returns a single MeasuredFunction(subclass) that is the mean of all in this bundle

simplePlot(*args, **kwargs)[source]
multiAxisPlot(*args, axList=None, titleRoot=None, **kwargs)[source]

titleRoot must take one argument in its format method, which is given the index :returns: The axes that were plotted upon :rtype: (list(axis))

histogram()[source]

Gives a MeasuredFunction of counts vs. ordinate values (typically voltage) Does not maintain any abscissa information

At this point, does not allow caller to set the arguments passed to np.histogram

This is mainly just for plotting

weightedAddition(weiVec)[source]

Calculates the weighted addition of the basis signals

Parameters:weiVec (array) – weights to be applied to the basis functions
Returns:weighted addition of basis signals
Return type:(MeasuredFunction)
moment(order=2, allDims=True, relativeGauss=False)[source]

The order’th moment of all the points in the bundle.

Parameters:
  • order (integer) – the polynomial moment of inertia. Don’t trust the normalization of > 2’th order. order = 1: mean order = 2: variance order = 3: skew order = 4: kurtosis
  • allDims (bool) – if true, collapses all signals, returning a scalar
Returns:

the specified moment(s)

Return type:

(ndarray or float)

componentAnalysis(*args, pcaIca=True, lNorm=2, expectedComponents=None, **kwargs)[source]

Gives the waveform representing the principal component of the order

Parameters:
  • pcaIca (bool) – if True, does PCA; if False, does ICA
  • lNorm (int) – how to normalize weight vectors. L1 norm uses the maximum abs weight, while L2 norm (default) is vector unit
  • expectedComponents (FunctionBundle or subclass) – Used for flipping signs
  • kwargs (args,) – Feed through to sklearn.decomposition.[PCA(), FastICA()]
Returns:

principal component waveforms

Return type:

(FunctionBundle or subclass)

correctSigns(otherBundle, maintainOrder=True)[source]

Goes through each component and flips the sign if correlation is negative

ICA also has a permutation indeterminism.

class FunctionalBasis(measFunList=None)[source]

Bases: lightlab.util.data.two_dim.FunctionBundle

A FunctionBundle that supports additional linear algebra methods

Created for weighted addition, decomposition, and component analysis

Can be initialized fully, or initialized with None to be built interactively.

Parameters:measFunList (list[MeasuredFunction] or None) – list of MeasuredFunctions that must have the same abscissa.
classmethod independentDefault(nDims)[source]

Gives a basis of non-overlapping pulses. Waveforms only

innerProds(trial)[source]

takes the inner products of the trial function onto this basis.

magnitudes()[source]

The inner product of the basis with itself

project(trial)[source]

Projects onto normalized basis If the basis is orthogonal, this is equivalent to weight decomposition

decompose(trial, moment=1)[source]

Uses the Moore-Penrose pseudoinverse to get weight decomposition without orthogonality

Parameters:
  • trial (MeasuredFunction) – signal to be decomposed
  • moment (float) – polynomial moment of the basis to use when decomposing
matrixMultiply(weiMat)[source]
getMoment(weiVecs=None, order=2, relativeGauss=False)[source]

This is actually the projected moment. Named for compatibility with bss package

Make sure weiVecs is two dimensional

remainder(trial)[source]

Gives the remaining parts of the signal that are not explained by the minimum-squared-error decomposition

covariance()[source]

Returns covariance matrix of the basis, which is nDims x nDims

class MeasuredSurface(absc, ordi)[source]

Bases: object

Basically a two dimensional measured function: “z” vs. “x”, “y”

Useful trick when gathering data: build incrementally using FunctionBundle.addDim(), then convert that to this class using MeasuredSurface.fromFunctionBundle().

Parameters:
  • absc (ndarray) – same meaning as measured function
  • ordi (ndarray) – two-dimensional array or matrix
classmethod fromFunctionBundle(otherBund, addedAbsc=None)[source]

gives back a MeasuredSurface from a function Bundle

Parameters:
  • otherBund (FunctionBundle) – The source. The ordering of functions matters
  • addedAbsc (np.ndarray) – the second dimension abscissa array (default, integers)
Returns:

(MeasuredSurface) new object

item(index, dim=None)[source]
shape()[source]
simplePlot(*args, **kwargs)[source]
class Spectrogram(absc, ordi)[source]

Bases: lightlab.util.data.two_dim.MeasuredSurface

Parameters:
  • absc (ndarray) – same meaning as measured function
  • ordi (ndarray) – two-dimensional array or matrix
class MeasuredErrorField(nominalGrid, measuredGrid)[source]

Bases: object

A field that hold two abscissa arrays and two ordinate matrices

Error is the measuredGrid - nominalGrid, which is a vector field

errorAt(testVec=None)[source]
invert(desiredVec)[source]
zeroCenteredSquareSize()[source]

Very stupid, just look at corner points

Returns:square sides of nominal and measured grids
Return type:(tuple(float))