Skip to main content

A sparse matrix implementation of Whittaker-Eilers smoothing and interpolation

Project description

Whittaker-Eilers Smoothing and Interpolation

The Whittaker-Eilers smoother is the perfect smoother. It offers extremely quick, efficient smoothing with built-in interpolation via weights on each measurement. This package provides a sparse-matrix implementation for additional speed and memory efficiency and can handle both equally and unequally spaced measurements. This package was originally written in Rust so additional examples, tests, and benchmarks are also available in addition to it being super speedy. The API is almost identical.


pip install whittaker-eilers

Usage

To start smoothing and interpolating data, create a reusable WhittakerSmoother class. You'll only need to recreate this class if the length or sampling rate of your data changes.

Equally spaced data

This is the fastest smoothing option. It smooths equally spaced y measurements using two tunable parameters, lambda (2e4) and the smoother order (2). The larger the lambda, the smoother the data.

from whittaker_eilers import WhittakerSmoother

data_to_smooth = [1.1, 1.9, 3.1, 3.91, 5.0, 6.02, 7.01, 7.7, 9.0, 10.0]

whittaker_smoother = WhittakerSmoother(lmbda=2e4, order=2, data_length = len(data_to_smooth))

smoothed_data = whittaker_smoother.smooth(data_to_smooth)

print("Smoothed data: {}".format(smoothed_data))

Non-equally spaced data

If you wish to smooth unequally spaced data, you need to provide an x_input with the sample times/positions.

from whittaker_eilers import WhittakerSmoother

x_input = [1.1, 1.9, 3.1, 3.91, 5.0, 6.02, 7.01, 7.7, 9.0, 10.0]
data_to_smooth = [1.1, 1.9, 3.1, 3.91, 5.0, 6.02, 7.01, 7.7, 9.0, 10.0]

whittaker_smoother = WhittakerSmoother(
    lmbda=2e4, order=2, data_length=len(data_to_smooth), x_input=x_input
)

smoothed_data = whittaker_smoother.smooth(data_to_smooth)

print("Smoothed non-equally spaced data: {}".format(smoothed_data))

Weighted data & Interpolation

Each measurement can then be weighted to trust some measurements more than others. Setting weights to 0 for measurements will lead to interpolation.

from whittaker_eilers import WhittakerSmoother

x_input = [1.1, 1.9, 3.1, 3.91, 5.0, 6.02, 7.01, 7.7, 9.0, 10.0]
data_to_smooth = [1.1, 1.9, 3.1, 3.91, 5.0, 6.02, 7.01, 7.7, 9.0, 10.0]
weights = [1.0] * len(x_input)
weights[5] = 0.0

whittaker_smoother = WhittakerSmoother(
    lmbda=2e4,
    order=2,
    data_length=len(data_to_smooth),
    x_input=x_input,
    weights=weights,
)

smoothed_data = whittaker_smoother.smooth(data_to_smooth)

print("Smoothed and interpolated weighted data: {}".format(smoothed_data))

You can use these methods in combination with each other for instance, interpolating measurements without providing an x input. For more advanced examples of usage take a look at the examples, tests, and benches in the Github repository. Here's an image of some smoothed data from an example:

Time-series smoothed by Whittaker-Eilers method

Other methods

from whittaker_eilers import WhittakerSmoother
x_input = [1.1, 1.9, 3.1, 3.91, 5.0, 6.02, 7.01, 7.7, 9.0, 10.0]
data_to_smooth = [1.1, 1.9, 3.1, 3.91, 5.0, 6.02, 7.01, 7.7, 9.0, 10.0]
weights = [1.0] * len(x_input)
weights[5] = 0.0

whittaker_smoother = WhittakerSmoother(
    lmbda=2e4,
    order=2,
    data_length=len(data_to_smooth),
    x_input=x_input,
    weights=weights,
)

whittaker_smoother.get_order()
whittaker_smoother.get_lambda()
whittaker_smoother.get_data_length()
whittaker_smoother.update_weights([0.5] * len(x_input))
whittaker_smoother.update_order(3)
whittaker_smoother.update_lambda(4321.0)

Future Features

  • Cross validation options to find optimal lambda.
  • Scatter plot smoothing
  • Generic typing

References

The algorithm implemented here mirrors a 2003 implementation by Paul H. C. Eilers in Matlab. I've included scripts and data from the original paper in the tests for this package. The original paper and code can be found here:

A Perfect Smoother Paul H. C. Eilers Analytical Chemistry 2003 75 (14), 3631-3636 DOI: 10.1021/ac034173t

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

whittaker_eilers-0.1.1.tar.gz (177.7 kB view details)

Uploaded Source

Built Distributions

whittaker_eilers-0.1.1-cp37-abi3-win_amd64.whl (230.7 kB view details)

Uploaded CPython 3.7+Windows x86-64

whittaker_eilers-0.1.1-cp37-abi3-win32.whl (218.7 kB view details)

Uploaded CPython 3.7+Windows x86

whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ s390x

whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.4 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ppc64le

whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.3 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARMv7l

whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl (1.3 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.12+ i686

whittaker_eilers-0.1.1-cp37-abi3-macosx_11_0_arm64.whl (379.2 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

whittaker_eilers-0.1.1-cp37-abi3-macosx_10_7_x86_64.whl (393.1 kB view details)

Uploaded CPython 3.7+macOS 10.7+ x86-64

File details

Details for the file whittaker_eilers-0.1.1.tar.gz.

File metadata

  • Download URL: whittaker_eilers-0.1.1.tar.gz
  • Upload date:
  • Size: 177.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.3.0

File hashes

Hashes for whittaker_eilers-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fa2f1095457e972a0a5f6e26fce7fbcb39b18cf34cd71c7067ca49374a35551d
MD5 b96bb99a610e59f30f0e4d0cf937547d
BLAKE2b-256 0292e3aeba8c89a2838abcf5304f57974adb67dcab2ff67fa85c5b0de87e1f34

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 106102fd396749b521ae94b1719da9098868f9f5ba30f1816bdd66ae505afbb6
MD5 3f7265da51fd1c581ef61b403525b3c8
BLAKE2b-256 1fffc5360ac25f3fb9bfb4d9705a728d7adc666555c04ebcd6e78bc2a5b59944

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-win32.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 7ef4b65185c208f1e5826b8241d597af34de5d1d6e52543b0d829b24aaa2c1db
MD5 c784966f5c0410cc9e163f3e0fee9f7c
BLAKE2b-256 5fac9033fad1d0ca0e1052d011eaef4fca2481a3592cb03ad0020403141a3bd6

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 13e1326bd8da8e8ea656dcc941e8926fbc6211ce7000cfb6d71b26becca924cb
MD5 006a2ce8ecd3f91d72ca4c0486922a2a
BLAKE2b-256 6abc00ad5b40faeff8565d44d9f27d65b9666317cdd2f98abbe26f2ff0bf6420

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 dd49f0b3bcf33529f477f3953645c486451fec5f6edaf3859e94ef08f2cd63e7
MD5 9ff86febc44522d594361759f8f5d32c
BLAKE2b-256 1a4fd9a8c87742a0776cd873fb5d876ca2230ce3307da5e17c3f6b1cfb2c29af

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 11c93d582bc5d9f164850fb00f8cd451805c699d8bd0d051975fddf2fddfce89
MD5 eded206ef218d8e461443365718f4fa9
BLAKE2b-256 975167a7402ba0300951a572bb94e09947c00d7cc2d9339f08d20d1c1de3d6ca

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 da2eac1c0167fbf9d4dd07ad4453dae4a926fcf5d8627743a9abc5742309a10e
MD5 06ff089d383941d2ce3e48c613dba64f
BLAKE2b-256 cc3c98de33536f2d8c7067d7fc52d4da5250d5376fb62e7778e8acdc150d308f

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 56b709cd797ac8f457ebe37eddfe5c93167759e76dca511bb222ea01fbbc722b
MD5 dd0714d5b0c8c9383caf914406424300
BLAKE2b-256 41b8f2286557ee00c6192252485156f8c83591364d28d073a8824b01bd20ce8a

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 4d91a822dca4c136b3fcc89eb42b86595bddce2b2c893fb07897602e1c736b56
MD5 6049beacc016a559f251c9c6682e4c4d
BLAKE2b-256 454903c51bbad9d939b5037fabe0d59a80fff3adbbbaed2a73ba76525a3c74c9

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 973bcbc511b7e7038ed162bf7e75074d2184d53211eeb6066c319e4bcf9d4fc3
MD5 5ea38aefc4246f51a7eb2a87c0c407f2
BLAKE2b-256 5a4596a14a439897ee2006ec89bfc9cfa5e596b300f8f2c33499d83f11def538

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.1-cp37-abi3-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.1-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 a7defa3e0bf7ce01f0611425be9bca14b5f9a61966c86fc2cc17f6bbe54025b5
MD5 d2638abce0bbe8f82eb6f339cbf486f3
BLAKE2b-256 3862606e1174390f7017f18c33afe6ce5c021aef97b2cc26975b487c29317658

See more details on using hashes here.

Supported by

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