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 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-1.0.1-cp310-abi3-win_amd64.whl (328.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

rsliding-1.0.1-cp310-abi3-win32.whl (295.6 kB view details)

Uploaded CPython 3.10+Windows x86

rsliding-1.0.1-cp310-abi3-manylinux_2_28_x86_64.whl (418.8 kB view details)

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

rsliding-1.0.1-cp310-abi3-manylinux_2_28_aarch64.whl (387.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

rsliding-1.0.1-cp310-abi3-macosx_11_0_x86_64.whl (381.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ x86-64

rsliding-1.0.1-cp310-abi3-macosx_11_0_arm64.whl (363.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

rsliding-1.0.1-cp310-abi3-macosx_10_12_x86_64.whl (381.2 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

rsliding-1.0.1-cp39-abi3-win_amd64.whl (332.9 kB view details)

Uploaded CPython 3.9+Windows x86-64

rsliding-1.0.1-cp39-abi3-win32.whl (298.5 kB view details)

Uploaded CPython 3.9+Windows x86

rsliding-1.0.1-cp39-abi3-manylinux_2_28_x86_64.whl (422.9 kB view details)

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

rsliding-1.0.1-cp39-abi3-manylinux_2_28_aarch64.whl (390.1 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

rsliding-1.0.1-cp39-abi3-macosx_11_0_arm64.whl (367.7 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

rsliding-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl (384.5 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: rsliding-1.0.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 328.9 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-1.0.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 aa74a31478a694fcf3d27fa8bbc0c3be31f648bbda736d726c0cd897815c10e8
MD5 e48762d15d63fa1d7c69d5ebc9fdb8d2
BLAKE2b-256 5bee1a6d35c6295407bb13fe4e8c51bf099403ae53a0ce3dab6e0d4628791162

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rsliding-1.0.1-cp310-abi3-win32.whl
  • Upload date:
  • Size: 295.6 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-1.0.1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 b08bb1b1a8591f3616ade81a432b6046e57f2fa7893c8ca50f43ea5f97783f48
MD5 f25d9d56d7c00665eb57493c4c1a3919
BLAKE2b-256 425fe2229b2ab27133b7978ccd6613cd12b1f9b688724664191c25e6a8af03f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsliding-1.0.1-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 731e79b7066fd170693adf6bf1bf06736d7b55590399870d99ab0a12195ec43d
MD5 66cdecfb898185584073502ff1886ba5
BLAKE2b-256 2cfb9d280b21b09b45abc509ec4c63f04cb895c6aa0484bd9211ef5acfd30f32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsliding-1.0.1-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a3544be61dfcecd99819d9932a336dd9c34bf35bb9a1071cfcdc0e65edbe3d32
MD5 56002b367032ebe22e033b0324d504fa
BLAKE2b-256 27f4e288e930e0d2a6353afda1b8090d44f5b1f4eb4f20608885dab2616abbca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsliding-1.0.1-cp310-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 21e1ab1ee7294d9ad0269de7570362dd7706be1bb9ef0e6d33ff9cf23cb289a5
MD5 1e717f24cb2e835bb93fd15896f11dfc
BLAKE2b-256 c3a46b8b00667eb08e6fb1db69d18d00e434b7a27e40b7dd84444a71a633c266

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsliding-1.0.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b06390176865934071116722ded89415a14e308c44a9c4accd78dde9e8a86fd6
MD5 1763efef6c20150b9781081d19fd3bc2
BLAKE2b-256 cb1208591ac26292e9ba9f82279697870a1aeff58c36066f90a59d99017370d1

See more details on using hashes here.

File details

Details for the file rsliding-1.0.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rsliding-1.0.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a19e4b1eb300268f7b21f90e898dece442cdd472fe951c4c30bea79c9020d7ab
MD5 f7abe98027a0cd759670730a2474e979
BLAKE2b-256 1fbfe2031fb634c7c469d4ef8d652b104e26453002e9f1150b9c369470a93f9f

See more details on using hashes here.

File details

Details for the file rsliding-1.0.1-cp39-abi3-win_amd64.whl.

File metadata

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

File hashes

Hashes for rsliding-1.0.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 751ed26c5f6c8480a19b627cde24852e6cbbb7c109c0bd4108d01d19bcdc6081
MD5 93efbe43871eba7bce8780a85bd6192f
BLAKE2b-256 f4cbef2ee777d7134d11bbb1ac765a769eb16c44965f79ad0864fd82a08e1d36

See more details on using hashes here.

File details

Details for the file rsliding-1.0.1-cp39-abi3-win32.whl.

File metadata

  • Download URL: rsliding-1.0.1-cp39-abi3-win32.whl
  • Upload date:
  • Size: 298.5 kB
  • Tags: CPython 3.9+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rsliding-1.0.1-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 90d1de51cabf16280d75ca64d80122e5602e0bb9c08454b855cf4db7364a15d6
MD5 7bb4c5c553c9859c2fca2cfb63301887
BLAKE2b-256 96beb01e039bde4d6f384d27f732b08ef5a43ddb5968d83c1223933ac5f3affb

See more details on using hashes here.

File details

Details for the file rsliding-1.0.1-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rsliding-1.0.1-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d83ec0054a877a85ef55ce7b54cd4f0c6de2c388d4668fb3a89e23acbd1c17d4
MD5 bddc9170f9f07191b658a919c7109e57
BLAKE2b-256 a86d2da48c621351089b0380771f25bb943cb0a1239696f48639724fca1d811f

See more details on using hashes here.

File details

Details for the file rsliding-1.0.1-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for rsliding-1.0.1-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3a497a9ab2ac5e7cbc2e8bfcce5bfca379396362e9f0a76b97bb153d30c15760
MD5 b5298dfcd41484e0007df0074dcad761
BLAKE2b-256 855a7415db04dbecb33521eba9c62ea716bb03806fd40b38c466875d05d4d86d

See more details on using hashes here.

File details

Details for the file rsliding-1.0.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rsliding-1.0.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83e0726e582e09e0cb66f1300eff511c24342a1fdb399fe9062396179f6b23bf
MD5 bbd986fcb876deedba84ffa223bfaa1f
BLAKE2b-256 322a6e699f17840324ce794901f86b6bb1ccb11f62cb85b1217afc09e9d37a42

See more details on using hashes here.

File details

Details for the file rsliding-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rsliding-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5fe19d003dee929858a310196d639daeec74ecfe46bc66802e1de5f29d0d8d7c
MD5 948408576693b7421b37e7ab1b55f690
BLAKE2b-256 191b15d958fc9e3596b9dd030c87a3efe5e617b9d1e0c44529e387d131349b8d

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