tsdownsample is an extremely fast Python library for time series downsampling, leveraging Rust for its core implementation. It utilizes SIMD instructions and multithreading (via Rayon in Rust) to provide highly optimized, memory-efficient, and flexible algorithms for visualization and analysis of large time series datasets. The library is actively maintained, with its current version being 0.1.4.1.
pip install tsdownsampleVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `MinMaxLTTBDownsampler` to reduce a large time series dataset to a smaller, representative subset of points for visualization or analysis. It shows how to initialize a downsampler and use the `downsample` method with both `x` (optional time/index) and `y` (values) arrays, specifying the desired output size `n_out` and enabling parallel processing.
Ensure `x` arrays are sorted and free of NaNs before passing them to downsampling functions. The library offers specific `NaN...Downsampler` classes (e.g., `NaNMinMaxDownsampler`) for handling NaNs in `y` data.
Be aware that the actual output length may vary. If a fixed output length is critical, consider pre-processing or handling the output length post-downsampling.
Set `parallel=True` in your `downsample` calls. For fine-grained control, use `os.environ["TSDOWNSAMPLE_MAX_THREADS"] = "4"` before downsampling to limit or specify thread count.
Upgrade to version 0.1.4.1 or later to ensure correct numerical precision. If comparing results with older versions, be aware of potential minor numerical differences due to this fix.
Always pass `n_out` as a keyword argument (e.g., `n_out=1000`) to avoid `TypeError`.
Install the package using 'pip install tsdownsample'.
Use 'from tsdownsample import MinMaxDownsampler' instead.
Ensure that the 'x' array is sorted before passing it to the downsampling function.
Provide the 'y' argument when calling the 'downsample' method, e.g., 'downsampler.downsample(y, n_out=1000)'.
Instantiate a downsampler class and call its 'downsample' method, e.g., 'downsampler = MinMaxDownsampler(); downsampler.downsample(y, n_out=1000)'.