Small C extensions for local image filters (fmedian, fsigma)
Project description
ftoolss
High-performance C extensions for image processing and curve fitting.
Features
| Export | Description |
|---|---|
fmedian |
Local median filter (2D/3D auto-dispatch) |
fmedian2d, fmedian3d |
Direct 2D/3D median |
fsigma |
Local sigma filter (2D/3D auto-dispatch) |
fsigma2d, fsigma3d |
Direct 2D/3D sigma |
fgaussian_f32, fgaussian_f64 |
Gaussian profile (Accelerate-optimized) |
fmpfit_pywrap |
Auto dtype dispatch (single spectrum) |
fmpfit_f64_pywrap, fmpfit_f32_pywrap |
Single spectrum fitting |
fmpfit_block_pywrap |
Auto dtype dispatch (block fitting) |
fmpfit_f64_block_pywrap, fmpfit_f32_block_pywrap |
Block fitting |
MPFitResult |
Named tuple for fit results |
Common features: NaN handling, edge handling, optional center exclusion (fmedian/fsigma).
Installation
pip install . # Standard install
pip install -e . # Editable (development)
python setup.py build_ext --inplace # Build extensions only
Repository hooks
This repository includes a pre-commit hook at hooks/pre-commit that will
automatically bump the semantic version in setup.py on each commit (default
behavior: bump the patch number). To enable the repository hooks for your
local clone run:
git config core.hooksPath hooks
chmod +x hooks/pre-commit
# Optionally: BUMP_LEVEL=minor git commit -m "..." # bump minor instead
Requirements: Python 3.8+, NumPy >=1.20, C compiler. macOS Accelerate used when available.
Quick Start
import numpy as np
from ftoolss import fmedian, fsigma, fgaussian_f32, fgaussian_f64
# 2D/3D median and sigma filters
data = np.random.randn(100, 200)
median = fmedian(data, (3, 3), exclude_center=1)
sigma = fsigma(data, (3, 3), exclude_center=1)
# 3D works the same way
data_3d = np.random.randn(50, 100, 50)
median_3d = fmedian(data_3d, (3, 3, 3))
# Gaussian profiles
x = np.linspace(-10, 10, 1000, dtype=np.float32)
profile = fgaussian_f32(x, i0=1.0, mu=0.0, sigma=1.5)
Curve Fitting (fmpfit)
Single-spectrum fitting with auto dtype dispatch:
from ftoolss.fmpfit import fmpfit_pywrap
import numpy as np
x = np.linspace(-5, 5, 100)
y = 2.5 * np.exp(-0.5 * ((x - 1.0) / 0.8)**2) + np.random.randn(100) * 0.1
result = fmpfit_pywrap(
deviate_type=0, # Gaussian model
parinfo=[
{'value': 1.0, 'limits': [0.0, 10.0]}, # amplitude
{'value': 0.0, 'limits': [-5.0, 5.0]}, # mean
{'value': 1.0, 'limits': [0.1, 5.0]} # sigma
],
functkw={'x': x, 'y': y, 'error': np.ones_like(y) * 0.1}
)
print(f"Best-fit: {result.best_params}, ?²={result.bestnorm:.2f}")
print(f"SciPy-style errors (full Hessian): {result.xerror_scipy}")
Block fitting (multiple spectra in one call, GIL-free):
from ftoolss.fmpfit import fmpfit_block_pywrap
import numpy as np
n_spectra, mpoints, npar = 100, 200, 3
x = np.tile(np.linspace(-5, 5, mpoints), (n_spectra, 1))
y = ... # shape (n_spectra, mpoints)
error = np.ones_like(y) * 0.1
p0 = np.tile([1.0, 0.0, 1.0], (n_spectra, 1))
bounds = np.array([[[0, 10], [-5, 5], [0.1, 5]]] * n_spectra)
results = fmpfit_block_pywrap(0, x, y, error, p0, bounds)
# results['best_params'] shape: (n_spectra, npar)
API Reference
fmedian / fsigma
fmedian(data, window_size, exclude_center=0)
fsigma(data, window_size, exclude_center=0)
window_size:(x, y)or(x, y, z)? odd positive integersexclude_center: 1 to exclude center from calculation (useful for outlier detection)- Returns: float64 array, same shape as input
fgaussian_f32 / fgaussian_f64
Computes: i0 * exp(-((x - mu)� / (2 * sigma�)))
fgaussian_f32(x, i0, mu, sigma) # float32, fastest
fgaussian_f64(x, i0, mu, sigma) # float64
fmpfit
Levenberg-Marquardt least-squares fitting. See src/ftoolss/fmpfit/README.md for details.
| Function | Description |
|---|---|
fmpfit_pywrap |
Auto dtype dispatch (single spectrum) |
fmpfit_f64_pywrap |
float64 single spectrum |
fmpfit_f32_pywrap |
float32 single spectrum |
fmpfit_block_pywrap |
Auto dtype dispatch (block of spectra) |
fmpfit_f64_block_pywrap |
float64 block fitting |
fmpfit_f32_block_pywrap |
float32 block fitting |
Examples
See examples/ directory for complete working examples.
Testing
pytest # Run all tests
pytest --cov=ftoolss --cov-report=html # With coverage
Performance
| Module | Speedup vs NumPy | Notes |
|---|---|---|
| fgaussian_f32 | 5-10× | Accelerate vvexpf |
| fgaussian_f64 | 2-3× | Accelerate vvexp |
| fmedian/fsigma | ? | Sorting networks for small windows |
| fmpfit | ? | GIL-free, 4× speedup with 6 threads |
License
MIT
Credits
- Sorting networks: Bert Dobbelaere
- MPFIT: Craig Markwardt (cmpfit, MINPACK-1 derivative)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ftoolss-6.1.4.tar.gz.
File metadata
- Download URL: ftoolss-6.1.4.tar.gz
- Upload date:
- Size: 139.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fad216b24d223e83ab0b7811582667bf7f1c4e9dc4ae6e6924a344e9ce7cccce
|
|
| MD5 |
8b163571d38d7d88e1fd6c6799947d99
|
|
| BLAKE2b-256 |
0ed3dda1e5739a54aeb1b47f3ea3749b65298948b17f0577164cb690297535ca
|
Provenance
The following attestation bundles were made for ftoolss-6.1.4.tar.gz:
Publisher:
release.yml on steinhh/ftools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ftoolss-6.1.4.tar.gz -
Subject digest:
fad216b24d223e83ab0b7811582667bf7f1c4e9dc4ae6e6924a344e9ce7cccce - Sigstore transparency entry: 1897420445
- Sigstore integration time:
-
Permalink:
steinhh/ftools@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Branch / Tag:
refs/tags/v6.1.4-prod1 - Owner: https://github.com/steinhh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ftoolss-6.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ftoolss-6.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 792.1 kB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4d52fb648bda8657f9e2502b9d17545745f6e6c072c6772e60867009ea4908f
|
|
| MD5 |
306bcfbff9542f0ca85df4851d359e25
|
|
| BLAKE2b-256 |
63f627d171efd3d47ea6ba7771f7248d886c52f45fac84d35924c9a0e13c2773
|
Provenance
The following attestation bundles were made for ftoolss-6.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on steinhh/ftools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ftoolss-6.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
d4d52fb648bda8657f9e2502b9d17545745f6e6c072c6772e60867009ea4908f - Sigstore transparency entry: 1897421086
- Sigstore integration time:
-
Permalink:
steinhh/ftools@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Branch / Tag:
refs/tags/v6.1.4-prod1 - Owner: https://github.com/steinhh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ftoolss-6.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ftoolss-6.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 791.4 kB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c62471f968974a94b08471bffc797da4de136b1a2cd104e0e0f574ea3cd4248
|
|
| MD5 |
ea7824ce3fdf6663a3fdad5574940889
|
|
| BLAKE2b-256 |
8d7781fe551eb8f40ac57b50f5dd44e8e4fd6b7627a2c99a6caf8ddb468de09f
|
Provenance
The following attestation bundles were made for ftoolss-6.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on steinhh/ftools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ftoolss-6.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
4c62471f968974a94b08471bffc797da4de136b1a2cd104e0e0f574ea3cd4248 - Sigstore transparency entry: 1897421327
- Sigstore integration time:
-
Permalink:
steinhh/ftools@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Branch / Tag:
refs/tags/v6.1.4-prod1 - Owner: https://github.com/steinhh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ftoolss-6.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ftoolss-6.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 784.0 kB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6efc6cc7b07d762069b053ba4f9c16748144915bed1fec9449f365398c64871
|
|
| MD5 |
5c637bf7628df7ca600142783f92b876
|
|
| BLAKE2b-256 |
c5e1f030b827dbe5f3762b4d6790be40080b2caffa1922373e8ddb0256aea7f2
|
Provenance
The following attestation bundles were made for ftoolss-6.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on steinhh/ftools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ftoolss-6.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
b6efc6cc7b07d762069b053ba4f9c16748144915bed1fec9449f365398c64871 - Sigstore transparency entry: 1897420815
- Sigstore integration time:
-
Permalink:
steinhh/ftools@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Branch / Tag:
refs/tags/v6.1.4-prod1 - Owner: https://github.com/steinhh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ftoolss-6.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ftoolss-6.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 777.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a675c40dba35f062651dfc821b549bcd00e30773cada727d83b901d94c67e6cd
|
|
| MD5 |
bf0ea50cff880c9bcd3b752e905ffc98
|
|
| BLAKE2b-256 |
cf8d5b8f0910e57c07747227ce86632115eb2dc980dc70974b1b895c39e43f60
|
Provenance
The following attestation bundles were made for ftoolss-6.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on steinhh/ftools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ftoolss-6.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
a675c40dba35f062651dfc821b549bcd00e30773cada727d83b901d94c67e6cd - Sigstore transparency entry: 1897421491
- Sigstore integration time:
-
Permalink:
steinhh/ftools@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Branch / Tag:
refs/tags/v6.1.4-prod1 - Owner: https://github.com/steinhh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fb2d4743d5569b2bc8b88b91d5aa6d7d89638c88 -
Trigger Event:
push
-
Statement type: