Skip to main content

Spectral smoothing in Rust/Python

Project description

PyPI PyPI Python Rust

Fast Konno-Ohmachi Spectral Smoothing

Implemented in Rust with a Python interface. The performance gain measured against the widely used Python/numpy implementation that comes with obspy approaches approximately a factor of 2.5 for large and 10 for small vectors (see Benchmarks).

Installation

Installation from pypi:

pip install konnoohmachi

Installation from source:

pip install .

Usage

This smoothes some random numbers:

Python

import konnoohmachi

bandwidth = 40

# using fake random data
frequencies = np.arange(1000)
amplitudes = np.random.rand(1000)

smoothed_amplitudes = konnoohmachi.smooth(frequencies, amplitudes, bandwidth)

Rust

use konnoohmachi;

let frequencies = Array1::<f64>::zeros(10);
let amplitudes = Array1::<f64>::ones(10);
let bandwidth = 40.0;
konnoohmachi_smooth(
    frequencies.view().into_dyn(),
    amplitudes.view().into_dyn(),
    bandwidth,
);

Benchmarks

Measuring the execution time based of increasing sized spectra yields:

❯ python3 benchmark.py
nsamples |    Rust      |    Python     | Performance Gain
----------------------------------------------------------
256      |    0.00017   |    0.00192    |   11.30802
512      |    0.00054   |    0.00431    |    7.97596
1024     |    0.00198   |    0.01117    |    5.63623
2048     |    0.00775   |    0.03143    |    4.05371
4096     |    0.03067   |    0.10024    |    3.26844
8192     |    0.12212   |    0.35058    |    2.87080
16384    |    0.49391   |    1.29653    |    2.62506
32768    |    1.98499   |    5.05335    |    2.54578

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

konnoohmachi-1.0.0-cp310-none-win_amd64.whl (148.8 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

konnoohmachi-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

konnoohmachi-1.0.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (393.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

konnoohmachi-1.0.0-cp310-cp310-macosx_10_7_x86_64.whl (202.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

konnoohmachi-1.0.0-cp39-none-win_amd64.whl (148.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

konnoohmachi-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

konnoohmachi-1.0.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (393.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

konnoohmachi-1.0.0-cp39-cp39-macosx_10_7_x86_64.whl (202.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

konnoohmachi-1.0.0-cp38-none-win_amd64.whl (148.8 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

konnoohmachi-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

konnoohmachi-1.0.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (393.1 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

konnoohmachi-1.0.0-cp38-cp38-macosx_10_7_x86_64.whl (202.3 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

konnoohmachi-1.0.0-cp37-none-win_amd64.whl (148.5 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

konnoohmachi-1.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.9 kB view hashes)

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

konnoohmachi-1.0.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (393.0 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

konnoohmachi-1.0.0-cp37-cp37m-macosx_10_7_x86_64.whl (202.3 kB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

Supported by

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