structure-factor-v2 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.so
5
+
6
+ # Build / packaging
7
+ build/
8
+ dist/
9
+ *.egg-info/
10
+ .eggs/
11
+ wheels/
12
+
13
+ # Virtual environments
14
+ .venv/
15
+ venv/
16
+ env/
17
+
18
+ # Tools caches
19
+ .pytest_cache/
20
+ .ruff_cache/
21
+ .mypy_cache/
22
+ .coverage
23
+ htmlcov/
24
+
25
+ # Jupyter
26
+ .ipynb_checkpoints/
27
+
28
+ # KeOps / CUDA build caches
29
+ .cache/
30
+ keops_build*/
31
+
32
+ # Editors / OS
33
+ .vscode/
34
+ .idea/
35
+ .DS_Store
36
+ Thumbs.db
37
+ desktop.ini
38
+
39
+ # Local outputs (figures, data)
40
+ *.png
41
+ *.jpg
42
+ *.npy
43
+ *.npz
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 adecacqueray
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,206 @@
1
+ Metadata-Version: 2.5
2
+ Name: structure-factor-v2
3
+ Version: 2.0.0
4
+ Summary: Structure factor S(k) of point sets in the unit cube: scattering intensity, Kaiser taper, NUFFT, plots
5
+ Project-URL: Repository, https://github.com/adecacqueray/structure-factor-v2
6
+ Project-URL: Issues, https://github.com/adecacqueray/structure-factor-v2/issues
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Keywords: Kaiser taper,NUFFT,finufft,hyperuniformity,point process,power spectrum,scattering intensity,structure factor
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
19
+ Classifier: Topic :: Scientific/Engineering :: Physics
20
+ Requires-Python: >=3.9
21
+ Requires-Dist: finufft
22
+ Requires-Dist: matplotlib
23
+ Requires-Dist: numpy
24
+ Provides-Extra: gpu12
25
+ Requires-Dist: cufinufft; extra == 'gpu12'
26
+ Requires-Dist: cupy-cuda12x; extra == 'gpu12'
27
+ Provides-Extra: gpu13
28
+ Requires-Dist: cufinufft; extra == 'gpu13'
29
+ Requires-Dist: cupy-cuda13x; extra == 'gpu13'
30
+ Provides-Extra: keops
31
+ Requires-Dist: pykeops; extra == 'keops'
32
+ Provides-Extra: torch
33
+ Requires-Dist: torch; extra == 'torch'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # structure-factor-v2
37
+
38
+ [![PyPI](https://img.shields.io/pypi/v/structure-factor-v2.svg)](https://pypi.org/project/structure-factor-v2/)
39
+ [![Python](https://img.shields.io/pypi/pyversions/structure-factor-v2.svg)](https://pypi.org/project/structure-factor-v2/)
40
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/adecacqueray/structure-factor-v2/blob/main/LICENSE)
41
+ [![GitHub](https://img.shields.io/badge/GitHub-adecacqueray%2Fstructure--factor--v2-181717?logo=github)](https://github.com/adecacqueray/structure-factor-v2)
42
+
43
+ **Structure factor $S(k)$ of point sets in the unit cube $[0, 1)^D$**, estimated by the
44
+ scattering intensity, with fast transforms (finufft / cufinufft) and ready-made log-log plots.
45
+
46
+ The structure factor measures the density fluctuations of a point set in Fourier space
47
+ (it is the power spectrum, up to normalisation). For a hyperuniform (blue-noise) pattern,
48
+ $S(k) \to 0$ as $k \to 0$; for an order-$\alpha$ hyperuniform pattern $S(k) \sim k^\alpha$.
49
+
50
+ ---
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install structure-factor-v2 # CPU: numpy + finufft
56
+ #pip install structure-factor-v2[gpu12] # GPU: [gpu12] or [gpu13], cupy + cufinufft
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Quick start
62
+
63
+ ```python
64
+ import structure_factor_v2 as sf
65
+
66
+ x = sf.jittered_lattice(10_000, 2) # (N, D) points in [0, 1)^D, hyperuniform
67
+
68
+ sf.plot(x) # scatter plot
69
+ sf.plot_structure_factor(x) # log-log S(k), raw values + radial average
70
+
71
+ kint, S = sf.structure_factor(x) # raw estimate: integer wave vectors (M, D), S (M,)
72
+ k, S, kgroup, Sgroup = sf.structure_factor_and_average(x) # normalised k, raw + smoothed
73
+ ```
74
+
75
+ A jittered lattice (a Korobov lattice, randomly shifted, every point moved uniformly within its
76
+ cell) is a cheap hyperuniform pattern: $S(k) \sim k^2$ at small $k$. Compare with i.i.d. points
77
+ ($S \equiv 1$) and with the bare lattice (a crystal: $S = 0$ except on its Bragg peaks):
78
+
79
+ ```python
80
+ import numpy as np
81
+ sf.plot_structure_factor(np.random.rand(10_000, 2)) # Poisson: S = 1
82
+ sf.plot_structure_factor(sf.korobov_lattice(10_000, 2)) # crystal
83
+ ```
84
+
85
+ A curled lattice goes further: the Korobov lattice is moved along a random periodic
86
+ divergence-free flow (curl noise jittering, Bærentzen, Frisvad & Martínez, SIGGRAPH Asia
87
+ 2023). The flow preserves volume, so the points stay well separated, and the Bragg peaks are
88
+ smeared out: a blue noise point set, with a much lower $S(k)$ at small $k$ than the jittered
89
+ lattice. Any dimension (tuned in 2D and 3D), about 3 s for $10^5$ points.
90
+
91
+ ```python
92
+ x = sf.curled_lattice(10_000, 2) # noise_scale=5.0, dt=1.2
93
+ sf.plot_structure_factor(x)
94
+ ```
95
+
96
+ Wave numbers returned by `structure_factor_and_average` (and shown by
97
+ `plot_structure_factor`) are normalised so that $k = 1$ is the inter-particle wave
98
+ number $N^{1/D}$.
99
+
100
+ ---
101
+
102
+ ## Two estimators: `trust_boundary`
103
+
104
+ | `trust_boundary` | When | Estimator |
105
+ |------------------|-------------------------------------------------------------|-----------|
106
+ | `True` (default) | the points are periodic on the unit torus | $S(n) = \lvert\sum_j e^{2i\pi n \cdot x_j}\rvert^2 / N$ on the integer wave vectors $n$ |
107
+ | `False` | the points are a window cut out of a larger, non-periodic pattern | points restricted to $[m, 1-m)^D$, separable Kaiser–Bessel taper, debiased with the density |
108
+ | `"both"` | (plots only) compare the two | |
109
+
110
+ ```python
111
+ sf.plot_structure_factor(x, trust_boundary=False) # margin m = 0.1, beta automatic
112
+ sf.plot_structure_factor(x, trust_boundary=False, margin=0.05, beta=10)
113
+ sf.plot_structure_factor(x, trust_boundary="both")
114
+ ```
115
+
116
+ With the taper, leakage decays like $e^{-2\beta}$ while the resolution at small $k$
117
+ coarsens (about $\beta/\pi$ modes). `beta=None` picks
118
+ $\beta = \min(15, \pi\, n_{\text{axis}} / 4)$, see `sf.auto_beta`; nothing is plotted
119
+ below the resolution limit `sf.tapered_kmin(N, D, margin, beta)`.
120
+
121
+ ---
122
+
123
+ ## Backends, precision and tolerance
124
+
125
+ Every function takes `backend`, `precision` and `nufft_tolerance`:
126
+
127
+ | `backend` | method | dimensions | accuracy |
128
+ |---------------|------------------------------------------|------------|----------|
129
+ | `"finufft"` | type-1 non-uniform FFT, CPU | D <= 3 | `nufft_tolerance` |
130
+ | `"cufinufft"` | type-1 non-uniform FFT, GPU (+ cupy) | D <= 3 | `nufft_tolerance` |
131
+ | `"keops"` | direct sums, pykeops (GPU if available) | any | exact |
132
+ | `"torch"` | direct sums, torch (cuda if available) | any | exact |
133
+ | `"numpy"` | direct sums, numpy, chunked | any | exact |
134
+ | `"cupy"` | direct sums, cupy, chunked | any | exact |
135
+
136
+ `"auto"` (default): (cu)finufft for D <= 3 (cufinufft when it works), direct sums with cupy or
137
+ numpy above; `device="cpu"` keeps "auto" off the GPU. `keops` and `torch` are optional
138
+ installs, only used when asked for (KeOps counts as working only if it compiles a test
139
+ reduction).
140
+
141
+ | Dimension | Wave vectors |
142
+ |-----------|--------------|
143
+ | $D \le 3$ | every integer mode of the cube up to $2 N^{1/D}$ |
144
+ | $D \ge 4$ | all low modes + isotropically sampled high modes (`resolution`) |
145
+
146
+ ```python
147
+ sf.plot_structure_factor(x, backend="keops") # exact sums
148
+ sf.plot_structure_factor(x, precision="float64", nufft_tolerance=1e-14)
149
+ sf.available_backends(D=2) # what works here
150
+ sf.check_gpu()
151
+ ```
152
+
153
+ `nufft_tolerance="auto"` means 1e-5 in float32 and 1e-12 in float64; float32 sets a floor on
154
+ the smallest resolvable S (float64 for S below ~1e-6 at large N).
155
+
156
+ Tunable constants (margin, $k_{\max}$, radial bins, smoothing...) are in `sf.CONFIG`, editable in place:
157
+
158
+ ```python
159
+ sf.CONFIG.k_max = 3.0 # wave numbers up to 3 N^(1/D)
160
+ ```
161
+
162
+ ---
163
+
164
+ ## API
165
+
166
+ | Function | Returns |
167
+ |----------|---------|
168
+ | `structure_factor(points, resolution=2000, device="auto", precision="float32", trust_boundary=True, margin=None, beta=None, backend="auto", nufft_tolerance="auto")` | `kint (M, D)`, `S (M,)`, sorted by $\lvert n\rvert$ |
169
+ | `structure_factor_and_average(points, resolution=20000, min_val=1e-20, precision="float32", trust_boundary=True, margin=None, beta=None, backend="auto", nufft_tolerance="auto", device="auto")` | `kraw, Sraw, kgroup, Sgroup` |
170
+ | `plot_structure_factor(points, resolution=20000, precision="float32", ax=None, return_fig=False, title=None, trust_boundary=True, margin=None, beta=None, backend="auto", nufft_tolerance="auto", device="auto", **plot_kw)` | `None`, or `(fig, ax)` |
171
+ | `plot(points, auto_zoom=False, max_points=30000, ax=None, return_fig=False, figsize=(8, 8), **scatter_kw)` | `None`, or `(fig, ax)` |
172
+ | `jittered_lattice(N, D, seed=None, max_candidates=100)`, `korobov_lattice(N, D, shift=True, seed=None, max_candidates=100)` | `(N, D)` test point sets |
173
+ | `curled_lattice(N, D, noise_scale=5.0, dt=1.2, n_modes=256, bandwidth=0.3, n_steps=1, seed=None, max_candidates=100)` | `(N, D)` blue noise point set |
174
+ | `auto_beta(n_points, D, margin)`, `tapered_kmin(n_points, D, margin=None, beta=None)` | Kaiser parameter, smallest trustworthy $k$ |
175
+ | `check_gpu()`, `available_backends(D=None)`, `BACKENDS` | diagnostic, backends that work here |
176
+
177
+ Points must lie in $[0, 1)^D$; this is not checked.
178
+
179
+ ---
180
+
181
+ ## References
182
+
183
+ - **Korobov lattices**: I. H. Sloan and S. Joe. *Lattice Methods for Multiple Integration.*
184
+ Oxford University Press, 1994.
185
+ - **Curl noise jittering**: J. A. Bærentzen, J. R. Frisvad, and J. Martínez. *Curl Noise
186
+ Jittering.* SIGGRAPH Asia 2023 Conference Papers, article 88, 2023.
187
+ [doi:10.1145/3610548.3618163](https://doi.org/10.1145/3610548.3618163),
188
+ code: [jonasmb/curlnoisejittering](https://github.com/jonasmb/curlnoisejittering).
189
+ `curled_lattice` starts from a Korobov lattice instead of their triangular / cubic grids,
190
+ and uses a random Fourier divergence-free field (exactly periodic, any dimension) instead
191
+ of the curl of a Perlin noise; independent implementation.
192
+ - **finufft / cufinufft**: A. H. Barnett, J. F. Magland, and L. af Klinteberg.
193
+ *A parallel non-uniform fast Fourier transform library based on an "exponential of
194
+ semicircle" kernel.* SIAM J. Sci. Comput. 41(5), C479–C504, 2019.
195
+ See [finufft](https://github.com/flatironinstitute/finufft).
196
+ - **structure-factor**: the original package of the same group,
197
+ [For-a-few-DPPs-more/structure-factor](https://github.com/For-a-few-DPPs-more/structure-factor).
198
+
199
+ Used by [blue-sampler](https://pypi.org/project/blue-sampler/), which re-exports
200
+ `plot`, `plot_structure_factor`, `structure_factor` and `structure_factor_and_average`.
201
+
202
+ ---
203
+
204
+ ## License
205
+
206
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,171 @@
1
+ # structure-factor-v2
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/structure-factor-v2.svg)](https://pypi.org/project/structure-factor-v2/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/structure-factor-v2.svg)](https://pypi.org/project/structure-factor-v2/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/adecacqueray/structure-factor-v2/blob/main/LICENSE)
6
+ [![GitHub](https://img.shields.io/badge/GitHub-adecacqueray%2Fstructure--factor--v2-181717?logo=github)](https://github.com/adecacqueray/structure-factor-v2)
7
+
8
+ **Structure factor $S(k)$ of point sets in the unit cube $[0, 1)^D$**, estimated by the
9
+ scattering intensity, with fast transforms (finufft / cufinufft) and ready-made log-log plots.
10
+
11
+ The structure factor measures the density fluctuations of a point set in Fourier space
12
+ (it is the power spectrum, up to normalisation). For a hyperuniform (blue-noise) pattern,
13
+ $S(k) \to 0$ as $k \to 0$; for an order-$\alpha$ hyperuniform pattern $S(k) \sim k^\alpha$.
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install structure-factor-v2 # CPU: numpy + finufft
21
+ #pip install structure-factor-v2[gpu12] # GPU: [gpu12] or [gpu13], cupy + cufinufft
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Quick start
27
+
28
+ ```python
29
+ import structure_factor_v2 as sf
30
+
31
+ x = sf.jittered_lattice(10_000, 2) # (N, D) points in [0, 1)^D, hyperuniform
32
+
33
+ sf.plot(x) # scatter plot
34
+ sf.plot_structure_factor(x) # log-log S(k), raw values + radial average
35
+
36
+ kint, S = sf.structure_factor(x) # raw estimate: integer wave vectors (M, D), S (M,)
37
+ k, S, kgroup, Sgroup = sf.structure_factor_and_average(x) # normalised k, raw + smoothed
38
+ ```
39
+
40
+ A jittered lattice (a Korobov lattice, randomly shifted, every point moved uniformly within its
41
+ cell) is a cheap hyperuniform pattern: $S(k) \sim k^2$ at small $k$. Compare with i.i.d. points
42
+ ($S \equiv 1$) and with the bare lattice (a crystal: $S = 0$ except on its Bragg peaks):
43
+
44
+ ```python
45
+ import numpy as np
46
+ sf.plot_structure_factor(np.random.rand(10_000, 2)) # Poisson: S = 1
47
+ sf.plot_structure_factor(sf.korobov_lattice(10_000, 2)) # crystal
48
+ ```
49
+
50
+ A curled lattice goes further: the Korobov lattice is moved along a random periodic
51
+ divergence-free flow (curl noise jittering, Bærentzen, Frisvad & Martínez, SIGGRAPH Asia
52
+ 2023). The flow preserves volume, so the points stay well separated, and the Bragg peaks are
53
+ smeared out: a blue noise point set, with a much lower $S(k)$ at small $k$ than the jittered
54
+ lattice. Any dimension (tuned in 2D and 3D), about 3 s for $10^5$ points.
55
+
56
+ ```python
57
+ x = sf.curled_lattice(10_000, 2) # noise_scale=5.0, dt=1.2
58
+ sf.plot_structure_factor(x)
59
+ ```
60
+
61
+ Wave numbers returned by `structure_factor_and_average` (and shown by
62
+ `plot_structure_factor`) are normalised so that $k = 1$ is the inter-particle wave
63
+ number $N^{1/D}$.
64
+
65
+ ---
66
+
67
+ ## Two estimators: `trust_boundary`
68
+
69
+ | `trust_boundary` | When | Estimator |
70
+ |------------------|-------------------------------------------------------------|-----------|
71
+ | `True` (default) | the points are periodic on the unit torus | $S(n) = \lvert\sum_j e^{2i\pi n \cdot x_j}\rvert^2 / N$ on the integer wave vectors $n$ |
72
+ | `False` | the points are a window cut out of a larger, non-periodic pattern | points restricted to $[m, 1-m)^D$, separable Kaiser–Bessel taper, debiased with the density |
73
+ | `"both"` | (plots only) compare the two | |
74
+
75
+ ```python
76
+ sf.plot_structure_factor(x, trust_boundary=False) # margin m = 0.1, beta automatic
77
+ sf.plot_structure_factor(x, trust_boundary=False, margin=0.05, beta=10)
78
+ sf.plot_structure_factor(x, trust_boundary="both")
79
+ ```
80
+
81
+ With the taper, leakage decays like $e^{-2\beta}$ while the resolution at small $k$
82
+ coarsens (about $\beta/\pi$ modes). `beta=None` picks
83
+ $\beta = \min(15, \pi\, n_{\text{axis}} / 4)$, see `sf.auto_beta`; nothing is plotted
84
+ below the resolution limit `sf.tapered_kmin(N, D, margin, beta)`.
85
+
86
+ ---
87
+
88
+ ## Backends, precision and tolerance
89
+
90
+ Every function takes `backend`, `precision` and `nufft_tolerance`:
91
+
92
+ | `backend` | method | dimensions | accuracy |
93
+ |---------------|------------------------------------------|------------|----------|
94
+ | `"finufft"` | type-1 non-uniform FFT, CPU | D <= 3 | `nufft_tolerance` |
95
+ | `"cufinufft"` | type-1 non-uniform FFT, GPU (+ cupy) | D <= 3 | `nufft_tolerance` |
96
+ | `"keops"` | direct sums, pykeops (GPU if available) | any | exact |
97
+ | `"torch"` | direct sums, torch (cuda if available) | any | exact |
98
+ | `"numpy"` | direct sums, numpy, chunked | any | exact |
99
+ | `"cupy"` | direct sums, cupy, chunked | any | exact |
100
+
101
+ `"auto"` (default): (cu)finufft for D <= 3 (cufinufft when it works), direct sums with cupy or
102
+ numpy above; `device="cpu"` keeps "auto" off the GPU. `keops` and `torch` are optional
103
+ installs, only used when asked for (KeOps counts as working only if it compiles a test
104
+ reduction).
105
+
106
+ | Dimension | Wave vectors |
107
+ |-----------|--------------|
108
+ | $D \le 3$ | every integer mode of the cube up to $2 N^{1/D}$ |
109
+ | $D \ge 4$ | all low modes + isotropically sampled high modes (`resolution`) |
110
+
111
+ ```python
112
+ sf.plot_structure_factor(x, backend="keops") # exact sums
113
+ sf.plot_structure_factor(x, precision="float64", nufft_tolerance=1e-14)
114
+ sf.available_backends(D=2) # what works here
115
+ sf.check_gpu()
116
+ ```
117
+
118
+ `nufft_tolerance="auto"` means 1e-5 in float32 and 1e-12 in float64; float32 sets a floor on
119
+ the smallest resolvable S (float64 for S below ~1e-6 at large N).
120
+
121
+ Tunable constants (margin, $k_{\max}$, radial bins, smoothing...) are in `sf.CONFIG`, editable in place:
122
+
123
+ ```python
124
+ sf.CONFIG.k_max = 3.0 # wave numbers up to 3 N^(1/D)
125
+ ```
126
+
127
+ ---
128
+
129
+ ## API
130
+
131
+ | Function | Returns |
132
+ |----------|---------|
133
+ | `structure_factor(points, resolution=2000, device="auto", precision="float32", trust_boundary=True, margin=None, beta=None, backend="auto", nufft_tolerance="auto")` | `kint (M, D)`, `S (M,)`, sorted by $\lvert n\rvert$ |
134
+ | `structure_factor_and_average(points, resolution=20000, min_val=1e-20, precision="float32", trust_boundary=True, margin=None, beta=None, backend="auto", nufft_tolerance="auto", device="auto")` | `kraw, Sraw, kgroup, Sgroup` |
135
+ | `plot_structure_factor(points, resolution=20000, precision="float32", ax=None, return_fig=False, title=None, trust_boundary=True, margin=None, beta=None, backend="auto", nufft_tolerance="auto", device="auto", **plot_kw)` | `None`, or `(fig, ax)` |
136
+ | `plot(points, auto_zoom=False, max_points=30000, ax=None, return_fig=False, figsize=(8, 8), **scatter_kw)` | `None`, or `(fig, ax)` |
137
+ | `jittered_lattice(N, D, seed=None, max_candidates=100)`, `korobov_lattice(N, D, shift=True, seed=None, max_candidates=100)` | `(N, D)` test point sets |
138
+ | `curled_lattice(N, D, noise_scale=5.0, dt=1.2, n_modes=256, bandwidth=0.3, n_steps=1, seed=None, max_candidates=100)` | `(N, D)` blue noise point set |
139
+ | `auto_beta(n_points, D, margin)`, `tapered_kmin(n_points, D, margin=None, beta=None)` | Kaiser parameter, smallest trustworthy $k$ |
140
+ | `check_gpu()`, `available_backends(D=None)`, `BACKENDS` | diagnostic, backends that work here |
141
+
142
+ Points must lie in $[0, 1)^D$; this is not checked.
143
+
144
+ ---
145
+
146
+ ## References
147
+
148
+ - **Korobov lattices**: I. H. Sloan and S. Joe. *Lattice Methods for Multiple Integration.*
149
+ Oxford University Press, 1994.
150
+ - **Curl noise jittering**: J. A. Bærentzen, J. R. Frisvad, and J. Martínez. *Curl Noise
151
+ Jittering.* SIGGRAPH Asia 2023 Conference Papers, article 88, 2023.
152
+ [doi:10.1145/3610548.3618163](https://doi.org/10.1145/3610548.3618163),
153
+ code: [jonasmb/curlnoisejittering](https://github.com/jonasmb/curlnoisejittering).
154
+ `curled_lattice` starts from a Korobov lattice instead of their triangular / cubic grids,
155
+ and uses a random Fourier divergence-free field (exactly periodic, any dimension) instead
156
+ of the curl of a Perlin noise; independent implementation.
157
+ - **finufft / cufinufft**: A. H. Barnett, J. F. Magland, and L. af Klinteberg.
158
+ *A parallel non-uniform fast Fourier transform library based on an "exponential of
159
+ semicircle" kernel.* SIAM J. Sci. Comput. 41(5), C479–C504, 2019.
160
+ See [finufft](https://github.com/flatironinstitute/finufft).
161
+ - **structure-factor**: the original package of the same group,
162
+ [For-a-few-DPPs-more/structure-factor](https://github.com/For-a-few-DPPs-more/structure-factor).
163
+
164
+ Used by [blue-sampler](https://pypi.org/project/blue-sampler/), which re-exports
165
+ `plot`, `plot_structure_factor`, `structure_factor` and `structure_factor_and_average`.
166
+
167
+ ---
168
+
169
+ ## License
170
+
171
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,71 @@
1
+ [build-system]
2
+ requires = ["hatchling >= 1.26"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "structure-factor-v2"
7
+ version = "2.0.0"
8
+ description = "Structure factor S(k) of point sets in the unit cube: scattering intensity, Kaiser taper, NUFFT, plots"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.9"
12
+
13
+ keywords = [
14
+ "structure factor",
15
+ "scattering intensity",
16
+ "hyperuniformity",
17
+ "point process",
18
+ "power spectrum",
19
+ "Kaiser taper",
20
+ "NUFFT",
21
+ "finufft",
22
+ ]
23
+
24
+ classifiers = [
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3.9",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "License :: OSI Approved :: MIT License",
32
+ "Operating System :: OS Independent",
33
+ "Topic :: Scientific/Engineering :: Mathematics",
34
+ "Topic :: Scientific/Engineering :: Physics",
35
+ ]
36
+
37
+ dependencies = [
38
+ "numpy",
39
+ "matplotlib",
40
+ "finufft",
41
+ ]
42
+
43
+ [project.optional-dependencies]
44
+ gpu12 = [
45
+ "cupy-cuda12x",
46
+ "cufinufft",
47
+ ]
48
+ gpu13 = [
49
+ "cupy-cuda13x",
50
+ "cufinufft",
51
+ ]
52
+ keops = ["pykeops"]
53
+ torch = ["torch"]
54
+
55
+ [project.urls]
56
+ Repository = "https://github.com/adecacqueray/structure-factor-v2"
57
+ Issues = "https://github.com/adecacqueray/structure-factor-v2/issues"
58
+
59
+ [tool.hatch.build.targets.wheel]
60
+ packages = ["src/structure_factor_v2"]
61
+
62
+ [tool.hatch.build]
63
+ exclude = [
64
+ "**/*.ipynb",
65
+ "**/*.jpg",
66
+ "**/*.png",
67
+ "**/__pycache__",
68
+ ]
69
+
70
+ [tool.ruff]
71
+ line-length = 100
@@ -0,0 +1,40 @@
1
+ """
2
+ structure_factor_v2: structure factor S(k) of point sets in the unit cube [0, 1)^D, and plots.
3
+
4
+ >>> import structure_factor_v2 as sf
5
+ >>> points = sf.jittered_lattice(10_000, 2) # a hyperuniform test pattern
6
+ >>> kint, S = sf.structure_factor(points) # raw scattering intensity
7
+ >>> sf.plot_structure_factor(points) # log-log plot, radial average
8
+ >>> sf.plot_structure_factor(points, trust_boundary=False) # non-periodic window: Kaiser taper
9
+ >>> sf.plot(points) # scatter plot of the points
10
+ >>> sf.plot_structure_factor(points, backend="keops", precision="float64")
11
+
12
+ Layout
13
+ ------
14
+ structure_factor estimation of S(k): scattering intensity, Kaiser taper, radial averages
15
+ viz plot (point sets), plot_structure_factor
16
+ lattices Korobov, jittered and curled lattices (test patterns, warm starts)
17
+ torus integer wave vectors of Z^D (grids, balls, isotropic sampling)
18
+ backend Fourier sums: finufft, cufinufft, keops, torch, numpy, cupy; check_gpu
19
+
20
+ Tunable constants live in `structure_factor_v2.CONFIG` (editable in place).
21
+ """
22
+ from .backend import BACKENDS, available_backends, check_gpu
23
+ from .lattices import curled_lattice, jittered_lattice, korobov_lattice
24
+ from .structure_factor import (
25
+ CFG as CONFIG,
26
+ auto_beta,
27
+ structure_factor,
28
+ structure_factor_and_average,
29
+ tapered_kmin,
30
+ )
31
+ from .viz import plot, plot_structure_factor
32
+
33
+ __all__ = [
34
+ "structure_factor", "structure_factor_and_average", "tapered_kmin", "auto_beta",
35
+ "plot", "plot_structure_factor",
36
+ "jittered_lattice", "curled_lattice", "korobov_lattice",
37
+ "check_gpu", "available_backends", "BACKENDS", "CONFIG",
38
+ ]
39
+
40
+ __version__ = "2.0.0"