differt 0.0.10__tar.gz → 0.0.11__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.11/.gitignore +22 -0
- differt-0.0.11/LICENSE.md +1 -0
- {DiffeRT-0.0.10 → differt-0.0.11}/PKG-INFO +68 -61
- differt-0.0.11/differt/em/__init__.py +1 -0
- differt-0.0.11/differt/em/constants.py +12 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/em/special.py +21 -47
- differt-0.0.11/differt/em/utils.py +83 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/geometry/triangle_mesh.py +40 -4
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/geometry/utils.py +40 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/plotting/__init__.py +8 -4
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/plotting/_core.py +1 -1
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/plotting/_utils.py +124 -19
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/rt/image_method.py +1 -1
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/rt/utils.py +21 -14
- differt-0.0.11/differt/scene/sionna.py +141 -0
- differt-0.0.11/differt/scene/triangle_scene.py +112 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/version.py +1 -1
- differt-0.0.11/pyproject.toml +85 -0
- DiffeRT-0.0.10/Cargo.lock +0 -1193
- DiffeRT-0.0.10/Cargo.toml +0 -38
- DiffeRT-0.0.10/LICENSE.md +0 -21
- DiffeRT-0.0.10/README.md +0 -108
- DiffeRT-0.0.10/ROADMAP.md +0 -46
- DiffeRT-0.0.10/pdm.lock +0 -3659
- DiffeRT-0.0.10/pyproject.toml +0 -167
- DiffeRT-0.0.10/python/differt/_core/__init__.pyi +0 -5
- DiffeRT-0.0.10/python/differt/_core/geometry/__init__.pyi +0 -3
- DiffeRT-0.0.10/python/differt/_core/geometry/triangle_mesh.pyi +0 -9
- DiffeRT-0.0.10/python/differt/_core/rt/__init__.pyi +0 -3
- DiffeRT-0.0.10/python/differt/_core/rt/graph.pyi +0 -66
- DiffeRT-0.0.10/python/differt/_core/rt/utils.pyi +0 -21
- DiffeRT-0.0.10/python/differt/em/__init__.py +0 -1
- DiffeRT-0.0.10/python/differt/py.typed +0 -0
- DiffeRT-0.0.10/python/differt/rt/graph.py +0 -27
- DiffeRT-0.0.10/python/differt/scene/scene.py +0 -1
- DiffeRT-0.0.10/src/geometry/mod.rs +0 -9
- DiffeRT-0.0.10/src/geometry/triangle_mesh.rs +0 -112
- DiffeRT-0.0.10/src/lib.rs +0 -15
- DiffeRT-0.0.10/src/rt/graph.rs +0 -1129
- DiffeRT-0.0.10/src/rt/mod.rs +0 -13
- DiffeRT-0.0.10/src/rt/utils.rs +0 -62
- DiffeRT-0.0.10/static/favicon.png +0 -0
- DiffeRT-0.0.10/static/logo.svg +0 -113
- DiffeRT-0.0.10/static/logo_250px.png +0 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/__init__.py +0 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/em/utd.py +0 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/geometry/__init__.py +0 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/rt/__init__.py +0 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/rt/fermat.py +0 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/scene/__init__.py +0 -0
- {DiffeRT-0.0.10/python → differt-0.0.11}/differt/utils.py +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Python build files and cache
|
|
2
|
+
|
|
3
|
+
*.pyc
|
|
4
|
+
*.so
|
|
5
|
+
*.egg-info
|
|
6
|
+
|
|
7
|
+
dist/
|
|
8
|
+
target/
|
|
9
|
+
|
|
10
|
+
# Docs
|
|
11
|
+
|
|
12
|
+
docs/build/
|
|
13
|
+
docs/source/reference/*.rst
|
|
14
|
+
|
|
15
|
+
# Sionna data
|
|
16
|
+
differt/src/differt/scene/scenes/
|
|
17
|
+
|
|
18
|
+
# Notebooks
|
|
19
|
+
|
|
20
|
+
.ipynb_checkpoints/
|
|
21
|
+
|
|
22
|
+
# Tools
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
../LICENSE.md
|
|
@@ -1,64 +1,56 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.11
|
|
4
|
+
Summary: Differentiable Ray Tracing Toolbox for Radio Propagation Simulations
|
|
5
|
+
Project-URL: Changelog, https://github.com/jeertmans/DiffeRT/releases
|
|
6
|
+
Project-URL: Documentation, https://eertmans.be/DiffeRT
|
|
7
|
+
Project-URL: Founding, https://github.com/sponsors/jeertmans
|
|
8
|
+
Project-URL: Homepage, https://github.com/jeertmans/DiffeRT
|
|
9
|
+
Project-URL: Repository, https://github.com/jeertmans/DiffeRT
|
|
10
|
+
Author-email: Jérome Eertmans <jeertmans@icloud.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE.md
|
|
13
|
+
Keywords: differentiable,jax,propagation,radio,ray tracing
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
4
16
|
Classifier: Programming Language :: Python :: 3
|
|
5
17
|
Classifier: Programming Language :: Python :: 3.9
|
|
6
18
|
Classifier: Programming Language :: Python :: 3.10
|
|
7
19
|
Classifier: Programming Language :: Python :: 3.11
|
|
8
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
21
|
Classifier: Topic :: Scientific/Engineering
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Requires-Dist:
|
|
16
|
-
Requires-Dist:
|
|
17
|
-
Requires-Dist:
|
|
18
|
-
Requires-Dist:
|
|
19
|
-
Requires-Dist:
|
|
20
|
-
Requires-Dist:
|
|
21
|
-
Requires-Dist:
|
|
22
|
-
Requires-Dist:
|
|
23
|
-
Requires-Dist: differt[all] ; extra == 'docs'
|
|
24
|
-
Requires-Dist: myst-nb >=0.17.2 ; extra == 'docs'
|
|
25
|
-
Requires-Dist: pillow >=10.1.0 ; extra == 'docs'
|
|
26
|
-
Requires-Dist: sphinx >=6 ; extra == 'docs'
|
|
27
|
-
Requires-Dist: sphinx-autodoc-typehints >=1.23 ; extra == 'docs'
|
|
28
|
-
Requires-Dist: sphinx-book-theme >=1.0.1 ; extra == 'docs'
|
|
29
|
-
Requires-Dist: sphinx-copybutton >=0.5.2 ; extra == 'docs'
|
|
30
|
-
Requires-Dist: sphinx-design >=0.5.0 ; extra == 'docs'
|
|
31
|
-
Requires-Dist: sphinx-remove-toctrees >=0.0.3 ; extra == 'docs'
|
|
32
|
-
Requires-Dist: sphinxext-opengraph >=0.9.0 ; extra == 'docs'
|
|
33
|
-
Requires-Dist: sphinxcontrib-apidoc >=0.4.0 ; extra == 'docs'
|
|
34
|
-
Requires-Dist: sphinxcontrib-bibtex >=2.6.0 ; extra == 'docs'
|
|
35
|
-
Requires-Dist: tqdm >=4.66.2 ; extra == 'docs'
|
|
36
|
-
Requires-Dist: sphinx-plotly-directive >=0.1.3 ; extra == 'docs'
|
|
37
|
-
Requires-Dist: notebook >=7 ; extra == 'jupyter'
|
|
38
|
-
Requires-Dist: jupyter-rfb >=0.4.2 ; extra == 'jupyter'
|
|
39
|
-
Requires-Dist: ipympl ; extra == 'jupyter'
|
|
40
|
-
Requires-Dist: matplotlib >=3.8.1 ; extra == 'maplotlib'
|
|
41
|
-
Requires-Dist: plotly >=5.18.0 ; extra == 'plotly'
|
|
42
|
-
Requires-Dist: vispy >=0.14.1 ; extra == 'vispy'
|
|
43
|
-
Requires-Dist: pyqt6 >=6.6.1 ; extra == 'vispy-backend'
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Requires-Dist: beartype>=0.17.2
|
|
24
|
+
Requires-Dist: differt-core==0.0.11
|
|
25
|
+
Requires-Dist: equinox>=0.11.2
|
|
26
|
+
Requires-Dist: jax>=0.4.20
|
|
27
|
+
Requires-Dist: jaxtyping>=0.2.24
|
|
28
|
+
Requires-Dist: numpy>=1.26.1
|
|
29
|
+
Requires-Dist: optax>=0.1.7
|
|
30
|
+
Requires-Dist: requests>=2.31.0
|
|
31
|
+
Requires-Dist: tqdm>=4.66.2
|
|
32
|
+
Requires-Dist: typing-extensions>=4.9.0; python_version < '3.11'
|
|
44
33
|
Provides-Extra: all
|
|
45
|
-
|
|
34
|
+
Requires-Dist: ipympl; extra == 'all'
|
|
35
|
+
Requires-Dist: jupyter-rfb>=0.4.2; extra == 'all'
|
|
36
|
+
Requires-Dist: matplotlib>=3.8.1; extra == 'all'
|
|
37
|
+
Requires-Dist: notebook>=7; extra == 'all'
|
|
38
|
+
Requires-Dist: plotly>=5.18.0; extra == 'all'
|
|
39
|
+
Requires-Dist: pyqt6>=6.6.1; extra == 'all'
|
|
40
|
+
Requires-Dist: vispy>=0.14.1; extra == 'all'
|
|
46
41
|
Provides-Extra: jupyter
|
|
47
|
-
|
|
42
|
+
Requires-Dist: ipympl; extra == 'jupyter'
|
|
43
|
+
Requires-Dist: jupyter-rfb>=0.4.2; extra == 'jupyter'
|
|
44
|
+
Requires-Dist: notebook>=7; extra == 'jupyter'
|
|
45
|
+
Provides-Extra: matplotlib
|
|
46
|
+
Requires-Dist: matplotlib>=3.8.1; extra == 'matplotlib'
|
|
48
47
|
Provides-Extra: plotly
|
|
48
|
+
Requires-Dist: plotly>=5.18.0; extra == 'plotly'
|
|
49
49
|
Provides-Extra: vispy
|
|
50
|
+
Requires-Dist: vispy>=0.14.1; extra == 'vispy'
|
|
50
51
|
Provides-Extra: vispy-backend
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
Keywords: ray tracing,differentiable,propagation,radio,jax
|
|
54
|
-
Author-email: Jérome Eertmans <jeertmans@icloud.com>
|
|
55
|
-
Requires-Python: >=3.9
|
|
56
|
-
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
57
|
-
Project-URL: Changelog, https://github.com/jeertmans/DiffeRT/releases
|
|
58
|
-
Project-URL: Documentation, https://eertmans.be/DiffeRT
|
|
59
|
-
Project-URL: Founding, https://github.com/sponsors/jeertmans
|
|
60
|
-
Project-URL: Homepage, https://github.com/jeertmans/DiffeRT
|
|
61
|
-
Project-URL: Repository, https://github.com/jeertmans/DiffeRT
|
|
52
|
+
Requires-Dist: pyqt6>=6.6.1; extra == 'vispy-backend'
|
|
53
|
+
Description-Content-Type: text/markdown
|
|
62
54
|
|
|
63
55
|
<div align="center">
|
|
64
56
|
<img src="https://raw.githubusercontent.com/jeertmans/DiffeRT/main/static/logo_250px.png" alt="DiffeRT logo"></img>
|
|
@@ -72,13 +64,12 @@ Project-URL: Repository, https://github.com/jeertmans/DiffeRT
|
|
|
72
64
|
[![Python version][pypi-python-version-badge]][pypi-version-url]
|
|
73
65
|
[![Documentation][documentation-badge]][documentation-url]
|
|
74
66
|
[![Codecov][codecov-badge]][codecov-url]
|
|
75
|
-
[![PDM][pdm-badge]][pdm-url]
|
|
76
67
|
|
|
77
68
|
</div>
|
|
78
69
|
|
|
79
70
|
## Usage
|
|
80
71
|
|
|
81
|
-
>
|
|
72
|
+
> **WARNING:**
|
|
82
73
|
> Until this package reaches version `0.1.x`, breaking changes
|
|
83
74
|
> should be expected. Checkout the [ROADMAP](./ROADMAP.md) for
|
|
84
75
|
> future features.
|
|
@@ -86,9 +77,19 @@ Project-URL: Repository, https://github.com/jeertmans/DiffeRT
|
|
|
86
77
|
> If you have any suggestion regarding the development of this package,
|
|
87
78
|
> please open an [issue](https://github.com/jeertmans/DiffeRT/issues).
|
|
88
79
|
|
|
80
|
+
The easiest way to install DiffeRT is through pip:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install differt
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
We provide pre-built binaries for most platforms. If you want (or need)
|
|
87
|
+
to build the package from the source distribution, check out the
|
|
88
|
+
requirements below.
|
|
89
|
+
|
|
89
90
|
## Contributing
|
|
90
91
|
|
|
91
|
-
>
|
|
92
|
+
> **IMPORTANT:**
|
|
92
93
|
> The current documentation is very light and a more complete guide for
|
|
93
94
|
> new contributors will be written in the near future.
|
|
94
95
|
>
|
|
@@ -105,15 +106,24 @@ To run build this package locally, you need:
|
|
|
105
106
|
|
|
106
107
|
- [Python 3.9](https://www.python.org/) or above;
|
|
107
108
|
- [Rust](https://www.rust-lang.org/) stable toolchain;
|
|
109
|
+
- `make` (e.g., GNU Make or Make for Windows);
|
|
108
110
|
- [Maturin](https://www.maturin.rs/) for building Python bindings from Rust code;
|
|
109
|
-
- and [
|
|
111
|
+
- and [Rye](https://rye-up.com/) to manage this project.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
## Local development
|
|
110
115
|
|
|
111
|
-
|
|
116
|
+
The following commands assume that you installed
|
|
117
|
+
the project locally with:
|
|
112
118
|
|
|
113
|
-
|
|
119
|
+
```bash
|
|
120
|
+
rye sync
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
and that you activate the corresponding Python virtual environment:
|
|
114
124
|
|
|
115
125
|
```bash
|
|
116
|
-
|
|
126
|
+
. .venv/bin/activate # or .venv\Scripts\activate on Windows
|
|
117
127
|
```
|
|
118
128
|
|
|
119
129
|
### Documentation
|
|
@@ -122,7 +132,7 @@ To generate the documentation, please run the following:
|
|
|
122
132
|
|
|
123
133
|
```bash
|
|
124
134
|
cd docs
|
|
125
|
-
|
|
135
|
+
make html
|
|
126
136
|
```
|
|
127
137
|
|
|
128
138
|
Finally, you can open `build/html/index.html` to see the generated docs.
|
|
@@ -150,13 +160,13 @@ cargo bench
|
|
|
150
160
|
in the same way, you can very test you code with Pytest:
|
|
151
161
|
|
|
152
162
|
```bash
|
|
153
|
-
|
|
163
|
+
pytest
|
|
154
164
|
```
|
|
155
165
|
|
|
156
166
|
or benchmark it:
|
|
157
167
|
|
|
158
168
|
```bash
|
|
159
|
-
|
|
169
|
+
pytest --benchmark-only
|
|
160
170
|
```
|
|
161
171
|
|
|
162
172
|
[pypi-version-badge]: https://img.shields.io/pypi/v/DiffeRT?label=DiffeRT&color=blueviolet
|
|
@@ -166,6 +176,3 @@ pdm run pytest --benchmark-only
|
|
|
166
176
|
[documentation-url]: https://differt.readthedocs.io/latest/?badge=latest
|
|
167
177
|
[codecov-badge]: https://codecov.io/gh/jeertmans/DiffeRT/branch/main/graph/badge.svg?token=8P4DY9JCE4
|
|
168
178
|
[codecov-url]: https://codecov.io/gh/jeertmans/DiffeRT
|
|
169
|
-
[pdm-badge]: https://img.shields.io/badge/pdm-managed-blueviolet
|
|
170
|
-
[pdm-url]: https://pdm-project.org
|
|
171
|
-
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Electromagnetic fields utilities."""
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Physical constants used for EM fields computation."""
|
|
2
|
+
|
|
3
|
+
__all__ = ("c", "mu_0", "epsilon_0")
|
|
4
|
+
|
|
5
|
+
c = 299792458.0
|
|
6
|
+
"""The speed of light in vacuum."""
|
|
7
|
+
|
|
8
|
+
mu_0 = 1.25663706212e-06
|
|
9
|
+
r"""The vacuum permeability :math:`\mu_0`."""
|
|
10
|
+
|
|
11
|
+
epsilon_0 = 8.8541878128e-12
|
|
12
|
+
r"""The vacuum permittivity :math:`\epsilon_0`."""
|
|
@@ -52,10 +52,13 @@ def erf(z: Inexact[Array, " *batch"]) -> Inexact[Array, " *batch"]:
|
|
|
52
52
|
have the same performances (when JIT compilation
|
|
53
53
|
is done). Compared to the SciPy equivalent, we measured
|
|
54
54
|
that our implementation is **~ 10 times faster**.
|
|
55
|
-
2. If ``z`` is complex, then our implementation is
|
|
56
|
-
|
|
55
|
+
2. If ``z`` is complex, then our implementation is
|
|
56
|
+
**~ 3 times faster** than
|
|
57
57
|
:py:data:`scipy.special.erf`.
|
|
58
58
|
|
|
59
|
+
Those results were measured on centered random uniform arrays
|
|
60
|
+
with :math:`10^5` elements.
|
|
61
|
+
|
|
59
62
|
Examples:
|
|
60
63
|
The following plots the error function for real-valued inputs.
|
|
61
64
|
|
|
@@ -118,57 +121,28 @@ def erf(z: Inexact[Array, " *batch"]) -> Inexact[Array, " *batch"]:
|
|
|
118
121
|
exp_r_squared = jnp.exp(-r_squared)
|
|
119
122
|
exp_2j_r_i = jnp.exp(-2j * r * i)
|
|
120
123
|
|
|
121
|
-
|
|
124
|
+
f_sum = jnp.zeros_like(z)
|
|
125
|
+
g_sum = jnp.zeros_like(z)
|
|
126
|
+
h_sum = jnp.zeros_like(z)
|
|
127
|
+
|
|
128
|
+
for n in range(1, N + 1):
|
|
122
129
|
n_squared = n * n
|
|
123
130
|
n_squared_over_four = n_squared / 4
|
|
124
|
-
|
|
131
|
+
den = 1 / (n_squared_over_four + r_squared)
|
|
132
|
+
exp_f = jnp.exp(-n_squared_over_four)
|
|
133
|
+
exp_g = jnp.exp(+n * i - n_squared_over_four)
|
|
134
|
+
exp_h = jnp.exp(-n * i - n_squared_over_four)
|
|
125
135
|
|
|
126
|
-
|
|
136
|
+
f_sum += exp_f * den
|
|
137
|
+
g_sum += exp_g * (r - 1j * n / 2) * den
|
|
138
|
+
h_sum += exp_h * (r + 1j * n / 2) * den
|
|
127
139
|
|
|
128
|
-
|
|
140
|
+
for n in range(N + 1, N + M + 1):
|
|
129
141
|
n_squared = n * n
|
|
130
142
|
n_squared_over_four = n_squared / 4
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
- r_squared
|
|
135
|
-
- jnp.log(2 * jnp.pi)
|
|
136
|
-
- jnp.log(n_squared_over_four + r_squared)
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
# return carrying_sum + exp * (r - 1j * n / 2), None
|
|
140
|
-
exp = jnp.exp(+n * i - n_squared_over_four)
|
|
141
|
-
|
|
142
|
-
return carrying_sum + exp * (r - 1j * n / 2) / (
|
|
143
|
-
n_squared_over_four + r_squared
|
|
144
|
-
), None
|
|
145
|
-
|
|
146
|
-
def h_scan(carrying_sum, n):
|
|
147
|
-
n_squared = n * n
|
|
148
|
-
n_squared_over_four = n_squared / 4
|
|
149
|
-
exp = jnp.exp(-n * i - n_squared_over_four)
|
|
150
|
-
|
|
151
|
-
return carrying_sum + exp * (r + 1j * n / 2) / (
|
|
152
|
-
n_squared_over_four + r_squared
|
|
153
|
-
), None
|
|
154
|
-
|
|
155
|
-
f_sum = jax.lax.scan(
|
|
156
|
-
f_scan,
|
|
157
|
-
init=jnp.zeros_like(z),
|
|
158
|
-
xs=jnp.arange(1.0, N + 1.0, dtype=z.dtype),
|
|
159
|
-
)[0]
|
|
160
|
-
|
|
161
|
-
g_sum = jax.lax.scan(
|
|
162
|
-
g_scan,
|
|
163
|
-
init=jnp.zeros_like(z),
|
|
164
|
-
xs=jnp.arange(1.0, N + M + 1.0, dtype=z.dtype),
|
|
165
|
-
)[0]
|
|
166
|
-
|
|
167
|
-
h_sum = jax.lax.scan(
|
|
168
|
-
h_scan,
|
|
169
|
-
init=jnp.zeros_like(z),
|
|
170
|
-
xs=jnp.arange(1.0, N + 1.0, dtype=z.dtype),
|
|
171
|
-
)[0]
|
|
143
|
+
exp_g = jnp.exp(+n * i - n_squared_over_four)
|
|
144
|
+
|
|
145
|
+
g_sum += exp_g * (r - 1j * n / 2) / (n_squared_over_four + r_squared)
|
|
172
146
|
|
|
173
147
|
r_non_zero = jnp.where(r == 0.0, 1.0, r)
|
|
174
148
|
e = jnp.where(
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Utilities for working with EM fields."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Union
|
|
4
|
+
|
|
5
|
+
import jax
|
|
6
|
+
from beartype import beartype as typechecker
|
|
7
|
+
from jaxtyping import Array, Float, jaxtyped
|
|
8
|
+
|
|
9
|
+
from ..geometry.utils import path_lengths
|
|
10
|
+
from .constants import c
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@jax.jit
|
|
14
|
+
@jaxtyped(typechecker=typechecker)
|
|
15
|
+
def lengths_to_delays(
|
|
16
|
+
lengths: Float[Array, " *#batch"],
|
|
17
|
+
speed: Union[float, Float[Array, " *#batch"]] = c,
|
|
18
|
+
) -> Float[Array, " *#batch"]:
|
|
19
|
+
"""
|
|
20
|
+
Compute the delay, in seconds, corresponding to each length.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
lengths: The array of lengths (in meters).
|
|
24
|
+
speed: The speed (in meters per second)
|
|
25
|
+
used to compute the delay. This can be
|
|
26
|
+
an array of speeds. Default is the speed
|
|
27
|
+
of light in vacuum.
|
|
28
|
+
|
|
29
|
+
Return:
|
|
30
|
+
The array of path delays.
|
|
31
|
+
|
|
32
|
+
Examples:
|
|
33
|
+
The following example shows how to compute a delay from a length.
|
|
34
|
+
|
|
35
|
+
>>> from differt.em.constants import c
|
|
36
|
+
>>> from differt.em.utils import (
|
|
37
|
+
... lengths_to_delays,
|
|
38
|
+
... )
|
|
39
|
+
>>>
|
|
40
|
+
>>> lengths = jnp.array([1.0, 2.0, 4.0])
|
|
41
|
+
>>> lengths_to_delays(lengths) * c
|
|
42
|
+
Array([1., 2., 4.], dtype=float32)
|
|
43
|
+
>>> lengths_to_delays(lengths, speed=2.0)
|
|
44
|
+
Array([0.5, 1. , 2. ], dtype=float32)
|
|
45
|
+
"""
|
|
46
|
+
return lengths / speed
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@jax.jit
|
|
50
|
+
@jaxtyped(typechecker=typechecker)
|
|
51
|
+
def path_delays(
|
|
52
|
+
paths: Float[Array, "*batch path_length 3"], **kwargs: Any
|
|
53
|
+
) -> Float[Array, " *batch"]:
|
|
54
|
+
"""
|
|
55
|
+
Compute the path delay, in seconds, of each path.
|
|
56
|
+
|
|
57
|
+
Each path is exactly made of ``path_length`` vertices.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
paths: The array of path vertices.
|
|
61
|
+
kwargs: Keyword arguments passed to
|
|
62
|
+
:func:`lengths_to_delays`.
|
|
63
|
+
|
|
64
|
+
Return:
|
|
65
|
+
The array of path delays.
|
|
66
|
+
|
|
67
|
+
Examples:
|
|
68
|
+
The following example shows how to compute the delay of a very simple path.
|
|
69
|
+
|
|
70
|
+
>>> from differt.em.constants import c
|
|
71
|
+
>>> from differt.em.utils import (
|
|
72
|
+
... path_delays,
|
|
73
|
+
... )
|
|
74
|
+
>>>
|
|
75
|
+
>>> path = jnp.array([[1.0, 0.0, 0.0], [1.0, 1.0, 0.0]])
|
|
76
|
+
>>> path_delays(path) * c
|
|
77
|
+
Array(1., dtype=float32)
|
|
78
|
+
>>> path_delays(path, speed=2.0)
|
|
79
|
+
Array(0.5, dtype=float32)
|
|
80
|
+
"""
|
|
81
|
+
lengths = path_lengths(paths)
|
|
82
|
+
|
|
83
|
+
return lengths_to_delays(lengths, **kwargs)
|
|
@@ -9,7 +9,8 @@ import numpy as np
|
|
|
9
9
|
from beartype import beartype as typechecker
|
|
10
10
|
from jaxtyping import Array, Bool, Float, UInt, jaxtyped
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
import differt_core.geometry.triangle_mesh
|
|
13
|
+
|
|
13
14
|
from ..plotting import draw_mesh
|
|
14
15
|
from ..rt.utils import rays_intersect_triangles
|
|
15
16
|
from .utils import normalize
|
|
@@ -133,6 +134,23 @@ class TriangleMesh(eqx.Module):
|
|
|
133
134
|
"""The diffraction edges."""
|
|
134
135
|
raise NotImplementedError
|
|
135
136
|
|
|
137
|
+
@classmethod
|
|
138
|
+
def empty(cls) -> "TriangleMesh":
|
|
139
|
+
"""
|
|
140
|
+
Create an empty scene.
|
|
141
|
+
|
|
142
|
+
Return:
|
|
143
|
+
A new empty scene.
|
|
144
|
+
"""
|
|
145
|
+
return cls(
|
|
146
|
+
vertices=jnp.empty((0, 3)), triangles=jnp.empty((0, 3), dtype=jnp.uint32)
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def is_empty(self) -> bool:
|
|
151
|
+
"""Whether this scene has no triangle."""
|
|
152
|
+
return self.triangles.size == 0
|
|
153
|
+
|
|
136
154
|
@classmethod
|
|
137
155
|
def load_obj(cls, file: str) -> "TriangleMesh":
|
|
138
156
|
"""
|
|
@@ -141,15 +159,33 @@ class TriangleMesh(eqx.Module):
|
|
|
141
159
|
Currently, only vertices and triangles are loaded. Triangle normals
|
|
142
160
|
are computed afterward (when first accessed).
|
|
143
161
|
|
|
144
|
-
This method will fail if it contains any geometry that is not a triangle.
|
|
145
|
-
|
|
146
162
|
Args:
|
|
147
163
|
file: The path to the Wavefront .obj file.
|
|
148
164
|
|
|
149
165
|
Return:
|
|
150
166
|
The corresponding mesh containing only triangles.
|
|
151
167
|
"""
|
|
152
|
-
mesh =
|
|
168
|
+
mesh = differt_core.geometry.triangle_mesh.TriangleMesh.load_obj(file)
|
|
169
|
+
return cls(
|
|
170
|
+
vertices=mesh.vertices,
|
|
171
|
+
triangles=mesh.triangles,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
@classmethod
|
|
175
|
+
def load_ply(cls, file: str) -> "TriangleMesh":
|
|
176
|
+
"""
|
|
177
|
+
Load a triangle mesh from a Stanford PLY .ply file.
|
|
178
|
+
|
|
179
|
+
Currently, only vertices and triangles are loaded. Triangle normals
|
|
180
|
+
are computed afterward (when first accessed).
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
file: The path to the Stanford PLY .ply file.
|
|
184
|
+
|
|
185
|
+
Return:
|
|
186
|
+
The corresponding mesh containing only triangles.
|
|
187
|
+
"""
|
|
188
|
+
mesh = differt_core.geometry.triangle_mesh.TriangleMesh.load_ply(file)
|
|
153
189
|
return cls(
|
|
154
190
|
vertices=mesh.vertices,
|
|
155
191
|
triangles=mesh.triangles,
|
|
@@ -44,6 +44,9 @@ def normalize(
|
|
|
44
44
|
The normalized vector and their length.
|
|
45
45
|
|
|
46
46
|
Examples:
|
|
47
|
+
The following examples shows how normalization works and
|
|
48
|
+
its special behavior at zero.
|
|
49
|
+
|
|
47
50
|
>>> from differt.geometry.utils import (
|
|
48
51
|
... normalize,
|
|
49
52
|
... )
|
|
@@ -84,6 +87,8 @@ def orthogonal_basis(
|
|
|
84
87
|
A pair of unit vectors, ``v`` and ``w``.
|
|
85
88
|
|
|
86
89
|
Examples:
|
|
90
|
+
The following example shows how this function works on basic input vectors.
|
|
91
|
+
|
|
87
92
|
>>> from differt.geometry.utils import (
|
|
88
93
|
... normalize,
|
|
89
94
|
... orthogonal_basis,
|
|
@@ -106,3 +111,38 @@ def orthogonal_basis(
|
|
|
106
111
|
w = w / jnp.linalg.norm(w, axis=-1, keepdims=True)
|
|
107
112
|
|
|
108
113
|
return v, w
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@jax.jit
|
|
117
|
+
@jaxtyped(typechecker=typechecker)
|
|
118
|
+
def path_lengths(
|
|
119
|
+
paths: Float[Array, "*batch path_length 3"],
|
|
120
|
+
) -> Float[Array, " *batch"]:
|
|
121
|
+
"""
|
|
122
|
+
Compute the path length of each path.
|
|
123
|
+
|
|
124
|
+
Each path is exactly made of ``path_length`` vertices.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
paths: The array of path vertices.
|
|
128
|
+
|
|
129
|
+
Return:
|
|
130
|
+
The array of path lengths.
|
|
131
|
+
|
|
132
|
+
Examples:
|
|
133
|
+
The following example shows how to compute the length of a very simple path.
|
|
134
|
+
|
|
135
|
+
>>> from differt.geometry.utils import (
|
|
136
|
+
... path_lengths,
|
|
137
|
+
... )
|
|
138
|
+
>>>
|
|
139
|
+
>>> path = jnp.array([[1.0, 0.0, 0.0], [1.0, 1.0, 0.0]])
|
|
140
|
+
>>> path_lengths(path)
|
|
141
|
+
Array(1., dtype=float32)
|
|
142
|
+
>>> path_lengths(jnp.vstack((path, path[::-1, :])))
|
|
143
|
+
Array(2., dtype=float32)
|
|
144
|
+
"""
|
|
145
|
+
vectors = jnp.diff(paths, axis=-2)
|
|
146
|
+
lengths = jnp.linalg.norm(vectors, axis=-1)
|
|
147
|
+
|
|
148
|
+
return jnp.sum(lengths, axis=-1)
|
|
@@ -31,7 +31,7 @@ to display contents, on which a view is attached. The view
|
|
|
31
31
|
is what contains
|
|
32
32
|
the data to be plotted.
|
|
33
33
|
|
|
34
|
-
To
|
|
34
|
+
To reuse an existing ``canvas`` object, just pass it as a keyword
|
|
35
35
|
argument to any of the ``draw_*`` functions in this module, i.e.,
|
|
36
36
|
with ``draw_*(..., canvas=canvas)``.
|
|
37
37
|
In turn, each of those functions returns a figure on which you
|
|
@@ -50,7 +50,7 @@ Matplotlib uses :py:class:`Figure<matplotlib.figure.Figure>` objects
|
|
|
50
50
|
to display contents, on which multiple axes can be attached. In turn, each
|
|
51
51
|
axis can contain data to be plotted.
|
|
52
52
|
|
|
53
|
-
To
|
|
53
|
+
To reuse an existing ``figure`` object, just pass it as a keyword
|
|
54
54
|
argument to any of the ``draw_*`` functions in this module, i.e.,
|
|
55
55
|
with ``draw_*(..., figure=figure)``.
|
|
56
56
|
In turn, each of those functions returns a figure on which you
|
|
@@ -64,7 +64,7 @@ on which data will be plotted: ``draw_*(..., ax=ax)``.
|
|
|
64
64
|
|
|
65
65
|
By default, Matplotlib instantiates 2D axes, but this module
|
|
66
66
|
extensively uses 3D plot methods. If an axis is provided,
|
|
67
|
-
it is your
|
|
67
|
+
it is your responsibility to ensure that it can plot 3D data
|
|
68
68
|
when needed.
|
|
69
69
|
|
|
70
70
|
By default, Matpotlib displays static images in Jupyter notebooks.
|
|
@@ -82,14 +82,16 @@ Plots are fully contained inside
|
|
|
82
82
|
:py:class:`Figure<plotly.graph_objects.Figure>` objects, and can be nicely
|
|
83
83
|
displayed within Jupyter notebooks without further configuration.
|
|
84
84
|
|
|
85
|
-
To
|
|
85
|
+
To reuse an existing ``figure`` object, you can do the same as with
|
|
86
86
|
the Matplotlib backend.
|
|
87
87
|
|
|
88
88
|
"""
|
|
89
89
|
|
|
90
90
|
__all__ = (
|
|
91
91
|
"dispatch",
|
|
92
|
+
"set_defaults",
|
|
92
93
|
"use",
|
|
94
|
+
"reuse",
|
|
93
95
|
"draw_image",
|
|
94
96
|
"draw_markers",
|
|
95
97
|
"draw_mesh",
|
|
@@ -106,6 +108,8 @@ from ._utils import (
|
|
|
106
108
|
process_matplotlib_kwargs,
|
|
107
109
|
process_plotly_kwargs,
|
|
108
110
|
process_vispy_kwargs,
|
|
111
|
+
reuse,
|
|
112
|
+
set_defaults,
|
|
109
113
|
use,
|
|
110
114
|
view_from_canvas,
|
|
111
115
|
)
|