Skip to main content

A collection of simple NumPy-based filters and trackers optimized for real-time performance

Project description

Simple Filters and Tracking for Time-Series using NumPy

Python package Upload Python Package

This is a collection of simple filters based on NumPy, which are optimized for real-time performance.

pip install simple-filters

Filter

A filter acts as a container for a time-series. The length of the time-series is kept constant after initial filling, according to the history_size specified.

Currently, two filters are implemented:

  • NumpyFilterStrategy: Applies a numpy function (e.g. numpy.mean) to the time-series.
  • PolynomialFilterStrategy: Returns the filtered last item (and optionally predicts the next item) of a multi-dimensional time series using a polynomial regression. The strategy can be applied to sensor data to retain smoothness while ensuring low latency and avoiding offsets with outliers.
  • DummyFilterStrategy: Simply returns the last item of the time-series.

Set up your filter:

from simple_filters import Filter, PolynomialFilterStrategy, NumpyFilterStrategy, DummyFilterStrategy

strategy_1 = PolynomialFilterStrategy(poly_degree=3, outlier_rejection_ratio=2.0)
strategy_2 = NumpyFilterStrategy(np.mean)
strategy_3 = DummyFilterStrategy()

filter = Filter(strategy_1, history_size=10)

Fill the history with a 1D array:

filter.update([1.0, 2.0])
filter.update([1.1, 2.1])

Get the last filtered item at the current_time, or by specifying a time step in the future (time=1). Note that only PolynomialFilterStrategy allows for predicting the future.

result_current = filter.eval()
result_future = filter.eval(time=1)

Tracker

Oftentimes, multiple objects must be tracked that also require filtering. SimpleFilters implements a simple multi-object tracker for this purpose.

The following properties can be defined:

  • distance_threshold: Maximum distance to match objects - when the threshold is exceeded, a new object will be created
  • time_to_live: If an object is not seen, it is still retained for the given number of state updates
  • filter_prototype: A filter that will be cloned for each new appearing object

The PolynomialFilterStrategy is especially suitable for tracking, as it can predict the future state of the object according to its reconstructed polynomial:

from simple_filters import Filter, PolynomialFilterStrategy, Tracker

strategy = PolynomialFilterStrategy(poly_degree=3, outlier_rejection_ratio=2.0)
filter_prototype = Filter(strategy, history_size=10)
tracker = Tracker(filter_prototype, distance_threshold=1.0, time_to_live=1)

Update your tracker with a 2D array:

tracker.update([[1.0, 1.0], [2.0, 2.1]])
tracker.update([[1.1, 1.1], [1.9, 2.0], [3.1, 3.0]])

Retrieve the results:

# Access the list of objects like any filter: 
list_of_objects = tracker.get_tracked_objects() 
list_of_objects[0].eval(0) # get the latest state ([1.1, 1.1])
list_of_objects[0].id # get the tracking ID

# Or convert to a NumPy array: 
np_array = tracker.to_numpy_array()

Testing

Simply run pytest in the project directory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple-filters-0.1.3.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

simple_filters-0.1.3-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file simple-filters-0.1.3.tar.gz.

File metadata

  • Download URL: simple-filters-0.1.3.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for simple-filters-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f56dc5f4a932d7bb9f8bc15927202adf17cad7a16edfee49606c6a4d855d6713
MD5 2d64b0b32c20c015b49a744f9be27f11
BLAKE2b-256 36c7a3f1eff2c383df5a656ecfc9f84f47c100c5140cc58b952be6a087774693

See more details on using hashes here.

File details

Details for the file simple_filters-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: simple_filters-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for simple_filters-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d2574bdf3f878e516a1ca312676357c1065b908b6d4deb31c49466b1bc475e3e
MD5 57cc9d99a9146b13f6b3efa948d15221
BLAKE2b-256 f8b665cc4217ae7b540b2040e49fe1b00c6515b6bcd33f704b0a1f7acf1fc764

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page