Skip to main content

structure-factor-v2

PyPI License: MIT GitHub

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) is

S(k) = \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)

example


Normalisation conventions

  • structure-factor-v2 only accepts points in the unit cube $[0, 1)^D$. If your points live in another domain, first extract a cubic sub-window, rescale it to $[0, 1)^D$, and use trust_boundary=False (see below) to compensate for the induced boundary effects.
  • To make plots comparable across $N$ and $D$, the x-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_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.
  • structure-factor: the original package, of which this is a rewrite, For-a-few-DPPs-more/structure-factor.

Used by blue-sampler.


License

MIT

  1. finufft and cufinufft natively support D <= 3, but D = 4, 5, 6 are handled with a slicing trick. ↩ ↩2

Metadata

Release files for structure-factor-v2 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for structure-factor-v2 2.2.0
File Size Uploaded Provenance Actions
structure_factor_v2-2.2.0.tar.gz 122.6 kB Without provenance Details for structure_factor_v2-2.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for structure-factor-v2 2.2.0
File Interpreter ABI Platform Actions
structure_factor_v2-2.2.0-py3-none-any.whl Python 3 none any Details for structure_factor_v2-2.2.0-py3-none-any.whl

Total release size: 152.7 kB

Release files / structure_factor_v2-2.2.0.tar.gz

Download URL structure_factor_v2-2.2.0.tar.gz
Size 122.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9f67fb07d5fb4830e82781b845cb1d6d2b8d5771ada5c964de7cba2bb816b1fa
BLAKE2b-256 checksum
How to use checksums
3dcb72a5eab88262e5307b6e6a949fba5f9b0ee8d15e30b1030b6de0e4c86486
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.0-py3-none-any.whl

Download URL structure_factor_v2-2.2.0-py3-none-any.whl
Size 30.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5f2c121d54ae7077943c7d4fca96b07c133f6846aaf97e1dba720d8443cf247
BLAKE2b-256 checksum
How to use checksums
0f7ec565162472db02262e7bbef794abebeb6e0bef7bbb14c99bbf37c3918c3f
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.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page