Skip to main content

downsample: Collection of downsample algorithms for Python (Python using a C implementation)

This packages includes low level implementations written in C-Python of:

  • The Largest Triangle Dynamic Buckets (LTD) downsampling algorithm
  • The Largest Triangle Three Buckets (LTTB) downsampling algorithm
  • The Largest Triangle One Bucket (LTOB) downsampling algorithm

The algorithm of LTTB was initially developed in (https://github.com/dgoeries/lttbc.git) Parts of this code have been translated and refers to the work of:

The algorithms are described in the work of Sveinn Steinarsson (https://github.com/sveinn-steinarsson/flot-downsample/).

Known features and requirements:

  • The algorithm requires that x data is increasing and finite.
  • y data must be finite; otherwise, issues may arise.
  • x and y data must have the same length.
  • The downsample algorithm returns a tuple of two arrays with data type double

Installing

You can also install it from PyPI to use in other environments with Python 3.10 or later:

pip install downsample

How to use on the field

All functions take an input for x and y in addition to the threshold:

from downsample import ltob, lttb, ltd
import numpy as np

array_size = 10000
threshold = 1000

x = np.arange(array_size, dtype=np.int32)
y = np.random.randint(1000, size=array_size, dtype=np.uint64)

x_l = x.tolist()
y_l = y.tolist()

for func in {ltd, ltob, lttb}:
    nx, ny = func(x, y, threshold)
    assert len(nx) == threshold
    assert len(ny) == threshold
    assert nx.dtype == np.double
    assert ny.dtype == np.double

    # List data or a mixture is accepted as well!
    nx, ny = func(x_l, y_l, threshold)
    assert len(nx) == threshold
    assert len(ny) == threshold
    assert nx.dtype == np.double
    assert ny.dtype == np.double

Performance Overview

For a performance overview, a sample of 7.500 data points was analyzed with a threshold set at 500 points. The performance test was conducted on a single core, utilizing a base clock speed of 3.70 GHz and 32 MB of L3 cache.

  • LTD: 89.3 us
  • LTOB: 51.6 us
  • LTTB: 60.6 us

Metadata

Release files for downsample 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for downsample 0.2.0
File Size Uploaded Provenance Actions
downsample-0.2.0.tar.gz 18.8 kB Without provenance Details for downsample-0.2.0.tar.gz

Release files / downsample-0.2.0.tar.gz

Download URL downsample-0.2.0.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
89071ae91590b30b2a16876149641a70f683b8e55585a01e731e2725c924f42e
BLAKE2b-256 checksum
How to use checksums
21dde1f0ba912819c98589a3a9b827555de7aa94c337c7f9dbc62e27dc7c2a03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Security for downsample 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page