Metadata-Version: 2.5
Name: structure-factor-v2
Version: 2.1.0
Summary: Structure factor S(k) of point sets in the unit cube: scattering intensity, Kaiser taper, NUFFT, plots
Project-URL: Repository, https://github.com/adecacqueray/structure-factor-v2
Project-URL: Issues, https://github.com/adecacqueray/structure-factor-v2/issues
License: MIT
License-File: LICENSE
Keywords: Kaiser taper,NUFFT,finufft,hyperuniformity,point process,power spectrum,scattering intensity,structure factor
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
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: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.9
Requires-Dist: finufft
Requires-Dist: matplotlib
Requires-Dist: numpy
Provides-Extra: gpu12
Requires-Dist: cufinufft; extra == 'gpu12'
Requires-Dist: cupy-cuda12x; extra == 'gpu12'
Provides-Extra: gpu13
Requires-Dist: cufinufft; extra == 'gpu13'
Requires-Dist: cupy-cuda13x; extra == 'gpu13'
Provides-Extra: keops
Requires-Dist: pykeops; extra == 'keops'
Provides-Extra: torch
Requires-Dist: torch; extra == 'torch'
Description-Content-Type: text/markdown

# structure-factor-v2

[![PyPI](https://img.shields.io/pypi/v/structure-factor-v2.svg)](https://pypi.org/project/structure-factor-v2/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/adecacqueray/structure-factor-v2/blob/main/LICENSE)
[![GitHub](https://img.shields.io/badge/GitHub-adecacqueray%2Fstructure--factor--v2-181717?logo=github)](https://github.com/adecacqueray/structure-factor-v2)

**Structure factor $S(k)$ of point sets in the unit cube $[0, 1)^D$**, estimated by the
scattering intensity, with fast transforms (finufft / cufinufft) and ready-made log-log plots.

The structure factor measures the density fluctuations of a point set in Fourier space
(it is the power spectrum, up to normalisation). For a hyperuniform (blue-noise) pattern,
$S(k) \to 0$ as $k \to 0$; for an order $\alpha$ hyperuniform pattern $S(k) \sim k^\alpha$.

---

## Installation

```bash
pip install structure-factor-v2              # CPU: numpy + finufft
#pip install structure-factor-v2[gpu12]      # GPU: [gpu12] or [gpu13], cupy + cufinufft
```

---

## Quick start

```python
import structure_factor_v2 as sf
import numpy as np

N, D = 10_000, 2
x = sf.jittered_lattice(N, D)           # (N, D) points in [0, 1)^D, hyperuniform

sf.plot(x)                                   # scatter plot
sf.plot_structure_factor(x)                  # log-log S(k), raw values + radial average
```

Built-in samplers:

```python
sf.plot_structure_factor(np.random.rand(N, D))          # Poisson: S = 1
sf.plot_structure_factor(sf.korobov_lattice(N, D))      # crystal
sf.plot_structure_factor(sf.jittered_lattice(N, D))     # noisy cristal (hyperuniform, but free of bragg peaks)
sf.plot_structure_factor(sf.curled_lattice(N, D))       # curl noise (replace iid jitter with divergence free perturbation)
```

![example](example.png)

---

## Two estimators: `trust_boundary`

| `trust_boundary` | When                                                        | 
|------------------|-------------------------------------------------------------|
| `True` (default) | the points self compensate for any boundary effects (eg they are periodic) |
| `False`          | the points need a procedure to compensate for boundary effect (here tapering, with a kaiser taper)| 
| `"both"`         | (plots only) compare the two                                | 

```python
sf.plot_structure_factor(x, trust_boundary="both")              
```

---

## Backends, precision and tolerance

Structure factor computation takes `backend`, `precision` and `nufft_tolerance`, assumming 
that the backend's dependency are properly installed :

| `backend`     | method                                   | dimensions |
|---------------|------------------------------------------|------------|
| `"finufft"`   | type-1 non-uniform FFT, CPU              | D <= 6     | 
| `"cufinufft"` | same, GPU                                | D <= 6     | 
| `"keops"`     | direct sums, pykeops (GPU if available)  | any        | 
| `"torch"`     | direct sums, torch (cuda if available)   | any        | 
| `"numpy"`     | direct sums, numpy                       | any        | 
| `"cupy"`      | direct sums, cupy                        | any        |


---

## References

- **Korobov lattices**: I. H. Sloan and S. Joe. *Lattice Methods for Multiple Integration.*
  Oxford University Press, 1994.
- **Curl noise jittering**: J. A. Bærentzen, J. R. Frisvad, and J. Martínez. *Curl Noise
  Jittering.* SIGGRAPH Asia 2023 Conference Papers, article 88, 2023.
  [doi:10.1145/3610548.3618163](https://doi.org/10.1145/3610548.3618163),
  code: [jonasmb/curlnoisejittering](https://github.com/jonasmb/curlnoisejittering).
  `curled_lattice` starts from a Korobov lattice instead of their triangular / cubic grids,
  and uses a random Fourier divergence-free field (exactly periodic, any dimension) instead
  of the curl of a Perlin noise; independent implementation.
- **finufft / cufinufft**: A. H. Barnett, J. F. Magland, and L. af Klinteberg.
  *A parallel non-uniform fast Fourier transform library based on an "exponential of
  semicircle" kernel.* SIAM J. Sci. Comput. 41(5), C479–C504, 2019.
  See [finufft](https://github.com/flatironinstitute/finufft).
- **structure-factor**: the original package of the same group,
  [For-a-few-DPPs-more/structure-factor](https://github.com/For-a-few-DPPs-more/structure-factor).

Used by [blue-sampler](https://pypi.org/project/blue-sampler/).

---

## License

MIT


[def]: example.png