lsurf 1.0.0__py3-none-any.whl

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 (180) hide show
  1. lsurf/__init__.py +471 -0
  2. lsurf/analysis/__init__.py +107 -0
  3. lsurf/analysis/healpix_utils.py +418 -0
  4. lsurf/analysis/sphere_viz.py +1280 -0
  5. lsurf/cli/__init__.py +48 -0
  6. lsurf/cli/build.py +398 -0
  7. lsurf/cli/config_schema.py +318 -0
  8. lsurf/cli/gui_cmd.py +76 -0
  9. lsurf/cli/interactive.py +850 -0
  10. lsurf/cli/main.py +81 -0
  11. lsurf/cli/run.py +806 -0
  12. lsurf/detectors/__init__.py +266 -0
  13. lsurf/detectors/analysis.py +289 -0
  14. lsurf/detectors/base.py +284 -0
  15. lsurf/detectors/constant_size_rings.py +485 -0
  16. lsurf/detectors/directional.py +45 -0
  17. lsurf/detectors/extended/__init__.py +73 -0
  18. lsurf/detectors/extended/local_sphere.py +353 -0
  19. lsurf/detectors/extended/recording_sphere.py +368 -0
  20. lsurf/detectors/planar.py +45 -0
  21. lsurf/detectors/protocol.py +187 -0
  22. lsurf/detectors/recording_spheres.py +63 -0
  23. lsurf/detectors/results.py +1140 -0
  24. lsurf/detectors/small/__init__.py +79 -0
  25. lsurf/detectors/small/directional.py +330 -0
  26. lsurf/detectors/small/planar.py +401 -0
  27. lsurf/detectors/small/spherical.py +450 -0
  28. lsurf/detectors/spherical.py +45 -0
  29. lsurf/geometry/__init__.py +199 -0
  30. lsurf/geometry/builder.py +478 -0
  31. lsurf/geometry/cell.py +228 -0
  32. lsurf/geometry/cell_geometry.py +247 -0
  33. lsurf/geometry/detector_arrays.py +1785 -0
  34. lsurf/geometry/geometry.py +222 -0
  35. lsurf/geometry/surface_analysis.py +375 -0
  36. lsurf/geometry/validation.py +91 -0
  37. lsurf/gui/__init__.py +51 -0
  38. lsurf/gui/app.py +903 -0
  39. lsurf/gui/core/__init__.py +39 -0
  40. lsurf/gui/core/scene.py +343 -0
  41. lsurf/gui/core/simulation.py +264 -0
  42. lsurf/gui/renderers/__init__.py +40 -0
  43. lsurf/gui/renderers/ray_renderer.py +353 -0
  44. lsurf/gui/renderers/source_renderer.py +505 -0
  45. lsurf/gui/renderers/surface_renderer.py +477 -0
  46. lsurf/gui/views/__init__.py +48 -0
  47. lsurf/gui/views/config_editor.py +3199 -0
  48. lsurf/gui/views/properties.py +257 -0
  49. lsurf/gui/views/results.py +291 -0
  50. lsurf/gui/views/scene_tree.py +180 -0
  51. lsurf/gui/views/viewport_3d.py +555 -0
  52. lsurf/gui/views/visualizations.py +712 -0
  53. lsurf/materials/__init__.py +169 -0
  54. lsurf/materials/base/__init__.py +64 -0
  55. lsurf/materials/base/full_inhomogeneous.py +208 -0
  56. lsurf/materials/base/grid_inhomogeneous.py +319 -0
  57. lsurf/materials/base/homogeneous.py +342 -0
  58. lsurf/materials/base/material_field.py +527 -0
  59. lsurf/materials/base/simple_inhomogeneous.py +418 -0
  60. lsurf/materials/base/spectral_inhomogeneous.py +497 -0
  61. lsurf/materials/implementations/__init__.py +120 -0
  62. lsurf/materials/implementations/data/alpha_values_typical_atmosphere_updated.txt +24 -0
  63. lsurf/materials/implementations/duct_atmosphere.py +390 -0
  64. lsurf/materials/implementations/exponential_atmosphere.py +435 -0
  65. lsurf/materials/implementations/gaussian_lens.py +120 -0
  66. lsurf/materials/implementations/interpolated_data.py +123 -0
  67. lsurf/materials/implementations/layered_atmosphere.py +134 -0
  68. lsurf/materials/implementations/linear_gradient.py +109 -0
  69. lsurf/materials/implementations/linsley_atmosphere.py +764 -0
  70. lsurf/materials/implementations/standard_materials.py +126 -0
  71. lsurf/materials/implementations/turbulent_atmosphere.py +135 -0
  72. lsurf/materials/implementations/us_standard_atmosphere.py +149 -0
  73. lsurf/materials/utils/__init__.py +77 -0
  74. lsurf/materials/utils/constants.py +45 -0
  75. lsurf/materials/utils/device_functions.py +117 -0
  76. lsurf/materials/utils/dispersion.py +160 -0
  77. lsurf/materials/utils/factories.py +142 -0
  78. lsurf/propagation/__init__.py +91 -0
  79. lsurf/propagation/detector_gpu.py +67 -0
  80. lsurf/propagation/gpu_device_rays.py +294 -0
  81. lsurf/propagation/kernels/__init__.py +175 -0
  82. lsurf/propagation/kernels/absorption/__init__.py +61 -0
  83. lsurf/propagation/kernels/absorption/grid.py +240 -0
  84. lsurf/propagation/kernels/absorption/simple.py +232 -0
  85. lsurf/propagation/kernels/absorption/spectral.py +410 -0
  86. lsurf/propagation/kernels/detection/__init__.py +64 -0
  87. lsurf/propagation/kernels/detection/protocol.py +102 -0
  88. lsurf/propagation/kernels/detection/spherical.py +255 -0
  89. lsurf/propagation/kernels/device_functions.py +790 -0
  90. lsurf/propagation/kernels/fresnel/__init__.py +64 -0
  91. lsurf/propagation/kernels/fresnel/protocol.py +97 -0
  92. lsurf/propagation/kernels/fresnel/standard.py +258 -0
  93. lsurf/propagation/kernels/intersection/__init__.py +79 -0
  94. lsurf/propagation/kernels/intersection/annular_plane.py +207 -0
  95. lsurf/propagation/kernels/intersection/bounded_plane.py +205 -0
  96. lsurf/propagation/kernels/intersection/plane.py +166 -0
  97. lsurf/propagation/kernels/intersection/protocol.py +95 -0
  98. lsurf/propagation/kernels/intersection/signed_distance.py +742 -0
  99. lsurf/propagation/kernels/intersection/sphere.py +190 -0
  100. lsurf/propagation/kernels/propagation/__init__.py +85 -0
  101. lsurf/propagation/kernels/propagation/grid.py +527 -0
  102. lsurf/propagation/kernels/propagation/protocol.py +105 -0
  103. lsurf/propagation/kernels/propagation/simple.py +460 -0
  104. lsurf/propagation/kernels/propagation/spectral.py +875 -0
  105. lsurf/propagation/kernels/registry.py +331 -0
  106. lsurf/propagation/kernels/surface/__init__.py +72 -0
  107. lsurf/propagation/kernels/surface/bisection.py +232 -0
  108. lsurf/propagation/kernels/surface/detection.py +402 -0
  109. lsurf/propagation/kernels/surface/reduction.py +166 -0
  110. lsurf/propagation/propagator_protocol.py +222 -0
  111. lsurf/propagation/propagators/__init__.py +101 -0
  112. lsurf/propagation/propagators/detector_handler.py +354 -0
  113. lsurf/propagation/propagators/factory.py +200 -0
  114. lsurf/propagation/propagators/fresnel_handler.py +305 -0
  115. lsurf/propagation/propagators/gpu_gradient.py +566 -0
  116. lsurf/propagation/propagators/gpu_surface_propagator.py +707 -0
  117. lsurf/propagation/propagators/gradient.py +429 -0
  118. lsurf/propagation/propagators/intersection_handler.py +327 -0
  119. lsurf/propagation/propagators/material_propagator.py +398 -0
  120. lsurf/propagation/propagators/signed_distance_handler.py +522 -0
  121. lsurf/propagation/propagators/spectral_gpu_gradient.py +553 -0
  122. lsurf/propagation/propagators/surface_interaction.py +616 -0
  123. lsurf/propagation/propagators/surface_propagator.py +719 -0
  124. lsurf/py.typed +1 -0
  125. lsurf/simulation/__init__.py +70 -0
  126. lsurf/simulation/config.py +164 -0
  127. lsurf/simulation/orchestrator.py +462 -0
  128. lsurf/simulation/result.py +299 -0
  129. lsurf/simulation/simulation.py +262 -0
  130. lsurf/sources/__init__.py +128 -0
  131. lsurf/sources/base.py +264 -0
  132. lsurf/sources/collimated.py +252 -0
  133. lsurf/sources/custom.py +409 -0
  134. lsurf/sources/diverging.py +228 -0
  135. lsurf/sources/gaussian.py +272 -0
  136. lsurf/sources/parallel_from_positions.py +197 -0
  137. lsurf/sources/point.py +172 -0
  138. lsurf/sources/uniform_diverging.py +258 -0
  139. lsurf/surfaces/__init__.py +184 -0
  140. lsurf/surfaces/cpu/__init__.py +50 -0
  141. lsurf/surfaces/cpu/curved_wave.py +463 -0
  142. lsurf/surfaces/cpu/gerstner_wave.py +381 -0
  143. lsurf/surfaces/cpu/wave_params.py +118 -0
  144. lsurf/surfaces/gpu/__init__.py +72 -0
  145. lsurf/surfaces/gpu/annular_plane.py +453 -0
  146. lsurf/surfaces/gpu/bounded_plane.py +390 -0
  147. lsurf/surfaces/gpu/curved_wave.py +483 -0
  148. lsurf/surfaces/gpu/gerstner_wave.py +377 -0
  149. lsurf/surfaces/gpu/multi_curved_wave.py +520 -0
  150. lsurf/surfaces/gpu/plane.py +299 -0
  151. lsurf/surfaces/gpu/recording_sphere.py +587 -0
  152. lsurf/surfaces/gpu/sphere.py +311 -0
  153. lsurf/surfaces/protocol.py +336 -0
  154. lsurf/surfaces/registry.py +373 -0
  155. lsurf/utilities/__init__.py +175 -0
  156. lsurf/utilities/detector_analysis.py +814 -0
  157. lsurf/utilities/fresnel.py +628 -0
  158. lsurf/utilities/interactions.py +1215 -0
  159. lsurf/utilities/propagation.py +602 -0
  160. lsurf/utilities/ray_data.py +532 -0
  161. lsurf/utilities/recording_sphere.py +745 -0
  162. lsurf/utilities/time_spread.py +463 -0
  163. lsurf/visualization/__init__.py +329 -0
  164. lsurf/visualization/absorption_plots.py +334 -0
  165. lsurf/visualization/atmospheric_plots.py +754 -0
  166. lsurf/visualization/common.py +348 -0
  167. lsurf/visualization/detector_plots.py +1350 -0
  168. lsurf/visualization/detector_sphere_plots.py +1173 -0
  169. lsurf/visualization/fresnel_plots.py +1061 -0
  170. lsurf/visualization/ocean_simulation_plots.py +999 -0
  171. lsurf/visualization/polarization_plots.py +916 -0
  172. lsurf/visualization/raytracing_plots.py +1521 -0
  173. lsurf/visualization/ring_detector_plots.py +1867 -0
  174. lsurf/visualization/time_spread_plots.py +531 -0
  175. lsurf-1.0.0.dist-info/METADATA +381 -0
  176. lsurf-1.0.0.dist-info/RECORD +180 -0
  177. lsurf-1.0.0.dist-info/WHEEL +5 -0
  178. lsurf-1.0.0.dist-info/entry_points.txt +2 -0
  179. lsurf-1.0.0.dist-info/licenses/LICENSE +32 -0
  180. lsurf-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,453 @@
1
+ # The Clear BSD License
2
+ #
3
+ # Copyright (c) 2026 Tobias Heibges
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted (subject to the limitations in the disclaimer
8
+ # below) provided that the following conditions are met:
9
+ #
10
+ # * Redistributions of source code must retain the above copyright notice,
11
+ # this list of conditions and the following disclaimer.
12
+ #
13
+ # * Redistributions in binary form must reproduce the above copyright
14
+ # notice, this list of conditions and the following disclaimer in the
15
+ # documentation and/or other materials provided with the distribution.
16
+ #
17
+ # * Neither the name of the copyright holder nor the names of its
18
+ # contributors may be used to endorse or promote products derived from this
19
+ # software without specific prior written permission.
20
+ #
21
+ # NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
22
+ # THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23
+ # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25
+ # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29
+ # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+
34
+ """
35
+ Annular Plane Surface (GPU-Capable)
36
+
37
+ Implements an annular (ring-shaped) planar detector surface with GPU acceleration.
38
+ Useful for creating concentric ring detector arrays that share a common center
39
+ and normal but have different inner/outer radii.
40
+ """
41
+
42
+ from __future__ import annotations
43
+
44
+ from dataclasses import dataclass, field
45
+ from typing import TYPE_CHECKING, Any
46
+
47
+ import numpy as np
48
+ import numpy.typing as npt
49
+
50
+ from ..protocol import Surface, SurfaceRole
51
+ from ..registry import register_surface_type
52
+
53
+ if TYPE_CHECKING:
54
+ from ...propagation.kernels.registry import IntersectionKernelID
55
+
56
+
57
+ @dataclass
58
+ class AnnularPlaneSurface(Surface):
59
+ """
60
+ Annular (ring-shaped) planar detector surface with GPU acceleration.
61
+
62
+ The annular plane is defined by a center point, normal vector, and
63
+ inner/outer radii. Useful for creating concentric ring detector arrays
64
+ that all face the same target point.
65
+
66
+ Parameters
67
+ ----------
68
+ center : tuple of float
69
+ Center point (cx, cy, cz) of the annulus.
70
+ normal : tuple of float
71
+ Unit normal vector (nx, ny, nz) pointing "outward" (front side).
72
+ inner_radius : float
73
+ Inner radius of the annulus (meters). Use 0 for a disk.
74
+ outer_radius : float
75
+ Outer radius of the annulus (meters).
76
+ role : SurfaceRole
77
+ What happens when a ray hits (DETECTOR, OPTICAL, or ABSORBER).
78
+ name : str
79
+ Human-readable name.
80
+ material_front : MaterialField, optional
81
+ Material on front side (where normal points). Required for OPTICAL.
82
+ material_back : MaterialField, optional
83
+ Material on back side. Required for OPTICAL.
84
+
85
+ Examples
86
+ --------
87
+ >>> # Annular detector ring at 33 km altitude
88
+ >>> ring = AnnularPlaneSurface(
89
+ ... center=(0, 0, 33000),
90
+ ... normal=(0, 0, -1), # Facing down toward origin
91
+ ... inner_radius=5000.0,
92
+ ... outer_radius=10000.0,
93
+ ... role=SurfaceRole.DETECTOR,
94
+ ... name="ring_5_10km",
95
+ ... )
96
+ >>>
97
+ >>> # Central disk (inner_radius=0)
98
+ >>> disk = AnnularPlaneSurface(
99
+ ... center=(0, 0, 33000),
100
+ ... normal=(0, 0, -1),
101
+ ... inner_radius=0.0,
102
+ ... outer_radius=2500.0,
103
+ ... role=SurfaceRole.DETECTOR,
104
+ ... name="disk_2.5km",
105
+ ... )
106
+ """
107
+
108
+ center: tuple[float, float, float]
109
+ normal: tuple[float, float, float]
110
+ inner_radius: float
111
+ outer_radius: float
112
+ role: SurfaceRole
113
+ name: str = "annular_plane"
114
+ material_front: Any = None
115
+ material_back: Any = None
116
+
117
+ # GPU capability
118
+ _gpu_capable: bool = field(default=True, init=False, repr=False)
119
+ _geometry_id: int = field(default=7, init=False, repr=False) # annular plane = 7
120
+
121
+ # Internal normalized normal (set in __post_init__)
122
+ _normal: tuple[float, float, float] = field(
123
+ default=(0, 0, 1), init=False, repr=False
124
+ )
125
+
126
+ # Local U/V axes for coordinate computation (set in __post_init__)
127
+ _u_axis: tuple[float, float, float] = field(
128
+ default=(1, 0, 0), init=False, repr=False
129
+ )
130
+ _v_axis: tuple[float, float, float] = field(
131
+ default=(0, 1, 0), init=False, repr=False
132
+ )
133
+
134
+ # Squared radii for bounds checking (set in __post_init__)
135
+ _inner_radius_sq: float = field(default=0.0, init=False, repr=False)
136
+ _outer_radius_sq: float = field(default=0.0, init=False, repr=False)
137
+
138
+ # Kernel ID for this instance (set in __post_init__)
139
+ _kernel_id: IntersectionKernelID | None = field(
140
+ default=None, init=False, repr=False
141
+ )
142
+
143
+ @classmethod
144
+ def _get_supported_kernels(cls) -> list[IntersectionKernelID]:
145
+ """Get supported intersection kernels (lazy initialization)."""
146
+ from ...propagation.kernels.registry import IntersectionKernelID
147
+
148
+ return [IntersectionKernelID.ANNULAR_PLANE_ANALYTICAL]
149
+
150
+ @classmethod
151
+ def _get_default_kernel(cls) -> IntersectionKernelID:
152
+ """Get default intersection kernel."""
153
+ from ...propagation.kernels.registry import IntersectionKernelID
154
+
155
+ return IntersectionKernelID.ANNULAR_PLANE_ANALYTICAL
156
+
157
+ @classmethod
158
+ def supported_kernels(cls) -> list[IntersectionKernelID]:
159
+ """Return list of intersection kernels supported by this surface type."""
160
+ return cls._get_supported_kernels()
161
+
162
+ @classmethod
163
+ def default_kernel(cls) -> IntersectionKernelID:
164
+ """Return the default intersection kernel for this surface type."""
165
+ return cls._get_default_kernel()
166
+
167
+ def __post_init__(self) -> None:
168
+ # Validate radii
169
+ if self.inner_radius < 0:
170
+ raise ValueError("Inner radius must be non-negative")
171
+ if self.outer_radius <= 0:
172
+ raise ValueError("Outer radius must be positive")
173
+ if self.inner_radius >= self.outer_radius:
174
+ raise ValueError("Inner radius must be less than outer radius")
175
+
176
+ # Pre-compute squared radii
177
+ self._inner_radius_sq = self.inner_radius * self.inner_radius
178
+ self._outer_radius_sq = self.outer_radius * self.outer_radius
179
+
180
+ # Normalize the normal vector
181
+ n = np.array(self.normal, dtype=np.float64)
182
+ norm = np.linalg.norm(n)
183
+ if norm < 1e-12:
184
+ raise ValueError("Normal vector cannot be zero")
185
+ n = n / norm
186
+ self._normal = tuple(n.tolist())
187
+
188
+ # Compute local U/V axes
189
+ self._compute_local_axes()
190
+
191
+ # Set default kernel
192
+ self._kernel_id = self._get_default_kernel()
193
+
194
+ def _compute_local_axes(self) -> None:
195
+ """Compute orthonormal U/V axes on the plane."""
196
+ n = np.array(self._normal)
197
+
198
+ # Choose reference vector not parallel to normal
199
+ if abs(n[2]) < 0.9:
200
+ ref = np.array([0.0, 0.0, 1.0])
201
+ else:
202
+ ref = np.array([1.0, 0.0, 0.0])
203
+
204
+ # U = normalize(ref - (ref.n)n)
205
+ u = ref - np.dot(ref, n) * n
206
+ u = u / np.linalg.norm(u)
207
+
208
+ # V = n x U (right-handed coordinate system)
209
+ v = np.cross(n, u)
210
+
211
+ self._u_axis = tuple(u.tolist())
212
+ self._v_axis = tuple(v.tolist())
213
+
214
+ @property
215
+ def gpu_capable(self) -> bool:
216
+ """This surface supports GPU acceleration."""
217
+ return True
218
+
219
+ @property
220
+ def geometry_id(self) -> int:
221
+ """GPU geometry type ID (annular plane = 7)."""
222
+ return 7
223
+
224
+ @property
225
+ def area(self) -> float:
226
+ """Area of the annular ring in square meters."""
227
+ return np.pi * (self._outer_radius_sq - self._inner_radius_sq)
228
+
229
+ def get_gpu_parameters(self) -> tuple:
230
+ """
231
+ Return parameters for GPU kernel.
232
+
233
+ Returns
234
+ -------
235
+ tuple
236
+ (normal_x, normal_y, normal_z, center_x, center_y, center_z,
237
+ u_axis_x, u_axis_y, u_axis_z, v_axis_x, v_axis_y, v_axis_z,
238
+ inner_radius_sq, outer_radius_sq)
239
+ """
240
+ return (
241
+ self._normal[0],
242
+ self._normal[1],
243
+ self._normal[2],
244
+ self.center[0],
245
+ self.center[1],
246
+ self.center[2],
247
+ self._u_axis[0],
248
+ self._u_axis[1],
249
+ self._u_axis[2],
250
+ self._v_axis[0],
251
+ self._v_axis[1],
252
+ self._v_axis[2],
253
+ self._inner_radius_sq,
254
+ self._outer_radius_sq,
255
+ )
256
+
257
+ def get_materials(self) -> tuple | None:
258
+ """
259
+ Return (material_front, material_back) for Fresnel calculation.
260
+
261
+ Returns
262
+ -------
263
+ tuple or None
264
+ (material_front, material_back) or None if not OPTICAL
265
+ """
266
+ if self.role == SurfaceRole.OPTICAL:
267
+ return (self.material_front, self.material_back)
268
+ return None
269
+
270
+ def signed_distance(
271
+ self,
272
+ positions: npt.NDArray[np.float32],
273
+ ) -> npt.NDArray[np.float32]:
274
+ """
275
+ Compute signed distance from positions to plane.
276
+
277
+ Note: This returns signed distance to the infinite plane.
278
+ Bounds checking is performed in the intersection kernel.
279
+
280
+ Parameters
281
+ ----------
282
+ positions : ndarray, shape (N, 3)
283
+ Points to compute distance for
284
+
285
+ Returns
286
+ -------
287
+ ndarray, shape (N,)
288
+ Signed distance (positive on normal side, negative on back side)
289
+ """
290
+ normal = np.array(self._normal, dtype=np.float32)
291
+ center = np.array(self.center, dtype=np.float32)
292
+
293
+ # d = dot(p - center, normal)
294
+ diff = positions - center
295
+ return np.dot(diff, normal)
296
+
297
+ def intersect(
298
+ self,
299
+ origins: npt.NDArray[np.float32],
300
+ directions: npt.NDArray[np.float32],
301
+ min_distance: float = 1e-6,
302
+ ) -> tuple[npt.NDArray[np.float32], npt.NDArray[np.bool_]]:
303
+ """
304
+ Compute ray-plane intersection with annular bounds checking.
305
+
306
+ Parameters
307
+ ----------
308
+ origins : ndarray, shape (N, 3)
309
+ Ray origins
310
+ directions : ndarray, shape (N, 3)
311
+ Ray directions (normalized)
312
+ min_distance : float
313
+ Minimum valid intersection distance
314
+
315
+ Returns
316
+ -------
317
+ distances : ndarray, shape (N,)
318
+ Distance to intersection (inf if no hit)
319
+ hit_mask : ndarray, shape (N,)
320
+ Boolean mask of valid intersections
321
+ """
322
+ normal = np.array(self._normal, dtype=np.float32)
323
+ center = np.array(self.center, dtype=np.float32)
324
+ u_axis = np.array(self._u_axis, dtype=np.float32)
325
+ v_axis = np.array(self._v_axis, dtype=np.float32)
326
+
327
+ # t = dot(center - origin, normal) / dot(direction, normal)
328
+ denom = np.dot(directions, normal)
329
+
330
+ # Parallel rays don't intersect
331
+ parallel_mask = np.abs(denom) < 1e-10
332
+
333
+ diff = center - origins
334
+ t = np.dot(diff, normal) / np.where(parallel_mask, 1.0, denom)
335
+
336
+ # Valid intersection: not parallel, t >= min_distance
337
+ valid_t = (~parallel_mask) & (t >= min_distance)
338
+
339
+ # Compute intersection points
340
+ intersection_points = origins + t[:, np.newaxis] * directions
341
+
342
+ # Compute local coordinates relative to center
343
+ rel = intersection_points - center
344
+
345
+ # Project onto local axes
346
+ u_coord = np.dot(rel, u_axis)
347
+ v_coord = np.dot(rel, v_axis)
348
+
349
+ # Check annular bounds (circular)
350
+ r_sq = u_coord * u_coord + v_coord * v_coord
351
+ within_bounds = (r_sq >= self._inner_radius_sq) & (
352
+ r_sq <= self._outer_radius_sq
353
+ )
354
+
355
+ # Final hit mask
356
+ hit_mask = valid_t & within_bounds
357
+ distances = np.where(hit_mask, t, np.inf)
358
+
359
+ return distances.astype(np.float32), hit_mask
360
+
361
+ def normal_at(
362
+ self,
363
+ positions: npt.NDArray[np.float32],
364
+ incoming_directions: npt.NDArray[np.float32] | None = None,
365
+ ) -> npt.NDArray[np.float32]:
366
+ """
367
+ Compute surface normal at positions.
368
+
369
+ For a plane, normal is constant everywhere.
370
+
371
+ Parameters
372
+ ----------
373
+ positions : ndarray, shape (N, 3)
374
+ Points on the surface
375
+ incoming_directions : ndarray, shape (N, 3), optional
376
+ Ray directions (used to flip normal if needed)
377
+
378
+ Returns
379
+ -------
380
+ ndarray, shape (N, 3)
381
+ Normal vectors at each position
382
+ """
383
+ n = len(positions)
384
+ normals = np.tile(np.array(self._normal, dtype=np.float32), (n, 1))
385
+
386
+ # Optionally flip normals to face incoming rays
387
+ if incoming_directions is not None:
388
+ dot = np.sum(normals * incoming_directions, axis=1)
389
+ flip_mask = dot > 0 # Normal facing same direction as ray
390
+ normals[flip_mask] = -normals[flip_mask]
391
+
392
+ return normals
393
+
394
+ def get_local_coordinates(
395
+ self,
396
+ positions: npt.NDArray[np.float64],
397
+ ) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]:
398
+ """
399
+ Get local (u, v) coordinates for positions on the annulus.
400
+
401
+ Useful for post-processing azimuthal binning.
402
+
403
+ Parameters
404
+ ----------
405
+ positions : ndarray, shape (N, 3)
406
+ Points on or near the annular plane
407
+
408
+ Returns
409
+ -------
410
+ u_coords : ndarray, shape (N,)
411
+ U coordinate in local frame
412
+ v_coords : ndarray, shape (N,)
413
+ V coordinate in local frame
414
+ """
415
+ center = np.array(self.center, dtype=np.float64)
416
+ u_axis = np.array(self._u_axis, dtype=np.float64)
417
+ v_axis = np.array(self._v_axis, dtype=np.float64)
418
+
419
+ rel = positions - center
420
+ u_coords = np.dot(rel, u_axis)
421
+ v_coords = np.dot(rel, v_axis)
422
+
423
+ return u_coords, v_coords
424
+
425
+ def get_polar_coordinates(
426
+ self,
427
+ positions: npt.NDArray[np.float64],
428
+ ) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]:
429
+ """
430
+ Get polar (r, theta) coordinates for positions on the annulus.
431
+
432
+ Useful for post-processing azimuthal binning.
433
+
434
+ Parameters
435
+ ----------
436
+ positions : ndarray, shape (N, 3)
437
+ Points on or near the annular plane
438
+
439
+ Returns
440
+ -------
441
+ radii : ndarray, shape (N,)
442
+ Radial distance from center
443
+ azimuths : ndarray, shape (N,)
444
+ Azimuthal angle in radians (-pi to pi)
445
+ """
446
+ u_coords, v_coords = self.get_local_coordinates(positions)
447
+ radii = np.sqrt(u_coords * u_coords + v_coords * v_coords)
448
+ azimuths = np.arctan2(v_coords, u_coords)
449
+ return radii, azimuths
450
+
451
+
452
+ # Register class with registry
453
+ register_surface_type("annular_plane", "gpu", 7, AnnularPlaneSurface)