differt 0.7.0__tar.gz → 0.8.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.
Files changed (34) hide show
  1. {differt-0.7.0 → differt-0.8.0}/PKG-INFO +3 -3
  2. {differt-0.7.0 → differt-0.8.0}/README.md +1 -1
  3. {differt-0.7.0 → differt-0.8.0}/pyproject.toml +1 -1
  4. {differt-0.7.0 → differt-0.8.0}/src/differt/geometry/_triangle_mesh.py +183 -33
  5. {differt-0.7.0 → differt-0.8.0}/src/differt/geometry/_utils.py +10 -5
  6. {differt-0.7.0 → differt-0.8.0}/src/differt/plotting/__init__.py +2 -0
  7. {differt-0.7.0 → differt-0.8.0}/src/differt/plotting/_core.py +1 -0
  8. {differt-0.7.0 → differt-0.8.0}/src/differt/plotting/_utils.py +30 -10
  9. {differt-0.7.0 → differt-0.8.0}/.gitignore +0 -0
  10. {differt-0.7.0 → differt-0.8.0}/LICENSE.md +0 -0
  11. {differt-0.7.0 → differt-0.8.0}/src/differt/__init__.py +0 -0
  12. {differt-0.7.0 → differt-0.8.0}/src/differt/_version.py +0 -0
  13. {differt-0.7.0 → differt-0.8.0}/src/differt/em/__init__.py +0 -0
  14. {differt-0.7.0 → differt-0.8.0}/src/differt/em/_antenna.py +0 -0
  15. {differt-0.7.0 → differt-0.8.0}/src/differt/em/_constants.py +0 -0
  16. {differt-0.7.0 → differt-0.8.0}/src/differt/em/_fresnel.py +0 -0
  17. {differt-0.7.0 → differt-0.8.0}/src/differt/em/_interaction_type.py +0 -0
  18. {differt-0.7.0 → differt-0.8.0}/src/differt/em/_material.py +0 -0
  19. {differt-0.7.0 → differt-0.8.0}/src/differt/em/_utd.py +0 -0
  20. {differt-0.7.0 → differt-0.8.0}/src/differt/em/_utils.py +0 -0
  21. {differt-0.7.0 → differt-0.8.0}/src/differt/geometry/__init__.py +0 -0
  22. {differt-0.7.0 → differt-0.8.0}/src/differt/geometry/_paths.py +0 -0
  23. {differt-0.7.0 → differt-0.8.0}/src/differt/plugins/__init__.py +0 -0
  24. {differt-0.7.0 → differt-0.8.0}/src/differt/plugins/_deepmimo_types.py +0 -0
  25. {differt-0.7.0 → differt-0.8.0}/src/differt/plugins/deepmimo.py +0 -0
  26. {differt-0.7.0 → differt-0.8.0}/src/differt/py.typed +0 -0
  27. {differt-0.7.0 → differt-0.8.0}/src/differt/rt/__init__.py +0 -0
  28. {differt-0.7.0 → differt-0.8.0}/src/differt/rt/_fermat.py +0 -0
  29. {differt-0.7.0 → differt-0.8.0}/src/differt/rt/_image_method.py +0 -0
  30. {differt-0.7.0 → differt-0.8.0}/src/differt/rt/_utils.py +0 -0
  31. {differt-0.7.0 → differt-0.8.0}/src/differt/scene/__init__.py +0 -0
  32. {differt-0.7.0 → differt-0.8.0}/src/differt/scene/_sionna.py +0 -0
  33. {differt-0.7.0 → differt-0.8.0}/src/differt/scene/_triangle_scene.py +0 -0
  34. {differt-0.7.0 → differt-0.8.0}/src/differt/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DiffeRT
3
- Version: 0.7.0
3
+ Version: 0.8.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,7 +21,7 @@ Classifier: Programming Language :: Python :: Free Threading
21
21
  Classifier: Topic :: Scientific/Engineering
22
22
  Requires-Python: >=3.11
23
23
  Requires-Dist: chex>=0.1.86
24
- Requires-Dist: differt-core==0.7.0
24
+ Requires-Dist: differt-core==0.8.0
25
25
  Requires-Dist: equinox>=0.13.4
26
26
  Requires-Dist: filelock>=3.15.4
27
27
  Requires-Dist: fpt-jax==0.1.0
@@ -156,7 +156,7 @@ or:
156
156
  author = {Eertmans, Jérome},
157
157
  url = {https://github.com/jeertmans/DiffeRT},
158
158
  license = {MIT},
159
- version = {v0.7.0}
159
+ version = {v0.8.0}
160
160
  }
161
161
  ```
162
162
 
@@ -100,7 +100,7 @@ or:
100
100
  author = {Eertmans, Jérome},
101
101
  url = {https://github.com/jeertmans/DiffeRT},
102
102
  license = {MIT},
103
- version = {v0.7.0}
103
+ version = {v0.8.0}
104
104
  }
105
105
  ```
106
106
 
@@ -16,7 +16,7 @@ classifiers = [
16
16
  ]
17
17
  dependencies = [
18
18
  "chex>=0.1.86",
19
- "differt-core==0.7.0",
19
+ "differt-core==0.8.0",
20
20
  "equinox>=0.13.4",
21
21
  "filelock>=3.15.4",
22
22
  "fpt-jax==0.1.0",
@@ -1,13 +1,15 @@
1
1
  import typing
2
- from collections.abc import Callable, Iterator, Mapping
2
+ from collections.abc import Callable, Iterator, Mapping, Sequence
3
3
  from dataclasses import replace
4
4
  from typing import (
5
5
  TYPE_CHECKING,
6
6
  Any,
7
7
  Generic,
8
8
  Literal,
9
+ NotRequired,
9
10
  TypedDict,
10
11
  TypeVar,
12
+ Unpack,
11
13
  overload,
12
14
  )
13
15
 
@@ -28,18 +30,27 @@ else:
28
30
 
29
31
 
30
32
  class _AtIndexingKwargs(TypedDict):
31
- indices_are_sorted: bool
32
- unique_indices: bool
33
- wrap_negative_indices: bool
33
+ mode: NotRequired[Literal["promise_in_bounds", "clip", "drop", "fill"]]
34
+ wrap_negative_indices: NotRequired[bool]
35
+ indices_are_sorted: NotRequired[bool]
36
+ unique_indices: NotRequired[bool]
34
37
 
35
38
 
36
39
  _AT_INDEXING_KWARGS: _AtIndexingKwargs = {
40
+ "wrap_negative_indices": False,
37
41
  "indices_are_sorted": True,
38
42
  "unique_indices": True,
39
- "wrap_negative_indices": False,
40
43
  }
41
44
 
42
45
 
46
+ class _GetIndexingKwargs(TypedDict):
47
+ mode: Literal["promise_in_bounds", "clip", "drop", "fill"]
48
+ wrap_negative_indices: NotRequired[bool]
49
+ fill_value: NotRequired[Any]
50
+ indices_are_sorted: NotRequired[bool]
51
+ unique_indices: NotRequired[bool]
52
+
53
+
43
54
  @jax.jit
44
55
  def triangles_contain_vertices_assuming_inside_same_plane(
45
56
  triangle_vertices: Float[ArrayLike, "*#batch 3 3"],
@@ -102,7 +113,14 @@ def triangles_contain_vertices_assuming_inside_same_plane(
102
113
  return all_pos | all_neg
103
114
 
104
115
 
105
- _Index = slice | Int[ArrayLike, ""] | Int[Array, " n"] | Bool[Array, " num_triangles"]
116
+ _Index = (
117
+ slice
118
+ | Int[ArrayLike, ""]
119
+ | Int[Array, " n"]
120
+ | Bool[Array, " num_triangles"]
121
+ | Sequence[int]
122
+ | Sequence[bool]
123
+ )
106
124
  _T = TypeVar("_T", bound="TriangleMesh")
107
125
 
108
126
 
@@ -127,19 +145,40 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
127
145
  __slots__ = ("index", "mesh")
128
146
 
129
147
  def __init__(self, mesh: _T, index: _Index) -> None:
148
+ if not isinstance(index, slice):
149
+ index_array = jnp.asarray(index)
150
+ if index_array.ndim > 1:
151
+ msg = f"Index must be at most one-dimensional, got array with shape {index_array.shape}."
152
+ raise ValueError(msg)
130
153
  self.mesh = mesh
131
154
  self.index = index
132
155
 
133
156
  def __repr__(self) -> str:
134
157
  return f"_TriangleMeshVerticesUpdateRef({self.mesh!r}, {self.index!r})"
135
158
 
136
- def _triangles_index(self, **kwargs: Any) -> _Index:
159
+ def _triangles_index(self, **kwargs: Unpack[_GetIndexingKwargs]) -> _Index:
137
160
  index = self.mesh.triangles.at[self.index, :].get(**kwargs).reshape(-1)
138
161
  return jnp.unique(
139
162
  index, size=len(index), fill_value=self.mesh.vertices.shape[0]
140
163
  )
141
164
 
142
- def set(self, values: Any, **kwargs: Any) -> _T:
165
+ def get(
166
+ self, **kwargs: Unpack[_GetIndexingKwargs]
167
+ ) -> Float[ArrayLike, "num_indexed_triangles 3"]:
168
+ # get() is allowed to return duplicates, so we do not use _triangles_index()
169
+ index = self.mesh.triangles.at[self.index, :].get(**kwargs).reshape(-1)
170
+ return self.mesh.vertices.at[index, :].get(wrap_negative_indices=False)
171
+
172
+ def set(
173
+ self,
174
+ values: (
175
+ Float[ArrayLike, "3"]
176
+ | Float[ArrayLike, "1"]
177
+ | Float[ArrayLike, ""]
178
+ | Sequence[float]
179
+ ),
180
+ **kwargs: Unpack[_GetIndexingKwargs],
181
+ ) -> _T:
143
182
  index = self._triangles_index(**kwargs)
144
183
  return eqx.tree_at(
145
184
  lambda m: m.vertices,
@@ -147,35 +186,50 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
147
186
  self.mesh.vertices.at[index, :].set(values, **_AT_INDEXING_KWARGS),
148
187
  )
149
188
 
150
- def get(self, **kwargs: Any) -> Float[ArrayLike, "num_indexed_triangles 3"]:
151
- # get() is allowed to return duplicates, so we do not use _triangles_index()
152
- index = self.mesh.triangles.at[self.index, :].get(**kwargs).reshape(-1)
153
- return self.mesh.vertices.at[index, :].get(wrap_negative_indices=False)
154
-
155
- def apply(
189
+ def add(
156
190
  self,
157
- func: Callable[
158
- [Float[ArrayLike, "num_indexed_triangles 3"]],
159
- Float[Array, "num_indexed_triangles 3"],
160
- ],
161
- **kwargs: Any,
191
+ values: (
192
+ Float[ArrayLike, "3"]
193
+ | Float[ArrayLike, "1"]
194
+ | Float[ArrayLike, ""]
195
+ | Sequence[float]
196
+ ),
197
+ **kwargs: Unpack[_GetIndexingKwargs],
162
198
  ) -> _T:
163
199
  index = self._triangles_index(**kwargs)
164
200
  return eqx.tree_at(
165
201
  lambda m: m.vertices,
166
202
  self.mesh,
167
- self.mesh.vertices.at[index, :].apply(func, **_AT_INDEXING_KWARGS),
203
+ self.mesh.vertices.at[index, :].add(values, **_AT_INDEXING_KWARGS),
168
204
  )
169
205
 
170
- def add(self, values: Any, **kwargs: Any) -> _T:
206
+ def sub(
207
+ self,
208
+ values: (
209
+ Float[ArrayLike, "3"]
210
+ | Float[ArrayLike, "1"]
211
+ | Float[ArrayLike, ""]
212
+ | Sequence[float]
213
+ ),
214
+ **kwargs: Unpack[_GetIndexingKwargs],
215
+ ) -> _T:
171
216
  index = self._triangles_index(**kwargs)
172
217
  return eqx.tree_at(
173
218
  lambda m: m.vertices,
174
219
  self.mesh,
175
- self.mesh.vertices.at[index, :].add(values, **_AT_INDEXING_KWARGS),
220
+ self.mesh.vertices.at[index, :].subtract(values, **_AT_INDEXING_KWARGS),
176
221
  )
177
222
 
178
- def mul(self, values: Any, **kwargs: Any) -> _T:
223
+ def mul(
224
+ self,
225
+ values: (
226
+ Float[ArrayLike, "3"]
227
+ | Float[ArrayLike, "1"]
228
+ | Float[ArrayLike, ""]
229
+ | Sequence[float]
230
+ ),
231
+ **kwargs: Unpack[_GetIndexingKwargs],
232
+ ) -> _T:
179
233
  index = self._triangles_index(**kwargs)
180
234
  return eqx.tree_at(
181
235
  lambda m: m.vertices,
@@ -183,6 +237,89 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
183
237
  self.mesh.vertices.at[index, :].mul(values, **_AT_INDEXING_KWARGS),
184
238
  )
185
239
 
240
+ def div(
241
+ self,
242
+ values: (
243
+ Float[ArrayLike, "3"]
244
+ | Float[ArrayLike, "1"]
245
+ | Float[ArrayLike, ""]
246
+ | Sequence[float]
247
+ ),
248
+ **kwargs: Unpack[_GetIndexingKwargs],
249
+ ) -> _T:
250
+ index = self._triangles_index(**kwargs)
251
+ return eqx.tree_at(
252
+ lambda m: m.vertices,
253
+ self.mesh,
254
+ self.mesh.vertices.at[index, :].divide(values, **_AT_INDEXING_KWARGS),
255
+ )
256
+
257
+ def pow(
258
+ self,
259
+ values: (
260
+ Float[ArrayLike, "3"]
261
+ | Float[ArrayLike, "1"]
262
+ | Float[ArrayLike, ""]
263
+ | Sequence[float]
264
+ ),
265
+ **kwargs: Unpack[_GetIndexingKwargs],
266
+ ) -> _T:
267
+ index = self._triangles_index(**kwargs)
268
+ return eqx.tree_at(
269
+ lambda m: m.vertices,
270
+ self.mesh,
271
+ self.mesh.vertices.at[index, :].power(values, **_AT_INDEXING_KWARGS),
272
+ )
273
+
274
+ def min(
275
+ self,
276
+ values: (
277
+ Float[ArrayLike, "3"]
278
+ | Float[ArrayLike, "1"]
279
+ | Float[ArrayLike, ""]
280
+ | Sequence[float]
281
+ ),
282
+ **kwargs: Unpack[_GetIndexingKwargs],
283
+ ) -> _T:
284
+ index = self._triangles_index(**kwargs)
285
+ return eqx.tree_at(
286
+ lambda m: m.vertices,
287
+ self.mesh,
288
+ self.mesh.vertices.at[index, :].min(values, **_AT_INDEXING_KWARGS),
289
+ )
290
+
291
+ def max(
292
+ self,
293
+ values: (
294
+ Float[ArrayLike, "3"]
295
+ | Float[ArrayLike, "1"]
296
+ | Float[ArrayLike, ""]
297
+ | Sequence[float]
298
+ ),
299
+ **kwargs: Unpack[_GetIndexingKwargs],
300
+ ) -> _T:
301
+ index = self._triangles_index(**kwargs)
302
+ return eqx.tree_at(
303
+ lambda m: m.vertices,
304
+ self.mesh,
305
+ self.mesh.vertices.at[index, :].max(values, **_AT_INDEXING_KWARGS),
306
+ )
307
+
308
+ def apply(
309
+ self,
310
+ func: Callable[
311
+ [Float[ArrayLike, "num_indexed_triangles 3"]],
312
+ Float[Array, "num_indexed_triangles 3"],
313
+ ],
314
+ **kwargs: Unpack[_GetIndexingKwargs],
315
+ ) -> _T:
316
+ index = self._triangles_index(**kwargs)
317
+ return eqx.tree_at(
318
+ lambda m: m.vertices,
319
+ self.mesh,
320
+ self.mesh.vertices.at[index, :].apply(func, **_AT_INDEXING_KWARGS),
321
+ )
322
+
186
323
 
187
324
  class TriangleMesh(eqx.Module):
188
325
  """A simple geometry made of triangles."""
@@ -509,15 +646,20 @@ class TriangleMesh(eqx.Module):
509
646
  """
510
647
  # Using self.triangle_vertices is important because, e.g., as a result of using
511
648
  # __getitem__, some vertices in 'self.vertices' may no longer be used by this mesh.
512
- vertices = self.triangle_vertices.reshape(-1, 3)
513
- where = jnp.repeat(self.mask, 3)[:, None] if self.mask is not None else None
649
+ vertices = self.triangle_vertices
650
+ where = self.mask[:, None] if self.mask is not None else None
514
651
  return jnp.vstack(
515
652
  (
516
- jnp.min(vertices, axis=0, initial=+jnp.inf, where=where),
517
- jnp.max(vertices, axis=0, initial=-jnp.inf, where=where),
653
+ jnp.min(vertices, axis=(0, 1), initial=+jnp.inf, where=where),
654
+ jnp.max(vertices, axis=(0, 1), initial=-jnp.inf, where=where),
518
655
  ),
519
656
  )
520
657
 
658
+ if TYPE_CHECKING:
659
+
660
+ @property
661
+ def at(self) -> _TriangleMeshVerticesUpdateHelper[Self]: ...
662
+
521
663
  @property
522
664
  def at(self): # noqa: ANN202
523
665
  """
@@ -529,17 +671,25 @@ class TriangleMesh(eqx.Module):
529
671
 
530
672
  In particular, the following methods are available:
531
673
 
674
+ - ``get(**kwargs)``: Get the vertices of selected triangles;
532
675
  - ``set(values, **kwargs)``: Set the vertices of selected triangles to some values;
533
- - ``apply(func, **kwargs)``: Apply a function to the vertices of selected triangles;
534
676
  - ``add(values, **kwargs)``: Add some values to the vertices of selected triangles;
677
+ - ``sub(values, **kwargs)``: Subtract some values from the vertices of selected triangles;
535
678
  - ``mul(values, **kwargs)``: Multiply the vertices of selected triangles by some values;
536
- - ``get(values, **kwargs)``: Get the vertices of selected triangles.
679
+ - ``div(values, **kwargs)``: Divide the vertices of selected triangles by some values;
680
+ - ``pow(values, **kwargs)``: Raise the vertices of selected triangles to some power;
681
+ - ``min(values, **kwargs)``: Take the element-wise minimum with the vertices of selected triangles;
682
+ - ``max(values, **kwargs)``: Take the element-wise maximum with the vertices of selected triangles;
683
+ - ``apply(func, **kwargs)``: Apply a function to the vertices of selected triangles.
537
684
 
538
685
  E.g., ``mesh.at[0:2].add([1.0, 2.0, 3.0])`` will translate the first two triangles.
539
686
 
540
- Each method takes additional keyword parameters that are passed to the methods
541
- of :attr:`jax.numpy.ndarray.at`. Because the vertices of a triangle mesh may be shared
542
- between multiple triangles, this method prevents updating the same vertice multiple times
687
+ Each method accepts the same keyword arguments as the corresponding ``get`` method of
688
+ :attr:`jax.numpy.ndarray.at`.
689
+ These keyword arguments control how triangle indices are resolved internally.
690
+
691
+ Because the vertices of a triangle mesh may be shared
692
+ between multiple triangles, this method prevents updating the same vertex multiple times
543
693
  by ignoring duplicate vertex indices. As a result, providing duplicate triangle indices
544
694
  will not result in duplicate updates.
545
695
 
@@ -1690,7 +1840,7 @@ class TriangleMesh(eqx.Module):
1690
1840
  it is discarded.
1691
1841
 
1692
1842
  .. warning::
1693
-
1843
+
1694
1844
  Not implemented yet.
1695
1845
 
1696
1846
  Setting this to :data:`True` has no effect if :attr:`object_bounds`
@@ -1,4 +1,5 @@
1
- from typing import Literal, no_type_check, overload
1
+ import typing
2
+ from typing import TYPE_CHECKING, Literal, no_type_check, overload
2
3
 
3
4
  import equinox as eqx
4
5
  import jax
@@ -450,15 +451,15 @@ def assemble_paths(
450
451
 
451
452
  # NOTE: Jaxtyping does not match the correct shape for `intermediate_vertices` and will match
452
453
  # `Float[ArrayLike, "*#batch 3"]` instead of `Float[ArrayLike, "*#batch num_inter_vertices 3"]`.
453
- # This is why we use `no_type_check` here.
454
- # TODO: fix this.
455
- @no_type_check
454
+ # This is why we need to disable type checking here. However, the `no_type_check` decorator also
455
+ # suppresses `typing.get_type_hints()`, which is used by Sphinx to extract type annotations for
456
+ # documentation. To work around this, we use `no_type_check` when not generating documentation.
456
457
  def assemble_paths(
457
458
  from_vertices: Float[ArrayLike, "*#batch 3"],
458
459
  intermediate_vertices: Float[ArrayLike, "*#batch num_inter_vertices 3"]
459
460
  | Float[ArrayLike, "*#batch 3"],
460
461
  to_vertices: Float[ArrayLike, "*#batch 3"] | None = None,
461
- ) -> Float[Array, "*batch num_inter_vertices+2 3"] | Float[Array, "*batch 2 3"]:
462
+ ) -> Float[Array, "*batch num_vertices+2 3"] | Float[Array, "*batch 2 3"]:
462
463
  """
463
464
  Assemble paths vertices by concatenating start-, intermediate, and end-vertices.
464
465
 
@@ -507,6 +508,10 @@ def assemble_paths(
507
508
  )
508
509
 
509
510
 
511
+ if not TYPE_CHECKING and not hasattr(typing, "GENERATING_DOCS"):
512
+ assemble_paths = no_type_check(assemble_paths)
513
+
514
+
510
515
  @jax.jit
511
516
  def min_distance_between_cells(
512
517
  cell_vertices: Float[ArrayLike, "*batch 3"],
@@ -99,6 +99,7 @@ __all__ = (
99
99
  "process_plotly_kwargs",
100
100
  "process_vispy_kwargs",
101
101
  "reuse",
102
+ "set_backend",
102
103
  "set_defaults",
103
104
  "update_defaults",
104
105
  "use",
@@ -123,6 +124,7 @@ from ._utils import (
123
124
  process_plotly_kwargs,
124
125
  process_vispy_kwargs,
125
126
  reuse,
127
+ set_backend,
126
128
  set_defaults,
127
129
  update_defaults,
128
130
  use,
@@ -136,6 +136,7 @@ def _(
136
136
  **kwargs: Any,
137
137
  ) -> Figure:
138
138
  fig = process_plotly_kwargs(kwargs)
139
+ kwargs.setdefault("flatshading", True)
139
140
 
140
141
  if (
141
142
  face_colors := kwargs.pop("face_colors", None)
@@ -184,6 +184,29 @@ def set_defaults(backend: LiteralString | None = None, **kwargs: Any) -> Backend
184
184
  return backend
185
185
 
186
186
 
187
+ def set_backend(backend: LiteralString) -> None:
188
+ """
189
+ Set default backend for future plotting utilities.
190
+
191
+ Args:
192
+ backend: The name of the backend to be passed to
193
+ :func:`get_backend`.
194
+
195
+ Examples:
196
+ The following example shows how to set the default plotting backend.
197
+
198
+ >>> import differt.plotting as dplt
199
+ >>>
200
+ >>> dplt.set_backend("matplotlib") # We can change the default backend
201
+ >>> dplt.get_backend() # So that now it defaults to 'matplotlib'
202
+ 'matplotlib'
203
+ >>> dplt.set_backend("vispy") # Reset to 'vispy'
204
+ >>> dplt.get_backend()
205
+ 'vispy'
206
+ """
207
+ set_defaults(backend=backend)
208
+
209
+
187
210
  def update_defaults(backend: LiteralString | None = None, **kwargs: Any) -> BackendName:
188
211
  """
189
212
  Update default backend and keyword arguments for future plotting utilities.
@@ -265,10 +288,7 @@ def use(backend: LiteralString | None = None, **kwargs: Any) -> Iterator[Backend
265
288
  kwargs = {**config.defaults.kwargs, **kwargs}
266
289
 
267
290
  with config.with_defaults(backend=backend, kwargs=kwargs):
268
- try:
269
- yield backend
270
- finally:
271
- pass
291
+ yield backend
272
292
 
273
293
 
274
294
  @runtime_checkable
@@ -459,11 +479,12 @@ def view_from_canvas(canvas: Canvas) -> ViewBox:
459
479
  Returns:
460
480
  The view on which contents are displayed.
461
481
  """
482
+ from vispy.scene.cameras.turntable import TurntableCamera # noqa: PLC0415
462
483
  from vispy.scene.widgets.viewbox import ViewBox # noqa: PLC0415
463
484
 
464
485
  def default_view() -> ViewBox:
465
486
  view = canvas.central_widget.add_view()
466
- view.camera = "turntable"
487
+ view.camera = TurntableCamera()
467
488
  view.camera.depth_value = 1e3
468
489
  return view
469
490
 
@@ -612,7 +633,9 @@ def process_plotly_kwargs(
612
633
  for key, value in config.defaults.kwargs.items():
613
634
  kwargs.setdefault(key, value)
614
635
 
615
- return kwargs.pop("figure", None) or go.Figure()
636
+ fig = kwargs.pop("figure", None) or go.Figure()
637
+ fig.update_scenes(aspectmode="data")
638
+ return fig
616
639
 
617
640
 
618
641
  def process_kwargs(
@@ -704,7 +727,4 @@ def reuse(
704
727
  with config.with_defaults(
705
728
  backend=backend, kwargs={**config.defaults.kwargs, **kwargs}
706
729
  ):
707
- try:
708
- yield canvas_or_fig
709
- finally:
710
- pass
730
+ yield canvas_or_fig
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes