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.
For a point set $(x_j)_{1 \le j \le N} \subset [0, 1)^D$, the structure factor (or power spectrum) can be estimated with the scattering intensity:
S(k) \simeq \frac{1}{N} \left| \sum_{j=1}^{N} e^{-2i\pi \langle k, x_j \rangle} \right|^2,
\qquad k \in \mathbb{Z}^D \setminus \{0\}.
$S(k)$ measures density fluctuations in Fourier space. A pattern is hyperuniform (blue noise) when $S(k) \to 0$ as $|k| \to 0$, and hyperuniform of order $\alpha > 0$ when $S(k) \sim |k|^\alpha$.
Installation
pip install structure-factor-v2 # CPU: numpy + finufft
# pip install "structure-factor-v2[gpu12]" # GPU: [gpu12] or [gpu13], cupy + cufinufft
Quick start
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
# ===== Bragg peaks detection: =======
sf.certify_no_bragg(x)
# ===== Full vizualisation ===========
sf.plot(x) # scatter plot
sf.plot_structure_factor(x) # log-log S(k), raw values + radial average
Built-in samplers:
sf.config.compute.precision = "float32" # fast, recommanded default. Use float64 for
# precise plot if S(k) is very small, essentially
# in the stealthy case or for a pure korobov lattice
sf.plot_structure_factor(np.random.rand(N, D)) # Poisson: S = 1
sf.plot_structure_factor(sf.jittered_lattice(N, D)) # noisy crystal (hyperuniform yet free of Bragg peaks)
sf.plot_structure_factor(sf.curled_lattice(N, D)) # curl noise (iid jitter replaced by a divergence-free perturbation)
sf.config.compute.precision = "float64"
sf.plot_structure_factor(sf.korobov_lattice(N, D)) # pure crystal, stealthy (yet with bragg peaks)
Normalisation conventions
structure-factor-v2only accepts points in the unit cube $[0, 1)^D$. If the points live in another domain, first extract a cubic sub-window, rescale it to $[0, 1)^D$, and usetrust_boundary=False(see below) to compensate for the induced boundary effects.- To make S(k) plots comparable across $N$ and $D$, the k-axis shows $|k| / N^{1/D}$: an abscissa of 1 corresponds to a wavelength of the order of the mean interparticle distance $N^{-1/D}$.
Two estimators: trust_boundary
trust_boundary |
When |
|---|---|
True |
Default: the points compensate for boundary effects by themselves (e.g. they are periodic) |
False |
The points need a procedure to compensate for boundary effects (here, a Kaiser taper) |
"both" |
Compare the two estimators |
sf.plot_structure_factor(x, trust_boundary="both")
Settings: sf.config
To keep the API simple and easy to use, functions expose only the essential parameters as arguments. All other settings can be configured at the module level through sf.config, where they are organized by topic.
These include precision, computational backend, NUFFT tolerance, Kaiser parameters, Bragg threshold, plotting options, lattice parameters, and more. Settings defined in sf.config apply globally to all subsequent function calls.
# ======== config =====================
sf.config.compute.precision = "float64" # default "auto": float32 (much faster) iff the input points are float32
sf.config.compute.backend = "torch" # default "auto", see the table below
sf.config.taper.beta = 5 # Kaiser parameter, default None: automatic
sf.config.bragg.threshold = 50 # S >= threshold: Bragg peak (default 100)
#and so one...
# ======== reset =======================
sf.config.reset() # back to the defaults
Sections: compute, nufft, direct_sums, wave_vectors, taper, bragg, average,
plot, lattice, curl_noise (each setting is documented in structure_factor_v2/config.py).
Backends (sf.config.compute.backend), assuming their dependencies are installed:
backend |
method | dimensions |
|---|---|---|
"finufft" |
type-1 non-uniform FFT, CPU | D <= 6 1 |
"cufinufft" |
same, GPU | D <= 6 1 |
"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,
code: jonasmb/curlnoisejittering.
curled_latticestarts 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.
- structure-factor: the original package, of which this is a rewrite, For-a-few-DPPs-more/structure-factor.
Used by blue-sampler.
License
MIT
Metadata
Release files for structure-factor-v2 2.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| structure_factor_v2-2.2.1.tar.gz | 122.6 kB | Without provenance | Details for structure_factor_v2-2.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| structure_factor_v2-2.2.1-py3-none-any.whl | Python 3 | none | any | Details for structure_factor_v2-2.2.1-py3-none-any.whl |
Total release size: 152.7 kB
Release files / structure_factor_v2-2.2.1.tar.gz
| Download URL | structure_factor_v2-2.2.1.tar.gz |
|---|---|
| Size | 122.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
18575587dfa4d3d28529ef591ead36a7f651480ec21814c28f3adff5e6d0e953
|
|
BLAKE2b-256 checksum How to use checksums |
19acf1c8ef00929614f559da45eb2173b3540e68210f5a8cdbf7478840f4f402
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / structure_factor_v2-2.2.1-py3-none-any.whl
| Download URL | structure_factor_v2-2.2.1-py3-none-any.whl |
|---|---|
| Size | 30.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c044e75786a405da34b8ffb37e3350670e371181962dc88eeecd06f3f0899b63
|
|
BLAKE2b-256 checksum How to use checksums |
fdfd5f681eb7273568161382600b5149680f30d4445087dcf52cb4d05bfc386e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for structure-factor-v2 2.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.