Skip to main content

Rust with Python bindings. Contains sliding (filtering) operations (padding, convolution, mean, median, standard deviation, sigma clipping) for float64 numpy data with NaN values and a kernel with weights.

Project description

rsliding package

This python package contains utilities to compute a sliding sigma clipping, where the kernel can contain weights and the data can contain NaN values (has to be float64).

The actual core code is in Rust. This package was created to have a less memory hungry sigma clipping code compared to the similar sliding python package (cf. https://github.com/avoyeux/sliding.git). It is also a few times faster than the sliding package equivalent (except in some cases when using the Convolution or SlidingMean class). Check the Functions markdown section to know about the different available classes.

For high numerical stability (c.f. https://dl.acm.org/doi/epdf/10.1145/359146.359152), the standard deviation is computed using the two-pass algorithm (i.e. mean computation then variance). Furthermore, the user can decide to use 'Neumaier's summation' for the standard deviation and mean computation (highest numerical stability that I know of). While the Welford algorithm is faster and quite stable, I did find (from literature and tests) that the two-pass algorithm is more stable, even more so when using Neumaier's summation.

IMPORTANT: the code only works if the kernel dimensions are odd and has the same dimensionality than the input data.

NOTES: for the standard deviation computation, compared to using numpy.std on each window, the rsliding implementation should be a little less numerically stable if 'neumaier=False'. This is because, while numpy.std seem to also use the two-pass algorithm (c.f. https://numpy.org/doc/stable/reference/generated/numpy.std.html), numpy functions also implement pairwise summation (not done in rsliding). That being said, Neumaier's summation is more stable than pairwise summation and, as such, when 'neumaier=True`, the 'SlidingMean' and 'SlidingStandardDeviation' implementation should be more numerically stable than implementing sliding operations using np.mean and np.std (or nanmean/nanstd).

Install package

Given that pre-compiled binaries are needed if the user doesn't have the Rust compiler installed, the user should install the package through PyPi.

(OPTIONAL) Create and activate a python virtual environnement:

python3 -m venv .venv
source .venv/bin/activate

or on Windows OS:

python -m venv .venv

# Command Prompt
.venv\Scripts\activate

# PowerShell
.venv\Scripts\Activate.ps1

# Git Bash or WSL
source .venv/Scripts/activate

Install package in virtual environnement (or on bare-metal - wouldn't recommend):

pip install --upgrade pip
pip install rsliding

Functions

The rsliding package has 6 different classes:

  • Padding which returns the padded data. Not really useful given np.pad is way more efficient. A Python binding exist just so that the user can check the results if wanted be.
  • Convolution which lets you perform a convolution (NaN handling done).
  • SlidingMean which performs a sliding mean (NaN handling done).
  • SlidingMedian which performs a sliding median (NaN handling done).
  • SlidingStandardDeviation which performs a sliding standard deviation (NaN handling done).
  • SlidingSigmaClipping which performs a sliding sigma clipping (NaN handling done).

Example

# IMPORTs
import numpy as np
from rsliding import SlidingSigmaClipping

# CREATE fake data
fake_data = np.random.rand(36, 1024, 128).astype(np.float64)
fake_data[10:15, 100:200, 50:75] = 1.3
fake_data[7:, 40:60, 70:] = 1.7

# KERNEL
kernel = np.ones((5, 3, 7), dtype=np.float64)
kernel[2, 1, 3] = 0.

# NaN ~5%
is_nan = np.random.rand(*fake_data.shape) < 0.05
fake_data[is_nan] = np.nan

# CLIPPING no lower value
clipped = SlidingSigmaClipping(
    data=fake_data,
    kernel=kernel,
    center_choice='median',
    sigma=3.,
    sigma_lower=None,
    max_iters=3,
    borders='reflect',
    threads=1,
    masked_array=False,
    neumaier=True,
).clipped

IMPORTANT

Before using this package some information is needed:

  • float64 values for the data: the data needs to be of float64 type. Given the default class argument values, the data will be cast to float64 before calling Rust.
  • threads: there is a threads argument for most of the classes. It is not used during the padding operations but used for in all other intensive operations. Done like so as using threads for the padding would most likely slow down the computation speed in most cases.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rsliding-2.0.0-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

rsliding-2.0.0-cp310-abi3-win_amd64.whl (344.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

rsliding-2.0.0-cp310-abi3-win32.whl (313.3 kB view details)

Uploaded CPython 3.10+Windows x86

rsliding-2.0.0-cp310-abi3-manylinux_2_28_x86_64.whl (434.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

rsliding-2.0.0-cp310-abi3-manylinux_2_28_aarch64.whl (403.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

rsliding-2.0.0-cp310-abi3-macosx_11_0_x86_64.whl (396.9 kB view details)

Uploaded CPython 3.10+macOS 11.0+ x86-64

rsliding-2.0.0-cp310-abi3-macosx_11_0_arm64.whl (381.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file rsliding-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: rsliding-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 30.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rsliding-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af7f12b899230bca4db9f4ac6aa3e5315e4e0b4bc6ca8a7b2ae42032f832ea9b
MD5 575d708f0b5d13f0a28354ea164975fd
BLAKE2b-256 d89f7473da2980e97e318abde8b7b9413213f0ebac0d8f37921cc870b861a601

See more details on using hashes here.

File details

Details for the file rsliding-2.0.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: rsliding-2.0.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 344.7 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rsliding-2.0.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7dc5891f8feba2f62ddd9ae96594ff6d9a7d351d44801d82019ad038303b499d
MD5 bf6229c84b5fe257264eeab32e54969c
BLAKE2b-256 1db07ba6a52be9b9ecb2b43c2cdaed17439d6500b7fa485f7e891ef151abdeb9

See more details on using hashes here.

File details

Details for the file rsliding-2.0.0-cp310-abi3-win32.whl.

File metadata

  • Download URL: rsliding-2.0.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 313.3 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rsliding-2.0.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 fc5ed46ce97efcddba8959a4149d8e630c205830d1a5e52096dea75a601c0012
MD5 20e182efc82d22cf587618bd2164d0ab
BLAKE2b-256 6c5f9b7a114bcbbec962646d168ca1dc39e0991aa97148186822696d88e3d0d9

See more details on using hashes here.

File details

Details for the file rsliding-2.0.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rsliding-2.0.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d851f3e6638940be9bcadaf875ad3b6c00bc13b736a3a698765354bace8c5908
MD5 f7a2cdcc51362a9f0d8d3061f840e5fa
BLAKE2b-256 197db77d0f9bafbb0b6b423107ae1cbd97e7065a3ee5f8829e43fe72c5a5cd37

See more details on using hashes here.

File details

Details for the file rsliding-2.0.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for rsliding-2.0.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ae8c8c60d2c8cdee2506ea3d6dff90649a3c518343bb999c14ea33b86310b66c
MD5 d75be3f537fde03bd73ab48426e43f5a
BLAKE2b-256 0fff63fcfff55f7e009400b0479facfd4517ed5efece3f1a5936ea7ceb89670a

See more details on using hashes here.

File details

Details for the file rsliding-2.0.0-cp310-abi3-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for rsliding-2.0.0-cp310-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 83c9b6547652f456f625296cf5bace2c814cb70c885c89f4b877f0804b6ae571
MD5 b06750edd5dd70f4ceb7f80a3f3c85bf
BLAKE2b-256 b43c57130fd2976bc53f274137509e5203de893b7219f518ea490553a8f439ec

See more details on using hashes here.

File details

Details for the file rsliding-2.0.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rsliding-2.0.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b1e59756aedda46418755b051f86cbc99ea1029169737f58e50ded4bf21a3ac7
MD5 f9b999d84ac32439ccef82e80a9bc34b
BLAKE2b-256 525ec4dce7cc9d7b80082de0276d2207a42b3404deec7911ff4a4607738281d6

See more details on using hashes here.

Supported by

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