Metadata-Version: 2.4
Name: enufft
Version: 2.0.0
Summary: Non-uniform FFT of scattered samples on analysis windows, with Kaiser-Bessel, exponential-of-semicircle, Gaussian and B-spline kernels, and elastic mode selection.
Author: Tridib Banerjee
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/TridibBanerjee/Elastic-Non-Uniform-FFT
Project-URL: Source, https://github.com/TridibBanerjee/Elastic-Non-Uniform-FFT
Project-URL: Issues, https://github.com/TridibBanerjee/Elastic-Non-Uniform-FFT/issues
Project-URL: DOI, https://doi.org/10.5281/zenodo.20544458
Keywords: nufft,fourier,terrain,orography,spectral-analysis
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10
Provides-Extra: test
Requires-Dist: pytest>=8.0; extra == "test"
Dynamic: license-file

# ENUFFT

[![PyPI](https://img.shields.io/pypi/v/enufft.svg)](https://pypi.org/project/enufft/)
[![Python](https://img.shields.io/pypi/pyversions/enufft.svg)](https://pypi.org/project/enufft/)
[![License](https://img.shields.io/badge/License-Apache--2.0-red.svg)](https://github.com/TridibBanerjee/Elastic-Non-Uniform-FFT/blob/main/package/LICENSE)
[![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.20544458-blue.svg)](https://doi.org/10.5281/zenodo.20544458)

**ENUFFT** computes local Fourier spectra of scattered two-dimensional samples,
such as irregular terrain inside a mesh cell, and compresses them with Elastic
Mode Selection (EMS). It has three parts.

- A type-1 non-uniform FFT on a periodic rectangle, with the Kaiser-Bessel,
  exponential-of-semicircle, Gaussian and B-spline kernels.
- Square analysis windows around a cell, with a square, cell-shaped or circular
  support and clipped Voronoi quadrature weights.
- EMS, which keeps an adaptive number of conjugate mode pairs.

The research code, derivations and test cases are in
[TridibBanerjee/Elastic-Non-Uniform-FFT](https://github.com/TridibBanerjee/Elastic-Non-Uniform-FFT).

## Install

```bash
pip install enufft
```

ENUFFT needs Python 3.10 or newer, NumPy and SciPy.

## Quick start

```python
import numpy as np
import enufft

rng = np.random.default_rng(0)
points = rng.uniform(0.0, 100.0, size=(5000, 2))                       # sample positions (km)
heights = 500.0 * np.cos(2 * np.pi * (points[:, 0] + 2 * points[:, 1]) / 60.0)
cell = np.array([[20.0, 25.0], [80.0, 30.0], [45.0, 75.0]])             # one mesh cell

window = enufft.Window.around(cell, alignment="edge", support="polygon", expansion=1.5)
inside = window.contains(points)
x, y = window.local(points[inside])
weights = enufft.voronoi_weights(x, y, window)

h_hat = enufft.nufft(x, y, heights[inside], 8, 8, window.L, window.L, kernel="kb", sigma=1.5, w=8, weights=weights)
sparse, pairs, result = enufft.select_modes(h_hat, k_max=8)
print(result.k_star, pairs)
```

`h_hat[m + M, n + N]` is the coefficient of the mode `(m, n)`, with the wave
vector `2 pi (m, n) / L` in the rotated window frame.

## Kernels

| Family | Name | Shape | Default parameter |
|---|---|---|---|
| Kaiser-Bessel | `"kb"` | `I0(gamma sqrt(1 - t^2))` | `gamma` of Beatty et al. (2005); `"potts"`, `"fessler"` or a number |
| Exponential of semicircle | `"es"` | `exp(beta [sqrt(1 - t^2) - 1])` | `beta = pi w (1 - 1 / 2 sigma)` |
| Gaussian | `"gauss"` | `exp(-u^2 / 2 s^2)`, cut at the half-width | `s^2 = (w / 2) / (pi (2 - 1 / sigma))` |
| B-spline | `"bspline"` | cardinal B-spline of order `w` | none |

`w` is the kernel width and `sigma` the oversampling factor of the auxiliary
grid. The Kaiser-Bessel kernel is the most accurate for a given width.

See [docs/API.md](docs/API.md) for every function.

## Citation

Please cite the Zenodo record
[10.5281/zenodo.20544458](https://doi.org/10.5281/zenodo.20544458).

## License

Apache-2.0.
