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.
- lsurf/__init__.py +471 -0
- lsurf/analysis/__init__.py +107 -0
- lsurf/analysis/healpix_utils.py +418 -0
- lsurf/analysis/sphere_viz.py +1280 -0
- lsurf/cli/__init__.py +48 -0
- lsurf/cli/build.py +398 -0
- lsurf/cli/config_schema.py +318 -0
- lsurf/cli/gui_cmd.py +76 -0
- lsurf/cli/interactive.py +850 -0
- lsurf/cli/main.py +81 -0
- lsurf/cli/run.py +806 -0
- lsurf/detectors/__init__.py +266 -0
- lsurf/detectors/analysis.py +289 -0
- lsurf/detectors/base.py +284 -0
- lsurf/detectors/constant_size_rings.py +485 -0
- lsurf/detectors/directional.py +45 -0
- lsurf/detectors/extended/__init__.py +73 -0
- lsurf/detectors/extended/local_sphere.py +353 -0
- lsurf/detectors/extended/recording_sphere.py +368 -0
- lsurf/detectors/planar.py +45 -0
- lsurf/detectors/protocol.py +187 -0
- lsurf/detectors/recording_spheres.py +63 -0
- lsurf/detectors/results.py +1140 -0
- lsurf/detectors/small/__init__.py +79 -0
- lsurf/detectors/small/directional.py +330 -0
- lsurf/detectors/small/planar.py +401 -0
- lsurf/detectors/small/spherical.py +450 -0
- lsurf/detectors/spherical.py +45 -0
- lsurf/geometry/__init__.py +199 -0
- lsurf/geometry/builder.py +478 -0
- lsurf/geometry/cell.py +228 -0
- lsurf/geometry/cell_geometry.py +247 -0
- lsurf/geometry/detector_arrays.py +1785 -0
- lsurf/geometry/geometry.py +222 -0
- lsurf/geometry/surface_analysis.py +375 -0
- lsurf/geometry/validation.py +91 -0
- lsurf/gui/__init__.py +51 -0
- lsurf/gui/app.py +903 -0
- lsurf/gui/core/__init__.py +39 -0
- lsurf/gui/core/scene.py +343 -0
- lsurf/gui/core/simulation.py +264 -0
- lsurf/gui/renderers/__init__.py +40 -0
- lsurf/gui/renderers/ray_renderer.py +353 -0
- lsurf/gui/renderers/source_renderer.py +505 -0
- lsurf/gui/renderers/surface_renderer.py +477 -0
- lsurf/gui/views/__init__.py +48 -0
- lsurf/gui/views/config_editor.py +3199 -0
- lsurf/gui/views/properties.py +257 -0
- lsurf/gui/views/results.py +291 -0
- lsurf/gui/views/scene_tree.py +180 -0
- lsurf/gui/views/viewport_3d.py +555 -0
- lsurf/gui/views/visualizations.py +712 -0
- lsurf/materials/__init__.py +169 -0
- lsurf/materials/base/__init__.py +64 -0
- lsurf/materials/base/full_inhomogeneous.py +208 -0
- lsurf/materials/base/grid_inhomogeneous.py +319 -0
- lsurf/materials/base/homogeneous.py +342 -0
- lsurf/materials/base/material_field.py +527 -0
- lsurf/materials/base/simple_inhomogeneous.py +418 -0
- lsurf/materials/base/spectral_inhomogeneous.py +497 -0
- lsurf/materials/implementations/__init__.py +120 -0
- lsurf/materials/implementations/data/alpha_values_typical_atmosphere_updated.txt +24 -0
- lsurf/materials/implementations/duct_atmosphere.py +390 -0
- lsurf/materials/implementations/exponential_atmosphere.py +435 -0
- lsurf/materials/implementations/gaussian_lens.py +120 -0
- lsurf/materials/implementations/interpolated_data.py +123 -0
- lsurf/materials/implementations/layered_atmosphere.py +134 -0
- lsurf/materials/implementations/linear_gradient.py +109 -0
- lsurf/materials/implementations/linsley_atmosphere.py +764 -0
- lsurf/materials/implementations/standard_materials.py +126 -0
- lsurf/materials/implementations/turbulent_atmosphere.py +135 -0
- lsurf/materials/implementations/us_standard_atmosphere.py +149 -0
- lsurf/materials/utils/__init__.py +77 -0
- lsurf/materials/utils/constants.py +45 -0
- lsurf/materials/utils/device_functions.py +117 -0
- lsurf/materials/utils/dispersion.py +160 -0
- lsurf/materials/utils/factories.py +142 -0
- lsurf/propagation/__init__.py +91 -0
- lsurf/propagation/detector_gpu.py +67 -0
- lsurf/propagation/gpu_device_rays.py +294 -0
- lsurf/propagation/kernels/__init__.py +175 -0
- lsurf/propagation/kernels/absorption/__init__.py +61 -0
- lsurf/propagation/kernels/absorption/grid.py +240 -0
- lsurf/propagation/kernels/absorption/simple.py +232 -0
- lsurf/propagation/kernels/absorption/spectral.py +410 -0
- lsurf/propagation/kernels/detection/__init__.py +64 -0
- lsurf/propagation/kernels/detection/protocol.py +102 -0
- lsurf/propagation/kernels/detection/spherical.py +255 -0
- lsurf/propagation/kernels/device_functions.py +790 -0
- lsurf/propagation/kernels/fresnel/__init__.py +64 -0
- lsurf/propagation/kernels/fresnel/protocol.py +97 -0
- lsurf/propagation/kernels/fresnel/standard.py +258 -0
- lsurf/propagation/kernels/intersection/__init__.py +79 -0
- lsurf/propagation/kernels/intersection/annular_plane.py +207 -0
- lsurf/propagation/kernels/intersection/bounded_plane.py +205 -0
- lsurf/propagation/kernels/intersection/plane.py +166 -0
- lsurf/propagation/kernels/intersection/protocol.py +95 -0
- lsurf/propagation/kernels/intersection/signed_distance.py +742 -0
- lsurf/propagation/kernels/intersection/sphere.py +190 -0
- lsurf/propagation/kernels/propagation/__init__.py +85 -0
- lsurf/propagation/kernels/propagation/grid.py +527 -0
- lsurf/propagation/kernels/propagation/protocol.py +105 -0
- lsurf/propagation/kernels/propagation/simple.py +460 -0
- lsurf/propagation/kernels/propagation/spectral.py +875 -0
- lsurf/propagation/kernels/registry.py +331 -0
- lsurf/propagation/kernels/surface/__init__.py +72 -0
- lsurf/propagation/kernels/surface/bisection.py +232 -0
- lsurf/propagation/kernels/surface/detection.py +402 -0
- lsurf/propagation/kernels/surface/reduction.py +166 -0
- lsurf/propagation/propagator_protocol.py +222 -0
- lsurf/propagation/propagators/__init__.py +101 -0
- lsurf/propagation/propagators/detector_handler.py +354 -0
- lsurf/propagation/propagators/factory.py +200 -0
- lsurf/propagation/propagators/fresnel_handler.py +305 -0
- lsurf/propagation/propagators/gpu_gradient.py +566 -0
- lsurf/propagation/propagators/gpu_surface_propagator.py +707 -0
- lsurf/propagation/propagators/gradient.py +429 -0
- lsurf/propagation/propagators/intersection_handler.py +327 -0
- lsurf/propagation/propagators/material_propagator.py +398 -0
- lsurf/propagation/propagators/signed_distance_handler.py +522 -0
- lsurf/propagation/propagators/spectral_gpu_gradient.py +553 -0
- lsurf/propagation/propagators/surface_interaction.py +616 -0
- lsurf/propagation/propagators/surface_propagator.py +719 -0
- lsurf/py.typed +1 -0
- lsurf/simulation/__init__.py +70 -0
- lsurf/simulation/config.py +164 -0
- lsurf/simulation/orchestrator.py +462 -0
- lsurf/simulation/result.py +299 -0
- lsurf/simulation/simulation.py +262 -0
- lsurf/sources/__init__.py +128 -0
- lsurf/sources/base.py +264 -0
- lsurf/sources/collimated.py +252 -0
- lsurf/sources/custom.py +409 -0
- lsurf/sources/diverging.py +228 -0
- lsurf/sources/gaussian.py +272 -0
- lsurf/sources/parallel_from_positions.py +197 -0
- lsurf/sources/point.py +172 -0
- lsurf/sources/uniform_diverging.py +258 -0
- lsurf/surfaces/__init__.py +184 -0
- lsurf/surfaces/cpu/__init__.py +50 -0
- lsurf/surfaces/cpu/curved_wave.py +463 -0
- lsurf/surfaces/cpu/gerstner_wave.py +381 -0
- lsurf/surfaces/cpu/wave_params.py +118 -0
- lsurf/surfaces/gpu/__init__.py +72 -0
- lsurf/surfaces/gpu/annular_plane.py +453 -0
- lsurf/surfaces/gpu/bounded_plane.py +390 -0
- lsurf/surfaces/gpu/curved_wave.py +483 -0
- lsurf/surfaces/gpu/gerstner_wave.py +377 -0
- lsurf/surfaces/gpu/multi_curved_wave.py +520 -0
- lsurf/surfaces/gpu/plane.py +299 -0
- lsurf/surfaces/gpu/recording_sphere.py +587 -0
- lsurf/surfaces/gpu/sphere.py +311 -0
- lsurf/surfaces/protocol.py +336 -0
- lsurf/surfaces/registry.py +373 -0
- lsurf/utilities/__init__.py +175 -0
- lsurf/utilities/detector_analysis.py +814 -0
- lsurf/utilities/fresnel.py +628 -0
- lsurf/utilities/interactions.py +1215 -0
- lsurf/utilities/propagation.py +602 -0
- lsurf/utilities/ray_data.py +532 -0
- lsurf/utilities/recording_sphere.py +745 -0
- lsurf/utilities/time_spread.py +463 -0
- lsurf/visualization/__init__.py +329 -0
- lsurf/visualization/absorption_plots.py +334 -0
- lsurf/visualization/atmospheric_plots.py +754 -0
- lsurf/visualization/common.py +348 -0
- lsurf/visualization/detector_plots.py +1350 -0
- lsurf/visualization/detector_sphere_plots.py +1173 -0
- lsurf/visualization/fresnel_plots.py +1061 -0
- lsurf/visualization/ocean_simulation_plots.py +999 -0
- lsurf/visualization/polarization_plots.py +916 -0
- lsurf/visualization/raytracing_plots.py +1521 -0
- lsurf/visualization/ring_detector_plots.py +1867 -0
- lsurf/visualization/time_spread_plots.py +531 -0
- lsurf-1.0.0.dist-info/METADATA +381 -0
- lsurf-1.0.0.dist-info/RECORD +180 -0
- lsurf-1.0.0.dist-info/WHEEL +5 -0
- lsurf-1.0.0.dist-info/entry_points.txt +2 -0
- lsurf-1.0.0.dist-info/licenses/LICENSE +32 -0
- lsurf-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,348 @@
|
|
|
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
|
+
Visualization Common Utilities
|
|
36
|
+
|
|
37
|
+
Shared styling, color mapping, and helper functions for all visualization modules.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
import matplotlib.pyplot as plt
|
|
41
|
+
import numpy as np
|
|
42
|
+
from matplotlib.cm import ScalarMappable
|
|
43
|
+
from matplotlib.colors import Normalize
|
|
44
|
+
|
|
45
|
+
# =============================================================================
|
|
46
|
+
# Default Style Configuration
|
|
47
|
+
# =============================================================================
|
|
48
|
+
|
|
49
|
+
DEFAULT_FIGSIZE = (10, 6)
|
|
50
|
+
DEFAULT_DPI = 150
|
|
51
|
+
|
|
52
|
+
# Color schemes
|
|
53
|
+
RAY_CMAP = "viridis"
|
|
54
|
+
INTENSITY_CMAP = "plasma"
|
|
55
|
+
WAVELENGTH_CMAP = "rainbow"
|
|
56
|
+
TIME_CMAP = "coolwarm"
|
|
57
|
+
GENERATION_CMAP = "tab10"
|
|
58
|
+
|
|
59
|
+
# Plot styling
|
|
60
|
+
GRID_ALPHA = 0.3
|
|
61
|
+
LINE_ALPHA = 0.6
|
|
62
|
+
SCATTER_ALPHA = 0.5
|
|
63
|
+
DEFAULT_LINEWIDTH = 0.5
|
|
64
|
+
DEFAULT_MARKERSIZE = 5
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# =============================================================================
|
|
68
|
+
# Color Mapping Utilities
|
|
69
|
+
# =============================================================================
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def get_color_mapping(
|
|
73
|
+
values: np.ndarray,
|
|
74
|
+
cmap_name: str = "viridis",
|
|
75
|
+
vmin: float | None = None,
|
|
76
|
+
vmax: float | None = None,
|
|
77
|
+
) -> tuple[np.ndarray, Normalize, ScalarMappable]:
|
|
78
|
+
"""
|
|
79
|
+
Create color mapping for values.
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
----------
|
|
83
|
+
values : ndarray
|
|
84
|
+
Values to map to colors.
|
|
85
|
+
cmap_name : str
|
|
86
|
+
Matplotlib colormap name.
|
|
87
|
+
vmin, vmax : float, optional
|
|
88
|
+
Value range. If None, uses data min/max.
|
|
89
|
+
|
|
90
|
+
Returns
|
|
91
|
+
-------
|
|
92
|
+
colors : ndarray
|
|
93
|
+
RGBA colors for each value.
|
|
94
|
+
norm : Normalize
|
|
95
|
+
Normalization object.
|
|
96
|
+
sm : ScalarMappable
|
|
97
|
+
ScalarMappable for colorbar.
|
|
98
|
+
"""
|
|
99
|
+
cmap = plt.cm.get_cmap(cmap_name)
|
|
100
|
+
|
|
101
|
+
if vmin is None:
|
|
102
|
+
vmin = np.min(values)
|
|
103
|
+
if vmax is None:
|
|
104
|
+
vmax = np.max(values)
|
|
105
|
+
|
|
106
|
+
norm = Normalize(vmin=vmin, vmax=vmax)
|
|
107
|
+
colors = cmap(norm(values))
|
|
108
|
+
sm = ScalarMappable(norm=norm, cmap=cmap)
|
|
109
|
+
sm.set_array([])
|
|
110
|
+
|
|
111
|
+
return colors, norm, sm
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def wavelength_to_color(
|
|
115
|
+
wavelength_m: float | np.ndarray,
|
|
116
|
+
) -> tuple[float, float, float] | np.ndarray:
|
|
117
|
+
"""
|
|
118
|
+
Convert wavelength (in meters) to approximate visible color.
|
|
119
|
+
|
|
120
|
+
Parameters
|
|
121
|
+
----------
|
|
122
|
+
wavelength_m : float or ndarray
|
|
123
|
+
Wavelength in meters.
|
|
124
|
+
|
|
125
|
+
Returns
|
|
126
|
+
-------
|
|
127
|
+
color : tuple or ndarray
|
|
128
|
+
RGB color tuple(s) in [0, 1] range.
|
|
129
|
+
|
|
130
|
+
Notes
|
|
131
|
+
-----
|
|
132
|
+
Uses simplified visible spectrum approximation.
|
|
133
|
+
Wavelengths outside visible range return gray.
|
|
134
|
+
"""
|
|
135
|
+
wavelength_nm = np.asarray(wavelength_m) * 1e9
|
|
136
|
+
|
|
137
|
+
# Simple approximation of visible spectrum
|
|
138
|
+
r = np.zeros_like(wavelength_nm)
|
|
139
|
+
g = np.zeros_like(wavelength_nm)
|
|
140
|
+
b = np.zeros_like(wavelength_nm)
|
|
141
|
+
|
|
142
|
+
# Violet to blue (380-440nm)
|
|
143
|
+
mask = (wavelength_nm >= 380) & (wavelength_nm < 440)
|
|
144
|
+
r[mask] = -(wavelength_nm[mask] - 440) / (440 - 380)
|
|
145
|
+
b[mask] = 1.0
|
|
146
|
+
|
|
147
|
+
# Blue to cyan (440-490nm)
|
|
148
|
+
mask = (wavelength_nm >= 440) & (wavelength_nm < 490)
|
|
149
|
+
g[mask] = (wavelength_nm[mask] - 440) / (490 - 440)
|
|
150
|
+
b[mask] = 1.0
|
|
151
|
+
|
|
152
|
+
# Cyan to green (490-510nm)
|
|
153
|
+
mask = (wavelength_nm >= 490) & (wavelength_nm < 510)
|
|
154
|
+
g[mask] = 1.0
|
|
155
|
+
b[mask] = -(wavelength_nm[mask] - 510) / (510 - 490)
|
|
156
|
+
|
|
157
|
+
# Green to yellow (510-580nm)
|
|
158
|
+
mask = (wavelength_nm >= 510) & (wavelength_nm < 580)
|
|
159
|
+
r[mask] = (wavelength_nm[mask] - 510) / (580 - 510)
|
|
160
|
+
g[mask] = 1.0
|
|
161
|
+
|
|
162
|
+
# Yellow to red (580-645nm)
|
|
163
|
+
mask = (wavelength_nm >= 580) & (wavelength_nm < 645)
|
|
164
|
+
r[mask] = 1.0
|
|
165
|
+
g[mask] = -(wavelength_nm[mask] - 645) / (645 - 580)
|
|
166
|
+
|
|
167
|
+
# Red (645-750nm)
|
|
168
|
+
mask = (wavelength_nm >= 645) & (wavelength_nm <= 750)
|
|
169
|
+
r[mask] = 1.0
|
|
170
|
+
|
|
171
|
+
# Gray for out-of-range
|
|
172
|
+
mask = (wavelength_nm < 380) | (wavelength_nm > 750)
|
|
173
|
+
r[mask] = g[mask] = b[mask] = 0.5
|
|
174
|
+
|
|
175
|
+
if np.isscalar(wavelength_m):
|
|
176
|
+
return (float(r), float(g), float(b))
|
|
177
|
+
|
|
178
|
+
return np.stack([r, g, b], axis=-1)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
# =============================================================================
|
|
182
|
+
# Axis Setup Utilities
|
|
183
|
+
# =============================================================================
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def setup_axis_grid(
|
|
187
|
+
ax: plt.Axes,
|
|
188
|
+
xlabel: str = "",
|
|
189
|
+
ylabel: str = "",
|
|
190
|
+
title: str = "",
|
|
191
|
+
grid: bool = True,
|
|
192
|
+
) -> None:
|
|
193
|
+
"""
|
|
194
|
+
Apply standard axis formatting.
|
|
195
|
+
|
|
196
|
+
Parameters
|
|
197
|
+
----------
|
|
198
|
+
ax : Axes
|
|
199
|
+
Matplotlib axes.
|
|
200
|
+
xlabel, ylabel : str
|
|
201
|
+
Axis labels.
|
|
202
|
+
title : str
|
|
203
|
+
Axis title.
|
|
204
|
+
grid : bool
|
|
205
|
+
Whether to show grid.
|
|
206
|
+
"""
|
|
207
|
+
ax.set_xlabel(xlabel)
|
|
208
|
+
ax.set_ylabel(ylabel)
|
|
209
|
+
if title:
|
|
210
|
+
ax.set_title(title)
|
|
211
|
+
if grid:
|
|
212
|
+
ax.grid(True, alpha=GRID_ALPHA)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def add_colorbar(
|
|
216
|
+
ax: plt.Axes,
|
|
217
|
+
mappable: ScalarMappable,
|
|
218
|
+
label: str = "",
|
|
219
|
+
orientation: str = "vertical",
|
|
220
|
+
) -> plt.colorbar:
|
|
221
|
+
"""
|
|
222
|
+
Add colorbar to axes.
|
|
223
|
+
|
|
224
|
+
Parameters
|
|
225
|
+
----------
|
|
226
|
+
ax : Axes
|
|
227
|
+
Matplotlib axes.
|
|
228
|
+
mappable : ScalarMappable
|
|
229
|
+
Object with color mapping.
|
|
230
|
+
label : str
|
|
231
|
+
Colorbar label.
|
|
232
|
+
orientation : str
|
|
233
|
+
'vertical' or 'horizontal'.
|
|
234
|
+
|
|
235
|
+
Returns
|
|
236
|
+
-------
|
|
237
|
+
colorbar
|
|
238
|
+
Matplotlib colorbar object.
|
|
239
|
+
"""
|
|
240
|
+
cbar = plt.colorbar(mappable, ax=ax, orientation=orientation, pad=0.02)
|
|
241
|
+
if label:
|
|
242
|
+
cbar.set_label(label)
|
|
243
|
+
return cbar
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
# =============================================================================
|
|
247
|
+
# Figure Creation Utilities
|
|
248
|
+
# =============================================================================
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def create_figure(
|
|
252
|
+
nrows: int = 1,
|
|
253
|
+
ncols: int = 1,
|
|
254
|
+
figsize: tuple[float, float] | None = None,
|
|
255
|
+
constrained_layout: bool = True,
|
|
256
|
+
**kwargs,
|
|
257
|
+
) -> tuple[plt.Figure, plt.Axes | np.ndarray]:
|
|
258
|
+
"""
|
|
259
|
+
Create figure with standard settings.
|
|
260
|
+
|
|
261
|
+
Parameters
|
|
262
|
+
----------
|
|
263
|
+
nrows, ncols : int
|
|
264
|
+
Number of subplot rows and columns.
|
|
265
|
+
figsize : tuple, optional
|
|
266
|
+
Figure size. Defaults to scaled DEFAULT_FIGSIZE.
|
|
267
|
+
constrained_layout : bool
|
|
268
|
+
Use constrained layout.
|
|
269
|
+
**kwargs
|
|
270
|
+
Additional arguments to plt.subplots.
|
|
271
|
+
|
|
272
|
+
Returns
|
|
273
|
+
-------
|
|
274
|
+
fig : Figure
|
|
275
|
+
Matplotlib figure.
|
|
276
|
+
axes : Axes or ndarray
|
|
277
|
+
Axes object(s).
|
|
278
|
+
"""
|
|
279
|
+
if figsize is None:
|
|
280
|
+
width = DEFAULT_FIGSIZE[0] * ncols / 2
|
|
281
|
+
height = DEFAULT_FIGSIZE[1] * nrows / 2
|
|
282
|
+
figsize = (width, height)
|
|
283
|
+
|
|
284
|
+
return plt.subplots(
|
|
285
|
+
nrows, ncols, figsize=figsize, constrained_layout=constrained_layout, **kwargs
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def save_figure(
|
|
290
|
+
fig: plt.Figure,
|
|
291
|
+
path: str,
|
|
292
|
+
dpi: int = DEFAULT_DPI,
|
|
293
|
+
bbox_inches: str = "tight",
|
|
294
|
+
**kwargs,
|
|
295
|
+
) -> None:
|
|
296
|
+
"""
|
|
297
|
+
Save figure with standard settings.
|
|
298
|
+
|
|
299
|
+
Parameters
|
|
300
|
+
----------
|
|
301
|
+
fig : Figure
|
|
302
|
+
Matplotlib figure.
|
|
303
|
+
path : str
|
|
304
|
+
Output path.
|
|
305
|
+
dpi : int
|
|
306
|
+
Resolution.
|
|
307
|
+
bbox_inches : str
|
|
308
|
+
Bounding box setting.
|
|
309
|
+
**kwargs
|
|
310
|
+
Additional arguments to savefig.
|
|
311
|
+
"""
|
|
312
|
+
fig.savefig(path, dpi=dpi, bbox_inches=bbox_inches, **kwargs)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
# =============================================================================
|
|
316
|
+
# Coordinate Projection Utilities
|
|
317
|
+
# =============================================================================
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def get_projection_config(projection: str) -> tuple[int, int, str, str]:
|
|
321
|
+
"""Get axis indices and labels for xy/xz/yz projections.
|
|
322
|
+
|
|
323
|
+
Parameters
|
|
324
|
+
----------
|
|
325
|
+
projection : str
|
|
326
|
+
Projection plane: 'xy', 'xz', or 'yz'.
|
|
327
|
+
|
|
328
|
+
Returns
|
|
329
|
+
-------
|
|
330
|
+
idx1 : int
|
|
331
|
+
First coordinate index (0=x, 1=y, 2=z).
|
|
332
|
+
idx2 : int
|
|
333
|
+
Second coordinate index.
|
|
334
|
+
xlabel : str
|
|
335
|
+
Label for first axis.
|
|
336
|
+
ylabel : str
|
|
337
|
+
Label for second axis.
|
|
338
|
+
"""
|
|
339
|
+
proj_map = {"xy": (0, 1), "xz": (0, 2), "yz": (1, 2)}
|
|
340
|
+
label_map = {
|
|
341
|
+
"xy": ("X (m)", "Y (m)"),
|
|
342
|
+
"xz": ("X (m)", "Z (m)"),
|
|
343
|
+
"yz": ("Y (m)", "Z (m)"),
|
|
344
|
+
}
|
|
345
|
+
projection = projection.lower()
|
|
346
|
+
idx1, idx2 = proj_map.get(projection, (0, 2))
|
|
347
|
+
xlabel, ylabel = label_map.get(projection, ("X (m)", "Z (m)"))
|
|
348
|
+
return idx1, idx2, xlabel, ylabel
|