Utils

The utils.py file contains many useful functions called by other classes in PyPulse.

Functions

acf(array[, var=False, norm_by_tau=True, lagaxis=False])

Uses numpy’s correlate function to calculate the autocorrelation function of an array \(x\), defined as

\[\frac{1}{N} \sum_{i\le j} x_i x_j\]

where

Parameters
  • array (list/numpy.ndarray) – Data array.

  • var (bool) – Divide by the variance (using numpy.var) of the time series

  • norm_by_tau (bool) – Normalize using the number of bins going into each lag bin’s computation (thus making each bin an average value). Otherwise just divide by the length of the input array.

  • lagaxis (bool) – Return the axis of lags and the autocorrelation function rather than just the autocorrelation function.

Returns

autocorrelation function, numpy.ndarray

imshow(x[, ax=None, origin='lower', interpolation='nearest', aspect='auto', **kwargs])

Convenience function for calling matplotlib’s imshow().

Parameters
  • x (list/numpy.ndarray) – 2D data array.

  • ax (axis) – Uses a matplotlib axis to draw to. If None, then just run open a new figure.

  • origin (str) – Explicitly pass origin argument to imshow()

  • interpolation (str) – Explicitly pass interpolation argument to imshow()

  • aspect (str) – Explicitly pass aspect argument to imshow()

  • **kwargs

    Additional arguments to pass to imshow()

Returns

im, the return value of either ax.imshow() or plt.imshow()

normalize(array[, simple=False, minimum=None])

Normalize an array to unit height.

Parameters
  • array (numpy.ndarray) – Data array

  • simple (bool) – If simple, divide by the maximum of the array. Otherwise, normalize according to \(\mathrm{(array-minimum)}/\mathrm{(maximum-minimum)}\), where the minimum is the minimum of the array.

  • minimum (float) – Provide the minimum value to normalize in the above equation.

Returns

array, numpy.ndarray