qats.cli

Command line interface to app (GUI).

Functions overview

launch_app([home, files, log_level])

Start desktop application.

link_app()

Create start menu item and desktop shortcut to QATS desktop app.

main()

Launch desktop application from command line with parameters.

unlink_app()

Remove start menu item and desktop shortcut to QATS desktop application.

API

Create start menu item and desktop shortcut to QATS desktop app.

Remove start menu item and desktop shortcut to QATS desktop application.

qats.cli.launch_app(home=True, files=None, log_level='info')

Start desktop application.

Parameters
  • home (bool, optional) – Use home directory as work directory. Else current work directory will be used.

  • files (list, optional) – Initialize the application with these time series files (paths).

  • log_level (str, optional) – Set logging level, default ‘info’

qats.cli.main()

Launch desktop application from command line with parameters.

qats.motions

Transformations and operations related to motion.

Functions overview

acceleration(x, t)

Numerical time differentiation to obtain acceleration of signal(s).

transform_motion(motion, newref[, rotunit])

Transform motion to new reference position.

velocity(x, t)

Numerical time differentiation to obtain velocity of signal(s).

API

qats.motions.transform_motion(motion, newref, rotunit='deg')

Transform motion to new reference position.

The following sequence of rotation is used: z-y-z (known as yaw-pitch-roll). For more detailed description, see https://en.wikipedia.org/wiki/Euler_angles or SIMO Theory Manual (ch. 6.2 in version 4.14.0).

Parameters
  • motion (tuple or np.ndarray) –

    Motion of old reference point, 6 dofs (hence shape (6, nt), where nt is number of time steps):
    • x (position of old reference point in global coord. system)

    • y (position of old reference point in global coord. system)

    • z (position of old reference point in global coord. system)

    • rx (rotation about local x-axis, aka. roll)

    • ry (rotation about local x-axis, aka. roll)

    • rz (rotation about local x-axis, aka. roll)

  • newref (3-tuple) – Position vector (in body coordinate system) of new reference point: (x, y, z).

  • rotunit ({'deg', 'rad'}) – Unit of rotations. Default is degrees.

Returns

xyz – Position vector for new reference position, shape (3, n).

Return type

np.ndarray

qats.motions.acceleration(x, t)

Numerical time differentiation to obtain acceleration of signal(s).

Parameters
  • x (list or np.array) – Signal(s) to perform time derivation on. See requirements given for function velocity().

  • t (float or np.array) – Time step or time array.

Returns

acc – Acceleration of input signal(s); same shape as input.

Return type

np.array

Notes

In practice, acceleration is calculated by calling function velocity twice.

qats.motions.velocity(x, t)

Numerical time differentiation to obtain velocity of signal(s).

Parameters
  • x (list or np.array) – Signal to perform time derivation on. If a 2-D array is given, it is required to be of shape (n, nt), where n is number of signals and nt is number of time steps. Time differentiation is then performed for each of the signals independently.

  • t (float or np.array) – Time step or time array.

Returns

vel – Velocity of input signal(s); same shape as input.

Return type

np.array

Notes

Velocity is calculated using second order central differences, with first order backwards and forward differences at start/end of signals. See numpy.gradient.

See also

numpy.gradient

qats.signal

Module with functions for signal processing.

Functions overview

autocorrelation(series)

Estimation of the auto-correlation coefficients of series

average_frequency(t, x[, up])

Average frequency of mean level crossings.

bandblock(x, dt, flow, fupp[, order])

Band block filter data signal x at cut off frequencies flow and fupp, blocking harmonic content inside the frequency band [flow, fupp]

bandpass(x, dt, flow, fupp[, order])

Band pass filter data signal x at cut off frequencies flow and fupp, blocking harmonic content outside the frequency band [flow, fupp]

coherence(x, y, dt, **kwargs)

Estimate the magnitude squared coherence estimate of discrete-time signals X and Y using Welch’s method.

csd(x, y, dt, **kwargs)

Estimate cross power spectral density of discrete-time signals X and Y using Welch’s method.

extend_signal_ends(x, n)

Extend the signal ends with n values to mitigate the edge effect.

find_maxima(x[, local, threshold, up, retind])

Return sorted maxima

highpass(x, dt, fc[, order])

High pass filter data signal x at cut off frequency fc, blocking harmonic content below fc.

lowpass(x, dt, fc[, order])

Low pass filter data signal x at cut off frequency fc, blocking harmonic content above fc.

psd(x, dt, **kwargs)

Estimate power spectral density of discrete time signal X using Welch’s method.

smooth(x[, window_len, window, mode])

Smooth time serie based on convolution of a window function and the time serie.

taper(x[, window, alpha])

Taper the input time serie using a window function

tfe(x, y, dt[, clim])

Estimate the transfer function between two discrete-time signals X and Y using Welch’s method.

threshold(x, thresholds)

Allow only frequency components whose amplitudes are between the lower threshold value and the upper threshold value to pass.

API

qats.signal.extend_signal_ends(x, n)

Extend the signal ends with n values to mitigate the edge effect.

Parameters
  • x (array_like) – Signal

  • n (int) – Number of values prepended and appended to signal.

Notes

At each end of the signal n values of the signal are replicated, flipped and joined with the signal to maintain continuity in the signal level and slope at the joining points. This should mitigate end effects when filterin the signal.

The original signal is retrieved as x[n:-n:1].

qats.signal.smooth(x, window_len=11, window='rectangular', mode='same')

Smooth time serie based on convolution of a window function and the time serie.

Parameters
  • x (array) – The input signal.

  • window_len (int, optional) – The dimension of the smoothing window.

  • window ({'rectangular', 'hanning', 'hamming', 'bartlett', 'blackman'}, optional) – The type of window. Rectangular window will produce a moving average smoothing.

  • mode ({‘same’, ‘valid’, ‘full’}, optional) –

    full:

    This returns the convolution at each point of overlap, with an output shape of (N+M-1,). At the end-points of the convolution, the signals do not overlap completely, and boundary effects may be seen.

    same:

    By default mode is ‘same’ which returns output of length max(M, N). Boundary effects are still visible.

    valid:

    Mode valid returns output of length max(M, N) - min(M, N) + 1. The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect

Returns

The smoothed signal.

Return type

array

Notes

This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the beginning and end of the output signal.

Examples

>>> from numpy import linspace
>>> from numpy.random import randn
>>> t = linspace(-2,2,0.1)
>>> x = sin(t)+randn(len(t))*0.1
>>> y = smooth(x)

References

  1. Wikipedia, http://en.wikipedia.org/wiki/Convolution

See also

numpy.convolve

qats.signal.taper(x, window='tukey', alpha=0.001)

Taper the input time serie using a window function

Parameters
  • x (array) – Time series (without time vector), dimension n*1.

  • window ({'tukey','cosine','hanning', 'flat', ....}) – Window function type. See numpy documentation for more windows

  • alpha (float, optional) – Fraction of time domain signal to be tapered. Applies only to tukey and kaiser windows.

Returns

  • array – Tapered time domain signal

  • float – correction factor to prevent FFT components from diminishing after the windowing.

Notes

All FFT based measurements assume that the signal is periodic in the time frame. When the measured signal is not periodic then leakage occurs. Leakage results in misleading information about the spectral amplitude and frequency. A window is shaped so that it is exactly zero at the beginning and end of the data block and has some special shape in between. This function is then multiplied with the time data block forcing the signal to be periodic and ultimately reduces the effects of leakage. There are many windows to choose from, each with advantages for specific applications. You must understand the effects of leakage and know the tradeoffs and advantages of the various windowing functions to accurately interpret frequency domain measurements.

The cosine window is also known as the sine window.

The Tukey window is also known as the tapered cosine window.

References

  1. Wikipedia, http://en.wikipedia.org/wiki/Window_function

  2. Melbourne G. Briscoe (1972), Energy loss in surface wave spectra due to data windowing, North Atlantic Treaty Organization (NATO), Saclant ASW Research Centre,

qats.signal.lowpass(x, dt, fc, order=5)

Low pass filter data signal x at cut off frequency fc, blocking harmonic content above fc.

Parameters
  • x (array_like) – Signal

  • dt (float) – Signal sampling rate (s)

  • fc (float) – Cut off frequency (Hz)

  • order (int, optional) – Butterworth filter order. Default 5.

Returns

Filtered signal

Return type

array

qats.signal.highpass(x, dt, fc, order=5)

High pass filter data signal x at cut off frequency fc, blocking harmonic content below fc.

Parameters
  • x (array_like) – Signal

  • dt (float) – Signal sampling rate (s)

  • fc (float) – Cut off frequency (Hz)

  • order (int, optional) – Butterworth filter order. Default 5.

Returns

Filtered signal

Return type

array

qats.signal.bandpass(x, dt, flow, fupp, order=5)

Band pass filter data signal x at cut off frequencies flow and fupp, blocking harmonic content outside the frequency band [flow, fupp]

Parameters
  • x (array_like) – Signal

  • dt (float) – Signal sampling rate (s)

  • flow (float) – Passing frequency band (Hz)

  • fupp (float) – Passing frequency band (Hz)

  • order (int, optional) – Butterworth filter order. Default 5.

Returns

Filtered signal

Return type

array

qats.signal.bandblock(x, dt, flow, fupp, order=5)

Band block filter data signal x at cut off frequencies flow and fupp, blocking harmonic content inside the frequency band [flow, fupp]

Parameters
  • x (array_like) – Signal

  • dt (float) – Signal sampling rate (s)

  • flow (float) – Blocked frequency band (Hz)

  • fupp (float) – Blocked frequency band (Hz)

  • order (int, optional) – Butterworth filter order. Default 5.

Returns

Filtered signal

Return type

array

Notes

SciPy bandpass/bandstop filters designed with b, a are unstable and may result in erroneous filters at higher filter orders. Here we use sos (second-order sections) output of filter design instead.

qats.signal.threshold(x, thresholds)

Allow only frequency components whose amplitudes are between the lower threshold value and the upper threshold value to pass.

Parameters
  • x (array_like) – input data signal

  • thresholds (tuple) – passing amplitude range, thresholds as fraction of maximum frequency component amplitude

Returns

filtered data signal

Return type

array

Notes

FFT filter.

See also

scipy.fftpack

qats.signal.autocorrelation(series)

Estimation of the auto-correlation coefficients of series

Parameters

series (array_like) – data series

Returns

arrays of autocorrelation coefficients for the entire series for lags in the range [dt, dt, duration]

Return type

list

Notes

I took a part of code from pandas autocorrelation_plot() function. I checked the answers and the values are matching exactly. The auto-correlation coefficients can be plotted against the time vector associated with series.

References

  1. Wikipedia, http://en.wikipedia.org/wiki/Autocorrelation

qats.signal.average_frequency(t, x, up=True)

Average frequency of mean level crossings.

Parameters
  • t (array_like) – Time (seconds).

  • x (array_like) – Signal.

  • up (bool, optional) –

    • True: Period based on average time between up-crossings

    • False: Period based on average time between down-crossings

Returns

Average frequency of mean level crossings (Hz)

Return type

float

qats.signal.find_maxima(x, local=False, threshold=None, up=True, retind=False)

Return sorted maxima

Parameters
  • x (array) – Signal.

  • local (bool, optional) – If True, local maxima are also included (see notes below). Default is to include only global maxima.

  • threshold (float, optional) – Include only maxima larger than specified treshold. Default is mean value of signal.

  • up (bool, optional) – If True (default), identify maxima between up-crossings. If False, identify maxima between down-crossings.

  • retind (bool, optional) – If True, return (maxima, indices), where indices is positions of maxima in input signal array.

Returns

  • array – Signal maxima, sorted from smallest to largest.

  • array – Only returned if retind is True. Indices of signal maxima.

Notes

By default only ‘global’ maxima are considered, i.e. the largest maximum between each mean-level up-crossing. If local=True, local maxima are also included (first derivative is zero, second derivative is negative).

Examples

Extract global maxima from time series signal x:

>>> maxima = find_maxima(x)

Extract global maxima and corresponding indices:

>>> maxima, indices = find_maxima(x, retind=True)

Assuming time is the time vector (numpy array) for signal x, the following example will provide an array of time instants associated with the maxima sample:

>>> maxima, indices = find_maxima(x, retind=True)
>>> time_maxima = time[indices]
qats.signal.psd(x, dt, **kwargs)

Estimate power spectral density of discrete time signal X using Welch’s method.

Parameters
  • x (array_like) – Time series data.

  • dt (float) – Time step.

  • kwargs (optional) – See scipy.signal.welch documentation for available options.

Returns

Two arrays: sample frequencies and corresponding power spectral density

Return type

tuple

Notes

This function basically wraps scipy.signal.welch to control defaults etc.

qats.signal.csd(x, y, dt, **kwargs)

Estimate cross power spectral density of discrete-time signals X and Y using Welch’s method.

Parameters
  • x (array_like) – Time series data.

  • y (array_like) – Time series data.

  • dt (float) – Time step.

  • kwargs (optional) – See scipy.signal.csd documentation for available options.

Returns

Two arrays: sample frequencies and corresponding cross power spectral density

Return type

tuple

Notes

This function basically wraps scipy.signal.csd to control defaults etc.

qats.signal.coherence(x, y, dt, **kwargs)

Estimate the magnitude squared coherence estimate of discrete-time signals X and Y using Welch’s method.

Parameters
  • x (array_like) – Time series data.

  • y (array_like) – Time series data.

  • dt (float) – Time step.

  • kwargs (optional) – See scipy.signal.coherence documentation for available options.

Returns

Two arrays: sample frequencies and corresponding cross power spectral density

Return type

tuple

Notes

This function basically wraps scipy.signal.coherence to control defaults etc.

qats.signal.tfe(x, y, dt, clim=None, **kwargs)

Estimate the transfer function between two discrete-time signals X and Y using Welch’s method.

Parameters
  • x (array_like) – Time series data.

  • y (array_like) – Time series data.

  • dt (float) – Time step.

  • clim (float, optional) – Discard transfer function estimates where the magnitude squared coherence estimate is below this limit.

  • kwargs (optional) – See scipy.signal.welch, scipy.signal.csd and scipy.signal.coherence documentation for available options.

Returns

Two arrays: sample frequencies and corresponding transfer function estimate

Return type

tuple

Examples

Estimate the transfer function between wave elevation and vessel heave motion recorded to a file “somefile.mat”. >>> from qats import TsDB >>> from qats.signal import tfe >>> import matplotlib.pyplot as plt >>> >>> db = TsDB.fromfile(“somefile.mat”) >>> wave = db.get(“wave_2”) >>> heave = db.get(“heave”) >>> >>> # discard the transient signal >>> t, w = wave.get(twin=(1000, 1e8)) >>> _, h = heave.get(twin=(1000, 1e8)) >>> dt = t[1] - t[0] >>> # discard part of signals with poor coherence and smooth using Welch’s method with 1000 values per segment. >>> f, tf = tfe(w, h, dt, clim=0.3, nperseg=1000) >>> # plot transfer function against period and limit to periods larger than 2 seconds (0.5Hz) >>> plt.plot(1. / f[(0. < f) & (f <= 0.5)], abs(tf[(0. < f) & (f <= 0.5)])) >>> plt.xlabel(“Period (Hz)”) >>> plt.ylabel(“Transfer function (-)”) >>> plt.grid() >>> plt.show()

Notes

For single input/single-output systems like this the transfer function is estimated as Pyx / Pxx where Pxx is the power spectral density of x and Pyx is the complex conjugate of the cross power spectral density of x and y.