Skip to main content

Spectral smoothing in Rust/Python

Project description

PyPI PyPI

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 spectra (see Benchmarks).

Dependencies

You need the rust compiler installed:

Rust

Installation

Installation from pypi:

pip install konnoohmachi

Installation from source:

pip install .

Usage

This smoothes some random numbers:

import konnoohmachi

b = 10
n = 1000
freqs = np.arange(n)
amplitudes = np.random.rand(n)
smoothed = konnoohmachi.smooth(freqs, amplitudes, b)
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 Distribution

konnoohmachi-0.2.0.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distributions

konnoohmachi-0.2.0-cp310-none-win_amd64.whl (148.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

konnoohmachi-0.2.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-0.2.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (393.1 kB view hashes)

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

konnoohmachi-0.2.0-cp310-cp310-macosx_10_7_x86_64.whl (202.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

konnoohmachi-0.2.0-cp39-none-win_amd64.whl (148.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

konnoohmachi-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

konnoohmachi-0.2.0-cp39-cp39-macosx_11_0_arm64.whl (189.4 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

konnoohmachi-0.2.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (393.2 kB view hashes)

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

konnoohmachi-0.2.0-cp39-cp39-macosx_10_7_x86_64.whl (201.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

konnoohmachi-0.2.0-cp38-none-win_amd64.whl (150.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

konnoohmachi-0.2.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-0.2.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (393.2 kB view hashes)

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

konnoohmachi-0.2.0-cp38-cp38-macosx_10_7_x86_64.whl (202.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

konnoohmachi-0.2.0-cp37-none-win_amd64.whl (150.6 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

konnoohmachi-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.8 kB view hashes)

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

konnoohmachi-0.2.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (393.1 kB view hashes)

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

konnoohmachi-0.2.0-cp37-cp37m-macosx_10_7_x86_64.whl (202.2 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