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)

Further Reading

If you'd like to see a more detailed run through of the library, check out this Medium post. Within it, I run through examples and benchmarks against other smoothing methods.

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.2.tar.gz (183.0 kB view details)

Uploaded Source

Built Distributions

whittaker_eilers-0.1.2-cp37-abi3-win_amd64.whl (226.0 kB view details)

Uploaded CPython 3.7+Windows x86-64

whittaker_eilers-0.1.2-cp37-abi3-win32.whl (218.2 kB view details)

Uploaded CPython 3.7+Windows x86

whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

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

whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.4 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ s390x

whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.3 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ppc64le

whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARMv7l

whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

whittaker_eilers-0.1.2-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.2-cp37-abi3-macosx_11_0_arm64.whl (350.7 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

whittaker_eilers-0.1.2-cp37-abi3-macosx_10_12_x86_64.whl (356.2 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for whittaker_eilers-0.1.2.tar.gz
Algorithm Hash digest
SHA256 703179c15da6ba08b2ddae96e4b0c772b6e8f5f6a5531503f7e6d5a180157ef3
MD5 ef30a2a36e9d8dc5588dea17e50f8ca8
BLAKE2b-256 1ec20a992ff69785601122a31e53b028538d28b25e8a81af687b1c46f1a32c7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 913663e0a40ae7776fa14c9b061bbcfeb3bc4b49f395f426a7411c22f0cba61d
MD5 3438c39df47789db86d6e1d707bef4a3
BLAKE2b-256 8280f1914c0c6527a0a991568b4ecf9594a10456288e386a69e188dacabcd5f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 eaa9ab8d8fb47a1c3e0943ad73a1a277a8d73bf7a8dabb65bd1a852b3b86f655
MD5 9316601a56e29fb0930d4230832dc4a5
BLAKE2b-256 cf805d726ac3e08287188b75512c0d627b3a7205ed6d7bd00addbb780fa9395b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cef71bf33cb9094ee4f08f1d61d2efea4fd1f21ed88549dba0a3f55a4872517a
MD5 2d53bf55a8632570c37928c0c0616269
BLAKE2b-256 fde7a8972a90f58dbe6c7d406d57dc0dc43041f78bdd2e8895814c7acb12d5d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 a5901893b1f1710b8a2743a6f95ddcc500668502c3b441faebfafd01e4e1eb58
MD5 42f58be31cde4d902c03dad90b002d9a
BLAKE2b-256 77231f281e70f080f95c0f05927f662c0c0968180be06e0f5f3ce2c0a9ae1414

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 5ef86e61e5f32d8e12c2a5b1ee6304f8caab59f416fe2734c0a09bc81162b3c7
MD5 727d8c339ebbde8a125ee1484500e758
BLAKE2b-256 c3ac5ae0c1d45f5eb74bc19f45e90c381abf47cecc349fc5d8170a3e961d7dc0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 7ec781fcc7568bea0fbc638236d1177e46f0a249597f6a65a3056d223ca8233a
MD5 ac313d6f38fdebef345d7ce3f14bf385
BLAKE2b-256 41a47467fbbac633f318de0091c925a9a9fa46ef9b76ca7af497d45580d4ebf6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 84766846e9661bde60c3572710665674378cdbb6001f4a4bcb48f78fb7964b3f
MD5 a6c64284903da0f08e4f40c8ae07b451
BLAKE2b-256 1559c1cb19ec6b1f6d0db5a8b848d464c0f0d8bd29160ab18d8bba13b7de3050

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 829c93be78e7a327816e713491f7afe32eb9ccb81cba0566c7b191353d218816
MD5 f6fad1b5a47cd0373124a5a654995adb
BLAKE2b-256 cf5de72596fd3d7893030afdbef866e96ade660f8573da19726d1493290c3d74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 490aa4662de8346a8feb840028eab8fd0fe7168fa131ad6d319d05cf620748aa
MD5 fdf8c63f4595fa0863ed3325645848ae
BLAKE2b-256 80327500b199270ada6938a57a367bd7c444f2a8e9e8fff415a7317bf7812e32

See more details on using hashes here.

File details

Details for the file whittaker_eilers-0.1.2-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for whittaker_eilers-0.1.2-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 04e8136651017e1c9e71427a1e7d66e5a3ccaff4870a736a7fcefe3e457346cb
MD5 90578a90a9e736db65ff13bbfcaf828d
BLAKE2b-256 c7d55d9de1f1c43badcb102e94444a7c735cfb672a7b9fbf6be8a642b210659a

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