cddm.viewer

A simple matlotlib-based video and correlation data viewers

Module Contents

class cddm.viewer.VideoViewer(video, count=None, id=0, norm_func=lambda x: ..., title='', **kw)

Bases: object

A matplotlib-based video viewer.

Parameters
  • video (list-like, iterator) – A list of a tuple of 2D arrays or a generator of a tuple of 2D arrays. If an iterator is provided, you must set ‘count’ as well.

  • count (int) – Length of the video. When this is set it displays only first ‘count’ frames of the video.

  • id (int, optional) – For multi-frame data specifies camera index.

  • norm_func (callable) – Normalization function that takes a single argument (array) and returns a single element (array). Can be used to apply custom normalization function to the image before it is shown.

  • title (str, optional) – Plot title.

  • kw (options, optional) – Extra arguments passed directly to imshow function

Examples

>>> from cddm.viewer import VideoViewer
>>> video = (np.random.randn(256,256) for i in range(256))
>>> vg = VideoViewer(video, 256, title = "iterator example") #must set nframes, because video has no __len__

#>>> vg.show()

>>> video = [np.random.randn(256,256) for i in range(256)]
>>> vl = VideoViewer(video, title = "list example")

#>>> vl.show()

show(self)

Shows video.

class cddm.viewer.DataViewer(semilogx=True, shape=None, mask=None)

Bases: object

Plots normalized correlation data. You need to hold reference to this object, otherwise it will not work in interactive mode.

Parameters
  • semilogx (bool) – Whether plot data with semilogx or not.

  • shape (tuple of ints, optional) – Original frame shape. For non-rectangular you must provide this so to define k step.

  • size (int, optional) – If specified, perform log_averaging of data with provided size parameter. If not given, no averaging is performed.

  • mask (ndarray, optional) – A boolean array indicating which data elements were computed.

set_data(self, data, t=None)

Sets correlation data.

Parameters

data (ndarray) – Normalized data.

get_data(self)

Returns computed k-averaged data and time

Returns

x, y – Time, data ndarrays.

Return type

ndarray, ndarray

get_k(self)

Returns average k value of current data.

set_mask(self, k, angle=0, sector=5, kstep=1)

Sets k-mask for averaging,

Parameters
  • k (int) – k index in kstep units.

  • angle (int) – Mean k-angle in degrees. Measure with respecto to image horizontal axis.

  • sector (int) – Averaging full angle in degrees.

  • kstep (float, optional) – K step in units of minimum k step for a given FFT dimensions.

Returns

ok – True if mask is valid else False

Return type

bool

plot(self)

Plots data. You must first call set_data() to set input data

show(self)

Shows plot.

class cddm.viewer.CorrViewer(semilogx=True, shape=None, size=None, norm=None, scale=False, mask=None)

Bases: cddm.viewer.DataViewer

Plots raw correlation data. You need to hold reference to this object, otherwise it will not work in interactive mode.

Parameters
  • semilogx (bool) – Whether plot data with semilogx or not.

  • shape (tuple of ints, optional) – Original frame shape. For non-rectangular you must provide this so to define k step.

  • size (int, optional) – If specified, perform log_averaging of data with provided size parameter. If not given, no averaging is performed.

  • norm (int, optional) – Normalization constant used in normalization

  • scale (bool, optional) – Scale constant used in normalization.

  • mask (ndarray, optional) – A boolean array indicating which data elements were computed.

set_norm(self, value)

Sets norm parameter

set_data(self, data, background=None, variance=None)

Sets correlation data.

Parameters
  • data (tuple) – A data tuple (as computed by ccorr, cdiff, adiff, acorr functions)

  • background (tuple or ndarray) – Background data for normalization. For adiff, acorr functions this is ndarray, for cdiff,ccorr, it is a tuple of ndarrays.

  • variance (tuple or ndarray) – Variance data for normalization. For adiff, acorr functions this is ndarray, for cdiff,ccorr, it is a tuple of ndarrays.

class cddm.viewer.MultitauViewer(semilogx=True, shape=None, norm=None, scale=False, mask=None)

Bases: cddm.viewer.CorrViewer

Shows multitau data in plot. You need to hold reference to this object, otherwise it will not work in interactive mode.

Parameters
  • semilogx (bool) – Whether plot data with semilogx or not.

  • shape (tuple of ints, optional) – Original frame shape. For non-rectangular you must provide this so to define k step.

  • norm (int, optional) – Normalization constant used in normalization

  • scale (bool, optional) – Scale constant used in normalization.

  • mask (ndarray, optional) – A boolean array indicating which data elements were computed.

set_norm(self, value)

Sets norm parameter

set_data(self, data, background=None, variance=None)

Sets correlation data.

Parameters
  • data (tuple) – A data tuple (as computed by ccorr, cdiff, adiff, acorr functions)

  • background (tuple or ndarray) – Background data for normalization. For adiff, acorr functions this is ndarray, for cdiff,ccorr, it is a tuple of ndarrays.

  • variance (tuple or ndarray) – Variance data for normalization. For adiff, acorr functions this is ndarray, for cdiff,ccorr, it is a tuple of ndarrays.