aquaduct.geom.smooth module

Smooth module defines methods for smoothing of trajectories.

Available methods:

SavgolSmooth Savitzky-Golay based smoothing.
WindowSmooth Defined size window smoothing.
DistanceWindowSmooth Distance defined size window smoothing.
ActiveWindowSmooth Active size window smoothing.
MaxStepSmooth Maximal step smoothing.
WindowOverMaxStepSmooth Window smoothing over maximal step smoothing.
DistanceWindowOverMaxStepSmooth Distance window smoothing over maximal step smoothing.
ActiveWindowOverMaxStepSmooth Active window smoothing over maximal step smoothing.
class Smooth(recursive=None, **kwargs)[source]

Bases: object

Base class for all smoothing methods.

__init__(recursive=None, **kwargs)[source]
Parameters:recursive (int) – Number of recursions of the method, everything evaluated to False is equivalent to 1.
smooth(coords)[source]

Abstract method for smoothing method implementation.

Parameters:coords (Iterable) – Input coordinates to be smoothed.
__call__(coords)[source]

Call method for all smoothing methods.

Input coordinates should be iterable and each element should be numpy.ndarray. If length of coords is less then 3 smoothing method is not run and coordinates are returned unchanged.

If recursive is set smoothing method is applied appropriate number of times.

Parameters:coords (Iterable) – Input coordinates to be smoothed.
Return type:numpy.ndarray
Returns:Smoothed coordinates.
class GeneralWindow(function=<function mean>, **kwargs)[source]

Bases: object

Base class for window based smoothing methods.

__init__(function=<function mean>, **kwargs)[source]
Parameters:function (function) – Function to be used for averaging coordinates within a window.
static max_window_at_pos(pos, size)[source]

Method returns maximal possible window at given position of the list with given size of the list. Returned window fits in to the list of given size and is symmetrical.

Parameters:
  • pos (int) – Position in question.
  • size (int) – Length of the list.
Return type:

2 element tuple of int

Returns:

Lowest possible bound and highest possible bound of the window.

check_bounds_at_max_window_at_pos(lb, ub, pos, size)[source]

Method checks if window fits in to maximal possible window calculated according to max_window_at_pos(). If not window is corrected.

Parameters:
  • lb (int) – Lower bound of the window in question.
  • ub (int) – Upper bound of the window in question.
  • pos (int) – Position in question.
  • size (int) – Length of the list.
Return type:

2 element tuple of int

Returns:

Lowest possible bound and highest possible bound of the window corrected to maximal possible window.

class IntWindow(window=5, **kwargs)[source]

Bases: aquaduct.geom.smooth.GeneralWindow

Base class for all window smoothing methods that require integer window.

__init__(window=5, **kwargs)[source]
Parameters:window (int) – One side size of the window.
class FloatWindow(window=5.0, **kwargs)[source]

Bases: aquaduct.geom.smooth.GeneralWindow

Base class for all window smoothing methods that require float window.

__init__(window=5.0, **kwargs)[source]
Parameters:window (float) – Size of the window.
class WindowSmooth(**kwargs)[source]

Bases: aquaduct.geom.smooth.Smooth, aquaduct.geom.smooth.IntWindow

Defined size window smoothing.

For each coordinate a symmetrical (if possible) window of size defined by window is created. In case of coordinates at the edges created window is truncated to the edges. Next, all coordinates within the window are averaged with a function defined by function. Resulting value(s) are the smoothed coordinates.

__init__(**kwargs)[source]
smooth(*args, **kwargs)[source]
Parameters:coords (Iterable) – Input coordinates to be smoothed.
class DistanceWindowSmooth(**kwargs)[source]

Bases: aquaduct.geom.smooth.Smooth, aquaduct.geom.smooth.FloatWindow

Distance defined size window smoothing.

This is modification of WindowSmooth method. The difference is in the definition of the window size. Here, it is an average distance between points of input coordinates. Thus, before smoothing average distance between all points is calculated and this value is used to calculate actual window size.

Next, for each coordinate a symmetrical (if possible) window of size calculated in the first step is created. In case of coordinates at the edges created window is truncated to the edges. Next, all coordinates within the window are averaged with a function defined by function. Resulting value(s) are the smoothed coordinates.

__init__(**kwargs)[source]
smooth(*args, **kwargs)[source]
Parameters:coords (Iterable) – Input coordinates to be smoothed.
class ActiveWindowSmooth(**kwargs)[source]

Bases: aquaduct.geom.smooth.Smooth, aquaduct.geom.smooth.FloatWindow

Active size window smoothing.

Similarly to DistanceWindowSmooth method the window size is defined as a distance. The difference is that the actual window size is calculated for each point separately. Thus, for each coordinate the window is calculated by examining the distance differences between points. In this method window is not necessarily symmetrical. Once window is calculated all coordinates within the window are averaged with a function defined by function. Resulting value(s) are the smoothed coordinates.

__init__(**kwargs)[source]
smooth(*args, **kwargs)[source]
Parameters:coords (Iterable) – Input coordinates to be smoothed.
class MaxStepSmooth(step=1.0, **kwargs)[source]

Bases: aquaduct.geom.smooth.Smooth

Maximal step smoothing.

This method moves thorough coordinates and calculates distance over the traversed path. If it is then step the coordinate is used as a “cardinal point”. The beginning and the end of the path are also added to the list of cardinal points. Next, all cardinal points and points of linear interpolation between cardinal points are returned as smoothed coordinates. Number of interpolated points is in accordance to points skipped between cardinal points.

__init__(step=1.0, **kwargs)[source]
smooth(*args, **kwargs)[source]
Parameters:coords (Iterable) – Input coordinates to be smoothed.
class SavgolSmooth(window_length=5, polyorder=2, **kwargs)[source]

Bases: aquaduct.geom.smooth.Smooth

Savitzky-Golay based smoothing.

Method uses 1D filter available in SciPy, see savgol_filter(). For each dimension filter is applied separately. Only window_length and polyorder attributes are used.

__init__(window_length=5, polyorder=2, **kwargs)[source]
Param:int window_length: Size of the window, odd number.
Param:int polyorder: Polynomial order.
smooth(*args, **kwargs)[source]
Parameters:coords (Iterable) – Input coordinates to be smoothed.
class WindowOverMaxStepSmooth(**kwargs)[source]

Bases: aquaduct.geom.smooth.Smooth

Window smoothing over maximal step smoothing.

First, MaxStepSmooth is applied, and then WindowSmooth.

__init__(**kwargs)[source]
smooth(coords)[source]
Parameters:coords (Iterable) – Input coordinates to be smoothed.
class ActiveWindowOverMaxStepSmooth(**kwargs)[source]

Bases: aquaduct.geom.smooth.Smooth

Active window smoothing over maximal step smoothing.

First, MaxStepSmooth is applied, and then ActiveWindowSmooth.

__init__(**kwargs)[source]
smooth(coords)[source]
Parameters:coords (Iterable) – Input coordinates to be smoothed.
class DistanceWindowOverMaxStepSmooth(**kwargs)[source]

Bases: aquaduct.geom.smooth.Smooth

Distance window smoothing over maximal step smoothing.

First, MaxStepSmooth is applied, and then DistanceWindowSmooth.

__init__(**kwargs)[source]
smooth(coords)[source]
Parameters:coords (Iterable) – Input coordinates to be smoothed.