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,531 @@
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
+ Time Spread Visualization
36
+
37
+ Plotting functions for geometric time spread estimation and analysis.
38
+ """
39
+
40
+ import matplotlib.pyplot as plt
41
+ import numpy as np
42
+
43
+ from ..utilities.time_spread import TimeSpreadResult
44
+ from .common import GRID_ALPHA, save_figure
45
+
46
+ # =============================================================================
47
+ # Single-Axis Functions
48
+ # =============================================================================
49
+
50
+
51
+ def plot_time_spread_geometry_side(
52
+ ax: plt.Axes,
53
+ result: TimeSpreadResult,
54
+ source_position: tuple[float, float, float],
55
+ detector_position: tuple[float, float, float],
56
+ scale: float = 1000.0,
57
+ ) -> None:
58
+ """
59
+ Plot side view (X-Z plane) of time spread geometry.
60
+
61
+ Parameters
62
+ ----------
63
+ ax : Axes
64
+ Matplotlib axes to plot on.
65
+ result : TimeSpreadResult
66
+ Time spread estimation result.
67
+ source_position : tuple
68
+ (x, y, z) source position in meters.
69
+ detector_position : tuple
70
+ (x, y, z) detector position in meters.
71
+ scale : float
72
+ Scale factor for display (default 1000 for km).
73
+ """
74
+ edge_points = result.edge_points
75
+ center_point = result.center_point
76
+ min_pt = result.min_path_point
77
+ max_pt = result.max_path_point
78
+ det = np.array(detector_position)
79
+ src = np.array(source_position)
80
+
81
+ # Ocean surface
82
+ x_range = max(
83
+ abs(edge_points[:, 0].min()), abs(edge_points[:, 0].max()), abs(det[0])
84
+ )
85
+ x_ocean = np.linspace(min(src[0] / scale - 2, -5), x_range / scale + 5, 200)
86
+ ax.fill_between(x_ocean, 0, -2, color="lightblue", alpha=0.5, label="Ocean")
87
+ ax.axhline(y=0, color="blue", linewidth=2)
88
+
89
+ # Source
90
+ ax.plot(
91
+ src[0] / scale, src[2] / scale, "ro", markersize=12, label="Source", zorder=10
92
+ )
93
+
94
+ # Detector point
95
+ ax.plot(
96
+ det[0] / scale, det[2] / scale, "g*", markersize=15, label="Detector", zorder=10
97
+ )
98
+
99
+ # Detector sphere arc (faint)
100
+ det_r = np.linalg.norm(det) / scale
101
+ theta_arc = np.linspace(0, np.pi / 2, 100)
102
+ ax.plot(
103
+ det_r * np.cos(theta_arc),
104
+ det_r * np.sin(theta_arc),
105
+ "g-",
106
+ alpha=0.3,
107
+ linewidth=1,
108
+ )
109
+
110
+ # Center ray path
111
+ ax.plot(
112
+ [src[0] / scale, center_point[0] / scale],
113
+ [src[2] / scale, center_point[2] / scale],
114
+ "k-",
115
+ linewidth=2,
116
+ alpha=0.5,
117
+ )
118
+ ax.plot(
119
+ [center_point[0] / scale, det[0] / scale],
120
+ [center_point[2] / scale, det[2] / scale],
121
+ "k-",
122
+ linewidth=2,
123
+ alpha=0.5,
124
+ label="Center ray",
125
+ )
126
+
127
+ # Shortest path (min time)
128
+ ax.plot(
129
+ [src[0] / scale, min_pt[0] / scale],
130
+ [src[2] / scale, min_pt[2] / scale],
131
+ "b-",
132
+ linewidth=2,
133
+ )
134
+ ax.plot(
135
+ [min_pt[0] / scale, det[0] / scale],
136
+ [min_pt[2] / scale, det[2] / scale],
137
+ "b--",
138
+ linewidth=2,
139
+ label=f"Shortest path ({result.min_path/1000:.2f} km)",
140
+ )
141
+ ax.plot(min_pt[0] / scale, min_pt[2] / scale, "bo", markersize=8)
142
+
143
+ # Longest path (max time)
144
+ ax.plot(
145
+ [src[0] / scale, max_pt[0] / scale],
146
+ [src[2] / scale, max_pt[2] / scale],
147
+ "r-",
148
+ linewidth=2,
149
+ )
150
+ ax.plot(
151
+ [max_pt[0] / scale, det[0] / scale],
152
+ [max_pt[2] / scale, det[2] / scale],
153
+ "r--",
154
+ linewidth=2,
155
+ label=f"Longest path ({result.max_path/1000:.2f} km)",
156
+ )
157
+ ax.plot(max_pt[0] / scale, max_pt[2] / scale, "rs", markersize=8)
158
+
159
+ ax.set_xlabel("X (km)", fontsize=12)
160
+ ax.set_ylabel("Z (km)", fontsize=12)
161
+ ax.set_title("Time Spread Geometry - Side View", fontsize=14, fontweight="bold")
162
+ ax.legend(loc="upper left", fontsize=9)
163
+ ax.grid(True, alpha=GRID_ALPHA)
164
+ ax.set_xlim(src[0] / scale - 2, det[0] / scale + 2)
165
+ ax.set_ylim(-1, det[2] / scale + 2)
166
+
167
+
168
+ def plot_beam_footprint_top(
169
+ ax: plt.Axes,
170
+ result: TimeSpreadResult,
171
+ source_position: tuple[float, float, float],
172
+ detector_position: tuple[float, float, float],
173
+ grazing_angle_deg: float | None = None,
174
+ ) -> None:
175
+ """
176
+ Plot top view (X-Y plane) of beam footprint.
177
+
178
+ Parameters
179
+ ----------
180
+ ax : Axes
181
+ Matplotlib axes to plot on.
182
+ result : TimeSpreadResult
183
+ Time spread estimation result.
184
+ source_position : tuple
185
+ (x, y, z) source position in meters.
186
+ detector_position : tuple
187
+ (x, y, z) detector position in meters.
188
+ grazing_angle_deg : float, optional
189
+ Grazing angle for display in info box.
190
+ """
191
+ edge_points = result.edge_points
192
+ center_point = result.center_point
193
+ min_pt = result.min_path_point
194
+ max_pt = result.max_path_point
195
+ src = np.array(source_position)
196
+ det = np.array(detector_position)
197
+
198
+ ax.fill(
199
+ edge_points[:, 0],
200
+ edge_points[:, 1],
201
+ color="lightblue",
202
+ alpha=0.5,
203
+ label="Beam footprint",
204
+ )
205
+ ax.plot(
206
+ np.append(edge_points[:, 0], edge_points[0, 0]),
207
+ np.append(edge_points[:, 1], edge_points[0, 1]),
208
+ "b-",
209
+ linewidth=2,
210
+ )
211
+
212
+ ax.plot(center_point[0], center_point[1], "ko", markersize=10, label="Center")
213
+ ax.plot(min_pt[0], min_pt[1], "bo", markersize=12, label="Shortest path point")
214
+ ax.plot(max_pt[0], max_pt[1], "rs", markersize=12, label="Longest path point")
215
+ ax.plot(src[0], src[1], "ro", markersize=12, label="Source (projected)")
216
+ ax.plot(det[0], det[1], "g*", markersize=15, label="Detector (projected)")
217
+
218
+ ax.set_xlabel("X (m)", fontsize=12)
219
+ ax.set_ylabel("Y (m)", fontsize=12)
220
+ ax.set_title("Beam Footprint - Top View", fontsize=14, fontweight="bold")
221
+ ax.legend(loc="upper right", fontsize=9)
222
+ ax.set_aspect("equal")
223
+ ax.grid(True, alpha=GRID_ALPHA)
224
+
225
+ # Info box
226
+ lines = [
227
+ f"Path spread: {result.path_spread:.2f} m",
228
+ f"Time spread: {result.time_spread_ns:.2f} ns",
229
+ ]
230
+ if grazing_angle_deg is not None:
231
+ lines.append(f"Grazing angle: {grazing_angle_deg}°")
232
+ textstr = "\n".join(lines)
233
+ props = {"boxstyle": "round", "facecolor": "wheat", "alpha": 0.8}
234
+ ax.text(
235
+ 0.02,
236
+ 0.98,
237
+ textstr,
238
+ transform=ax.transAxes,
239
+ fontsize=11,
240
+ verticalalignment="top",
241
+ bbox=props,
242
+ )
243
+
244
+
245
+ def plot_arrival_time_histogram(
246
+ ax: plt.Axes,
247
+ result: TimeSpreadResult,
248
+ threshold_ns: float = 10.0,
249
+ ) -> None:
250
+ """
251
+ Plot histogram of arrival times for edge rays.
252
+
253
+ Parameters
254
+ ----------
255
+ ax : Axes
256
+ Matplotlib axes to plot on.
257
+ result : TimeSpreadResult
258
+ Time spread estimation result.
259
+ threshold_ns : float
260
+ Time threshold to mark on plot.
261
+ """
262
+ speed_of_light = 299792458.0
263
+ arrival_times_ns = (result.path_lengths / speed_of_light) * 1e9
264
+ relative_times_ns = arrival_times_ns - arrival_times_ns.min()
265
+
266
+ ax.hist(relative_times_ns, bins=30, color="steelblue", edgecolor="black", alpha=0.7)
267
+ ax.axvline(x=0, color="blue", linestyle="-", linewidth=2, label="Earliest arrival")
268
+ ax.axvline(
269
+ x=result.time_spread_ns,
270
+ color="red",
271
+ linestyle="-",
272
+ linewidth=2,
273
+ label="Latest arrival",
274
+ )
275
+ ax.axvline(
276
+ x=threshold_ns,
277
+ color="orange",
278
+ linestyle="--",
279
+ linewidth=1.5,
280
+ label=f"{threshold_ns:.0f} ns threshold",
281
+ )
282
+
283
+ ax.set_xlabel("Relative Arrival Time (ns)", fontsize=12)
284
+ ax.set_ylabel("Number of Edge Rays", fontsize=12)
285
+ ax.set_title("Arrival Time Distribution", fontsize=14, fontweight="bold")
286
+ ax.legend(fontsize=9)
287
+ ax.grid(True, alpha=GRID_ALPHA)
288
+
289
+ # Stats box
290
+ textstr = "\n".join(
291
+ [
292
+ f"Mean: {np.mean(relative_times_ns):.2f} ns",
293
+ f"Std: {np.std(relative_times_ns):.2f} ns",
294
+ f"Range: {result.time_spread_ns:.2f} ns",
295
+ ]
296
+ )
297
+ props = {"boxstyle": "round", "facecolor": "wheat", "alpha": 0.8}
298
+ ax.text(
299
+ 0.97,
300
+ 0.97,
301
+ textstr,
302
+ transform=ax.transAxes,
303
+ fontsize=10,
304
+ verticalalignment="top",
305
+ horizontalalignment="right",
306
+ bbox=props,
307
+ )
308
+
309
+
310
+ def plot_footprint_arrival_times(
311
+ ax: plt.Axes,
312
+ result: TimeSpreadResult,
313
+ ) -> None:
314
+ """
315
+ Plot footprint colored by arrival time.
316
+
317
+ Parameters
318
+ ----------
319
+ ax : Axes
320
+ Matplotlib axes to plot on.
321
+ result : TimeSpreadResult
322
+ Time spread estimation result.
323
+ """
324
+ speed_of_light = 299792458.0
325
+ arrival_times_ns = (result.path_lengths / speed_of_light) * 1e9
326
+ relative_times_ns = arrival_times_ns - arrival_times_ns.min()
327
+
328
+ edge_points = result.edge_points
329
+
330
+ sc = ax.scatter(
331
+ edge_points[:, 0],
332
+ edge_points[:, 1],
333
+ c=relative_times_ns,
334
+ s=50,
335
+ cmap="coolwarm",
336
+ edgecolors="black",
337
+ linewidths=0.5,
338
+ )
339
+
340
+ ax.plot(
341
+ result.min_path_point[0],
342
+ result.min_path_point[1],
343
+ "bo",
344
+ markersize=15,
345
+ markeredgecolor="black",
346
+ markeredgewidth=2,
347
+ label="Earliest",
348
+ zorder=10,
349
+ )
350
+ ax.plot(
351
+ result.max_path_point[0],
352
+ result.max_path_point[1],
353
+ "ro",
354
+ markersize=15,
355
+ markeredgecolor="black",
356
+ markeredgewidth=2,
357
+ label="Latest",
358
+ zorder=10,
359
+ )
360
+ ax.plot(
361
+ result.center_point[0],
362
+ result.center_point[1],
363
+ "k+",
364
+ markersize=15,
365
+ markeredgewidth=2,
366
+ label="Center",
367
+ )
368
+
369
+ cbar = plt.colorbar(sc, ax=ax)
370
+ cbar.set_label("Relative Arrival Time (ns)", fontsize=11)
371
+
372
+ ax.set_xlabel("X (m)", fontsize=12)
373
+ ax.set_ylabel("Y (m)", fontsize=12)
374
+ ax.set_title("Footprint Colored by Arrival Time", fontsize=14, fontweight="bold")
375
+ ax.legend(loc="upper right", fontsize=9)
376
+ ax.set_aspect("equal")
377
+ ax.grid(True, alpha=GRID_ALPHA)
378
+
379
+
380
+ def plot_time_spread_vs_divergence(
381
+ ax: plt.Axes,
382
+ divergences_deg: np.ndarray,
383
+ time_spreads_ns: np.ndarray,
384
+ threshold_ns: float = 10.0,
385
+ source_altitude: float | None = None,
386
+ grazing_angle_deg: float | None = None,
387
+ detector_altitude: float | None = None,
388
+ ) -> None:
389
+ """
390
+ Plot time spread as function of beam divergence.
391
+
392
+ Parameters
393
+ ----------
394
+ ax : Axes
395
+ Matplotlib axes to plot on.
396
+ divergences_deg : ndarray
397
+ Array of divergence angles in degrees.
398
+ time_spreads_ns : ndarray
399
+ Corresponding time spreads in nanoseconds.
400
+ threshold_ns : float
401
+ Time threshold to mark on plot.
402
+ source_altitude, grazing_angle_deg, detector_altitude : float, optional
403
+ Parameters for title display.
404
+ """
405
+ ax.plot(divergences_deg, time_spreads_ns, "b-", linewidth=2)
406
+ ax.axhline(
407
+ y=threshold_ns,
408
+ color="r",
409
+ linestyle="--",
410
+ linewidth=1.5,
411
+ label=f"{threshold_ns:.0f} ns threshold",
412
+ )
413
+
414
+ # Find and mark crossing point
415
+ if time_spreads_ns[0] < threshold_ns < time_spreads_ns[-1]:
416
+ cross_idx = np.where(time_spreads_ns > threshold_ns)[0][0]
417
+ cross_div = divergences_deg[cross_idx]
418
+ ax.axvline(x=cross_div, color="orange", linestyle=":", linewidth=1.5)
419
+ ax.annotate(
420
+ f"{cross_div:.2f}°",
421
+ (cross_div, threshold_ns),
422
+ xytext=(cross_div + 0.3, threshold_ns * 1.5),
423
+ fontsize=10,
424
+ arrowprops={"arrowstyle": "->", "color": "orange"},
425
+ )
426
+
427
+ ax.set_xlabel("Beam Divergence Half-Angle (degrees)", fontsize=12)
428
+ ax.set_ylabel("Maximum Time Spread (ns)", fontsize=12)
429
+
430
+ # Build title
431
+ title_parts = ["Time Spread vs Beam Divergence"]
432
+ if source_altitude is not None or grazing_angle_deg is not None:
433
+ subtitle_parts = []
434
+ if source_altitude is not None:
435
+ subtitle_parts.append(f"Altitude: {source_altitude/1000:.1f} km")
436
+ if grazing_angle_deg is not None:
437
+ subtitle_parts.append(f"Grazing: {grazing_angle_deg}°")
438
+ if detector_altitude is not None:
439
+ subtitle_parts.append(f"Detector: {detector_altitude/1000:.0f} km")
440
+ title_parts.append(f"({', '.join(subtitle_parts)})")
441
+ ax.set_title("\n".join(title_parts), fontsize=12, fontweight="bold")
442
+
443
+ ax.legend(fontsize=10)
444
+ ax.grid(True, alpha=GRID_ALPHA)
445
+ ax.set_xlim(divergences_deg.min(), divergences_deg.max())
446
+ ax.set_yscale("log")
447
+
448
+
449
+ # =============================================================================
450
+ # Composite Figure Builders
451
+ # =============================================================================
452
+
453
+
454
+ def create_time_spread_schematic(
455
+ result: TimeSpreadResult,
456
+ source_position: tuple[float, float, float],
457
+ detector_position: tuple[float, float, float],
458
+ grazing_angle_deg: float | None = None,
459
+ save_path: str | None = None,
460
+ ) -> plt.Figure:
461
+ """
462
+ Create composite figure showing time spread geometry.
463
+
464
+ Parameters
465
+ ----------
466
+ result : TimeSpreadResult
467
+ Time spread estimation result.
468
+ source_position : tuple
469
+ (x, y, z) source position in meters.
470
+ detector_position : tuple
471
+ (x, y, z) detector position in meters.
472
+ grazing_angle_deg : float, optional
473
+ Grazing angle for display.
474
+ save_path : str, optional
475
+ Path to save figure.
476
+
477
+ Returns
478
+ -------
479
+ fig : Figure
480
+ Matplotlib figure.
481
+ """
482
+ fig, axes = plt.subplots(1, 2, figsize=(16, 7))
483
+
484
+ plot_time_spread_geometry_side(axes[0], result, source_position, detector_position)
485
+ plot_beam_footprint_top(
486
+ axes[1], result, source_position, detector_position, grazing_angle_deg
487
+ )
488
+
489
+ plt.tight_layout()
490
+
491
+ if save_path:
492
+ save_figure(fig, save_path)
493
+ print(f" Saved: {save_path}")
494
+
495
+ return fig
496
+
497
+
498
+ def create_arrival_time_figure(
499
+ result: TimeSpreadResult,
500
+ threshold_ns: float = 10.0,
501
+ save_path: str | None = None,
502
+ ) -> plt.Figure:
503
+ """
504
+ Create composite figure showing arrival time distribution.
505
+
506
+ Parameters
507
+ ----------
508
+ result : TimeSpreadResult
509
+ Time spread estimation result.
510
+ threshold_ns : float
511
+ Time threshold to mark on plot.
512
+ save_path : str, optional
513
+ Path to save figure.
514
+
515
+ Returns
516
+ -------
517
+ fig : Figure
518
+ Matplotlib figure.
519
+ """
520
+ fig, axes = plt.subplots(1, 2, figsize=(14, 5))
521
+
522
+ plot_arrival_time_histogram(axes[0], result, threshold_ns)
523
+ plot_footprint_arrival_times(axes[1], result)
524
+
525
+ plt.tight_layout()
526
+
527
+ if save_path:
528
+ save_figure(fig, save_path)
529
+ print(f" Saved: {save_path}")
530
+
531
+ return fig