phased-array-modeling 1.6.0__tar.gz → 1.7.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.
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/PKG-INFO +12 -9
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/README.md +2 -2
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/__init__.py +3 -2
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/beamforming.py +6 -4
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/core.py +124 -31
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/export.py +7 -8
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/geometry.py +30 -27
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/impairments.py +82 -46
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/polarization.py +0 -1
- phased_array_modeling-1.7.0/phased_array/py.typed +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/utils.py +36 -6
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/visualization.py +1 -6
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/wideband.py +23 -13
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array_modeling.egg-info/PKG-INFO +12 -9
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array_modeling.egg-info/SOURCES.txt +3 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array_modeling.egg-info/requires.txt +4 -2
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/pyproject.toml +31 -8
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_core.py +100 -0
- phased_array_modeling-1.7.0/tests/test_docs_snippets.py +103 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_impairments.py +135 -2
- phased_array_modeling-1.7.0/tests/test_notebooks.py +39 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_polarization.py +0 -1
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_utils.py +1 -2
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_wideband.py +41 -7
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/LICENSE +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/coordinates.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array/vector_patterns.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array_modeling.egg-info/dependency_links.txt +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/phased_array_modeling.egg-info/top_level.txt +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/setup.cfg +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_beamforming.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_coordinates.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_directivity.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_docstrings.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_export.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_geometry.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_textbook_benchmarks.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_vector_patterns.py +0 -0
- {phased_array_modeling-1.6.0 → phased_array_modeling-1.7.0}/tests/test_visualization.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: phased-array-modeling
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
4
4
|
Summary: Comprehensive Python library for phased array antenna modeling and visualization
|
|
5
5
|
Author-email: John Hodge <jah70@vt.edu>
|
|
6
|
-
License: MIT
|
|
6
|
+
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/jman4162/Phased-Array-Antenna-Model
|
|
8
8
|
Project-URL: Documentation, https://phased-array-antenna-model.readthedocs.io/
|
|
9
9
|
Project-URL: Repository, https://github.com/jman4162/Phased-Array-Antenna-Model
|
|
@@ -12,21 +12,22 @@ Keywords: phased array,antenna,beamforming,radar,electromagnetics,array factor,r
|
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
13
13
|
Classifier: Intended Audience :: Science/Research
|
|
14
14
|
Classifier: Intended Audience :: Education
|
|
15
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
16
15
|
Classifier: Operating System :: OS Independent
|
|
17
16
|
Classifier: Programming Language :: Python :: 3
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
22
|
Classifier: Topic :: Scientific/Engineering
|
|
23
23
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
24
|
-
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
25
26
|
Description-Content-Type: text/markdown
|
|
26
27
|
License-File: LICENSE
|
|
27
|
-
Requires-Dist: numpy>=1.
|
|
28
|
+
Requires-Dist: numpy>=1.21.3
|
|
28
29
|
Requires-Dist: matplotlib>=3.5.0
|
|
29
|
-
Requires-Dist: scipy>=1.7.
|
|
30
|
+
Requires-Dist: scipy>=1.7.2
|
|
30
31
|
Provides-Extra: plotting
|
|
31
32
|
Requires-Dist: plotly>=5.0.0; extra == "plotting"
|
|
32
33
|
Provides-Extra: full
|
|
@@ -37,6 +38,8 @@ Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
|
37
38
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
38
39
|
Requires-Dist: plotly>=5.0.0; extra == "dev"
|
|
39
40
|
Requires-Dist: seaborn>=0.11.0; extra == "dev"
|
|
41
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
42
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
40
43
|
Provides-Extra: docs
|
|
41
44
|
Requires-Dist: sphinx>=7.0.0; extra == "docs"
|
|
42
45
|
Requires-Dist: pydata-sphinx-theme>=0.14.0; extra == "docs"
|
|
@@ -54,7 +57,7 @@ Dynamic: license-file
|
|
|
54
57
|
[](https://phased-array-antenna-model.streamlit.app/)
|
|
55
58
|
[](https://phased-array-antenna-model.readthedocs.io/en/latest/)
|
|
56
59
|
|
|
57
|
-
A comprehensive Python library for computing and visualizing phased array antenna radiation patterns. Features vectorized
|
|
60
|
+
A comprehensive Python library for computing and visualizing phased array antenna radiation patterns. Features vectorized array-factor computation with bounded memory, multiple array geometries, advanced beamforming, and interactive 3D visualization.
|
|
58
61
|
|
|
59
62
|
Full walkthrough of the physics and API:
|
|
60
63
|
[Modeling phased arrays in Python, from physics to trade study](https://john-hodge.com/blog/modeling-phased-arrays-in-python/).
|
|
@@ -63,7 +66,7 @@ What's new in v1.4.0:
|
|
|
63
66
|
|
|
64
67
|
## Features
|
|
65
68
|
|
|
66
|
-
- **High Performance**: Vectorized array factor
|
|
69
|
+
- **High Performance**: Vectorized array factor with bounded memory; on rectangular, triangular and thinned grids the sum factors over x and y (32x32 array on a 181x361 grid: 15x faster than a NumPy loop over elements, 320x faster than pure Python; see `benchmarks/bench_array_factor.py`)
|
|
67
70
|
- **Multiple Geometries**: Rectangular, triangular, circular, cylindrical, spherical, sparse/thinned arrays
|
|
68
71
|
- **Beamforming**: Amplitude tapering (Taylor, Chebyshev, etc.), null steering, multi-beam
|
|
69
72
|
- **Realistic Impairments**: Mutual coupling, phase quantization, element failures, scan blindness
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[](https://phased-array-antenna-model.streamlit.app/)
|
|
10
10
|
[](https://phased-array-antenna-model.readthedocs.io/en/latest/)
|
|
11
11
|
|
|
12
|
-
A comprehensive Python library for computing and visualizing phased array antenna radiation patterns. Features vectorized
|
|
12
|
+
A comprehensive Python library for computing and visualizing phased array antenna radiation patterns. Features vectorized array-factor computation with bounded memory, multiple array geometries, advanced beamforming, and interactive 3D visualization.
|
|
13
13
|
|
|
14
14
|
Full walkthrough of the physics and API:
|
|
15
15
|
[Modeling phased arrays in Python, from physics to trade study](https://john-hodge.com/blog/modeling-phased-arrays-in-python/).
|
|
@@ -18,7 +18,7 @@ What's new in v1.4.0:
|
|
|
18
18
|
|
|
19
19
|
## Features
|
|
20
20
|
|
|
21
|
-
- **High Performance**: Vectorized array factor
|
|
21
|
+
- **High Performance**: Vectorized array factor with bounded memory; on rectangular, triangular and thinned grids the sum factors over x and y (32x32 array on a 181x361 grid: 15x faster than a NumPy loop over elements, 320x faster than pure Python; see `benchmarks/bench_array_factor.py`)
|
|
22
22
|
- **Multiple Geometries**: Rectangular, triangular, circular, cylindrical, spherical, sparse/thinned arrays
|
|
23
23
|
- **Beamforming**: Amplitude tapering (Taylor, Chebyshev, etc.), null steering, multi-beam
|
|
24
24
|
- **Realistic Impairments**: Mutual coupling, phase quantization, element failures, scan blindness
|
|
@@ -4,7 +4,8 @@ Phased Array Antenna Modeling Package
|
|
|
4
4
|
A comprehensive Python library for computing and visualizing phased array
|
|
5
5
|
antenna radiation patterns, including:
|
|
6
6
|
|
|
7
|
-
- Vectorized array factor computation
|
|
7
|
+
- Vectorized array factor computation with bounded memory and a fast
|
|
8
|
+
path for elements on a rectilinear lattice
|
|
8
9
|
- FFT-based pattern computation for uniform rectangular arrays
|
|
9
10
|
- Various array geometries (rectangular, circular, conformal, sparse)
|
|
10
11
|
- Beamforming techniques (tapering, null steering, multi-beam)
|
|
@@ -33,7 +34,7 @@ Example
|
|
|
33
34
|
>>> theta, phi, pattern_dB = pa.compute_full_pattern(geom.x, geom.y, weights, k)
|
|
34
35
|
"""
|
|
35
36
|
|
|
36
|
-
__version__ = "1.
|
|
37
|
+
__version__ = "1.7.0"
|
|
37
38
|
|
|
38
39
|
# Beamforming functions
|
|
39
40
|
from .beamforming import ( # Amplitude tapers; Null steering; Multiple beams; Beam spoiling; Adaptive
|
|
@@ -1099,8 +1099,9 @@ def adaptive_weights_smi(
|
|
|
1099
1099
|
>>> k = pa.wavelength_to_k(1.0)
|
|
1100
1100
|
>>> # Simulate interference data (normally from receiver)
|
|
1101
1101
|
>>> n_snapshots = 100
|
|
1102
|
-
>>>
|
|
1103
|
-
|
|
1102
|
+
>>> rng = np.random.default_rng(0)
|
|
1103
|
+
>>> interference = rng.standard_normal((n_snapshots, geom.n_elements)) + \\
|
|
1104
|
+
... 1j * rng.standard_normal((n_snapshots, geom.n_elements))
|
|
1104
1105
|
>>> weights = pa.adaptive_weights_smi(
|
|
1105
1106
|
... geom, k, theta_desired_deg=0, phi_desired_deg=0,
|
|
1106
1107
|
... interference_data=interference, diagonal_loading=0.01
|
|
@@ -1206,8 +1207,9 @@ def adaptive_weights_gsc(
|
|
|
1206
1207
|
>>> import phased_array as pa
|
|
1207
1208
|
>>> geom = pa.create_rectangular_array(8, 8, dx=0.5, dy=0.5)
|
|
1208
1209
|
>>> k = pa.wavelength_to_k(1.0)
|
|
1209
|
-
>>>
|
|
1210
|
-
|
|
1210
|
+
>>> rng = np.random.default_rng(0)
|
|
1211
|
+
>>> interference = rng.standard_normal((50, geom.n_elements)) + \\
|
|
1212
|
+
... 1j * rng.standard_normal((50, geom.n_elements))
|
|
1211
1213
|
>>> weights, B = pa.adaptive_weights_gsc(
|
|
1212
1214
|
... geom, k, theta_desired_deg=0, phi_desired_deg=0,
|
|
1213
1215
|
... interference_data=interference
|
|
@@ -11,7 +11,7 @@ from typing import Optional, Tuple, Union
|
|
|
11
11
|
import numpy as np
|
|
12
12
|
from scipy.integrate import trapezoid
|
|
13
13
|
|
|
14
|
-
from .utils import create_theta_phi_grid, linear_to_db
|
|
14
|
+
from .utils import create_theta_phi_grid, linear_to_db
|
|
15
15
|
|
|
16
16
|
ArrayLike = Union[np.ndarray, float]
|
|
17
17
|
|
|
@@ -158,8 +158,10 @@ def array_factor_vectorized(
|
|
|
158
158
|
"""
|
|
159
159
|
Compute array factor using vectorized NumPy operations.
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
The element sum is a matrix-vector product over chunks of angles, so
|
|
162
|
+
memory stays bounded (about 64 MiB of intermediate phase terms) for
|
|
163
|
+
any grid and array size. See ``benchmarks/bench_array_factor.py`` for
|
|
164
|
+
timings against loop implementations.
|
|
163
165
|
|
|
164
166
|
Parameters
|
|
165
167
|
----------
|
|
@@ -211,7 +213,8 @@ def array_factor_vectorized(
|
|
|
211
213
|
>>> AF_grid.shape
|
|
212
214
|
(91, 181)
|
|
213
215
|
"""
|
|
214
|
-
|
|
216
|
+
theta = np.asarray(theta)
|
|
217
|
+
phi = np.asarray(phi)
|
|
215
218
|
original_shape = theta.shape
|
|
216
219
|
theta_flat = theta.ravel()
|
|
217
220
|
phi_flat = phi.ravel()
|
|
@@ -219,25 +222,124 @@ def array_factor_vectorized(
|
|
|
219
222
|
# Direction cosines for all observation angles: shape (n_angles,)
|
|
220
223
|
u = np.sin(theta_flat) * np.cos(phi_flat)
|
|
221
224
|
v = np.sin(theta_flat) * np.sin(phi_flat)
|
|
225
|
+
w = np.cos(theta_flat) if z is not None else None
|
|
222
226
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
AF = _array_factor_from_cosines(u, v, w, x, y, z, weights, k)
|
|
228
|
+
return AF.reshape(original_shape)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
# Upper bound on the (angles x elements) phase matrix built per chunk
|
|
232
|
+
_AF_CHUNK_BYTES = 64 * 2**20
|
|
233
|
+
|
|
234
|
+
# Below this many angles the direct sum beats lattice detection overhead
|
|
235
|
+
_LATTICE_MIN_ANGLES = 256
|
|
227
236
|
|
|
228
|
-
# Phase contributions: shape (n_angles, n_elements)
|
|
229
|
-
# Using broadcasting: (n_angles, 1) * (1, n_elements)
|
|
230
|
-
phase = k * (np.outer(u, x) + np.outer(v, y))
|
|
231
237
|
|
|
238
|
+
def _array_factor_from_cosines(
|
|
239
|
+
u: np.ndarray,
|
|
240
|
+
v: np.ndarray,
|
|
241
|
+
w: Optional[np.ndarray],
|
|
242
|
+
x: np.ndarray,
|
|
243
|
+
y: np.ndarray,
|
|
244
|
+
z: Optional[np.ndarray],
|
|
245
|
+
weights: np.ndarray,
|
|
246
|
+
k: float
|
|
247
|
+
) -> np.ndarray:
|
|
248
|
+
"""
|
|
249
|
+
AF(u) = sum_n w_n exp(+j k r_n . u) for flat direction-cosine arrays.
|
|
250
|
+
|
|
251
|
+
Angles are processed in chunks so the intermediate phase matrix stays
|
|
252
|
+
below ``_AF_CHUNK_BYTES`` (complex128) regardless of grid and array
|
|
253
|
+
size; the element sum is a matrix-vector product.
|
|
254
|
+
"""
|
|
255
|
+
x = np.asarray(x, dtype=float).ravel()
|
|
256
|
+
y = np.asarray(y, dtype=float).ravel()
|
|
257
|
+
# Scalar or length-1 weights broadcast to every element
|
|
258
|
+
weights = np.broadcast_to(np.asarray(weights), x.shape).ravel()
|
|
232
259
|
if z is not None:
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
260
|
+
z = np.asarray(z, dtype=float).ravel()
|
|
261
|
+
|
|
262
|
+
# Planar elements on a rectilinear lattice (any z offset is common):
|
|
263
|
+
# factor exp(jk(xu + yv)) = exp(jkxu) exp(jkyv) over the distinct x and
|
|
264
|
+
# y coordinates, which needs far fewer complex exponentials. The
|
|
265
|
+
# one-time lattice detection only pays off over many angles.
|
|
266
|
+
if (x.size >= 16 and u.size >= _LATTICE_MIN_ANGLES
|
|
267
|
+
and (z is None or np.ptp(z) == 0)):
|
|
268
|
+
lattice = _lattice_factorization(x, y, weights)
|
|
269
|
+
if lattice is not None:
|
|
270
|
+
AF = _array_factor_lattice(u, v, *lattice, k)
|
|
271
|
+
if z is not None and z[0] != 0:
|
|
272
|
+
AF *= np.exp(1j * k * w * z[0])
|
|
273
|
+
return AF
|
|
274
|
+
|
|
275
|
+
n_angles = u.size
|
|
276
|
+
n_elements = max(x.size, 1)
|
|
277
|
+
chunk = max(1, _AF_CHUNK_BYTES // (16 * n_elements))
|
|
278
|
+
|
|
279
|
+
AF = np.empty(n_angles, dtype=complex)
|
|
280
|
+
for start in range(0, n_angles, chunk):
|
|
281
|
+
sl = slice(start, start + chunk)
|
|
282
|
+
phase = np.outer(u[sl], x)
|
|
283
|
+
phase += np.outer(v[sl], y)
|
|
284
|
+
if z is not None:
|
|
285
|
+
phase += np.outer(w[sl], z)
|
|
286
|
+
phase *= k
|
|
287
|
+
# Separate cos/sin is ~25% faster than np.exp of a complex array
|
|
288
|
+
AF[sl] = np.cos(phase) @ weights + 1j * (np.sin(phase) @ weights)
|
|
289
|
+
return AF
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def _distinct_coordinates(c: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
|
|
293
|
+
"""Distinct values of c (to ~1e-9 of its span) and each element's index."""
|
|
294
|
+
span = float(np.ptp(c)) or 1.0
|
|
295
|
+
keys = np.round((c - c.min()) / (span * 1e-9)).astype(np.int64)
|
|
296
|
+
_, index = np.unique(keys, return_inverse=True)
|
|
297
|
+
index = index.ravel()
|
|
298
|
+
values = np.bincount(index, weights=c) / np.bincount(index)
|
|
299
|
+
return values, index
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _lattice_factorization(
|
|
303
|
+
x: np.ndarray,
|
|
304
|
+
y: np.ndarray,
|
|
305
|
+
weights: np.ndarray
|
|
306
|
+
) -> Optional[Tuple[np.ndarray, np.ndarray, np.ndarray]]:
|
|
307
|
+
"""
|
|
308
|
+
Distinct x and y coordinates and the weight matrix W[ix, iy], or None.
|
|
236
309
|
|
|
237
|
-
|
|
238
|
-
|
|
310
|
+
Returns None when the positions do not sit on a rectilinear lattice
|
|
311
|
+
compact enough for the factorized sum to pay off (more lattice points
|
|
312
|
+
than four times the element count).
|
|
313
|
+
"""
|
|
314
|
+
xs, ix = _distinct_coordinates(x)
|
|
315
|
+
ys, iy = _distinct_coordinates(y)
|
|
316
|
+
if xs.size * ys.size > 4 * x.size:
|
|
317
|
+
return None
|
|
318
|
+
W = np.zeros((xs.size, ys.size), dtype=complex)
|
|
319
|
+
np.add.at(W, (ix, iy), weights)
|
|
320
|
+
return xs, ys, W
|
|
239
321
|
|
|
240
|
-
|
|
322
|
+
|
|
323
|
+
def _array_factor_lattice(
|
|
324
|
+
u: np.ndarray,
|
|
325
|
+
v: np.ndarray,
|
|
326
|
+
xs: np.ndarray,
|
|
327
|
+
ys: np.ndarray,
|
|
328
|
+
W: np.ndarray,
|
|
329
|
+
k: float
|
|
330
|
+
) -> np.ndarray:
|
|
331
|
+
"""AF = sum_ij W_ij exp(jk xs_i u) exp(jk ys_j v), chunked over angles."""
|
|
332
|
+
n_angles = u.size
|
|
333
|
+
per_angle = 16 * (2 * xs.size + ys.size)
|
|
334
|
+
chunk = max(1, _AF_CHUNK_BYTES // per_angle)
|
|
335
|
+
WT = W.T
|
|
336
|
+
AF = np.empty(n_angles, dtype=complex)
|
|
337
|
+
for start in range(0, n_angles, chunk):
|
|
338
|
+
sl = slice(start, start + chunk)
|
|
339
|
+
A = np.exp(1j * k * np.outer(u[sl], xs))
|
|
340
|
+
B = np.exp(1j * k * np.outer(v[sl], ys))
|
|
341
|
+
AF[sl] = np.einsum('ai,ai->a', A, B @ WT)
|
|
342
|
+
return AF
|
|
241
343
|
|
|
242
344
|
|
|
243
345
|
def array_factor_uv(
|
|
@@ -271,20 +373,11 @@ def array_factor_uv(
|
|
|
271
373
|
AF : ndarray
|
|
272
374
|
Complex array factor, same shape as u/v
|
|
273
375
|
"""
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
y = np.asarray(y).ravel()
|
|
280
|
-
weights = np.asarray(weights).ravel()
|
|
281
|
-
|
|
282
|
-
# Phase: (n_angles, n_elements)
|
|
283
|
-
phase = k * (np.outer(u_flat, x) + np.outer(v_flat, y))
|
|
284
|
-
|
|
285
|
-
AF = np.sum(weights * np.exp(1j * phase), axis=1)
|
|
286
|
-
|
|
287
|
-
return AF.reshape(original_shape)
|
|
376
|
+
u = np.asarray(u, dtype=float)
|
|
377
|
+
v = np.asarray(v, dtype=float)
|
|
378
|
+
AF = _array_factor_from_cosines(u.ravel(), v.ravel(), None, x, y, None,
|
|
379
|
+
weights, k)
|
|
380
|
+
return AF.reshape(u.shape)
|
|
288
381
|
|
|
289
382
|
|
|
290
383
|
def array_factor_fft(
|
|
@@ -8,8 +8,7 @@ import io
|
|
|
8
8
|
import json
|
|
9
9
|
import warnings
|
|
10
10
|
from datetime import datetime
|
|
11
|
-
from
|
|
12
|
-
from typing import Any, Dict, Optional, Tuple, Union
|
|
11
|
+
from typing import Any, Dict, Optional
|
|
13
12
|
|
|
14
13
|
import numpy as np
|
|
15
14
|
|
|
@@ -77,7 +76,7 @@ def export_pattern_csv(
|
|
|
77
76
|
|
|
78
77
|
# Write metadata as comments
|
|
79
78
|
if metadata:
|
|
80
|
-
buffer.write(
|
|
79
|
+
buffer.write("# Phased Array Pattern Export\n")
|
|
81
80
|
buffer.write(f"# Generated: {datetime.now().isoformat()}\n")
|
|
82
81
|
for key, value in metadata.items():
|
|
83
82
|
buffer.write(f"# {key}: {value}\n")
|
|
@@ -180,7 +179,7 @@ def export_pattern_2d_csv(
|
|
|
180
179
|
|
|
181
180
|
# Write metadata
|
|
182
181
|
if metadata:
|
|
183
|
-
buffer.write(
|
|
182
|
+
buffer.write("# Phased Array 2D Pattern Export\n")
|
|
184
183
|
buffer.write(f"# Generated: {datetime.now().isoformat()}\n")
|
|
185
184
|
for key, value in metadata.items():
|
|
186
185
|
buffer.write(f"# {key}: {value}\n")
|
|
@@ -244,7 +243,7 @@ def export_uv_pattern_csv(
|
|
|
244
243
|
buffer = io.StringIO()
|
|
245
244
|
|
|
246
245
|
if metadata:
|
|
247
|
-
buffer.write(
|
|
246
|
+
buffer.write("# Phased Array UV-Space Pattern Export\n")
|
|
248
247
|
buffer.write(f"# Generated: {datetime.now().isoformat()}\n")
|
|
249
248
|
for key, value in metadata.items():
|
|
250
249
|
buffer.write(f"# {key}: {value}\n")
|
|
@@ -304,7 +303,7 @@ def export_weights_csv(
|
|
|
304
303
|
buffer = io.StringIO()
|
|
305
304
|
|
|
306
305
|
if metadata:
|
|
307
|
-
buffer.write(
|
|
306
|
+
buffer.write("# Phased Array Weights Export\n")
|
|
308
307
|
buffer.write(f"# Generated: {datetime.now().isoformat()}\n")
|
|
309
308
|
buffer.write(f"# N_elements: {geometry.n_elements}\n")
|
|
310
309
|
for key, value in metadata.items():
|
|
@@ -357,7 +356,7 @@ def export_geometry_csv(
|
|
|
357
356
|
buffer = io.StringIO()
|
|
358
357
|
|
|
359
358
|
if metadata:
|
|
360
|
-
buffer.write(
|
|
359
|
+
buffer.write("# Phased Array Geometry Export\n")
|
|
361
360
|
buffer.write(f"# Generated: {datetime.now().isoformat()}\n")
|
|
362
361
|
buffer.write(f"# N_elements: {geometry.n_elements}\n")
|
|
363
362
|
for key, value in metadata.items():
|
|
@@ -608,7 +607,7 @@ def export_coupling_matrix_csv(
|
|
|
608
607
|
n = coupling_matrix.shape[0]
|
|
609
608
|
|
|
610
609
|
if metadata:
|
|
611
|
-
buffer.write(
|
|
610
|
+
buffer.write("# Mutual Coupling Matrix Export\n")
|
|
612
611
|
buffer.write(f"# Generated: {datetime.now().isoformat()}\n")
|
|
613
612
|
buffer.write(f"# Format: {format}\n")
|
|
614
613
|
buffer.write(f"# Size: {n} x {n}\n")
|
|
@@ -4,12 +4,13 @@ Array geometry definitions and generation functions.
|
|
|
4
4
|
Includes rectangular, circular, conformal, sparse, and subarray architectures.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
from dataclasses import dataclass, field
|
|
7
|
+
from dataclasses import dataclass
|
|
9
8
|
from typing import Callable, List, Optional, Tuple, Union
|
|
10
9
|
|
|
11
10
|
import numpy as np
|
|
12
11
|
|
|
12
|
+
from .utils import SeedLike, _make_rng
|
|
13
|
+
|
|
13
14
|
|
|
14
15
|
@dataclass
|
|
15
16
|
class ArrayGeometry:
|
|
@@ -676,7 +677,7 @@ def _subset(geometry: ArrayGeometry, keep: np.ndarray) -> ArrayGeometry:
|
|
|
676
677
|
def thin_array_random(
|
|
677
678
|
geometry: ArrayGeometry,
|
|
678
679
|
thinning_factor: float,
|
|
679
|
-
seed:
|
|
680
|
+
seed: SeedLike = None
|
|
680
681
|
) -> ArrayGeometry:
|
|
681
682
|
"""
|
|
682
683
|
Randomly thin an array by removing elements.
|
|
@@ -687,8 +688,10 @@ def thin_array_random(
|
|
|
687
688
|
Original array geometry
|
|
688
689
|
thinning_factor : float
|
|
689
690
|
Fraction of elements to keep (0 to 1)
|
|
690
|
-
seed : int, optional
|
|
691
|
-
|
|
691
|
+
seed : int, numpy.random.Generator or numpy.random.RandomState, optional
|
|
692
|
+
Seed or generator for reproducibility. An int reproduces the
|
|
693
|
+
results of earlier releases for the same seed without reseeding
|
|
694
|
+
NumPy's global generator; None draws from the global generator.
|
|
692
695
|
|
|
693
696
|
Returns
|
|
694
697
|
-------
|
|
@@ -696,11 +699,10 @@ def thin_array_random(
|
|
|
696
699
|
Thinned array geometry. ``element_indices`` index the original
|
|
697
700
|
(unthinned) array, also when thinning an already thinned geometry.
|
|
698
701
|
"""
|
|
699
|
-
|
|
700
|
-
np.random.seed(seed)
|
|
702
|
+
rng = _make_rng(seed)
|
|
701
703
|
|
|
702
704
|
n_keep = int(geometry.n_elements * thinning_factor)
|
|
703
|
-
keep_indices =
|
|
705
|
+
keep_indices = rng.choice(geometry.n_elements, n_keep, replace=False)
|
|
704
706
|
keep_indices = np.sort(keep_indices)
|
|
705
707
|
|
|
706
708
|
return _subset(geometry, keep_indices)
|
|
@@ -709,7 +711,7 @@ def thin_array_random(
|
|
|
709
711
|
def thin_array_density_tapered(
|
|
710
712
|
geometry: ArrayGeometry,
|
|
711
713
|
density_func: Callable[[np.ndarray, np.ndarray], np.ndarray],
|
|
712
|
-
seed:
|
|
714
|
+
seed: SeedLike = None
|
|
713
715
|
) -> ArrayGeometry:
|
|
714
716
|
"""
|
|
715
717
|
Thin array with position-dependent density (statistical thinning).
|
|
@@ -720,23 +722,24 @@ def thin_array_density_tapered(
|
|
|
720
722
|
Original array geometry
|
|
721
723
|
density_func : callable
|
|
722
724
|
Function(x, y) -> probability of keeping each element (0 to 1)
|
|
723
|
-
seed : int, optional
|
|
724
|
-
|
|
725
|
+
seed : int, numpy.random.Generator or numpy.random.RandomState, optional
|
|
726
|
+
Seed or generator for reproducibility. An int reproduces the
|
|
727
|
+
results of earlier releases for the same seed without reseeding
|
|
728
|
+
NumPy's global generator; None draws from the global generator.
|
|
725
729
|
|
|
726
730
|
Returns
|
|
727
731
|
-------
|
|
728
732
|
geometry : ArrayGeometry
|
|
729
733
|
Thinned geometry. ``element_indices`` index the original array.
|
|
730
734
|
"""
|
|
731
|
-
|
|
732
|
-
np.random.seed(seed)
|
|
735
|
+
rng = _make_rng(seed)
|
|
733
736
|
|
|
734
737
|
# Compute keep probability for each element
|
|
735
738
|
keep_prob = density_func(geometry.x, geometry.y)
|
|
736
739
|
keep_prob = np.clip(keep_prob, 0, 1)
|
|
737
740
|
|
|
738
741
|
# Random selection based on probability
|
|
739
|
-
keep_mask =
|
|
742
|
+
keep_mask = rng.random(geometry.n_elements) < keep_prob
|
|
740
743
|
keep_indices = np.where(keep_mask)[0]
|
|
741
744
|
|
|
742
745
|
return _subset(geometry, keep_indices)
|
|
@@ -749,7 +752,7 @@ def thin_array_genetic_algorithm(
|
|
|
749
752
|
population_size: int = 50,
|
|
750
753
|
n_generations: int = 100,
|
|
751
754
|
mutation_rate: float = 0.1,
|
|
752
|
-
seed:
|
|
755
|
+
seed: SeedLike = None
|
|
753
756
|
) -> ArrayGeometry:
|
|
754
757
|
"""
|
|
755
758
|
Optimize element selection using a genetic algorithm.
|
|
@@ -768,22 +771,23 @@ def thin_array_genetic_algorithm(
|
|
|
768
771
|
Number of generations
|
|
769
772
|
mutation_rate : float
|
|
770
773
|
Probability of mutation per gene
|
|
771
|
-
seed : int, optional
|
|
772
|
-
|
|
774
|
+
seed : int, numpy.random.Generator or numpy.random.RandomState, optional
|
|
775
|
+
Seed or generator for reproducibility. An int reproduces the
|
|
776
|
+
results of earlier releases for the same seed without reseeding
|
|
777
|
+
NumPy's global generator; None draws from the global generator.
|
|
773
778
|
|
|
774
779
|
Returns
|
|
775
780
|
-------
|
|
776
781
|
geometry : ArrayGeometry
|
|
777
782
|
Optimized thinned geometry
|
|
778
783
|
"""
|
|
779
|
-
|
|
780
|
-
np.random.seed(seed)
|
|
784
|
+
rng = _make_rng(seed)
|
|
781
785
|
|
|
782
786
|
n_elements = geometry.n_elements
|
|
783
787
|
|
|
784
788
|
def create_individual():
|
|
785
789
|
"""Create a random selection of n_target elements."""
|
|
786
|
-
return
|
|
790
|
+
return rng.choice(n_elements, n_target, replace=False)
|
|
787
791
|
|
|
788
792
|
def evaluate(individual):
|
|
789
793
|
"""Evaluate fitness on the same geometry the function returns."""
|
|
@@ -794,22 +798,22 @@ def thin_array_genetic_algorithm(
|
|
|
794
798
|
# Combine unique elements from both parents
|
|
795
799
|
combined = np.unique(np.concatenate([parent1, parent2]))
|
|
796
800
|
if len(combined) >= n_target:
|
|
797
|
-
return
|
|
801
|
+
return rng.choice(combined, n_target, replace=False)
|
|
798
802
|
else:
|
|
799
803
|
# Fill with random elements if needed
|
|
800
804
|
remaining = np.setdiff1d(np.arange(n_elements), combined)
|
|
801
|
-
additional =
|
|
805
|
+
additional = rng.choice(remaining, n_target - len(combined), replace=False)
|
|
802
806
|
return np.concatenate([combined, additional])
|
|
803
807
|
|
|
804
808
|
def mutate(individual):
|
|
805
809
|
"""Mutate by swapping elements."""
|
|
806
810
|
individual = individual.copy()
|
|
807
811
|
for i in range(len(individual)):
|
|
808
|
-
if
|
|
812
|
+
if rng.random() < mutation_rate:
|
|
809
813
|
# Swap with a random element not in the array
|
|
810
814
|
available = np.setdiff1d(np.arange(n_elements), individual)
|
|
811
815
|
if len(available) > 0:
|
|
812
|
-
individual[i] =
|
|
816
|
+
individual[i] = rng.choice(available)
|
|
813
817
|
return individual
|
|
814
818
|
|
|
815
819
|
# Initialize population
|
|
@@ -824,10 +828,10 @@ def thin_array_genetic_algorithm(
|
|
|
824
828
|
|
|
825
829
|
while len(new_population) < population_size:
|
|
826
830
|
# Tournament selection
|
|
827
|
-
i1, i2 =
|
|
831
|
+
i1, i2 = rng.choice(population_size, 2, replace=False)
|
|
828
832
|
parent1 = population[i1] if fitness[i1] < fitness[i2] else population[i2]
|
|
829
833
|
|
|
830
|
-
i3, i4 =
|
|
834
|
+
i3, i4 = rng.choice(population_size, 2, replace=False)
|
|
831
835
|
parent2 = population[i3] if fitness[i3] < fitness[i4] else population[i4]
|
|
832
836
|
|
|
833
837
|
child = crossover(parent1, parent2)
|
|
@@ -962,7 +966,6 @@ def compute_subarray_weights(
|
|
|
962
966
|
weights : ndarray
|
|
963
967
|
Complex weights for all elements
|
|
964
968
|
"""
|
|
965
|
-
from .core import steering_vector
|
|
966
969
|
|
|
967
970
|
geom = architecture.geometry
|
|
968
971
|
weights = np.ones(geom.n_elements, dtype=complex)
|