differt 0.0.37__tar.gz → 0.1.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.
- {differt-0.0.37 → differt-0.1.0}/PKG-INFO +11 -10
- {differt-0.0.37 → differt-0.1.0}/README.md +6 -5
- {differt-0.0.37 → differt-0.1.0}/pyproject.toml +4 -4
- {differt-0.0.37 → differt-0.1.0}/src/differt/em/__init__.py +2 -2
- {differt-0.0.37 → differt-0.1.0}/src/differt/em/_antenna.py +10 -12
- {differt-0.0.37 → differt-0.1.0}/src/differt/em/_fresnel.py +84 -24
- {differt-0.0.37 → differt-0.1.0}/src/differt/geometry/__init__.py +0 -1
- {differt-0.0.37 → differt-0.1.0}/src/differt/geometry/_paths.py +62 -7
- {differt-0.0.37 → differt-0.1.0}/src/differt/geometry/_triangle_mesh.py +265 -25
- {differt-0.0.37 → differt-0.1.0}/src/differt/geometry/_utils.py +1 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/plotting/__init__.py +2 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/plotting/_core.py +6 -3
- {differt-0.0.37 → differt-0.1.0}/src/differt/plotting/_utils.py +56 -17
- {differt-0.0.37 → differt-0.1.0}/src/differt/rt/__init__.py +2 -1
- differt-0.1.0/src/differt/rt/_fermat.py +321 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/rt/_image_method.py +47 -12
- {differt-0.0.37 → differt-0.1.0}/src/differt/rt/_utils.py +140 -23
- {differt-0.0.37 → differt-0.1.0}/src/differt/scene/_triangle_scene.py +134 -38
- {differt-0.0.37 → differt-0.1.0}/src/differt/utils.py +91 -25
- differt-0.0.37/src/differt/rt/_fermat.py +0 -137
- {differt-0.0.37 → differt-0.1.0}/.gitignore +0 -0
- {differt-0.0.37 → differt-0.1.0}/LICENSE.md +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/__init__.py +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/_version.py +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/em/_constants.py +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/em/_interaction_type.py +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/em/_material.py +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/em/_utd.py +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/em/_utils.py +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/py.typed +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/scene/__init__.py +0 -0
- {differt-0.0.37 → differt-0.1.0}/src/differt/scene/_sionna.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.1.0
|
|
4
4
|
Summary: Differentiable Ray Tracing Toolbox for Radio Propagation Simulations
|
|
5
5
|
Project-URL: Changelog, https://github.com/jeertmans/DiffeRT/releases
|
|
6
6
|
Project-URL: Documentation, https://eertmans.be/DiffeRT
|
|
@@ -21,11 +21,11 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
21
21
|
Classifier: Topic :: Scientific/Engineering
|
|
22
22
|
Requires-Python: >=3.10
|
|
23
23
|
Requires-Dist: chex>=0.1.86
|
|
24
|
-
Requires-Dist: differt-core==0.0
|
|
25
|
-
Requires-Dist: equinox>=0.
|
|
24
|
+
Requires-Dist: differt-core==0.1.0
|
|
25
|
+
Requires-Dist: equinox>=0.12.2
|
|
26
26
|
Requires-Dist: filelock>=3.15.4
|
|
27
|
-
Requires-Dist: jax
|
|
28
|
-
Requires-Dist: jaxtyping>=0.2
|
|
27
|
+
Requires-Dist: jax<0.6,>=0.4.32
|
|
28
|
+
Requires-Dist: jaxtyping>=0.3.2
|
|
29
29
|
Requires-Dist: numpy>=1.26.1
|
|
30
30
|
Requires-Dist: optax>=0.1.7
|
|
31
31
|
Requires-Dist: requests>=2.32.0
|
|
@@ -63,6 +63,8 @@ Description-Content-Type: text/markdown
|
|
|
63
63
|
|
|
64
64
|
# DiffeRT
|
|
65
65
|
|
|
66
|
+
Differentiable Ray Tracing toolbox for Radio Propagation powered by the [JAX ecosystem](https://github.com/jax-ml/jax).
|
|
67
|
+
|
|
66
68
|
[![Latest Release][pypi-version-badge]][pypi-version-url]
|
|
67
69
|
[![Python version][pypi-python-version-badge]][pypi-version-url]
|
|
68
70
|
[![Documentation][documentation-badge]][documentation-url]
|
|
@@ -74,11 +76,10 @@ Description-Content-Type: text/markdown
|
|
|
74
76
|
## Usage
|
|
75
77
|
|
|
76
78
|
> **WARNING:**
|
|
77
|
-
>
|
|
78
|
-
>
|
|
79
|
-
>
|
|
80
|
-
>
|
|
81
|
-
> features.
|
|
79
|
+
> This package is still under important development, see
|
|
80
|
+
> the [v1.0.0](https://github.com/jeertmans/DiffeRT/milestone/2) milestone for future
|
|
81
|
+
> features, and the [CHANGELOG](https://github.com/jeertmans/DiffeRT/blob/main/README.md)
|
|
82
|
+
> for versioning policy.
|
|
82
83
|
>
|
|
83
84
|
> If you have any suggestion regarding the development of this package,
|
|
84
85
|
> please open an [issue](https://github.com/jeertmans/DiffeRT/issues).
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
# DiffeRT
|
|
8
8
|
|
|
9
|
+
Differentiable Ray Tracing toolbox for Radio Propagation powered by the [JAX ecosystem](https://github.com/jax-ml/jax).
|
|
10
|
+
|
|
9
11
|
[![Latest Release][pypi-version-badge]][pypi-version-url]
|
|
10
12
|
[![Python version][pypi-python-version-badge]][pypi-version-url]
|
|
11
13
|
[![Documentation][documentation-badge]][documentation-url]
|
|
@@ -17,11 +19,10 @@
|
|
|
17
19
|
## Usage
|
|
18
20
|
|
|
19
21
|
> [!WARNING]
|
|
20
|
-
>
|
|
21
|
-
>
|
|
22
|
-
>
|
|
23
|
-
>
|
|
24
|
-
> features.
|
|
22
|
+
> This package is still under important development, see
|
|
23
|
+
> the [v1.0.0](https://github.com/jeertmans/DiffeRT/milestone/2) milestone for future
|
|
24
|
+
> features, and the [CHANGELOG](https://github.com/jeertmans/DiffeRT/blob/main/README.md)
|
|
25
|
+
> for versioning policy.
|
|
25
26
|
>
|
|
26
27
|
> If you have any suggestion regarding the development of this package,
|
|
27
28
|
> please open an [issue](https://github.com/jeertmans/DiffeRT/issues).
|
|
@@ -16,11 +16,11 @@ classifiers = [
|
|
|
16
16
|
]
|
|
17
17
|
dependencies = [
|
|
18
18
|
"chex>=0.1.86",
|
|
19
|
-
"differt-core==0.0
|
|
20
|
-
"equinox>=0.
|
|
19
|
+
"differt-core==0.1.0",
|
|
20
|
+
"equinox>=0.12.2",
|
|
21
21
|
"filelock>=3.15.4",
|
|
22
|
-
"jax>=0.4.32",
|
|
23
|
-
"jaxtyping>=0.2
|
|
22
|
+
"jax>=0.4.32,<0.6", # TODO: fixme, issue with pmap
|
|
23
|
+
"jaxtyping>=0.3.2",
|
|
24
24
|
"numpy>=1.26.1",
|
|
25
25
|
"optax>=0.1.7",
|
|
26
26
|
"typing-extensions>=4.9.0;python_version<'3.11'",
|
|
@@ -21,7 +21,7 @@ __all__ = (
|
|
|
21
21
|
"materials",
|
|
22
22
|
"mu_0",
|
|
23
23
|
"path_delays",
|
|
24
|
-
"
|
|
24
|
+
"poynting_vector",
|
|
25
25
|
"reflection_coefficients",
|
|
26
26
|
"refraction_coefficients",
|
|
27
27
|
"refractive_indices",
|
|
@@ -39,7 +39,7 @@ from ._antenna import (
|
|
|
39
39
|
RadiationPattern,
|
|
40
40
|
ShortDipole,
|
|
41
41
|
ShortDipolePattern,
|
|
42
|
-
|
|
42
|
+
poynting_vector,
|
|
43
43
|
)
|
|
44
44
|
from ._constants import c, epsilon_0, mu_0, z_0
|
|
45
45
|
from ._fresnel import (
|
|
@@ -19,12 +19,12 @@ from ._constants import c, epsilon_0, mu_0
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
@jax.jit
|
|
22
|
-
def
|
|
22
|
+
def poynting_vector(
|
|
23
23
|
e: Inexact[ArrayLike, "*#batch 3"],
|
|
24
24
|
b: Inexact[ArrayLike, "*#batch 3"],
|
|
25
25
|
) -> Inexact[Array, "*batch 3"]:
|
|
26
26
|
r"""
|
|
27
|
-
Compute the
|
|
27
|
+
Compute the Pointing vector in vacuum at from electric :math:`\vec{E}` and magnetic :math:`\vec{B}` fields.
|
|
28
28
|
|
|
29
29
|
Args:
|
|
30
30
|
e: The electrical field.
|
|
@@ -35,9 +35,7 @@ def pointing_vector(
|
|
|
35
35
|
|
|
36
36
|
It can be either real of complex-valued.
|
|
37
37
|
"""
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return jnp.cross(jnp.asarray(e), h)
|
|
38
|
+
return jnp.cross(jnp.asarray(e), jnp.asarray(b)) / mu_0
|
|
41
39
|
|
|
42
40
|
|
|
43
41
|
class BaseAntenna(eqx.Module):
|
|
@@ -117,13 +115,13 @@ class Antenna(BaseAntenna):
|
|
|
117
115
|
"""
|
|
118
116
|
|
|
119
117
|
@eqx.filter_jit
|
|
120
|
-
def
|
|
118
|
+
def poynting_vector(
|
|
121
119
|
self,
|
|
122
120
|
r: Float[ArrayLike, "*#batch 3"],
|
|
123
121
|
t: Float[ArrayLike, "*#batch"] | None = None,
|
|
124
122
|
) -> Inexact[Array, "*batch 3"]:
|
|
125
123
|
r"""
|
|
126
|
-
Compute the
|
|
124
|
+
Compute the Poynting vector in vacuum at given position and (optional) time.
|
|
127
125
|
|
|
128
126
|
Args:
|
|
129
127
|
r: The array of positions.
|
|
@@ -138,7 +136,7 @@ class Antenna(BaseAntenna):
|
|
|
138
136
|
It can be either real of complex-valued.
|
|
139
137
|
"""
|
|
140
138
|
e, b = self.fields(r, t)
|
|
141
|
-
return
|
|
139
|
+
return poynting_vector(e, b)
|
|
142
140
|
|
|
143
141
|
def directivity(
|
|
144
142
|
self,
|
|
@@ -176,7 +174,7 @@ class Antenna(BaseAntenna):
|
|
|
176
174
|
|
|
177
175
|
r = self.center + jnp.stack((x, y, z), axis=-1)
|
|
178
176
|
|
|
179
|
-
s = self.
|
|
177
|
+
s = self.poynting_vector(r)
|
|
180
178
|
|
|
181
179
|
p = jnp.linalg.norm(s, axis=-1)
|
|
182
180
|
|
|
@@ -251,7 +249,7 @@ class Antenna(BaseAntenna):
|
|
|
251
249
|
|
|
252
250
|
r = self.center + distance * jnp.stack((x, y, z), axis=-1)
|
|
253
251
|
|
|
254
|
-
s = self.
|
|
252
|
+
s = self.poynting_vector(r)
|
|
255
253
|
|
|
256
254
|
p = jnp.linalg.norm(s, axis=-1, keepdims=True)
|
|
257
255
|
|
|
@@ -323,7 +321,7 @@ class Dipole(Antenna):
|
|
|
323
321
|
... )
|
|
324
322
|
>>> for ratio in [0.5, 1.0, 1.25, 1.5, 2.0]:
|
|
325
323
|
... ant = Dipole(1e9, ratio)
|
|
326
|
-
... power = jnp.linalg.norm(ant.
|
|
324
|
+
... power = jnp.linalg.norm(ant.poynting_vector(r), axis=-1)
|
|
327
325
|
... _ = ax.plot(theta, power, label=rf"$\ell/\lambda = {ratio:1.2f}$")
|
|
328
326
|
>>>
|
|
329
327
|
>>> ax.tick_params(grid_color="palegoldenrod")
|
|
@@ -647,7 +645,7 @@ class RadiationPattern(BaseAntenna):
|
|
|
647
645
|
|
|
648
646
|
r = self.center + distance * jnp.stack((x, y, z), axis=-1)
|
|
649
647
|
|
|
650
|
-
s = self.
|
|
648
|
+
s = self.poynting_vector(r) # type: ignore[reportAttributeAccessIssue]
|
|
651
649
|
|
|
652
650
|
p = jnp.linalg.norm(s, axis=-1, keepdims=True)
|
|
653
651
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import equinox as eqx
|
|
2
2
|
import jax
|
|
3
3
|
import jax.numpy as jnp
|
|
4
|
-
from jaxtyping import Array, ArrayLike, Float, Inexact
|
|
4
|
+
from jaxtyping import Array, ArrayLike, Complex, Float, Inexact
|
|
5
5
|
|
|
6
6
|
from differt.utils import safe_divide
|
|
7
7
|
|
|
@@ -48,8 +48,8 @@ def fresnel_coefficients(
|
|
|
48
48
|
n_r: Inexact[ArrayLike, " *#batch"],
|
|
49
49
|
cos_theta_i: Float[ArrayLike, " *#batch"],
|
|
50
50
|
) -> tuple[
|
|
51
|
-
tuple[
|
|
52
|
-
tuple[
|
|
51
|
+
tuple[Complex[Array, " *batch"], Complex[Array, " *batch"]],
|
|
52
|
+
tuple[Complex[Array, " *batch"], Complex[Array, " *batch"]],
|
|
53
53
|
]:
|
|
54
54
|
r"""
|
|
55
55
|
Compute the Fresnel reflection and refraction coefficients at an interface.
|
|
@@ -108,9 +108,6 @@ def fresnel_coefficients(
|
|
|
108
108
|
Returns:
|
|
109
109
|
The reflection and refraction coefficients for s and p polarizations.
|
|
110
110
|
|
|
111
|
-
The output dtype will only be complex if any of the provided arguments
|
|
112
|
-
has a complex dtype.
|
|
113
|
-
|
|
114
111
|
.. seealso::
|
|
115
112
|
|
|
116
113
|
:func:`reflection_coefficients`
|
|
@@ -128,10 +125,13 @@ def fresnel_coefficients(
|
|
|
128
125
|
|
|
129
126
|
>>> from differt.em import fresnel_coefficients
|
|
130
127
|
>>>
|
|
131
|
-
>>> n = 1.5
|
|
128
|
+
>>> n = 1.5 # Air to glass
|
|
132
129
|
>>> theta = jnp.linspace(0, jnp.pi / 2)
|
|
133
130
|
>>> cos_theta = jnp.cos(theta)
|
|
134
|
-
>>> (r_s, r_p), (t_s, t_p) =
|
|
131
|
+
>>> (r_s, r_p), (t_s, t_p) = jax.tree.map(
|
|
132
|
+
... jnp.real,
|
|
133
|
+
... fresnel_coefficients(n, cos_theta)
|
|
134
|
+
... ) # Here Fresnel coefficients are purely real numbers
|
|
135
135
|
>>> theta_d = jnp.rad2deg(theta)
|
|
136
136
|
>>> theta_b = jnp.rad2deg(jnp.arctan(n))
|
|
137
137
|
>>> plt.plot(theta_d, r_s, "b:", label=r"$r_s$") # doctest: +SKIP
|
|
@@ -155,10 +155,14 @@ def fresnel_coefficients(
|
|
|
155
155
|
|
|
156
156
|
>>> from differt.em import fresnel_coefficients
|
|
157
157
|
>>>
|
|
158
|
-
>>> n = 1 / 1.5
|
|
158
|
+
>>> n = 1 / 1.5 # Glass to air
|
|
159
159
|
>>> theta = jnp.linspace(0, jnp.pi / 2, 300)
|
|
160
160
|
>>> cos_theta = jnp.cos(theta)
|
|
161
|
-
>>> (r_s, r_p), (t_s, t_p) =
|
|
161
|
+
>>> (r_s, r_p), (t_s, t_p) = jax.tree.map(
|
|
162
|
+
... lambda x: jnp.where(jnp.imag(x) == 0, jnp.real(x), jnp.inf),
|
|
163
|
+
... fresnel_coefficients(n, cos_theta)
|
|
164
|
+
... ) # Here Fresnel coefficients are purely real numbers before
|
|
165
|
+
... # the critical angle. After the critical angle, they become complex.
|
|
162
166
|
>>> theta_d = jnp.rad2deg(theta)
|
|
163
167
|
>>> theta_b = jnp.rad2deg(jnp.arctan(n))
|
|
164
168
|
>>> theta_c = jnp.rad2deg(jnp.arcsin(n))
|
|
@@ -176,11 +180,17 @@ def fresnel_coefficients(
|
|
|
176
180
|
>>> plt.legend() # doctest: +SKIP
|
|
177
181
|
>>> plt.tight_layout() # doctest: +SKIP
|
|
178
182
|
"""
|
|
179
|
-
|
|
183
|
+
# Fresnel coefficients are only defined for theta in [-pi/2, pi/2]
|
|
184
|
+
cos_theta_i = jnp.abs(jnp.asarray(cos_theta_i))
|
|
180
185
|
n_r_squared = jax.lax.integer_pow(n_r, 2)
|
|
181
186
|
cos_theta_i_squared = jax.lax.integer_pow(cos_theta_i, 2)
|
|
182
187
|
n_r_squared_cos_theta_i = n_r_squared * cos_theta_i
|
|
183
|
-
|
|
188
|
+
dtype = jnp.result_type(n_r, cos_theta_i)
|
|
189
|
+
n_r_cos_theta_t = jnp.sqrt(
|
|
190
|
+
(n_r_squared + cos_theta_i_squared - 1).astype(
|
|
191
|
+
jnp.complex128 if dtype == jnp.float64 else jnp.complex64
|
|
192
|
+
)
|
|
193
|
+
)
|
|
184
194
|
two_cos_theta_i = 2 * cos_theta_i
|
|
185
195
|
|
|
186
196
|
r_s = safe_divide(
|
|
@@ -207,7 +217,7 @@ def fresnel_coefficients(
|
|
|
207
217
|
def reflection_coefficients(
|
|
208
218
|
n_r: Inexact[ArrayLike, " *#batch"],
|
|
209
219
|
cos_theta_i: Float[ArrayLike, " *#batch"],
|
|
210
|
-
) -> tuple[
|
|
220
|
+
) -> tuple[Complex[Array, " *batch"], Complex[Array, " *batch"]]:
|
|
211
221
|
r"""
|
|
212
222
|
Compute the Fresnel reflection coefficients at an interface.
|
|
213
223
|
|
|
@@ -221,9 +231,6 @@ def reflection_coefficients(
|
|
|
221
231
|
Returns:
|
|
222
232
|
The reflection coefficients for s and p polarizations.
|
|
223
233
|
|
|
224
|
-
The output dtype will only be complex if any of the provided arguments
|
|
225
|
-
has a complex dtype.
|
|
226
|
-
|
|
227
234
|
.. seealso::
|
|
228
235
|
|
|
229
236
|
:func:`fresnel_coefficients`
|
|
@@ -243,8 +250,9 @@ def reflection_coefficients(
|
|
|
243
250
|
>>> from differt.em import (
|
|
244
251
|
... Dipole,
|
|
245
252
|
... c,
|
|
253
|
+
... z_0,
|
|
246
254
|
... fspl,
|
|
247
|
-
...
|
|
255
|
+
... poynting_vector,
|
|
248
256
|
... reflection_coefficients,
|
|
249
257
|
... sp_directions,
|
|
250
258
|
... )
|
|
@@ -296,7 +304,7 @@ def reflection_coefficients(
|
|
|
296
304
|
>>> # [num_positions 3]
|
|
297
305
|
>>> E_los, B_los = ant.fields(rx_positions - tx_position)
|
|
298
306
|
>>> # [num_positions]
|
|
299
|
-
>>> P_los = A_e * jnp.linalg.norm(
|
|
307
|
+
>>> P_los = A_e * jnp.linalg.norm(poynting_vector(E_los, B_los), axis=-1)
|
|
300
308
|
>>> plt.semilogx(
|
|
301
309
|
... x,
|
|
302
310
|
... 10 * jnp.log10(P_los / ant.reference_power),
|
|
@@ -385,7 +393,7 @@ def reflection_coefficients(
|
|
|
385
393
|
>>> phase_shift = jnp.exp(1j * s_r * ant.wavenumber)
|
|
386
394
|
>>> E_r *= spreading_factor * phase_shift
|
|
387
395
|
>>> B_r *= spreading_factor * phase_shift
|
|
388
|
-
>>> P_r = A_e * jnp.linalg.norm(
|
|
396
|
+
>>> P_r = A_e * jnp.linalg.norm(poynting_vector(E_r, B_r), axis=-1)
|
|
389
397
|
>>> plt.semilogx(
|
|
390
398
|
... x,
|
|
391
399
|
... 10 * jnp.log10(P_r / ant.reference_power),
|
|
@@ -397,7 +405,7 @@ def reflection_coefficients(
|
|
|
397
405
|
|
|
398
406
|
>>> E_tot = E_los + E_r
|
|
399
407
|
>>> B_tot = B_los + B_r
|
|
400
|
-
>>> P_tot = A_e * jnp.linalg.norm(
|
|
408
|
+
>>> P_tot = A_e * jnp.linalg.norm(poynting_vector(E_tot, B_tot), axis=-1)
|
|
401
409
|
>>> plt.semilogx(
|
|
402
410
|
... x,
|
|
403
411
|
... 10 * jnp.log10(P_tot / ant.reference_power),
|
|
@@ -421,6 +429,61 @@ def reflection_coefficients(
|
|
|
421
429
|
>>> distance = x[jnp.argmin(cos_distance)]
|
|
422
430
|
>>> print(f"Corresponding distance: {distance:.1f} m")
|
|
423
431
|
Corresponding distance: 6.0 m
|
|
432
|
+
|
|
433
|
+
Two common approximations are used when estimating the path loss, see :ref:`coherence`.
|
|
434
|
+
The first one is to assume that the wavefronts are planar, and the
|
|
435
|
+
second one is to assume that small-scale fading is negligible, or
|
|
436
|
+
incorrectly modeled, and that the received power can be computed
|
|
437
|
+
by non-coherent summation of each path.
|
|
438
|
+
|
|
439
|
+
.. plot::
|
|
440
|
+
:context: close-figs
|
|
441
|
+
|
|
442
|
+
>>> plt.semilogx(
|
|
443
|
+
... x,
|
|
444
|
+
... 10 * jnp.log10(P_tot / ant.reference_power),
|
|
445
|
+
... "-.",
|
|
446
|
+
... color="green",
|
|
447
|
+
... label="Exact",
|
|
448
|
+
... ) # doctest: +SKIP
|
|
449
|
+
>>> P_tot_pw = A_e * dot(E_tot, E_tot) / z_0
|
|
450
|
+
>>> plt.semilogx(
|
|
451
|
+
... x,
|
|
452
|
+
... 10 * jnp.log10(P_tot_pw / ant.reference_power),
|
|
453
|
+
... ":",
|
|
454
|
+
... color="red",
|
|
455
|
+
... label="Plane-wave",
|
|
456
|
+
... ) # doctest: +SKIP
|
|
457
|
+
>>> P_tot_nc = A_e * (
|
|
458
|
+
... jnp.linalg.norm( # Power from LOS path
|
|
459
|
+
... poynting_vector(E_los, B_los),
|
|
460
|
+
... axis=-1,
|
|
461
|
+
... )
|
|
462
|
+
... + jnp.linalg.norm( # Power from reflection path
|
|
463
|
+
... poynting_vector(E_r, B_r),
|
|
464
|
+
... axis=-1,
|
|
465
|
+
... )
|
|
466
|
+
... )
|
|
467
|
+
>>> plt.semilogx(
|
|
468
|
+
... x,
|
|
469
|
+
... 10 * jnp.log10(P_tot_nc / ant.reference_power),
|
|
470
|
+
... ":",
|
|
471
|
+
... color="purple",
|
|
472
|
+
... label="Non-coherent",
|
|
473
|
+
... ) # doctest: +SKIP
|
|
474
|
+
>>> plt.xlabel("Distance to transmitter on x-axis (m)") # doctest: +SKIP
|
|
475
|
+
>>> plt.ylabel("Gain (dB)") # doctest: +SKIP
|
|
476
|
+
>>> plt.legend() # doctest: +SKIP
|
|
477
|
+
>>> plt.tight_layout() # doctest: +SKIP
|
|
478
|
+
|
|
479
|
+
The plane-wave approximation is relatively good for large distances, but
|
|
480
|
+
it can be off by several dBs for short distances, as shown below.
|
|
481
|
+
|
|
482
|
+
.. plot::
|
|
483
|
+
:context:
|
|
484
|
+
|
|
485
|
+
>>> plt.xlim([1, 10]) # doctest: +SKIP
|
|
486
|
+
>>> plt.ylim([-65, -35]) # doctest: +SKIP
|
|
424
487
|
"""
|
|
425
488
|
return fresnel_coefficients(n_r, cos_theta_i)[0]
|
|
426
489
|
|
|
@@ -429,7 +492,7 @@ def reflection_coefficients(
|
|
|
429
492
|
def refraction_coefficients(
|
|
430
493
|
n_r: Inexact[ArrayLike, " *#batch"],
|
|
431
494
|
cos_theta_i: Float[ArrayLike, " *#batch"],
|
|
432
|
-
) -> tuple[
|
|
495
|
+
) -> tuple[Complex[Array, " *batch"], Complex[Array, " *batch"]]:
|
|
433
496
|
"""
|
|
434
497
|
Compute the Fresnel refraction coefficients at an interface.
|
|
435
498
|
|
|
@@ -443,9 +506,6 @@ def refraction_coefficients(
|
|
|
443
506
|
Returns:
|
|
444
507
|
The refraction coefficients for s and p polarizations.
|
|
445
508
|
|
|
446
|
-
The output dtype will only be complex if any of the provided arguments
|
|
447
|
-
has a complex dtype.
|
|
448
|
-
|
|
449
509
|
.. seealso::
|
|
450
510
|
|
|
451
511
|
:func:`fresnel_coefficients`
|
|
@@ -111,6 +111,27 @@ class Paths(eqx.Module):
|
|
|
111
111
|
|
|
112
112
|
If not specified, :attr:`InteractionType.REFLECTION<differt.em.InteractionType.REFLECTION>` is assumed.
|
|
113
113
|
"""
|
|
114
|
+
confidence: Float[Array, " *batch"] | None = eqx.field(
|
|
115
|
+
converter=lambda x: jnp.asarray(x) if x is not None else None, default=None
|
|
116
|
+
)
|
|
117
|
+
"""An optional array to indicate the confidence of each path.
|
|
118
|
+
|
|
119
|
+
The confidence value is between 0 and 1.
|
|
120
|
+
"""
|
|
121
|
+
confidence_threshold: Float[ArrayLike, " "] = 0.5
|
|
122
|
+
"""A threshold used to decide, e.g., when plotting, whether a given path is valid or not.
|
|
123
|
+
|
|
124
|
+
A path is considered valid if its confidence is greater than or equal to this threshold.
|
|
125
|
+
Unused if :attr:`confidence` is :data:`None`.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
def __post_init__(self) -> None:
|
|
129
|
+
if self.mask is not None and self.confidence is not None:
|
|
130
|
+
msg = (
|
|
131
|
+
"Setting both 'mask' and 'confidence' arguments "
|
|
132
|
+
"will result in 'confidence' being ignored."
|
|
133
|
+
)
|
|
134
|
+
warnings.warn(msg, UserWarning, stacklevel=2)
|
|
114
135
|
|
|
115
136
|
def reshape(self, *batch: int) -> Self:
|
|
116
137
|
"""
|
|
@@ -130,11 +151,20 @@ class Paths(eqx.Module):
|
|
|
130
151
|
if self.interaction_types is not None
|
|
131
152
|
else None
|
|
132
153
|
)
|
|
154
|
+
confidence = (
|
|
155
|
+
self.confidence.reshape(*batch) if self.confidence is not None else None
|
|
156
|
+
)
|
|
133
157
|
|
|
134
158
|
return eqx.tree_at(
|
|
135
|
-
lambda p: (
|
|
159
|
+
lambda p: (
|
|
160
|
+
p.vertices,
|
|
161
|
+
p.objects,
|
|
162
|
+
p.mask,
|
|
163
|
+
p.interaction_types,
|
|
164
|
+
p.confidence,
|
|
165
|
+
),
|
|
136
166
|
self,
|
|
137
|
-
(vertices, objects, mask, interaction_types),
|
|
167
|
+
(vertices, objects, mask, interaction_types, confidence),
|
|
138
168
|
is_leaf=lambda x: x is None,
|
|
139
169
|
)
|
|
140
170
|
|
|
@@ -173,11 +203,20 @@ class Paths(eqx.Module):
|
|
|
173
203
|
if self.interaction_types is not None
|
|
174
204
|
else None
|
|
175
205
|
)
|
|
206
|
+
confidence = (
|
|
207
|
+
self.confidence.squeeze(axis) if self.confidence is not None else None
|
|
208
|
+
)
|
|
176
209
|
|
|
177
210
|
return eqx.tree_at(
|
|
178
|
-
lambda p: (
|
|
211
|
+
lambda p: (
|
|
212
|
+
p.vertices,
|
|
213
|
+
p.objects,
|
|
214
|
+
p.mask,
|
|
215
|
+
p.interaction_types,
|
|
216
|
+
p.confidence,
|
|
217
|
+
),
|
|
179
218
|
self,
|
|
180
|
-
(vertices, objects, mask, interaction_types),
|
|
219
|
+
(vertices, objects, mask, interaction_types, confidence),
|
|
181
220
|
is_leaf=lambda x: x is None,
|
|
182
221
|
)
|
|
183
222
|
|
|
@@ -231,6 +270,8 @@ class Paths(eqx.Module):
|
|
|
231
270
|
for _ in range(max(ndim - 1, 0)):
|
|
232
271
|
f = jax.vmap(f)
|
|
233
272
|
|
|
273
|
+
# TODO: mask the 'confidence' attribute too
|
|
274
|
+
|
|
234
275
|
mask = f(objects)
|
|
235
276
|
mask = jnp.moveaxis(mask, -1, axis)
|
|
236
277
|
mask = mask & self.mask if self.mask is not None else mask
|
|
@@ -260,6 +301,8 @@ class Paths(eqx.Module):
|
|
|
260
301
|
"""
|
|
261
302
|
if self.mask is not None:
|
|
262
303
|
return self.mask.sum()
|
|
304
|
+
if self.confidence is not None:
|
|
305
|
+
return (self.confidence >= self.confidence_threshold).sum()
|
|
263
306
|
return self.objects[..., 0].size
|
|
264
307
|
|
|
265
308
|
@property
|
|
@@ -275,6 +318,9 @@ class Paths(eqx.Module):
|
|
|
275
318
|
if self.mask is not None:
|
|
276
319
|
mask = self.mask.reshape(-1)
|
|
277
320
|
return vertices[mask, ...]
|
|
321
|
+
if self.confidence is not None:
|
|
322
|
+
mask = self.confidence.reshape(-1) >= self.confidence_threshold
|
|
323
|
+
return vertices[mask, ...]
|
|
278
324
|
return vertices
|
|
279
325
|
|
|
280
326
|
@property
|
|
@@ -289,6 +335,9 @@ class Paths(eqx.Module):
|
|
|
289
335
|
if self.mask is not None:
|
|
290
336
|
mask = self.mask.reshape(-1)
|
|
291
337
|
return objects[mask, ...]
|
|
338
|
+
if self.confidence is not None:
|
|
339
|
+
mask = self.confidence.reshape(-1) >= self.confidence_threshold
|
|
340
|
+
return objects[mask, ...]
|
|
292
341
|
return objects
|
|
293
342
|
|
|
294
343
|
@eqx.filter_jit
|
|
@@ -334,11 +383,14 @@ class Paths(eqx.Module):
|
|
|
334
383
|
Raises:
|
|
335
384
|
ValueError: If :attr:`mask` is None.
|
|
336
385
|
"""
|
|
337
|
-
if self.mask is None:
|
|
338
|
-
msg = "Cannot create multiplath cells from non-existing mask!"
|
|
386
|
+
if self.mask is None and self.confidence is None:
|
|
387
|
+
msg = "Cannot create multiplath cells from non-existing mask (or confidence matrix)!"
|
|
339
388
|
raise ValueError(msg)
|
|
340
389
|
|
|
341
|
-
|
|
390
|
+
if self.mask is not None:
|
|
391
|
+
mask = jnp.moveaxis(self.mask, axis, -1)
|
|
392
|
+
else:
|
|
393
|
+
mask = jnp.moveaxis(self.confidence >= self.confidence_threshold, axis, -1)
|
|
342
394
|
*partial_batch, last_axis = mask.shape
|
|
343
395
|
|
|
344
396
|
return _cell_ids(mask.reshape(-1, last_axis)).reshape(partial_batch)
|
|
@@ -427,6 +479,9 @@ class Paths(eqx.Module):
|
|
|
427
479
|
The sum of the results, with contributions from
|
|
428
480
|
invalid paths that are set to zero.
|
|
429
481
|
"""
|
|
482
|
+
if self.mask is None and self.confidence is not None:
|
|
483
|
+
return jnp.sum(fun(self.vertices) * self.confidence, axis=axis)
|
|
484
|
+
|
|
430
485
|
return jnp.sum(fun(self.vertices), axis=axis, where=self.mask)
|
|
431
486
|
|
|
432
487
|
def plot(self, **kwargs: Any) -> PlotOutput:
|