solprop-gui 0.2.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.
- solprop_gui/__init__.py +24 -0
- solprop_gui/__main__.py +11 -0
- solprop_gui/app.py +67 -0
- solprop_gui/classes/__init__.py +9 -0
- solprop_gui/classes/catalog.py +854 -0
- solprop_gui/classes/problem.py +868 -0
- solprop_gui/classes/workflow.py +139 -0
- solprop_gui/help/__init__.py +7 -0
- solprop_gui/help/figures/antiresonant.svg +70 -0
- solprop_gui/help/figures/capillary-averaged.svg +63 -0
- solprop_gui/help/figures/capillary-modal.svg +65 -0
- solprop_gui/help/figures/cartesian.svg +164 -0
- solprop_gui/help/figures/gnlse.svg +64 -0
- solprop_gui/help/figures/grin.svg +63 -0
- solprop_gui/help/figures/line.svg +84 -0
- solprop_gui/help/figures/radial.svg +68 -0
- solprop_gui/help/figures/rectangular.svg +63 -0
- solprop_gui/help/figures/slab.svg +68 -0
- solprop_gui/help/figures/step-index.svg +63 -0
- solprop_gui/help/figures.py +106 -0
- solprop_gui/help/guide/analysis.md +96 -0
- solprop_gui/help/guide/classes.md +94 -0
- solprop_gui/help/guide/design.md +59 -0
- solprop_gui/help/guide/first-run.md +101 -0
- solprop_gui/help/guide/images/capillary-along.png +0 -0
- solprop_gui/help/guide/images/capillary-overview.png +0 -0
- solprop_gui/help/guide/images/capillary-plane.png +0 -0
- solprop_gui/help/guide/images/capillary-run.png +0 -0
- solprop_gui/help/guide/images/capillary-sheet.png +0 -0
- solprop_gui/help/guide/images/capillary-target.png +0 -0
- solprop_gui/help/guide/images/design.png +0 -0
- solprop_gui/help/guide/images/filament-overview.png +0 -0
- solprop_gui/help/guide/images/filament-sheet.png +0 -0
- solprop_gui/help/guide/images/home.png +0 -0
- solprop_gui/help/guide/images/plot-menu.png +0 -0
- solprop_gui/help/guide/images/scan.png +0 -0
- solprop_gui/help/guide/index.md +104 -0
- solprop_gui/help/guide/scans.md +55 -0
- solprop_gui/help/guide.py +48 -0
- solprop_gui/help/manual.py +199 -0
- solprop_gui/model/__init__.py +12 -0
- solprop_gui/model/compressor.py +407 -0
- solprop_gui/model/display.py +501 -0
- solprop_gui/model/plot_options.py +343 -0
- solprop_gui/model/quantities.py +179 -0
- solprop_gui/model/recipe.py +473 -0
- solprop_gui/model/scans.py +288 -0
- solprop_gui/model/snippets.py +118 -0
- solprop_gui/model/stats_layout.py +115 -0
- solprop_gui/model/values.py +195 -0
- solprop_gui/model/workspace.py +151 -0
- solprop_gui/py.typed +0 -0
- solprop_gui/registry/__init__.py +12 -0
- solprop_gui/registry/explore.py +481 -0
- solprop_gui/registry/pages.py +273 -0
- solprop_gui/registry/routes.py +450 -0
- solprop_gui/registry/units.py +135 -0
- solprop_gui/service/__init__.py +12 -0
- solprop_gui/service/beam.py +226 -0
- solprop_gui/service/beams.py +257 -0
- solprop_gui/service/client.py +398 -0
- solprop_gui/service/design.py +362 -0
- solprop_gui/service/figures.py +106 -0
- solprop_gui/service/handlers.py +709 -0
- solprop_gui/service/kernel.py +187 -0
- solprop_gui/service/messages.py +210 -0
- solprop_gui/service/outbox.py +139 -0
- solprop_gui/service/postprocess.py +513 -0
- solprop_gui/service/reduce.py +368 -0
- solprop_gui/service/remote.py +513 -0
- solprop_gui/service/results.py +951 -0
- solprop_gui/service/run.py +648 -0
- solprop_gui/service/scan_reductions.py +261 -0
- solprop_gui/service/server.py +501 -0
- solprop_gui/service/sheet.py +1023 -0
- solprop_gui/service/states.py +146 -0
- solprop_gui/service/waveguide.py +320 -0
- solprop_gui/service/worker.py +97 -0
- solprop_gui/ui/__init__.py +11 -0
- solprop_gui/ui/analyse.py +808 -0
- solprop_gui/ui/analysis.py +338 -0
- solprop_gui/ui/analysis_pages.py +2954 -0
- solprop_gui/ui/assets/chevron.svg +6 -0
- solprop_gui/ui/assets/fonts/IBMPlexSans-Medium.ttf +0 -0
- solprop_gui/ui/assets/fonts/IBMPlexSans-Regular.ttf +0 -0
- solprop_gui/ui/assets/fonts/IBMPlexSans-SemiBold.ttf +0 -0
- solprop_gui/ui/assets/fonts/LICENSE.txt +93 -0
- solprop_gui/ui/assets/icon/solprop-1024.png +0 -0
- solprop_gui/ui/assets/icon/solprop-128.png +0 -0
- solprop_gui/ui/assets/icon/solprop-16.png +0 -0
- solprop_gui/ui/assets/icon/solprop-24.png +0 -0
- solprop_gui/ui/assets/icon/solprop-256.png +0 -0
- solprop_gui/ui/assets/icon/solprop-32.png +0 -0
- solprop_gui/ui/assets/icon/solprop-48.png +0 -0
- solprop_gui/ui/assets/icon/solprop-512.png +0 -0
- solprop_gui/ui/assets/icon/solprop-64.png +0 -0
- solprop_gui/ui/assets/icon/solprop-compact.svg +19 -0
- solprop_gui/ui/assets/icon/solprop.svg +20 -0
- solprop_gui/ui/betas.py +245 -0
- solprop_gui/ui/bridge.py +258 -0
- solprop_gui/ui/design_stage.py +956 -0
- solprop_gui/ui/document.py +693 -0
- solprop_gui/ui/fields.py +812 -0
- solprop_gui/ui/help_window.py +214 -0
- solprop_gui/ui/home.py +291 -0
- solprop_gui/ui/icons.py +191 -0
- solprop_gui/ui/identity.py +230 -0
- solprop_gui/ui/launch.py +261 -0
- solprop_gui/ui/objects.py +530 -0
- solprop_gui/ui/pages.py +436 -0
- solprop_gui/ui/pin.py +286 -0
- solprop_gui/ui/plot_options.py +439 -0
- solprop_gui/ui/postprocess.py +532 -0
- solprop_gui/ui/quantity.py +532 -0
- solprop_gui/ui/results.py +482 -0
- solprop_gui/ui/run_options.py +179 -0
- solprop_gui/ui/run_panel.py +767 -0
- solprop_gui/ui/scan_editor.py +421 -0
- solprop_gui/ui/scan_stage.py +724 -0
- solprop_gui/ui/sheet.py +1371 -0
- solprop_gui/ui/theme.py +247 -0
- solprop_gui/ui/tile_art.py +146 -0
- solprop_gui/ui/workflow_window.py +1332 -0
- solprop_gui/views/__init__.py +11 -0
- solprop_gui/views/compare.py +114 -0
- solprop_gui/views/compression.py +146 -0
- solprop_gui/views/controls.py +211 -0
- solprop_gui/views/cross_section.py +124 -0
- solprop_gui/views/live.py +704 -0
- solprop_gui/views/page_plots.py +1073 -0
- solprop_gui/views/plane.py +650 -0
- solprop_gui/views/plotting.py +381 -0
- solprop_gui/views/scan_browser.py +149 -0
- solprop_gui/views/sparkline.py +131 -0
- solprop_gui/views/splitter.py +141 -0
- solprop_gui/views/statistics.py +501 -0
- solprop_gui-0.2.0.dist-info/METADATA +92 -0
- solprop_gui-0.2.0.dist-info/RECORD +143 -0
- solprop_gui-0.2.0.dist-info/WHEEL +4 -0
- solprop_gui-0.2.0.dist-info/entry_points.txt +2 -0
- solprop_gui-0.2.0.dist-info/licenses/LICENSE +674 -0
- solprop_gui-0.2.0.dist-info/licenses/LICENSE-CC-BY-4.0.txt +156 -0
- solprop_gui-0.2.0.dist-info/licenses/src/solprop_gui/ui/assets/fonts/LICENSE.txt +93 -0
|
@@ -0,0 +1,2954 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 John C. Travers and contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
4
|
+
|
|
5
|
+
"""The pages of the Analyse rail (design 11.3).
|
|
6
|
+
|
|
7
|
+
A page draws one thing large and keeps its controls beside it. It asks the session for
|
|
8
|
+
what it shows, only while it is on screen: a hidden page is marked stale, and catches up
|
|
9
|
+
when it is next shown, so scrubbing costs only what can be seen.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
13
|
+
from dataclasses import replace
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
import numpy as np
|
|
17
|
+
import pyqtgraph as pg
|
|
18
|
+
from PySide6.QtCore import Qt, QTimer, Signal
|
|
19
|
+
from PySide6.QtGui import QShowEvent
|
|
20
|
+
from PySide6.QtWidgets import (
|
|
21
|
+
QComboBox,
|
|
22
|
+
QFrame,
|
|
23
|
+
QGridLayout,
|
|
24
|
+
QLineEdit,
|
|
25
|
+
QListWidget,
|
|
26
|
+
QListWidgetItem,
|
|
27
|
+
QPlainTextEdit,
|
|
28
|
+
QPushButton,
|
|
29
|
+
QVBoxLayout,
|
|
30
|
+
QWidget,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
from solprop_gui.model.display import (
|
|
34
|
+
beam_reach,
|
|
35
|
+
decibels,
|
|
36
|
+
duration_text,
|
|
37
|
+
even_rows,
|
|
38
|
+
length_unit,
|
|
39
|
+
light_range,
|
|
40
|
+
mirrored_rows,
|
|
41
|
+
pulse_window,
|
|
42
|
+
scaled_unit,
|
|
43
|
+
size_text,
|
|
44
|
+
wants_log,
|
|
45
|
+
)
|
|
46
|
+
from solprop_gui.registry.units import pretty, si
|
|
47
|
+
from solprop_gui.service.reduce import C
|
|
48
|
+
from solprop_gui.ui.analysis import AnalysisSession
|
|
49
|
+
from solprop_gui.ui.postprocess import PostprocessPage
|
|
50
|
+
from solprop_gui.ui.theme import clear_layout, named_label
|
|
51
|
+
from solprop_gui.views.controls import LabelledSlider, Segments, control_panel
|
|
52
|
+
from solprop_gui.views.page_plots import ORANGE, LinePlot, MapPlot
|
|
53
|
+
|
|
54
|
+
__all__ = [
|
|
55
|
+
"PAGE_VIEWS",
|
|
56
|
+
"AlongPage",
|
|
57
|
+
"BeamOverviewPage",
|
|
58
|
+
"BeamPlanePage",
|
|
59
|
+
"CompressPage",
|
|
60
|
+
"FarFieldPage",
|
|
61
|
+
"HealthPage",
|
|
62
|
+
"ModesPage",
|
|
63
|
+
"OnAxisPage",
|
|
64
|
+
"OverviewPage",
|
|
65
|
+
"PageView",
|
|
66
|
+
"PlanePage",
|
|
67
|
+
"SpectrogramPage",
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
_AXES = (("wavelength", "Wavelength"), ("f", "Frequency"))
|
|
71
|
+
_AXIS_LABEL = {"wavelength": "Wavelength (nm)", "f": "Frequency (THz)"}
|
|
72
|
+
_AXIS_UNIT = {"wavelength": "nm", "f": "THz"}
|
|
73
|
+
_AXIS_SCALE = {"wavelength": 1e9, "f": 1e-12}
|
|
74
|
+
_FS = 1e15
|
|
75
|
+
_LIVE_MS = 250
|
|
76
|
+
"""The live maps redraw at most this often, whatever the run's speed."""
|
|
77
|
+
|
|
78
|
+
_PHASE_WITHIN_DB = 30.0
|
|
79
|
+
"""A spectral phase is drawn only where the spectrum is within this of its peak."""
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _plotted(title: str, plot: QWidget) -> QVBoxLayout:
|
|
83
|
+
"""Return a plot under its plain-language title.
|
|
84
|
+
|
|
85
|
+
Parameters
|
|
86
|
+
----------
|
|
87
|
+
title : str
|
|
88
|
+
The title.
|
|
89
|
+
plot : PySide6.QtWidgets.QWidget
|
|
90
|
+
The plot.
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
-------
|
|
94
|
+
PySide6.QtWidgets.QVBoxLayout
|
|
95
|
+
The two together.
|
|
96
|
+
"""
|
|
97
|
+
box = QVBoxLayout()
|
|
98
|
+
box.setContentsMargins(0, 0, 0, 0)
|
|
99
|
+
box.setSpacing(2)
|
|
100
|
+
box.addWidget(named_label(title, "plotTitle"))
|
|
101
|
+
box.addWidget(plot, 1)
|
|
102
|
+
return box
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class PageView(QWidget):
|
|
106
|
+
"""What every page shares.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
111
|
+
The open file.
|
|
112
|
+
|
|
113
|
+
Attributes
|
|
114
|
+
----------
|
|
115
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
116
|
+
The open file.
|
|
117
|
+
controls : PySide6.QtWidgets.QWidget or None
|
|
118
|
+
What sits beside the plots.
|
|
119
|
+
note : PySide6.QtWidgets.QLabel
|
|
120
|
+
A line above the plots, for what they show or why they do not.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
124
|
+
"""Mark the page stale until it is first shown."""
|
|
125
|
+
super().__init__()
|
|
126
|
+
self.setObjectName("page")
|
|
127
|
+
self.session = session
|
|
128
|
+
self.controls: QWidget | None = None
|
|
129
|
+
self.note = named_label("", "pageNote")
|
|
130
|
+
self._stale = True
|
|
131
|
+
session.described.connect(lambda _value: self.stale())
|
|
132
|
+
session.plane_moved.connect(self.plane_moved)
|
|
133
|
+
session.options_changed.connect(self.stale)
|
|
134
|
+
session.mode_changed.connect(self.stale)
|
|
135
|
+
|
|
136
|
+
def stale(self) -> None:
|
|
137
|
+
"""Bring the page up to date now if it is on screen, or else when it is next."""
|
|
138
|
+
self._stale = True
|
|
139
|
+
if self.isVisible():
|
|
140
|
+
self._stale = False
|
|
141
|
+
self.refresh()
|
|
142
|
+
|
|
143
|
+
def plane_moved(self) -> None:
|
|
144
|
+
"""Follow the scrubber."""
|
|
145
|
+
self.stale()
|
|
146
|
+
|
|
147
|
+
def showEvent(self, event: QShowEvent) -> None: # noqa: N802 - Qt's name
|
|
148
|
+
"""Catch up as the page comes on screen.
|
|
149
|
+
|
|
150
|
+
Parameters
|
|
151
|
+
----------
|
|
152
|
+
event : PySide6.QtGui.QShowEvent
|
|
153
|
+
The event.
|
|
154
|
+
"""
|
|
155
|
+
super().showEvent(event)
|
|
156
|
+
if self._stale:
|
|
157
|
+
self._stale = False
|
|
158
|
+
self.refresh()
|
|
159
|
+
|
|
160
|
+
def refresh(self) -> None:
|
|
161
|
+
"""Ask for, or draw, what the page shows."""
|
|
162
|
+
|
|
163
|
+
def _failed(self, reason: str) -> None:
|
|
164
|
+
"""Say why a read failed, and leave nothing of an earlier file on the page.
|
|
165
|
+
|
|
166
|
+
Parameters
|
|
167
|
+
----------
|
|
168
|
+
reason : str
|
|
169
|
+
The reason.
|
|
170
|
+
"""
|
|
171
|
+
self.note.setText(reason)
|
|
172
|
+
for plot in self.findChildren(LinePlot):
|
|
173
|
+
plot.set_data(np.zeros(0), [np.zeros(0) for _ in plot.curves])
|
|
174
|
+
|
|
175
|
+
def data(self) -> tuple[list[str], np.ndarray] | None:
|
|
176
|
+
"""Return what the page shows as columns, for a CSV file.
|
|
177
|
+
|
|
178
|
+
Returns
|
|
179
|
+
-------
|
|
180
|
+
tuple or None
|
|
181
|
+
The columns' names and their values, a column to each; ``None`` for a page
|
|
182
|
+
with nothing to export that way.
|
|
183
|
+
"""
|
|
184
|
+
return None
|
|
185
|
+
|
|
186
|
+
def figure(self) -> dict[str, object] | None:
|
|
187
|
+
"""Return what asks solprop to draw the page as a publication figure.
|
|
188
|
+
|
|
189
|
+
Returns
|
|
190
|
+
-------
|
|
191
|
+
dict or None
|
|
192
|
+
The kernel's ``figure`` keys; ``None`` for a page with no such figure.
|
|
193
|
+
"""
|
|
194
|
+
return None
|
|
195
|
+
|
|
196
|
+
def python(self) -> str | None:
|
|
197
|
+
"""Return the page's name in :func:`~solprop_gui.model.snippets.snippet`.
|
|
198
|
+
|
|
199
|
+
Returns
|
|
200
|
+
-------
|
|
201
|
+
str or None
|
|
202
|
+
The key; ``None`` for a page with no snippet.
|
|
203
|
+
"""
|
|
204
|
+
return None
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
_FLAT_PHASE = 1e-3
|
|
208
|
+
"""A spectral phase moving less than this, in radians, is drawn as flat."""
|
|
209
|
+
|
|
210
|
+
_STEADY = 1e-12
|
|
211
|
+
"""A statistic moving less than this share of its size does not vary."""
|
|
212
|
+
|
|
213
|
+
_STAT_TITLES = {
|
|
214
|
+
"density": "Gas density",
|
|
215
|
+
"fwhm_f": "Bandwidth",
|
|
216
|
+
"fwhm_t": "Duration",
|
|
217
|
+
"fwhm_t_outer": "Outer duration",
|
|
218
|
+
"omega0": "Centre frequency",
|
|
219
|
+
"peak_power_total": "Peak power, all modes",
|
|
220
|
+
"species_density": "Density by species",
|
|
221
|
+
"species_electron_density": "Electron density by species",
|
|
222
|
+
"species_ionisation": "Ionised fraction by species",
|
|
223
|
+
"species_ionisation_energy": "Ionisation energy by species",
|
|
224
|
+
"species_peak_ionisation_rate": "Peak ionisation rate by species",
|
|
225
|
+
}
|
|
226
|
+
"""What a page calls a statistic whose name does not read as it stands."""
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _shown_range(
|
|
230
|
+
value: Mapping[str, Any], axis: str, x: np.ndarray
|
|
231
|
+
) -> tuple[float, float]:
|
|
232
|
+
"""Return the range of a plane's spectral axis to show: the run's own window.
|
|
233
|
+
|
|
234
|
+
Parameters
|
|
235
|
+
----------
|
|
236
|
+
value : Mapping
|
|
237
|
+
The kernel's ``plane`` reply.
|
|
238
|
+
axis : str
|
|
239
|
+
The spectral axis.
|
|
240
|
+
x : numpy.ndarray
|
|
241
|
+
The spectrum's positions on it, ascending.
|
|
242
|
+
|
|
243
|
+
Returns
|
|
244
|
+
-------
|
|
245
|
+
tuple of float
|
|
246
|
+
The range, in the axis's unit.
|
|
247
|
+
"""
|
|
248
|
+
window = value.get("window")
|
|
249
|
+
if window is None:
|
|
250
|
+
return float(x[0]), float(x[-1])
|
|
251
|
+
return float(window[0]) * _AXIS_SCALE[axis], float(window[1]) * _AXIS_SCALE[axis]
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _mode_box(session: AnalysisSession) -> QComboBox:
|
|
255
|
+
"""Return a combo box of the file's modes, kept in step with the session.
|
|
256
|
+
|
|
257
|
+
Parameters
|
|
258
|
+
----------
|
|
259
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
260
|
+
The open file.
|
|
261
|
+
|
|
262
|
+
Returns
|
|
263
|
+
-------
|
|
264
|
+
PySide6.QtWidgets.QComboBox
|
|
265
|
+
The box.
|
|
266
|
+
"""
|
|
267
|
+
box = QComboBox()
|
|
268
|
+
box.setObjectName("mode-choice")
|
|
269
|
+
|
|
270
|
+
def fill(_value: object = None) -> None:
|
|
271
|
+
"""List the file's modes.
|
|
272
|
+
|
|
273
|
+
Parameters
|
|
274
|
+
----------
|
|
275
|
+
_value : object, optional
|
|
276
|
+
Not read.
|
|
277
|
+
"""
|
|
278
|
+
box.blockSignals(True)
|
|
279
|
+
box.clear()
|
|
280
|
+
box.addItem("Every mode, summed", "sum")
|
|
281
|
+
for index, label in enumerate(session.labels):
|
|
282
|
+
box.addItem(label, index)
|
|
283
|
+
box.setCurrentIndex(max(box.findData(session.mode), 0))
|
|
284
|
+
box.setVisible(len(session.labels) > 1)
|
|
285
|
+
box.blockSignals(False)
|
|
286
|
+
|
|
287
|
+
session.described.connect(fill)
|
|
288
|
+
box.activated.connect(lambda place: session.set_mode(box.itemData(place)))
|
|
289
|
+
fill()
|
|
290
|
+
return box
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class OverviewPage(PageView):
|
|
294
|
+
"""The spectrum and pulse along z, and at the plane selected.
|
|
295
|
+
|
|
296
|
+
One page serves a run as it goes and a file read back, so what you watch grow is
|
|
297
|
+
what you then analyse. It takes the calls
|
|
298
|
+
:class:`~solprop_gui.ui.run_panel.RunPanel` makes of a view.
|
|
299
|
+
|
|
300
|
+
Parameters
|
|
301
|
+
----------
|
|
302
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
303
|
+
The open file.
|
|
304
|
+
|
|
305
|
+
Attributes
|
|
306
|
+
----------
|
|
307
|
+
rows_grew : Signal
|
|
308
|
+
Emitted with the planes' positions as a run saves another.
|
|
309
|
+
rows : list of Mapping
|
|
310
|
+
The planes' reduced data.
|
|
311
|
+
band : tuple or None
|
|
312
|
+
The band the rows' power is computed within.
|
|
313
|
+
"""
|
|
314
|
+
|
|
315
|
+
rows_grew = Signal(object)
|
|
316
|
+
|
|
317
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
318
|
+
"""Make the maps and the plane's lines."""
|
|
319
|
+
super().__init__(session)
|
|
320
|
+
self.rows: list[Mapping[str, Any]] = []
|
|
321
|
+
self.band: tuple[float, float] | None = None
|
|
322
|
+
self.spectra: dict[str, np.ndarray] = {}
|
|
323
|
+
self._power_unit = "GW"
|
|
324
|
+
self.time = np.zeros(0)
|
|
325
|
+
self.extent: tuple[float, float] | None = None
|
|
326
|
+
self.shown = 0
|
|
327
|
+
self.half_range = 0.0
|
|
328
|
+
self.following = True
|
|
329
|
+
self._live = False
|
|
330
|
+
self._db = np.zeros((0, 0))
|
|
331
|
+
self._power = np.zeros((0, 0))
|
|
332
|
+
self._map_rows = np.zeros(0, dtype=int)
|
|
333
|
+
self._unit = ("m", 1.0)
|
|
334
|
+
|
|
335
|
+
self._build()
|
|
336
|
+
self._timer = QTimer(self)
|
|
337
|
+
self._timer.setSingleShot(True)
|
|
338
|
+
self._timer.setInterval(_LIVE_MS)
|
|
339
|
+
self._timer.timeout.connect(self._draw_maps)
|
|
340
|
+
|
|
341
|
+
def _build(self) -> None:
|
|
342
|
+
"""Make the plots and their controls."""
|
|
343
|
+
session = self.session
|
|
344
|
+
self.spectrum_map = MapPlot(
|
|
345
|
+
xlabel=_AXIS_LABEL["wavelength"],
|
|
346
|
+
ylabel="z",
|
|
347
|
+
colours="viridis",
|
|
348
|
+
unit="dB",
|
|
349
|
+
)
|
|
350
|
+
self.spectrum_map.set_along("y")
|
|
351
|
+
self.power_map = MapPlot(
|
|
352
|
+
xlabel="Time (fs)", ylabel="z", colours="inferno", unit="GW"
|
|
353
|
+
)
|
|
354
|
+
self.power_map.set_along("y")
|
|
355
|
+
self.spectrum_line = LinePlot(
|
|
356
|
+
xlabel=_AXIS_LABEL["wavelength"], ylabel="dB", unit="dB"
|
|
357
|
+
)
|
|
358
|
+
self.power_line = LinePlot(xlabel="Time (fs)", ylabel="Power (GW)", unit="GW")
|
|
359
|
+
for plot in (self.spectrum_map, self.power_map):
|
|
360
|
+
plot.plane_at.connect(self._picked)
|
|
361
|
+
self.spectrum_map.reader = self._read_spectrum
|
|
362
|
+
self.power_map.reader = self._read_power
|
|
363
|
+
grid = QGridLayout(self)
|
|
364
|
+
grid.setContentsMargins(0, 0, 0, 0)
|
|
365
|
+
grid.setHorizontalSpacing(14)
|
|
366
|
+
grid.setVerticalSpacing(10)
|
|
367
|
+
grid.setRowStretch(0, 3)
|
|
368
|
+
grid.setRowStretch(1, 2)
|
|
369
|
+
grid.setColumnStretch(0, 1)
|
|
370
|
+
grid.setColumnStretch(1, 1)
|
|
371
|
+
grid.addLayout(_plotted("Spectrum along z", self.spectrum_map), 0, 0)
|
|
372
|
+
grid.addLayout(_plotted("Pulse along z", self.power_map), 0, 1)
|
|
373
|
+
grid.addLayout(_plotted("Spectrum at this plane", self.spectrum_line), 1, 0)
|
|
374
|
+
grid.addLayout(_plotted("Pulse at this plane", self.power_line), 1, 1)
|
|
375
|
+
|
|
376
|
+
self.axis_choice = Segments("Spectral axis", _AXES, session.options.axis)
|
|
377
|
+
self.axis_choice.chosen.connect(lambda axis: session.set_options(axis=axis))
|
|
378
|
+
self.floor = LabelledSlider(
|
|
379
|
+
"Floor", -80, -10, int(session.options.floor), " dB"
|
|
380
|
+
)
|
|
381
|
+
self.floor.moved.connect(self._floor_moved)
|
|
382
|
+
self.range = LabelledSlider("Time range", 5, 500, 40, " fs")
|
|
383
|
+
self.range.moved.connect(self._range_moved)
|
|
384
|
+
self.controls = control_panel(self.axis_choice, self.floor, self.range)
|
|
385
|
+
|
|
386
|
+
# -------------------------------------------------- what a run's panel calls
|
|
387
|
+
|
|
388
|
+
def clear(self) -> None:
|
|
389
|
+
"""Start empty, for a new run."""
|
|
390
|
+
self.rows = []
|
|
391
|
+
self.extent = None
|
|
392
|
+
self.shown = 0
|
|
393
|
+
self.half_range = 0.0
|
|
394
|
+
self.following = True
|
|
395
|
+
self._live = True
|
|
396
|
+
self._db = np.zeros((0, 0))
|
|
397
|
+
for plot in (self.spectrum_map, self.power_map):
|
|
398
|
+
plot.say("") # the stage covers them while the run starts
|
|
399
|
+
for line in (self.spectrum_line, self.power_line):
|
|
400
|
+
line.set_data(np.zeros(0), [np.zeros(0)])
|
|
401
|
+
|
|
402
|
+
def set_axes(self, axes: Mapping[str, object]) -> None:
|
|
403
|
+
"""Take the display bins' centres.
|
|
404
|
+
|
|
405
|
+
Parameters
|
|
406
|
+
----------
|
|
407
|
+
axes : Mapping
|
|
408
|
+
``wavelength`` (m), ``f`` (Hz) and ``time`` (s), and the ``bandpass`` the
|
|
409
|
+
rows' power is computed within.
|
|
410
|
+
"""
|
|
411
|
+
self.spectra = {
|
|
412
|
+
axis: np.asarray(axes[axis], dtype=float)
|
|
413
|
+
for axis in ("wavelength", "f")
|
|
414
|
+
if axis in axes
|
|
415
|
+
}
|
|
416
|
+
self.time = np.asarray(axes["time"], dtype=float)
|
|
417
|
+
band = axes.get("bandpass")
|
|
418
|
+
self.band = None if band is None else tuple(band) # pyright: ignore[reportArgumentType, reportAttributeAccessIssue]
|
|
419
|
+
|
|
420
|
+
def set_extent(self, z_start: float, z_end: float) -> None:
|
|
421
|
+
"""Take how far the run will go, for the maps' axes.
|
|
422
|
+
|
|
423
|
+
Parameters
|
|
424
|
+
----------
|
|
425
|
+
z_start : float
|
|
426
|
+
Where it starts, m.
|
|
427
|
+
z_end : float
|
|
428
|
+
Where it ends, m.
|
|
429
|
+
"""
|
|
430
|
+
self.extent = (z_start, z_end)
|
|
431
|
+
|
|
432
|
+
def add_row(self, row: Mapping[str, Any]) -> None:
|
|
433
|
+
"""Take a plane of a run as it is saved.
|
|
434
|
+
|
|
435
|
+
Parameters
|
|
436
|
+
----------
|
|
437
|
+
row : Mapping
|
|
438
|
+
``index``, ``z``, ``density`` by axis, ``power`` and ``stats``.
|
|
439
|
+
"""
|
|
440
|
+
self.rows.append(row)
|
|
441
|
+
self.rows_grew.emit([float(r["z"]) for r in self.rows])
|
|
442
|
+
if self.following:
|
|
443
|
+
self.shown = len(self.rows) - 1
|
|
444
|
+
if not self._timer.isActive():
|
|
445
|
+
self._timer.start()
|
|
446
|
+
|
|
447
|
+
def set_rows(
|
|
448
|
+
self, axes: Mapping[str, object], rows: Sequence[Mapping[str, Any]]
|
|
449
|
+
) -> None:
|
|
450
|
+
"""Take every plane at once.
|
|
451
|
+
|
|
452
|
+
Parameters
|
|
453
|
+
----------
|
|
454
|
+
axes : Mapping
|
|
455
|
+
As :meth:`set_axes` takes.
|
|
456
|
+
rows : Sequence of Mapping
|
|
457
|
+
As :meth:`add_row` takes.
|
|
458
|
+
"""
|
|
459
|
+
if axes:
|
|
460
|
+
self.set_axes(axes)
|
|
461
|
+
self.rows = list(rows)
|
|
462
|
+
self._live = False
|
|
463
|
+
self._draw_maps()
|
|
464
|
+
|
|
465
|
+
def apply_options(self, _options: object) -> None:
|
|
466
|
+
"""Take new options, which the session already holds.
|
|
467
|
+
|
|
468
|
+
Parameters
|
|
469
|
+
----------
|
|
470
|
+
_options : object
|
|
471
|
+
The options.
|
|
472
|
+
"""
|
|
473
|
+
self._draw_maps()
|
|
474
|
+
|
|
475
|
+
def end_of_run(self) -> None:
|
|
476
|
+
"""Stop following: what is on screen is the whole file."""
|
|
477
|
+
self._live = False
|
|
478
|
+
|
|
479
|
+
# ------------------------------------------------------------------ the session
|
|
480
|
+
|
|
481
|
+
def refresh(self) -> None:
|
|
482
|
+
"""Read the file back, unless a run has just drawn all of it."""
|
|
483
|
+
session = self.session
|
|
484
|
+
if session.path is None or self._live:
|
|
485
|
+
self._draw_maps()
|
|
486
|
+
return
|
|
487
|
+
if len(self.rows) == len(session.planes) > 0:
|
|
488
|
+
self._draw_maps()
|
|
489
|
+
return
|
|
490
|
+
self.spectrum_map.say("Reading…")
|
|
491
|
+
self.power_map.say("Reading…")
|
|
492
|
+
session.ask(
|
|
493
|
+
"overview",
|
|
494
|
+
{"path": session.path},
|
|
495
|
+
self._arrived,
|
|
496
|
+
key="page-overview",
|
|
497
|
+
failed=self._refused,
|
|
498
|
+
)
|
|
499
|
+
|
|
500
|
+
def _arrived(self, value: Mapping[str, Any]) -> None:
|
|
501
|
+
"""Draw a file read back.
|
|
502
|
+
|
|
503
|
+
Parameters
|
|
504
|
+
----------
|
|
505
|
+
value : Mapping
|
|
506
|
+
The kernel's ``overview`` reply.
|
|
507
|
+
"""
|
|
508
|
+
self.extent = None
|
|
509
|
+
self.set_rows(value.get("axes", {}), value.get("rows", []))
|
|
510
|
+
self.half_range = 0.0
|
|
511
|
+
self._draw_maps()
|
|
512
|
+
|
|
513
|
+
def _refused(self, reason: str) -> None:
|
|
514
|
+
"""Say why there is nothing to draw.
|
|
515
|
+
|
|
516
|
+
Parameters
|
|
517
|
+
----------
|
|
518
|
+
reason : str
|
|
519
|
+
The reason solprop gave.
|
|
520
|
+
"""
|
|
521
|
+
self.spectrum_map.say(reason)
|
|
522
|
+
self.power_map.say("")
|
|
523
|
+
|
|
524
|
+
def plane_moved(self) -> None:
|
|
525
|
+
"""Follow the scrubber, at no cost in the maps."""
|
|
526
|
+
self.shown = self.session.place
|
|
527
|
+
self._draw_plane()
|
|
528
|
+
|
|
529
|
+
def show_place(self, place: int) -> None:
|
|
530
|
+
"""Select a plane of a run going, whose planes the session does not hold yet.
|
|
531
|
+
|
|
532
|
+
Parameters
|
|
533
|
+
----------
|
|
534
|
+
place : int
|
|
535
|
+
Which row.
|
|
536
|
+
"""
|
|
537
|
+
self.shown = place
|
|
538
|
+
self.following = place >= len(self.rows) - 1
|
|
539
|
+
self._draw_plane()
|
|
540
|
+
|
|
541
|
+
def _picked(self, value: float) -> None:
|
|
542
|
+
"""Take a plane picked on a map.
|
|
543
|
+
|
|
544
|
+
Parameters
|
|
545
|
+
----------
|
|
546
|
+
value : float
|
|
547
|
+
The position, in the map's unit.
|
|
548
|
+
"""
|
|
549
|
+
z = value / self._unit[1]
|
|
550
|
+
if self.session.positions and not self._live:
|
|
551
|
+
self.session.move_near(z)
|
|
552
|
+
elif self.rows:
|
|
553
|
+
positions = np.array([float(r["z"]) for r in self.rows])
|
|
554
|
+
self.show_place(int(np.argmin(np.abs(positions - z))))
|
|
555
|
+
|
|
556
|
+
# ------------------------------------------------------------------ drawing
|
|
557
|
+
|
|
558
|
+
def _time_window(self) -> float:
|
|
559
|
+
"""Return the half-width of the time range, in fs, set from the light at first.
|
|
560
|
+
|
|
561
|
+
Returns
|
|
562
|
+
-------
|
|
563
|
+
float
|
|
564
|
+
The half-width.
|
|
565
|
+
"""
|
|
566
|
+
if self.half_range <= 0 and self.time.size and self.rows:
|
|
567
|
+
found = pulse_window(self.time * _FS, self._power)
|
|
568
|
+
whole = float(np.abs(self.time).max()) * _FS
|
|
569
|
+
self.half_range = max(min(found, whole), 1.0)
|
|
570
|
+
self.range.set_range(1, max(round(whole), 2))
|
|
571
|
+
self.range.set_value(round(self.half_range))
|
|
572
|
+
return self.half_range or 1.0
|
|
573
|
+
|
|
574
|
+
def _draw_maps(self) -> None:
|
|
575
|
+
"""Draw both maps from the rows."""
|
|
576
|
+
options = self.session.options
|
|
577
|
+
axis = options.axis
|
|
578
|
+
if not self.rows or axis not in self.spectra:
|
|
579
|
+
return
|
|
580
|
+
x = self.spectra[axis] * _AXIS_SCALE[axis]
|
|
581
|
+
density = np.array([np.asarray(r["density"][axis], float) for r in self.rows])
|
|
582
|
+
self._db = decibels(density)
|
|
583
|
+
power = np.array([np.asarray(r["power"], float) for r in self.rows])
|
|
584
|
+
self._power_unit, scale = scaled_unit(power, "W")
|
|
585
|
+
self._power = power * scale
|
|
586
|
+
self.power_map.set_unit(self._power_unit)
|
|
587
|
+
self.power_line.set_ylabel(f"Power ({self._power_unit})")
|
|
588
|
+
self.power_line.unit = self._power_unit
|
|
589
|
+
view = light_range(x, density, margin=0.1)
|
|
590
|
+
z = np.array([float(r["z"]) for r in self.rows])
|
|
591
|
+
self._map_rows, z_first, step = even_rows(z)
|
|
592
|
+
reach = self.extent[1] if self.extent else float(z[-1])
|
|
593
|
+
name, factor = length_unit(reach or 1.0)
|
|
594
|
+
self._unit = (name, factor)
|
|
595
|
+
window = self._time_window()
|
|
596
|
+
t = self.time * _FS
|
|
597
|
+
bottom = (z_first - step / 2) * factor
|
|
598
|
+
height = step * self._map_rows.size * factor
|
|
599
|
+
z_view = (float(z[0]) * factor, max(reach * factor, float(z[-1]) * factor))
|
|
600
|
+
label = _AXIS_LABEL[axis]
|
|
601
|
+
for plot in (self.spectrum_map, self.spectrum_line):
|
|
602
|
+
plot.set_xlabel(label)
|
|
603
|
+
for plot in (self.spectrum_map, self.power_map):
|
|
604
|
+
plot.set_ylabel(f"z ({name})")
|
|
605
|
+
self.spectrum_map.show_map(
|
|
606
|
+
self._db[self._map_rows],
|
|
607
|
+
(float(x[0]), bottom, float(x[-1] - x[0]), height),
|
|
608
|
+
(view, z_view),
|
|
609
|
+
(options.floor, 0.0),
|
|
610
|
+
)
|
|
611
|
+
self.power_map.show_map(
|
|
612
|
+
self._power[self._map_rows],
|
|
613
|
+
(float(t[0]), bottom, float(t[-1] - t[0]), height),
|
|
614
|
+
((-window, window), z_view),
|
|
615
|
+
(0.0, float(self._power.max()) or 1.0),
|
|
616
|
+
)
|
|
617
|
+
self.spectrum_line.set_view(view, (options.floor, 3.0))
|
|
618
|
+
self.power_line.set_view(
|
|
619
|
+
(-window, window), (0.0, float(self._power.max()) * 1.05 or 1.0)
|
|
620
|
+
)
|
|
621
|
+
self._draw_plane()
|
|
622
|
+
|
|
623
|
+
def _draw_plane(self) -> None:
|
|
624
|
+
"""Draw the plane selected, and mark it on the maps."""
|
|
625
|
+
if self._db.size == 0 or not self.rows:
|
|
626
|
+
return
|
|
627
|
+
at = min(self.shown, self._db.shape[0] - 1)
|
|
628
|
+
z = float(self.rows[at]["z"]) * self._unit[1]
|
|
629
|
+
axis = self.session.options.axis
|
|
630
|
+
self.spectrum_map.set_mark(z)
|
|
631
|
+
self.power_map.set_mark(z)
|
|
632
|
+
x = self.spectra[axis] * _AXIS_SCALE[axis]
|
|
633
|
+
self.spectrum_line.set_data(x, [self._db[at]])
|
|
634
|
+
self.power_line.set_data(self.time * _FS, [self._power[at]])
|
|
635
|
+
|
|
636
|
+
def _floor_moved(self, value: int) -> None:
|
|
637
|
+
"""Move the dB floor, at no cost in the data.
|
|
638
|
+
|
|
639
|
+
Parameters
|
|
640
|
+
----------
|
|
641
|
+
value : int
|
|
642
|
+
The floor, dB.
|
|
643
|
+
"""
|
|
644
|
+
self.session.options = replace(self.session.options, floor=float(value))
|
|
645
|
+
self.spectrum_map.set_levels((float(value), 0.0))
|
|
646
|
+
x_range = self.spectrum_line.box.viewRange()[0]
|
|
647
|
+
self.spectrum_line.set_view((x_range[0], x_range[1]), (float(value), 3.0))
|
|
648
|
+
|
|
649
|
+
def _range_moved(self, value: int) -> None:
|
|
650
|
+
"""Move the time range, at no cost in the data.
|
|
651
|
+
|
|
652
|
+
Parameters
|
|
653
|
+
----------
|
|
654
|
+
value : int
|
|
655
|
+
The half-width, fs.
|
|
656
|
+
"""
|
|
657
|
+
self.half_range = float(value)
|
|
658
|
+
self.power_map.box.setXRange(-value, value, padding=0)
|
|
659
|
+
self.power_line.box.setXRange(-value, value, padding=0)
|
|
660
|
+
|
|
661
|
+
def _read_spectrum(self, x: float, y: float) -> str:
|
|
662
|
+
"""Say what is at a point of the spectrum's map.
|
|
663
|
+
|
|
664
|
+
Parameters
|
|
665
|
+
----------
|
|
666
|
+
x : float
|
|
667
|
+
The position on the spectral axis.
|
|
668
|
+
y : float
|
|
669
|
+
The position along z, in the map's unit.
|
|
670
|
+
|
|
671
|
+
Returns
|
|
672
|
+
-------
|
|
673
|
+
str
|
|
674
|
+
The readout.
|
|
675
|
+
"""
|
|
676
|
+
if self._db.size == 0:
|
|
677
|
+
return ""
|
|
678
|
+
axis = self.session.options.axis
|
|
679
|
+
bins = self.spectra[axis] * _AXIS_SCALE[axis]
|
|
680
|
+
row = self._nearest_row(y, self._db.shape[0])
|
|
681
|
+
if row is None:
|
|
682
|
+
return ""
|
|
683
|
+
at = int(np.clip(np.searchsorted(bins, x), 0, bins.size - 1))
|
|
684
|
+
text = f"{x:.4g} {_AXIS_UNIT[axis]}, {y:.3g} {self._unit[0]}"
|
|
685
|
+
return f"{text}: {self._db[row, at]:.1f} dB"
|
|
686
|
+
|
|
687
|
+
def _read_power(self, x: float, y: float) -> str:
|
|
688
|
+
"""Say what is at a point of the pulse's map.
|
|
689
|
+
|
|
690
|
+
Parameters
|
|
691
|
+
----------
|
|
692
|
+
x : float
|
|
693
|
+
The time, fs.
|
|
694
|
+
y : float
|
|
695
|
+
The position along z, in the map's unit.
|
|
696
|
+
|
|
697
|
+
Returns
|
|
698
|
+
-------
|
|
699
|
+
str
|
|
700
|
+
The readout.
|
|
701
|
+
"""
|
|
702
|
+
if self._power.size == 0:
|
|
703
|
+
return ""
|
|
704
|
+
t = self.time * _FS
|
|
705
|
+
row = self._nearest_row(y, self._power.shape[0])
|
|
706
|
+
if row is None:
|
|
707
|
+
return ""
|
|
708
|
+
at = int(np.clip(np.searchsorted(t, x), 0, t.size - 1))
|
|
709
|
+
text = f"{x:.3g} fs, {y:.3g} {self._unit[0]}"
|
|
710
|
+
return f"{text}: {self._power[row, at]:.3g} {self._power_unit}"
|
|
711
|
+
|
|
712
|
+
def _nearest_row(self, y: float, drawn: int) -> int | None:
|
|
713
|
+
"""Return the row nearest a position on a map.
|
|
714
|
+
|
|
715
|
+
Parameters
|
|
716
|
+
----------
|
|
717
|
+
y : float
|
|
718
|
+
The position, in the map's unit.
|
|
719
|
+
drawn : int
|
|
720
|
+
The rows the map being read holds: during a run, planes arrive between
|
|
721
|
+
drawings, and one map may be drawn before the other.
|
|
722
|
+
|
|
723
|
+
Returns
|
|
724
|
+
-------
|
|
725
|
+
int or None
|
|
726
|
+
The row; ``None`` where the map holds none yet.
|
|
727
|
+
"""
|
|
728
|
+
rows = self.rows[:drawn]
|
|
729
|
+
if not rows:
|
|
730
|
+
return None
|
|
731
|
+
z = np.array([float(r["z"]) for r in rows]) * self._unit[1]
|
|
732
|
+
return int(np.argmin(np.abs(z - y)))
|
|
733
|
+
|
|
734
|
+
def data(self) -> tuple[list[str], np.ndarray] | None:
|
|
735
|
+
"""Return the plane selected, as columns.
|
|
736
|
+
|
|
737
|
+
Returns
|
|
738
|
+
-------
|
|
739
|
+
tuple or None
|
|
740
|
+
Time and power in the columns' units; ``None`` with no planes.
|
|
741
|
+
"""
|
|
742
|
+
if self._power.size == 0:
|
|
743
|
+
return None
|
|
744
|
+
at = min(self.shown, self._power.shape[0] - 1)
|
|
745
|
+
return ["time (fs)", f"power ({self._power_unit})"], np.column_stack(
|
|
746
|
+
(self.time * _FS, self._power[at])
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
def figure(self) -> dict[str, object] | None:
|
|
750
|
+
"""Return the page as solprop draws it.
|
|
751
|
+
|
|
752
|
+
Returns
|
|
753
|
+
-------
|
|
754
|
+
dict
|
|
755
|
+
Its maps, one figure each.
|
|
756
|
+
"""
|
|
757
|
+
return {"plot": "prop_2d"}
|
|
758
|
+
|
|
759
|
+
def python(self) -> str | None:
|
|
760
|
+
"""Return the page's snippet.
|
|
761
|
+
|
|
762
|
+
Returns
|
|
763
|
+
-------
|
|
764
|
+
str
|
|
765
|
+
Its key.
|
|
766
|
+
"""
|
|
767
|
+
return "overview"
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
class PlanePage(PageView):
|
|
771
|
+
"""One plane: its spectrum with a band and the energy in it, its pulse and phase.
|
|
772
|
+
|
|
773
|
+
Parameters
|
|
774
|
+
----------
|
|
775
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
776
|
+
The open file.
|
|
777
|
+
"""
|
|
778
|
+
|
|
779
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
780
|
+
"""Make the plots and the band's controls."""
|
|
781
|
+
super().__init__(session)
|
|
782
|
+
self.spectrum = LinePlot(
|
|
783
|
+
xlabel=_AXIS_LABEL["wavelength"], ylabel="dB", unit="dB"
|
|
784
|
+
)
|
|
785
|
+
self.power = LinePlot(xlabel="Time (fs)", ylabel="Power (GW)", unit="GW")
|
|
786
|
+
self.phase = LinePlot(
|
|
787
|
+
xlabel=_AXIS_LABEL["wavelength"], ylabel="Phase (rad)", unit="rad"
|
|
788
|
+
)
|
|
789
|
+
self.region = pg.LinearRegionItem(
|
|
790
|
+
brush=(11, 110, 153, 40),
|
|
791
|
+
pen=pg.mkPen("#0b6e99"),
|
|
792
|
+
movable=True,
|
|
793
|
+
)
|
|
794
|
+
self.region.hide()
|
|
795
|
+
self.spectrum.addItem(self.region, ignoreBounds=True) # pyright: ignore[reportCallIssue]
|
|
796
|
+
self.region.sigRegionChangeFinished.connect(self._region_moved)
|
|
797
|
+
self._last: Mapping[str, Any] | None = None
|
|
798
|
+
grid = QGridLayout()
|
|
799
|
+
grid.setContentsMargins(0, 0, 0, 0)
|
|
800
|
+
grid.setHorizontalSpacing(14)
|
|
801
|
+
grid.setVerticalSpacing(10)
|
|
802
|
+
grid.addLayout(_plotted("Spectrum", self.spectrum), 0, 0, 1, 2)
|
|
803
|
+
grid.addLayout(_plotted("Pulse", self.power), 1, 0)
|
|
804
|
+
grid.addLayout(_plotted("Spectral phase", self.phase), 1, 1)
|
|
805
|
+
column = QVBoxLayout(self)
|
|
806
|
+
column.setContentsMargins(0, 0, 0, 0)
|
|
807
|
+
column.setSpacing(6)
|
|
808
|
+
column.addWidget(self.note)
|
|
809
|
+
column.addLayout(grid, 1)
|
|
810
|
+
|
|
811
|
+
self.axis_choice = Segments("Spectral axis", _AXES, session.options.axis)
|
|
812
|
+
self.axis_choice.chosen.connect(lambda axis: session.set_options(axis=axis))
|
|
813
|
+
self.floor = LabelledSlider(
|
|
814
|
+
"Floor", -80, -10, int(session.options.floor), " dB"
|
|
815
|
+
)
|
|
816
|
+
self.floor.moved.connect(lambda v: session.set_options(floor=float(v)))
|
|
817
|
+
self.band_low = QLineEdit()
|
|
818
|
+
self.band_low.setObjectName("band-low")
|
|
819
|
+
self.band_low.setPlaceholderText("from")
|
|
820
|
+
self.band_high = QLineEdit()
|
|
821
|
+
self.band_high.setObjectName("band-high")
|
|
822
|
+
self.band_high.setPlaceholderText("to")
|
|
823
|
+
for box in (self.band_low, self.band_high):
|
|
824
|
+
box.editingFinished.connect(self._band_typed)
|
|
825
|
+
band_clear = QPushButton("Whole spectrum")
|
|
826
|
+
band_clear.setObjectName("plain")
|
|
827
|
+
band_clear.clicked.connect(lambda: session.set_options(bandpass=None))
|
|
828
|
+
band_box = QWidget()
|
|
829
|
+
band_box.setObjectName("page")
|
|
830
|
+
band_grid = QGridLayout(band_box)
|
|
831
|
+
band_grid.setContentsMargins(0, 0, 0, 0)
|
|
832
|
+
band_grid.addWidget(named_label("Band (nm)", "control"), 0, 0, 1, 2)
|
|
833
|
+
band_grid.addWidget(self.band_low, 1, 0)
|
|
834
|
+
band_grid.addWidget(self.band_high, 1, 1)
|
|
835
|
+
band_grid.addWidget(band_clear, 2, 0, 1, 2)
|
|
836
|
+
self.modes = _mode_box(session)
|
|
837
|
+
self.controls = control_panel(
|
|
838
|
+
self.axis_choice, self.floor, band_box, self.modes
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
def refresh(self) -> None:
|
|
842
|
+
"""Ask for the plane selected."""
|
|
843
|
+
session = self.session
|
|
844
|
+
if session.path is None or not session.planes:
|
|
845
|
+
return
|
|
846
|
+
session.ask(
|
|
847
|
+
"plane",
|
|
848
|
+
{
|
|
849
|
+
"path": session.path,
|
|
850
|
+
"index": session.index,
|
|
851
|
+
"modes": session.mode,
|
|
852
|
+
"axis": session.options.axis,
|
|
853
|
+
"bandpass": session.options.bandpass,
|
|
854
|
+
},
|
|
855
|
+
self._show,
|
|
856
|
+
key="page-plane",
|
|
857
|
+
failed=self._failed,
|
|
858
|
+
)
|
|
859
|
+
|
|
860
|
+
def _show(self, value: Mapping[str, Any]) -> None:
|
|
861
|
+
"""Draw a plane.
|
|
862
|
+
|
|
863
|
+
Parameters
|
|
864
|
+
----------
|
|
865
|
+
value : Mapping
|
|
866
|
+
The kernel's ``plane`` reply.
|
|
867
|
+
"""
|
|
868
|
+
self._last = value
|
|
869
|
+
options = self.session.options
|
|
870
|
+
axis = str(value["axis"])
|
|
871
|
+
spectrum = value["spectrum"]
|
|
872
|
+
self._show_pulse(value)
|
|
873
|
+
if "x" not in spectrum:
|
|
874
|
+
# A planar run's plane has a power and no spectrum to read.
|
|
875
|
+
self.spectrum.set_data(np.zeros(0), [np.zeros(0)])
|
|
876
|
+
self.phase.set_data(np.zeros(0), [np.zeros(0)])
|
|
877
|
+
self.note.setText(str(spectrum.get("error", "")))
|
|
878
|
+
return
|
|
879
|
+
x = np.asarray(spectrum["x"], float) * _AXIS_SCALE[axis]
|
|
880
|
+
order = np.argsort(x)
|
|
881
|
+
x = x[order]
|
|
882
|
+
db = decibels(np.asarray(spectrum["y"], float))[order]
|
|
883
|
+
self.spectrum.set_data(x, [db])
|
|
884
|
+
self.spectrum.set_xlabel(_AXIS_LABEL[axis])
|
|
885
|
+
view = _shown_range(value, axis, x)
|
|
886
|
+
self.spectrum.set_view(view, (options.floor, 3.0))
|
|
887
|
+
self._show_band(axis)
|
|
888
|
+
self._show_phase(value, axis, x, db)
|
|
889
|
+
self._say(value)
|
|
890
|
+
|
|
891
|
+
def _show_band(self, axis: str) -> None:
|
|
892
|
+
"""Mark the band on the spectrum, and in its boxes.
|
|
893
|
+
|
|
894
|
+
Parameters
|
|
895
|
+
----------
|
|
896
|
+
axis : str
|
|
897
|
+
The spectral axis.
|
|
898
|
+
"""
|
|
899
|
+
band = self.session.options.bandpass
|
|
900
|
+
self.region.blockSignals(True)
|
|
901
|
+
self.band_low.setText("" if band is None else f"{band[0] * 1e9:.4g}")
|
|
902
|
+
self.band_high.setText("" if band is None else f"{band[1] * 1e9:.4g}")
|
|
903
|
+
if band is None:
|
|
904
|
+
view = self.spectrum.box.viewRange()[0]
|
|
905
|
+
span = view[1] - view[0]
|
|
906
|
+
self.region.setRegion((view[0] + 0.4 * span, view[0] + 0.6 * span))
|
|
907
|
+
self.region.setOpacity(0.35)
|
|
908
|
+
elif axis == "wavelength":
|
|
909
|
+
self.region.setRegion((band[0] * 1e9, band[1] * 1e9)) # pyright: ignore[reportIndexIssue]
|
|
910
|
+
self.region.setOpacity(1.0)
|
|
911
|
+
else:
|
|
912
|
+
self.region.setRegion((C / band[1] * 1e-12, C / band[0] * 1e-12)) # pyright: ignore[reportIndexIssue]
|
|
913
|
+
self.region.setOpacity(1.0)
|
|
914
|
+
self.region.show()
|
|
915
|
+
self.region.blockSignals(False)
|
|
916
|
+
|
|
917
|
+
def _show_pulse(self, value: Mapping[str, Any]) -> None:
|
|
918
|
+
"""Draw the pulse, and within the band if there is one.
|
|
919
|
+
|
|
920
|
+
Parameters
|
|
921
|
+
----------
|
|
922
|
+
value : Mapping
|
|
923
|
+
The kernel's ``plane`` reply.
|
|
924
|
+
"""
|
|
925
|
+
t = np.asarray(value["power"]["t"], float) * _FS
|
|
926
|
+
power = np.asarray(value["power"]["y"], float)
|
|
927
|
+
full = value.get("full_power")
|
|
928
|
+
unit, scale = scaled_unit(power if full is None else np.asarray(full), "W")
|
|
929
|
+
self.power.set_ylabel(f"Power ({unit})")
|
|
930
|
+
self.power.unit = unit
|
|
931
|
+
power = power * scale
|
|
932
|
+
if full is None:
|
|
933
|
+
self.power.set_names([""])
|
|
934
|
+
self.power.set_data(t, [power])
|
|
935
|
+
trace = power
|
|
936
|
+
else:
|
|
937
|
+
whole = np.asarray(full, float) * scale
|
|
938
|
+
self.power.set_names(["whole spectrum", "in the band"])
|
|
939
|
+
self.power.set_data(t, [whole, power])
|
|
940
|
+
trace = whole
|
|
941
|
+
window = pulse_window(t, trace)
|
|
942
|
+
self.power.set_view((-window, window), (0.0, float(trace.max()) * 1.05 or 1.0))
|
|
943
|
+
|
|
944
|
+
def _show_phase(
|
|
945
|
+
self, value: Mapping[str, Any], axis: str, x: np.ndarray, db: np.ndarray
|
|
946
|
+
) -> None:
|
|
947
|
+
"""Draw the spectral phase where the spectrum is strong enough to have one.
|
|
948
|
+
|
|
949
|
+
Parameters
|
|
950
|
+
----------
|
|
951
|
+
value : Mapping
|
|
952
|
+
The kernel's ``plane`` reply.
|
|
953
|
+
axis : str
|
|
954
|
+
The spectral axis.
|
|
955
|
+
x : numpy.ndarray
|
|
956
|
+
The spectrum's positions, ascending.
|
|
957
|
+
db : numpy.ndarray
|
|
958
|
+
The spectrum, dB.
|
|
959
|
+
"""
|
|
960
|
+
phase = value["phase"]
|
|
961
|
+
self.phase.set_xlabel(_AXIS_LABEL[axis])
|
|
962
|
+
if "omega" not in phase:
|
|
963
|
+
self.phase.set_data(np.zeros(0), [np.zeros(0)])
|
|
964
|
+
return
|
|
965
|
+
omega = np.asarray(phase["omega"], float)
|
|
966
|
+
f = omega / (2.0 * np.pi)
|
|
967
|
+
on_axis = C / f * 1e9 if axis == "wavelength" else f * 1e-12
|
|
968
|
+
order = np.argsort(on_axis)
|
|
969
|
+
on_axis = on_axis[order]
|
|
970
|
+
y = np.asarray(phase["y"], float)[order]
|
|
971
|
+
keep = np.interp(on_axis, x, db) > -_PHASE_WITHIN_DB
|
|
972
|
+
y = np.where(keep, y, np.nan)
|
|
973
|
+
self.phase.set_data(on_axis, [y])
|
|
974
|
+
limits = (-1.0, 1.0)
|
|
975
|
+
if keep.any():
|
|
976
|
+
low, high = float(np.nanmin(y)), float(np.nanmax(y))
|
|
977
|
+
# A flat phase is flat: its rounding is not to fill the axis.
|
|
978
|
+
middle = (low + high) / 2.0
|
|
979
|
+
flat = high - low < _FLAT_PHASE
|
|
980
|
+
limits = (middle - 1.0, middle + 1.0) if flat else (low, high)
|
|
981
|
+
self.phase.set_view(_shown_range(value, axis, x), limits)
|
|
982
|
+
|
|
983
|
+
def _say(self, value: Mapping[str, Any]) -> None:
|
|
984
|
+
"""Say the numbers of the plane.
|
|
985
|
+
|
|
986
|
+
Parameters
|
|
987
|
+
----------
|
|
988
|
+
value : Mapping
|
|
989
|
+
The kernel's ``plane`` reply.
|
|
990
|
+
"""
|
|
991
|
+
if "energy" not in value:
|
|
992
|
+
# A beam's plane is a profile across it; its numbers are its maps'.
|
|
993
|
+
self.note.setText("The power and spectrum summed across the beam.")
|
|
994
|
+
return
|
|
995
|
+
total = float(value["energy"])
|
|
996
|
+
parts = [f"Energy {si(total, 'J', digits=3)}"]
|
|
997
|
+
band_energy = value.get("band_energy")
|
|
998
|
+
if band_energy is not None:
|
|
999
|
+
share = 100.0 * float(band_energy) / total if total else 0.0
|
|
1000
|
+
parts.append(
|
|
1001
|
+
f"in the band {si(float(band_energy), 'J', 3)} ({share:.2g} %)"
|
|
1002
|
+
)
|
|
1003
|
+
width = float(value["fwhm"])
|
|
1004
|
+
if np.isfinite(width):
|
|
1005
|
+
parts.append(f"duration {width * _FS:.3g} fs")
|
|
1006
|
+
if "error" in value["phase"]:
|
|
1007
|
+
parts.append("phase of the first mode only")
|
|
1008
|
+
self.note.setText(" · ".join(parts))
|
|
1009
|
+
|
|
1010
|
+
def _region_moved(self) -> None:
|
|
1011
|
+
"""Take a band dragged on the spectrum."""
|
|
1012
|
+
low, high = self.region.getRegion() # pyright: ignore[reportGeneralTypeIssues]
|
|
1013
|
+
axis = self.session.options.axis
|
|
1014
|
+
if axis == "wavelength":
|
|
1015
|
+
band = (float(low) * 1e-9, float(high) * 1e-9) # pyright: ignore[reportArgumentType]
|
|
1016
|
+
else:
|
|
1017
|
+
band = (C / (float(high) * 1e12), C / (float(low) * 1e12)) # pyright: ignore[reportArgumentType]
|
|
1018
|
+
self.session.set_options(bandpass=band)
|
|
1019
|
+
|
|
1020
|
+
def _band_typed(self) -> None:
|
|
1021
|
+
"""Take a band typed in its boxes."""
|
|
1022
|
+
try:
|
|
1023
|
+
low, high = float(self.band_low.text()), float(self.band_high.text())
|
|
1024
|
+
except ValueError:
|
|
1025
|
+
return
|
|
1026
|
+
if 0 < low < high:
|
|
1027
|
+
self.session.set_options(bandpass=(low * 1e-9, high * 1e-9))
|
|
1028
|
+
|
|
1029
|
+
def data(self) -> tuple[list[str], np.ndarray] | None:
|
|
1030
|
+
"""Return the plane's spectrum, as columns.
|
|
1031
|
+
|
|
1032
|
+
Returns
|
|
1033
|
+
-------
|
|
1034
|
+
tuple or None
|
|
1035
|
+
Its axis and dB, in the columns' units.
|
|
1036
|
+
"""
|
|
1037
|
+
if self.spectrum.xs.size == 0:
|
|
1038
|
+
return None
|
|
1039
|
+
axis = self.session.options.axis
|
|
1040
|
+
return [_AXIS_LABEL[axis], "spectral density (dB)"], np.column_stack(
|
|
1041
|
+
(self.spectrum.xs, self.spectrum.ys[0])
|
|
1042
|
+
)
|
|
1043
|
+
|
|
1044
|
+
def figure(self) -> dict[str, object] | None:
|
|
1045
|
+
"""Return the page as solprop draws it.
|
|
1046
|
+
|
|
1047
|
+
Returns
|
|
1048
|
+
-------
|
|
1049
|
+
dict
|
|
1050
|
+
The spectrum at the plane.
|
|
1051
|
+
"""
|
|
1052
|
+
return {"plot": "spec_1d", "z": self.session.z, "modes": self.session.mode}
|
|
1053
|
+
|
|
1054
|
+
def python(self) -> str | None:
|
|
1055
|
+
"""Return the page's snippet.
|
|
1056
|
+
|
|
1057
|
+
Returns
|
|
1058
|
+
-------
|
|
1059
|
+
str
|
|
1060
|
+
Its key.
|
|
1061
|
+
"""
|
|
1062
|
+
return "plane"
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
class SpectrogramPage(PageView):
|
|
1066
|
+
"""A plane's spectrogram.
|
|
1067
|
+
|
|
1068
|
+
Parameters
|
|
1069
|
+
----------
|
|
1070
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
1071
|
+
The open file.
|
|
1072
|
+
"""
|
|
1073
|
+
|
|
1074
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
1075
|
+
"""Make the map and its gate."""
|
|
1076
|
+
super().__init__(session)
|
|
1077
|
+
self.map = MapPlot(
|
|
1078
|
+
xlabel="Time (fs)",
|
|
1079
|
+
ylabel=_AXIS_LABEL["wavelength"],
|
|
1080
|
+
colours="viridis",
|
|
1081
|
+
unit="dB",
|
|
1082
|
+
)
|
|
1083
|
+
self._values = np.zeros((0, 0))
|
|
1084
|
+
self._t = np.zeros(0)
|
|
1085
|
+
self._x = np.zeros(0)
|
|
1086
|
+
self.map.reader = self._read
|
|
1087
|
+
column = QVBoxLayout(self)
|
|
1088
|
+
column.setContentsMargins(0, 0, 0, 0)
|
|
1089
|
+
column.setSpacing(6)
|
|
1090
|
+
column.addWidget(self.note)
|
|
1091
|
+
column.addWidget(self.map, 1)
|
|
1092
|
+
self.gate = LabelledSlider("Gate", 1, 200, 20, " fs")
|
|
1093
|
+
self.gate.moved.connect(
|
|
1094
|
+
lambda v: session.set_options(gate_fwhm=float(v) * 1e-15)
|
|
1095
|
+
)
|
|
1096
|
+
self.axis_choice = Segments("Spectral axis", _AXES, session.options.axis)
|
|
1097
|
+
self.axis_choice.chosen.connect(lambda axis: session.set_options(axis=axis))
|
|
1098
|
+
self.floor = LabelledSlider(
|
|
1099
|
+
"Floor", -80, -10, int(session.options.floor), " dB"
|
|
1100
|
+
)
|
|
1101
|
+
self.floor.moved.connect(lambda v: self.map.set_levels((float(v), 0.0)))
|
|
1102
|
+
self.floor.slider.sliderReleased.connect(
|
|
1103
|
+
lambda: session.set_options(floor=float(self.floor.slider.value()))
|
|
1104
|
+
)
|
|
1105
|
+
self.modes = _mode_box(session)
|
|
1106
|
+
self.controls = control_panel(
|
|
1107
|
+
self.axis_choice, self.gate, self.floor, self.modes
|
|
1108
|
+
)
|
|
1109
|
+
|
|
1110
|
+
def refresh(self) -> None:
|
|
1111
|
+
"""Ask for the plane selected's spectrogram."""
|
|
1112
|
+
session = self.session
|
|
1113
|
+
if session.path is None or not session.planes:
|
|
1114
|
+
return
|
|
1115
|
+
options = session.options
|
|
1116
|
+
session.ask(
|
|
1117
|
+
"spectrogram",
|
|
1118
|
+
{
|
|
1119
|
+
"path": session.path,
|
|
1120
|
+
"index": session.index,
|
|
1121
|
+
"modes": session.mode,
|
|
1122
|
+
"axis": options.axis,
|
|
1123
|
+
"gate_fwhm": options.gate_fwhm,
|
|
1124
|
+
"positions": options.positions,
|
|
1125
|
+
},
|
|
1126
|
+
self._show,
|
|
1127
|
+
key="page-spectrogram",
|
|
1128
|
+
failed=self._refused,
|
|
1129
|
+
)
|
|
1130
|
+
|
|
1131
|
+
def _refused(self, reason: str) -> None:
|
|
1132
|
+
"""Say why there is no spectrogram.
|
|
1133
|
+
|
|
1134
|
+
Parameters
|
|
1135
|
+
----------
|
|
1136
|
+
reason : str
|
|
1137
|
+
The reason solprop gave.
|
|
1138
|
+
"""
|
|
1139
|
+
self.map.say(reason)
|
|
1140
|
+
|
|
1141
|
+
def _show(self, value: Mapping[str, Any]) -> None:
|
|
1142
|
+
"""Draw a spectrogram.
|
|
1143
|
+
|
|
1144
|
+
Parameters
|
|
1145
|
+
----------
|
|
1146
|
+
value : Mapping
|
|
1147
|
+
The kernel's ``spectrogram`` reply.
|
|
1148
|
+
"""
|
|
1149
|
+
options = self.session.options
|
|
1150
|
+
axis = str(value["axis"])
|
|
1151
|
+
t = np.asarray(value["t"], float) * _FS
|
|
1152
|
+
x = np.asarray(value["x"], float) * _AXIS_SCALE[axis]
|
|
1153
|
+
values = np.asarray(value["values"], float)
|
|
1154
|
+
self._values = decibels(values)
|
|
1155
|
+
self._t, self._x = t, x
|
|
1156
|
+
self.map.set_ylabel(_AXIS_LABEL[axis])
|
|
1157
|
+
self.map.show_map(
|
|
1158
|
+
self._values,
|
|
1159
|
+
(float(t[0]), float(x[0]), float(t[-1] - t[0]), float(x[-1] - x[0])),
|
|
1160
|
+
((float(t[0]), float(t[-1])), (float(x[0]), float(x[-1]))),
|
|
1161
|
+
(options.floor, 0.0),
|
|
1162
|
+
)
|
|
1163
|
+
gate = float(value["gate_fwhm"])
|
|
1164
|
+
self.gate.set_value(round(gate * _FS))
|
|
1165
|
+
labels = self.session.labels
|
|
1166
|
+
mode = int(value["mode"])
|
|
1167
|
+
name = labels[mode] if mode < len(labels) else f"mode {mode}"
|
|
1168
|
+
shown = f"{name}, gate" if len(labels) > 1 else "Gate"
|
|
1169
|
+
self.note.setText(f"{shown} {gate * _FS:.3g} fs")
|
|
1170
|
+
|
|
1171
|
+
def _read(self, x: float, y: float) -> str:
|
|
1172
|
+
"""Say what is at a point of the map.
|
|
1173
|
+
|
|
1174
|
+
Parameters
|
|
1175
|
+
----------
|
|
1176
|
+
x : float
|
|
1177
|
+
The time, fs.
|
|
1178
|
+
y : float
|
|
1179
|
+
The position on the spectral axis.
|
|
1180
|
+
|
|
1181
|
+
Returns
|
|
1182
|
+
-------
|
|
1183
|
+
str
|
|
1184
|
+
The readout.
|
|
1185
|
+
"""
|
|
1186
|
+
if self._values.size == 0:
|
|
1187
|
+
return ""
|
|
1188
|
+
column = int(np.clip(np.searchsorted(self._t, x), 0, self._t.size - 1))
|
|
1189
|
+
row = int(np.clip(np.searchsorted(self._x, y), 0, self._x.size - 1))
|
|
1190
|
+
unit = _AXIS_UNIT[self.session.options.axis]
|
|
1191
|
+
return f"{x:.3g} fs, {y:.4g} {unit}: {self._values[row, column]:.1f} dB"
|
|
1192
|
+
|
|
1193
|
+
def figure(self) -> dict[str, object] | None:
|
|
1194
|
+
"""Return the page as solprop draws it.
|
|
1195
|
+
|
|
1196
|
+
Returns
|
|
1197
|
+
-------
|
|
1198
|
+
dict
|
|
1199
|
+
The spectrogram at the plane.
|
|
1200
|
+
"""
|
|
1201
|
+
return {"plot": "spectrogram", "z": self.session.z, "modes": self.session.mode}
|
|
1202
|
+
|
|
1203
|
+
def python(self) -> str | None:
|
|
1204
|
+
"""Return the page's snippet.
|
|
1205
|
+
|
|
1206
|
+
Returns
|
|
1207
|
+
-------
|
|
1208
|
+
str
|
|
1209
|
+
Its key.
|
|
1210
|
+
"""
|
|
1211
|
+
return "spectrogram"
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
class AlongPage(PageView):
|
|
1215
|
+
"""What was recorded along z, up to four quantities at once.
|
|
1216
|
+
|
|
1217
|
+
Parameters
|
|
1218
|
+
----------
|
|
1219
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
1220
|
+
The open file.
|
|
1221
|
+
|
|
1222
|
+
Attributes
|
|
1223
|
+
----------
|
|
1224
|
+
wanted : tuple of str
|
|
1225
|
+
What the class shows first, where it was recorded.
|
|
1226
|
+
"""
|
|
1227
|
+
|
|
1228
|
+
_SHOWN = 4
|
|
1229
|
+
|
|
1230
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
1231
|
+
"""Make the empty grid and the chooser."""
|
|
1232
|
+
super().__init__(session)
|
|
1233
|
+
self.wanted: tuple[str, ...] = ()
|
|
1234
|
+
self.reference: float | None = None
|
|
1235
|
+
self._said = ""
|
|
1236
|
+
self._stats: Mapping[str, Mapping[str, Any]] = {}
|
|
1237
|
+
self._z = np.zeros(0)
|
|
1238
|
+
self._plots: list[LinePlot] = []
|
|
1239
|
+
self._log = "auto"
|
|
1240
|
+
self.grid = QGridLayout()
|
|
1241
|
+
self.grid.setContentsMargins(0, 0, 0, 0)
|
|
1242
|
+
self.grid.setHorizontalSpacing(14)
|
|
1243
|
+
self.grid.setVerticalSpacing(10)
|
|
1244
|
+
column = QVBoxLayout(self)
|
|
1245
|
+
column.setContentsMargins(0, 0, 0, 0)
|
|
1246
|
+
column.setSpacing(6)
|
|
1247
|
+
column.addWidget(self.note)
|
|
1248
|
+
column.addLayout(self.grid, 1)
|
|
1249
|
+
self.choice = QListWidget()
|
|
1250
|
+
self.choice.setObjectName("statistics-choice")
|
|
1251
|
+
self.choice.setFrameShape(QFrame.Shape.NoFrame)
|
|
1252
|
+
self.choice.itemChanged.connect(self._chosen)
|
|
1253
|
+
self.log = Segments(
|
|
1254
|
+
"Log axes",
|
|
1255
|
+
(("auto", "Auto"), ("on", "On"), ("off", "Off")),
|
|
1256
|
+
self._log,
|
|
1257
|
+
)
|
|
1258
|
+
self.log.chosen.connect(self._log_chosen)
|
|
1259
|
+
box = QWidget()
|
|
1260
|
+
box.setObjectName("page")
|
|
1261
|
+
boxed = QVBoxLayout(box)
|
|
1262
|
+
boxed.setContentsMargins(0, 0, 0, 0)
|
|
1263
|
+
boxed.addWidget(named_label("Quantities", "control"))
|
|
1264
|
+
boxed.addWidget(self.choice, 1)
|
|
1265
|
+
panel = QWidget()
|
|
1266
|
+
panel.setObjectName("page")
|
|
1267
|
+
layout = QVBoxLayout(panel)
|
|
1268
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
1269
|
+
layout.setSpacing(14)
|
|
1270
|
+
layout.addWidget(self.log)
|
|
1271
|
+
layout.addWidget(box, 1)
|
|
1272
|
+
self.controls = panel
|
|
1273
|
+
|
|
1274
|
+
def refresh(self) -> None:
|
|
1275
|
+
"""Ask for what was recorded."""
|
|
1276
|
+
session = self.session
|
|
1277
|
+
if session.path is None:
|
|
1278
|
+
return
|
|
1279
|
+
if self._stats:
|
|
1280
|
+
self._mark()
|
|
1281
|
+
return
|
|
1282
|
+
session.ask(
|
|
1283
|
+
"statistics",
|
|
1284
|
+
{"path": session.path},
|
|
1285
|
+
self._show,
|
|
1286
|
+
key="page-along",
|
|
1287
|
+
failed=self._failed,
|
|
1288
|
+
)
|
|
1289
|
+
|
|
1290
|
+
def forget(self) -> None:
|
|
1291
|
+
"""Drop what was read, as another file opens."""
|
|
1292
|
+
self._stats = {}
|
|
1293
|
+
|
|
1294
|
+
def set_reference(self, z: float | None) -> None:
|
|
1295
|
+
"""Say where to mark a reference distance, as Marburger's is for a filament.
|
|
1296
|
+
|
|
1297
|
+
Parameters
|
|
1298
|
+
----------
|
|
1299
|
+
z : float or None
|
|
1300
|
+
The distance, m; ``None`` for none.
|
|
1301
|
+
"""
|
|
1302
|
+
if z != self.reference:
|
|
1303
|
+
self.reference = z
|
|
1304
|
+
if self._stats:
|
|
1305
|
+
self._draw()
|
|
1306
|
+
|
|
1307
|
+
def _show(self, value: Mapping[str, Any]) -> None:
|
|
1308
|
+
"""Take what was recorded.
|
|
1309
|
+
|
|
1310
|
+
Parameters
|
|
1311
|
+
----------
|
|
1312
|
+
value : Mapping
|
|
1313
|
+
The kernel's ``statistics`` reply.
|
|
1314
|
+
"""
|
|
1315
|
+
self._stats = {
|
|
1316
|
+
str(entry["name"]): entry for entry in value["stats"] if _varies(entry)
|
|
1317
|
+
}
|
|
1318
|
+
self._z = np.asarray(value["z"], float)
|
|
1319
|
+
accepted = np.asarray(value["steps"]["z"]).size
|
|
1320
|
+
rejected = np.asarray(value["steps"]["rejected_z"]).size
|
|
1321
|
+
self._said = f"{self._z.size} planes; {accepted} steps, {rejected} rejected."
|
|
1322
|
+
first = [name for name in self.wanted if name in self._stats]
|
|
1323
|
+
for fallback in ("energy", "peak_power", "peak_intensity", "fwhm_t"):
|
|
1324
|
+
if fallback in self._stats and fallback not in first:
|
|
1325
|
+
first.append(fallback)
|
|
1326
|
+
first = first[: self._SHOWN]
|
|
1327
|
+
self.choice.blockSignals(True)
|
|
1328
|
+
self.choice.clear()
|
|
1329
|
+
for name, entry in self._stats.items():
|
|
1330
|
+
item = QListWidgetItem(_title(name))
|
|
1331
|
+
item.setData(Qt.ItemDataRole.UserRole, name)
|
|
1332
|
+
item.setToolTip(str(entry.get("summary") or ""))
|
|
1333
|
+
item.setCheckState(
|
|
1334
|
+
Qt.CheckState.Checked if name in first else Qt.CheckState.Unchecked
|
|
1335
|
+
)
|
|
1336
|
+
self.choice.addItem(item)
|
|
1337
|
+
self.choice.blockSignals(False)
|
|
1338
|
+
self._draw()
|
|
1339
|
+
|
|
1340
|
+
def _chosen(self, _item: QListWidgetItem) -> None:
|
|
1341
|
+
"""Redraw for the quantities ticked.
|
|
1342
|
+
|
|
1343
|
+
Parameters
|
|
1344
|
+
----------
|
|
1345
|
+
_item : PySide6.QtWidgets.QListWidgetItem
|
|
1346
|
+
The item changed.
|
|
1347
|
+
"""
|
|
1348
|
+
self._draw()
|
|
1349
|
+
|
|
1350
|
+
def _log_chosen(self, value: object) -> None:
|
|
1351
|
+
"""Take the choice of log axes.
|
|
1352
|
+
|
|
1353
|
+
Parameters
|
|
1354
|
+
----------
|
|
1355
|
+
value : object
|
|
1356
|
+
``"auto"``, ``"on"`` or ``"off"``.
|
|
1357
|
+
"""
|
|
1358
|
+
self._log = str(value)
|
|
1359
|
+
self._draw()
|
|
1360
|
+
|
|
1361
|
+
def _names(self) -> list[str]:
|
|
1362
|
+
"""Return the quantities ticked.
|
|
1363
|
+
|
|
1364
|
+
Returns
|
|
1365
|
+
-------
|
|
1366
|
+
list of str
|
|
1367
|
+
At most four: a page shows what it can show large.
|
|
1368
|
+
"""
|
|
1369
|
+
items = (self.choice.item(i) for i in range(self.choice.count()))
|
|
1370
|
+
names = [
|
|
1371
|
+
str(item.data(Qt.ItemDataRole.UserRole))
|
|
1372
|
+
for item in items
|
|
1373
|
+
if item is not None and item.checkState() == Qt.CheckState.Checked
|
|
1374
|
+
]
|
|
1375
|
+
return names[: self._SHOWN]
|
|
1376
|
+
|
|
1377
|
+
def _draw(self) -> None:
|
|
1378
|
+
"""Lay out a plot per quantity ticked."""
|
|
1379
|
+
clear_layout(self.grid)
|
|
1380
|
+
self._plots = []
|
|
1381
|
+
marked = "" if self.reference is None else " Dotted: Marburger's distance."
|
|
1382
|
+
self.note.setText(self._said + marked)
|
|
1383
|
+
name, factor = length_unit(float(self._z[-1]) if self._z.size else 1.0)
|
|
1384
|
+
names = self._names()
|
|
1385
|
+
for index, stat in enumerate(names):
|
|
1386
|
+
entry = self._stats[stat]
|
|
1387
|
+
columns = entry["columns"]
|
|
1388
|
+
ys = [np.asarray(column["y"], float) for column in columns]
|
|
1389
|
+
unit = pretty(str(entry.get("units") or ""))
|
|
1390
|
+
shown_unit, scale = scaled_unit(np.concatenate(ys), unit)
|
|
1391
|
+
label = f"{_title(stat)} ({shown_unit})" if shown_unit else _title(stat)
|
|
1392
|
+
plot = LinePlot(
|
|
1393
|
+
xlabel=f"z ({name})",
|
|
1394
|
+
ylabel=label,
|
|
1395
|
+
names=_column_names(stat, columns),
|
|
1396
|
+
unit=shown_unit,
|
|
1397
|
+
left=None,
|
|
1398
|
+
)
|
|
1399
|
+
plot.along = "x"
|
|
1400
|
+
plot.setCursor(Qt.CursorShape.SizeHorCursor)
|
|
1401
|
+
plot.plane_at.connect(lambda v, f=factor: self.session.move_near(v / f))
|
|
1402
|
+
logged = self._log == "on" or (
|
|
1403
|
+
self._log == "auto" and wants_log(np.concatenate(ys))
|
|
1404
|
+
)
|
|
1405
|
+
plot.set_log(logged)
|
|
1406
|
+
plot.set_data(self._z * factor, [y * scale for y in ys])
|
|
1407
|
+
plot.fit()
|
|
1408
|
+
plot.setProperty("z_factor", factor)
|
|
1409
|
+
if self.reference is not None:
|
|
1410
|
+
line = pg.InfiniteLine(
|
|
1411
|
+
self.reference * factor,
|
|
1412
|
+
angle=90,
|
|
1413
|
+
pen=pg.mkPen(ORANGE, style=Qt.PenStyle.DotLine),
|
|
1414
|
+
)
|
|
1415
|
+
plot.addItem(line, ignoreBounds=True) # pyright: ignore[reportCallIssue]
|
|
1416
|
+
self._plots.append(plot)
|
|
1417
|
+
row, col = (index // 2, index % 2) if len(names) > 1 else (0, 0)
|
|
1418
|
+
self.grid.addLayout(_plotted(_title(stat), plot), row, col)
|
|
1419
|
+
self._mark()
|
|
1420
|
+
|
|
1421
|
+
def _mark(self) -> None:
|
|
1422
|
+
"""Mark the plane selected on the plots."""
|
|
1423
|
+
z = self.session.z
|
|
1424
|
+
for plot in self._plots:
|
|
1425
|
+
if z is None:
|
|
1426
|
+
plot.marker.hide()
|
|
1427
|
+
else:
|
|
1428
|
+
plot.marker.setPos(z * float(plot.property("z_factor")))
|
|
1429
|
+
plot.marker.show()
|
|
1430
|
+
|
|
1431
|
+
def plane_moved(self) -> None:
|
|
1432
|
+
"""Follow the scrubber, at no cost."""
|
|
1433
|
+
self._mark()
|
|
1434
|
+
|
|
1435
|
+
def data(self) -> tuple[list[str], np.ndarray] | None:
|
|
1436
|
+
"""Return the quantities shown, as columns.
|
|
1437
|
+
|
|
1438
|
+
Returns
|
|
1439
|
+
-------
|
|
1440
|
+
tuple or None
|
|
1441
|
+
The position and each column, in SI; ``None`` with none shown.
|
|
1442
|
+
"""
|
|
1443
|
+
names = self._names()
|
|
1444
|
+
if not names or self._z.size == 0:
|
|
1445
|
+
return None
|
|
1446
|
+
headers = ["z (m)"]
|
|
1447
|
+
columns = [self._z]
|
|
1448
|
+
for stat in names:
|
|
1449
|
+
for column in self._stats[stat]["columns"]:
|
|
1450
|
+
headers.append(str(column["label"]))
|
|
1451
|
+
columns.append(np.asarray(column["y"], float))
|
|
1452
|
+
return headers, np.column_stack(columns)
|
|
1453
|
+
|
|
1454
|
+
def figure(self) -> dict[str, object] | None:
|
|
1455
|
+
"""Return the page as solprop draws it.
|
|
1456
|
+
|
|
1457
|
+
Returns
|
|
1458
|
+
-------
|
|
1459
|
+
dict
|
|
1460
|
+
One figure per statistic.
|
|
1461
|
+
"""
|
|
1462
|
+
return {"plot": "plot_stats"}
|
|
1463
|
+
|
|
1464
|
+
def python(self) -> str | None:
|
|
1465
|
+
"""Return the page's snippet.
|
|
1466
|
+
|
|
1467
|
+
Returns
|
|
1468
|
+
-------
|
|
1469
|
+
str
|
|
1470
|
+
Its key.
|
|
1471
|
+
"""
|
|
1472
|
+
return "along"
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
_COLUMNS = {"beam_radius": ("second moment", "1/e²")}
|
|
1476
|
+
"""What the columns of a statistic mean, where solprop numbers them."""
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
def _column_names(stat: str, columns: Sequence[Mapping[str, Any]]) -> list[str]:
|
|
1480
|
+
"""Return what a statistic's curves are called.
|
|
1481
|
+
|
|
1482
|
+
Parameters
|
|
1483
|
+
----------
|
|
1484
|
+
stat : str
|
|
1485
|
+
The statistic.
|
|
1486
|
+
columns : Sequence of Mapping
|
|
1487
|
+
Its columns, as the kernel gives them.
|
|
1488
|
+
|
|
1489
|
+
Returns
|
|
1490
|
+
-------
|
|
1491
|
+
list of str
|
|
1492
|
+
Their names.
|
|
1493
|
+
|
|
1494
|
+
Examples
|
|
1495
|
+
--------
|
|
1496
|
+
>>> _column_names("beam_radius", [{"label": "a"}, {"label": "b"}])
|
|
1497
|
+
['second moment', '1/e²']
|
|
1498
|
+
>>> _column_names("energy", [{"label": "a"}])
|
|
1499
|
+
['a']
|
|
1500
|
+
"""
|
|
1501
|
+
named = _COLUMNS.get(stat)
|
|
1502
|
+
if named is not None and len(named) == len(columns):
|
|
1503
|
+
return list(named)
|
|
1504
|
+
return [str(column["label"]) for column in columns]
|
|
1505
|
+
|
|
1506
|
+
|
|
1507
|
+
def _title(name: str) -> str:
|
|
1508
|
+
"""Return a statistic's plain name.
|
|
1509
|
+
|
|
1510
|
+
Parameters
|
|
1511
|
+
----------
|
|
1512
|
+
name : str
|
|
1513
|
+
The name solprop gives it.
|
|
1514
|
+
|
|
1515
|
+
Returns
|
|
1516
|
+
-------
|
|
1517
|
+
str
|
|
1518
|
+
What the page calls it.
|
|
1519
|
+
|
|
1520
|
+
Examples
|
|
1521
|
+
--------
|
|
1522
|
+
>>> _title("peak_intensity"), _title("fwhm_t"), _title("energy")
|
|
1523
|
+
('Peak intensity', 'Duration', 'Energy')
|
|
1524
|
+
"""
|
|
1525
|
+
return _STAT_TITLES.get(name, name.replace("_", " ").capitalize())
|
|
1526
|
+
|
|
1527
|
+
|
|
1528
|
+
def _varies(entry: Mapping[str, Any]) -> bool:
|
|
1529
|
+
"""Return whether a statistic changes along z, and so has anything to plot.
|
|
1530
|
+
|
|
1531
|
+
The gas's pressure in a straight fibre, or an ionised fraction with plasma off, is
|
|
1532
|
+
recorded all the same, and would only lengthen the list.
|
|
1533
|
+
|
|
1534
|
+
Parameters
|
|
1535
|
+
----------
|
|
1536
|
+
entry : Mapping
|
|
1537
|
+
The statistic, from the kernel's ``statistics`` reply.
|
|
1538
|
+
|
|
1539
|
+
Returns
|
|
1540
|
+
-------
|
|
1541
|
+
bool
|
|
1542
|
+
Whether any of its columns moves by more than rounding.
|
|
1543
|
+
|
|
1544
|
+
Examples
|
|
1545
|
+
--------
|
|
1546
|
+
>>> _varies({"columns": [{"y": [1.0, 1.0]}, {"y": [1.0, 2.0]}]})
|
|
1547
|
+
True
|
|
1548
|
+
>>> _varies({"columns": [{"y": [0.0, 0.0]}]})
|
|
1549
|
+
False
|
|
1550
|
+
"""
|
|
1551
|
+
for column in entry["columns"]:
|
|
1552
|
+
y = np.asarray(column["y"], float)
|
|
1553
|
+
if y.size and np.ptp(y) > _STEADY * float(np.abs(y).max()):
|
|
1554
|
+
return True
|
|
1555
|
+
return False
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
class ModesPage(PageView):
|
|
1559
|
+
"""The energy in each mode along z, and each mode's spectrum at the plane.
|
|
1560
|
+
|
|
1561
|
+
Parameters
|
|
1562
|
+
----------
|
|
1563
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
1564
|
+
The open file.
|
|
1565
|
+
"""
|
|
1566
|
+
|
|
1567
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
1568
|
+
"""Make the two plots and the chooser."""
|
|
1569
|
+
super().__init__(session)
|
|
1570
|
+
self.energy = LinePlot(xlabel="z", ylabel="Energy", unit="")
|
|
1571
|
+
self.spectra = LinePlot(
|
|
1572
|
+
xlabel=_AXIS_LABEL["wavelength"], ylabel="dB", unit="dB"
|
|
1573
|
+
)
|
|
1574
|
+
self.energy.along = "x"
|
|
1575
|
+
self._spectra: dict[int, np.ndarray] = {}
|
|
1576
|
+
self._x = np.zeros(0)
|
|
1577
|
+
self._read_stats = False
|
|
1578
|
+
self._factor = 1.0
|
|
1579
|
+
self.energy.plane_at.connect(lambda v: session.move_near(v / self._factor))
|
|
1580
|
+
column = QVBoxLayout(self)
|
|
1581
|
+
column.setContentsMargins(0, 0, 0, 0)
|
|
1582
|
+
column.setSpacing(10)
|
|
1583
|
+
self.energy_title = named_label("Energy in each mode along z", "plotTitle")
|
|
1584
|
+
column.addWidget(self.energy_title)
|
|
1585
|
+
column.addWidget(self.energy, 1)
|
|
1586
|
+
column.addLayout(
|
|
1587
|
+
_plotted("Each mode's spectrum at this plane", self.spectra), 1
|
|
1588
|
+
)
|
|
1589
|
+
self.choice = QListWidget()
|
|
1590
|
+
self.choice.setObjectName("modes-choice")
|
|
1591
|
+
self.choice.setFrameShape(QFrame.Shape.NoFrame)
|
|
1592
|
+
self.choice.itemChanged.connect(lambda _item: self._ask_spectra())
|
|
1593
|
+
self.controls = control_panel(named_label("Modes", "control"), self.choice)
|
|
1594
|
+
session.described.connect(self._fill)
|
|
1595
|
+
|
|
1596
|
+
def forget(self) -> None:
|
|
1597
|
+
"""Drop what was read, as another file opens."""
|
|
1598
|
+
self._read_stats = False
|
|
1599
|
+
self._spectra = {}
|
|
1600
|
+
|
|
1601
|
+
def _fill(self, _value: object = None) -> None:
|
|
1602
|
+
"""List the file's modes, all ticked.
|
|
1603
|
+
|
|
1604
|
+
Parameters
|
|
1605
|
+
----------
|
|
1606
|
+
_value : object, optional
|
|
1607
|
+
Not read.
|
|
1608
|
+
"""
|
|
1609
|
+
self.choice.blockSignals(True)
|
|
1610
|
+
self.choice.clear()
|
|
1611
|
+
for index, label in enumerate(self.session.labels):
|
|
1612
|
+
item = QListWidgetItem(label)
|
|
1613
|
+
item.setData(Qt.ItemDataRole.UserRole, index)
|
|
1614
|
+
item.setCheckState(Qt.CheckState.Checked)
|
|
1615
|
+
self.choice.addItem(item)
|
|
1616
|
+
self.choice.blockSignals(False)
|
|
1617
|
+
|
|
1618
|
+
def _selected(self) -> list[int]:
|
|
1619
|
+
"""Return the modes ticked.
|
|
1620
|
+
|
|
1621
|
+
Returns
|
|
1622
|
+
-------
|
|
1623
|
+
list of int
|
|
1624
|
+
Their indices.
|
|
1625
|
+
"""
|
|
1626
|
+
items = (self.choice.item(i) for i in range(self.choice.count()))
|
|
1627
|
+
return [
|
|
1628
|
+
int(item.data(Qt.ItemDataRole.UserRole))
|
|
1629
|
+
for item in items
|
|
1630
|
+
if item is not None and item.checkState() == Qt.CheckState.Checked
|
|
1631
|
+
]
|
|
1632
|
+
|
|
1633
|
+
def refresh(self) -> None:
|
|
1634
|
+
"""Ask for what the page shows."""
|
|
1635
|
+
session = self.session
|
|
1636
|
+
if session.path is None:
|
|
1637
|
+
return
|
|
1638
|
+
if not self._read_stats:
|
|
1639
|
+
session.ask(
|
|
1640
|
+
"statistics",
|
|
1641
|
+
{"path": session.path},
|
|
1642
|
+
self._show_energy,
|
|
1643
|
+
key="page-modes",
|
|
1644
|
+
)
|
|
1645
|
+
self._ask_spectra()
|
|
1646
|
+
|
|
1647
|
+
def _show_energy(self, value: Mapping[str, Any]) -> None:
|
|
1648
|
+
"""Draw the energy per mode.
|
|
1649
|
+
|
|
1650
|
+
Parameters
|
|
1651
|
+
----------
|
|
1652
|
+
value : Mapping
|
|
1653
|
+
The kernel's ``statistics`` reply.
|
|
1654
|
+
"""
|
|
1655
|
+
self._read_stats = True
|
|
1656
|
+
z = np.asarray(value["z"], float)
|
|
1657
|
+
name, self._factor = length_unit(float(z[-1]) if z.size else 1.0)
|
|
1658
|
+
entry = next((e for e in value["stats"] if e["name"] == "energy"), None)
|
|
1659
|
+
self.energy.setVisible(entry is not None)
|
|
1660
|
+
self.energy_title.setVisible(entry is not None)
|
|
1661
|
+
if entry is None:
|
|
1662
|
+
# A guide whose modes are not orthogonal records only their total.
|
|
1663
|
+
self.note.setText(
|
|
1664
|
+
"This run's modes are not orthogonal, so their energies do not add: "
|
|
1665
|
+
"it records their total (Along z), and each mode's spectrum below."
|
|
1666
|
+
)
|
|
1667
|
+
return
|
|
1668
|
+
self.note.setText("")
|
|
1669
|
+
ys = [np.asarray(column["y"], float) for column in entry["columns"]]
|
|
1670
|
+
unit, scale = scaled_unit(np.concatenate(ys), "J")
|
|
1671
|
+
self.energy.set_names([str(column["label"]) for column in entry["columns"]])
|
|
1672
|
+
self.energy.set_xlabel(f"z ({name})")
|
|
1673
|
+
self.energy.set_ylabel(f"Energy ({unit})")
|
|
1674
|
+
self.energy.unit = unit
|
|
1675
|
+
self.energy.set_log(wants_log(np.concatenate(ys)))
|
|
1676
|
+
self.energy.set_data(z * self._factor, [y * scale for y in ys])
|
|
1677
|
+
self.energy.fit()
|
|
1678
|
+
self._mark()
|
|
1679
|
+
|
|
1680
|
+
def _ask_spectra(self) -> None:
|
|
1681
|
+
"""Ask for each mode ticked's spectrum at the plane selected."""
|
|
1682
|
+
session = self.session
|
|
1683
|
+
if session.path is None or not session.planes:
|
|
1684
|
+
return
|
|
1685
|
+
self._spectra = {}
|
|
1686
|
+
selected = self._selected()
|
|
1687
|
+
self.spectra.set_names([session.labels[index] for index in selected])
|
|
1688
|
+
for index in selected:
|
|
1689
|
+
session.ask(
|
|
1690
|
+
"plane",
|
|
1691
|
+
{
|
|
1692
|
+
"path": session.path,
|
|
1693
|
+
"index": session.index,
|
|
1694
|
+
"modes": index,
|
|
1695
|
+
"axis": session.options.axis,
|
|
1696
|
+
},
|
|
1697
|
+
lambda value, i=index: self._take_spectrum(i, value),
|
|
1698
|
+
key=f"page-modes-{index}",
|
|
1699
|
+
)
|
|
1700
|
+
self._mark()
|
|
1701
|
+
|
|
1702
|
+
def _take_spectrum(self, index: int, value: Mapping[str, Any]) -> None:
|
|
1703
|
+
"""Draw the spectra once each mode's has come.
|
|
1704
|
+
|
|
1705
|
+
Parameters
|
|
1706
|
+
----------
|
|
1707
|
+
index : int
|
|
1708
|
+
The mode.
|
|
1709
|
+
value : Mapping
|
|
1710
|
+
The kernel's ``plane`` reply.
|
|
1711
|
+
"""
|
|
1712
|
+
axis = str(value["axis"])
|
|
1713
|
+
self._x = np.asarray(value["spectrum"]["x"], float) * _AXIS_SCALE[axis]
|
|
1714
|
+
self._spectra[index] = np.asarray(value["spectrum"]["y"], float)
|
|
1715
|
+
selected = self._selected()
|
|
1716
|
+
if all(i in self._spectra for i in selected) and selected:
|
|
1717
|
+
order = np.argsort(self._x)
|
|
1718
|
+
x = self._x[order]
|
|
1719
|
+
top = max(float(self._spectra[i].max()) for i in selected) or 1.0
|
|
1720
|
+
lines = [
|
|
1721
|
+
decibels(np.append(self._spectra[i][order], top))[:-1] for i in selected
|
|
1722
|
+
]
|
|
1723
|
+
self.spectra.set_xlabel(_AXIS_LABEL[axis])
|
|
1724
|
+
self.spectra.set_data(x, lines)
|
|
1725
|
+
floor = self.session.options.floor
|
|
1726
|
+
self.spectra.set_view(_shown_range(value, axis, x), (floor, 3.0))
|
|
1727
|
+
|
|
1728
|
+
def _mark(self) -> None:
|
|
1729
|
+
"""Mark the plane selected."""
|
|
1730
|
+
z = self.session.z
|
|
1731
|
+
if z is not None:
|
|
1732
|
+
self.energy.marker.setPos(z * self._factor)
|
|
1733
|
+
self.energy.marker.show()
|
|
1734
|
+
|
|
1735
|
+
def python(self) -> str | None:
|
|
1736
|
+
"""Return the page's snippet.
|
|
1737
|
+
|
|
1738
|
+
Returns
|
|
1739
|
+
-------
|
|
1740
|
+
str
|
|
1741
|
+
Its key.
|
|
1742
|
+
"""
|
|
1743
|
+
return "modes"
|
|
1744
|
+
|
|
1745
|
+
|
|
1746
|
+
class CompressPage(PageView):
|
|
1747
|
+
"""The pulse before, after and at its transform limit, through a compressor chain.
|
|
1748
|
+
|
|
1749
|
+
Parameters
|
|
1750
|
+
----------
|
|
1751
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
1752
|
+
The open file.
|
|
1753
|
+
"""
|
|
1754
|
+
|
|
1755
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
1756
|
+
"""Host the chain beside its plots."""
|
|
1757
|
+
super().__init__(session)
|
|
1758
|
+
self.chain = PostprocessPage(session.bridge, session)
|
|
1759
|
+
self.chain.heading.hide()
|
|
1760
|
+
column = QVBoxLayout(self)
|
|
1761
|
+
column.setContentsMargins(0, 0, 0, 0)
|
|
1762
|
+
column.addWidget(self.chain.view, 1)
|
|
1763
|
+
self.controls = self.chain
|
|
1764
|
+
|
|
1765
|
+
def refresh(self) -> None:
|
|
1766
|
+
"""Say what will be compressed."""
|
|
1767
|
+
self.chain.refresh()
|
|
1768
|
+
|
|
1769
|
+
def python(self) -> str | None:
|
|
1770
|
+
"""Return the page's snippet.
|
|
1771
|
+
|
|
1772
|
+
Returns
|
|
1773
|
+
-------
|
|
1774
|
+
str
|
|
1775
|
+
Its key.
|
|
1776
|
+
"""
|
|
1777
|
+
return "compress"
|
|
1778
|
+
|
|
1779
|
+
|
|
1780
|
+
class HealthPage(PageView):
|
|
1781
|
+
"""How the run went: its steps, its boundary, its record and its log.
|
|
1782
|
+
|
|
1783
|
+
Parameters
|
|
1784
|
+
----------
|
|
1785
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
1786
|
+
The open file.
|
|
1787
|
+
"""
|
|
1788
|
+
|
|
1789
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
1790
|
+
"""Make the plots and the log."""
|
|
1791
|
+
super().__init__(session)
|
|
1792
|
+
self.steps = LinePlot(xlabel="z", ylabel="Step size", names=["accepted"])
|
|
1793
|
+
self.steps.setProperty("rejected", None)
|
|
1794
|
+
self.rejected = pg.ScatterPlotItem(
|
|
1795
|
+
size=6, brush=pg.mkBrush(ORANGE), pen=None, name="rejected"
|
|
1796
|
+
)
|
|
1797
|
+
self.steps.addItem(self.rejected)
|
|
1798
|
+
self.boundary = LinePlot(xlabel="z", ylabel="Share removed at the edges")
|
|
1799
|
+
self.boundary.set_log(True)
|
|
1800
|
+
self.budget = pg.InfiniteLine(
|
|
1801
|
+
angle=0, pen=pg.mkPen(ORANGE, style=Qt.PenStyle.DashLine)
|
|
1802
|
+
)
|
|
1803
|
+
self.budget.hide()
|
|
1804
|
+
self.boundary.addItem(self.budget, ignoreBounds=True) # pyright: ignore[reportCallIssue]
|
|
1805
|
+
self.log = QPlainTextEdit()
|
|
1806
|
+
self.log.setObjectName("drawerText")
|
|
1807
|
+
self.log.setReadOnly(True)
|
|
1808
|
+
grid = QGridLayout()
|
|
1809
|
+
grid.setContentsMargins(0, 0, 0, 0)
|
|
1810
|
+
grid.setHorizontalSpacing(14)
|
|
1811
|
+
grid.addLayout(_plotted("Step size along z", self.steps), 0, 0)
|
|
1812
|
+
grid.addLayout(
|
|
1813
|
+
_plotted("Light removed at the time window's edges", self.boundary), 0, 1
|
|
1814
|
+
)
|
|
1815
|
+
column = QVBoxLayout(self)
|
|
1816
|
+
column.setContentsMargins(0, 0, 0, 0)
|
|
1817
|
+
column.setSpacing(6)
|
|
1818
|
+
column.addWidget(self.note)
|
|
1819
|
+
column.addLayout(grid, 2)
|
|
1820
|
+
column.addLayout(_plotted("Log", self.log), 1)
|
|
1821
|
+
self.facts = named_label("", "note")
|
|
1822
|
+
self.facts.setWordWrap(True)
|
|
1823
|
+
self.facts.setAlignment(Qt.AlignmentFlag.AlignTop)
|
|
1824
|
+
self.controls = control_panel(named_label("This run", "control"), self.facts)
|
|
1825
|
+
|
|
1826
|
+
def refresh(self) -> None:
|
|
1827
|
+
"""Ask how the run went."""
|
|
1828
|
+
session = self.session
|
|
1829
|
+
if session.path is None:
|
|
1830
|
+
return
|
|
1831
|
+
session.ask(
|
|
1832
|
+
"run_health",
|
|
1833
|
+
{"path": session.path},
|
|
1834
|
+
self._show,
|
|
1835
|
+
key="page-health",
|
|
1836
|
+
failed=self._failed,
|
|
1837
|
+
)
|
|
1838
|
+
|
|
1839
|
+
def _show(self, value: Mapping[str, Any]) -> None:
|
|
1840
|
+
"""Draw how the run went.
|
|
1841
|
+
|
|
1842
|
+
Parameters
|
|
1843
|
+
----------
|
|
1844
|
+
value : Mapping
|
|
1845
|
+
The kernel's ``run_health`` reply.
|
|
1846
|
+
"""
|
|
1847
|
+
steps = value["steps"]
|
|
1848
|
+
z = np.asarray(steps["z"], float)
|
|
1849
|
+
h = np.asarray(steps["h"], float)
|
|
1850
|
+
rejected_z = np.asarray(steps["rejected_z"], float)
|
|
1851
|
+
rejected_h = np.asarray(steps["rejected_h"], float)
|
|
1852
|
+
name, factor = length_unit(float(z.max()) if z.size else 1.0)
|
|
1853
|
+
unit, scale = scaled_unit(h, "m")
|
|
1854
|
+
self.steps.set_xlabel(f"z ({name})")
|
|
1855
|
+
self.steps.set_ylabel(f"Step size ({unit})")
|
|
1856
|
+
self.steps.unit = unit
|
|
1857
|
+
self.steps.set_data(z * factor, [h * scale])
|
|
1858
|
+
self.steps.fit()
|
|
1859
|
+
self.rejected.setData(rejected_z * factor, rejected_h * scale)
|
|
1860
|
+
self._show_boundary(value.get("boundary"), name, factor)
|
|
1861
|
+
status = str(value.get("status") or "no record of how it ended")
|
|
1862
|
+
message = value.get("message")
|
|
1863
|
+
self.note.setText(
|
|
1864
|
+
f"{status.capitalize()}; {z.size} steps, {rejected_z.size} rejected"
|
|
1865
|
+
+ (f". {message}" if message else ".")
|
|
1866
|
+
)
|
|
1867
|
+
self.facts.setText(_facts_text(value.get("facts") or {}))
|
|
1868
|
+
log = value.get("log")
|
|
1869
|
+
self.log.setPlainText("" if log is None else str(log))
|
|
1870
|
+
|
|
1871
|
+
def _show_boundary(self, boundary: object, name: str, factor: float) -> None:
|
|
1872
|
+
"""Draw what the boundary monitor recorded.
|
|
1873
|
+
|
|
1874
|
+
Parameters
|
|
1875
|
+
----------
|
|
1876
|
+
boundary : object
|
|
1877
|
+
The reply's ``boundary``.
|
|
1878
|
+
name : str
|
|
1879
|
+
The unit along z.
|
|
1880
|
+
factor : float
|
|
1881
|
+
What metres are multiplied by to read in it.
|
|
1882
|
+
"""
|
|
1883
|
+
self.boundary.set_xlabel(f"z ({name})")
|
|
1884
|
+
if not isinstance(boundary, Mapping) or not len(boundary["z"]):
|
|
1885
|
+
self.boundary.set_data(np.zeros(0), [np.zeros(0)])
|
|
1886
|
+
self.budget.hide()
|
|
1887
|
+
return
|
|
1888
|
+
z = np.asarray(boundary["z"], float) * factor
|
|
1889
|
+
removed = np.asarray(boundary["removed"], float)
|
|
1890
|
+
self.boundary.set_data(z, [removed])
|
|
1891
|
+
budget = boundary.get("budget")
|
|
1892
|
+
high = float(removed.max())
|
|
1893
|
+
if isinstance(budget, int | float):
|
|
1894
|
+
self.budget.setPos(np.log10(budget))
|
|
1895
|
+
self.budget.show()
|
|
1896
|
+
high = max(high, float(budget))
|
|
1897
|
+
positive = removed[removed > 0]
|
|
1898
|
+
low = float(positive.min()) if positive.size else high * 1e-6
|
|
1899
|
+
self.boundary.set_view((float(z[0]), float(z[-1])), (low / 3.0, high * 3.0))
|
|
1900
|
+
|
|
1901
|
+
def python(self) -> str | None:
|
|
1902
|
+
"""Return the page's snippet.
|
|
1903
|
+
|
|
1904
|
+
Returns
|
|
1905
|
+
-------
|
|
1906
|
+
str
|
|
1907
|
+
Its key.
|
|
1908
|
+
"""
|
|
1909
|
+
return "health"
|
|
1910
|
+
|
|
1911
|
+
|
|
1912
|
+
def _facts_text(facts: Mapping[str, Any]) -> str:
|
|
1913
|
+
r"""Write what the run's record says.
|
|
1914
|
+
|
|
1915
|
+
Parameters
|
|
1916
|
+
----------
|
|
1917
|
+
facts : Mapping
|
|
1918
|
+
The reply's ``facts``.
|
|
1919
|
+
|
|
1920
|
+
Returns
|
|
1921
|
+
-------
|
|
1922
|
+
str
|
|
1923
|
+
One line each, of those it has.
|
|
1924
|
+
|
|
1925
|
+
Examples
|
|
1926
|
+
--------
|
|
1927
|
+
>>> _facts_text({"backend": "native", "wall_time": 42.0})
|
|
1928
|
+
'Backend: native\nTook 0:42'
|
|
1929
|
+
>>> _facts_text({"peak_memory": 2e8, "plasma_source": [1e-16, 1e-10]})
|
|
1930
|
+
'Peak memory 200 MB\nPlasma source check 1e-16 (limit 1e-10)'
|
|
1931
|
+
"""
|
|
1932
|
+
lines = []
|
|
1933
|
+
if facts.get("backend"):
|
|
1934
|
+
lines.append(f"Backend: {facts['backend']}")
|
|
1935
|
+
if facts.get("precision"):
|
|
1936
|
+
lines.append(f"Precision: {facts['precision']}")
|
|
1937
|
+
if facts.get("threads"):
|
|
1938
|
+
lines.append(f"Threads: {facts['threads']}")
|
|
1939
|
+
if facts.get("wall_time") is not None:
|
|
1940
|
+
lines.append(f"Took {duration_text(float(facts['wall_time']))}")
|
|
1941
|
+
if facts.get("peak_memory") is not None:
|
|
1942
|
+
lines.append(f"Peak memory {size_text(float(facts['peak_memory']))}")
|
|
1943
|
+
plasma = facts.get("plasma_source")
|
|
1944
|
+
if plasma:
|
|
1945
|
+
lines.append(f"Plasma source check {plasma[0]:.2g} (limit {plasma[1]:.2g})")
|
|
1946
|
+
return "\n".join(lines)
|
|
1947
|
+
|
|
1948
|
+
|
|
1949
|
+
class BeamOverviewPage(OverviewPage):
|
|
1950
|
+
"""A filament: its fluence along z, on-axis spectrum, and the plane across the beam.
|
|
1951
|
+
|
|
1952
|
+
While a run goes it shows the fluence and the beam's spectrum, which each plane
|
|
1953
|
+
reports; the on-axis spectrum and the plane's map are read from the file after.
|
|
1954
|
+
|
|
1955
|
+
Parameters
|
|
1956
|
+
----------
|
|
1957
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
1958
|
+
The open file.
|
|
1959
|
+
"""
|
|
1960
|
+
|
|
1961
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
1962
|
+
"""Make the maps and the plane's profile."""
|
|
1963
|
+
self._data: Mapping[str, Any] | None = None
|
|
1964
|
+
self._scale = "dB"
|
|
1965
|
+
self._fluence_floor = -30.0
|
|
1966
|
+
super().__init__(session)
|
|
1967
|
+
|
|
1968
|
+
def _build(self) -> None:
|
|
1969
|
+
"""Make the plots and their controls."""
|
|
1970
|
+
session = self.session
|
|
1971
|
+
self.fluence_map = MapPlot(
|
|
1972
|
+
xlabel="z", ylabel="r (µm)", colours="inferno", unit="dB"
|
|
1973
|
+
)
|
|
1974
|
+
self.fluence_map.set_along("x")
|
|
1975
|
+
self.spectrum_map = MapPlot(
|
|
1976
|
+
xlabel=_AXIS_LABEL["wavelength"], ylabel="z", colours="viridis", unit="dB"
|
|
1977
|
+
)
|
|
1978
|
+
self.spectrum_map.set_along("y")
|
|
1979
|
+
self.across_map = MapPlot(
|
|
1980
|
+
xlabel=_AXIS_LABEL["wavelength"],
|
|
1981
|
+
ylabel="r (µm)",
|
|
1982
|
+
colours="viridis",
|
|
1983
|
+
unit="dB",
|
|
1984
|
+
)
|
|
1985
|
+
self.profile = LinePlot(xlabel="r (µm)", ylabel="Fluence (J/cm²)", unit="J/cm²")
|
|
1986
|
+
for plot in (self.fluence_map, self.spectrum_map):
|
|
1987
|
+
plot.plane_at.connect(self._picked)
|
|
1988
|
+
self.fluence_map.reader = self._read_fluence
|
|
1989
|
+
self.spectrum_title = named_label("Beam spectrum along z", "plotTitle")
|
|
1990
|
+
grid = QGridLayout(self)
|
|
1991
|
+
grid.setContentsMargins(0, 0, 0, 0)
|
|
1992
|
+
grid.setHorizontalSpacing(14)
|
|
1993
|
+
grid.setVerticalSpacing(10)
|
|
1994
|
+
grid.setRowStretch(0, 3)
|
|
1995
|
+
grid.setRowStretch(1, 2)
|
|
1996
|
+
grid.setColumnStretch(0, 1)
|
|
1997
|
+
grid.setColumnStretch(1, 1)
|
|
1998
|
+
grid.addLayout(_plotted("Fluence along z", self.fluence_map), 0, 0)
|
|
1999
|
+
right = QVBoxLayout()
|
|
2000
|
+
right.setContentsMargins(0, 0, 0, 0)
|
|
2001
|
+
right.setSpacing(2)
|
|
2002
|
+
right.addWidget(self.spectrum_title)
|
|
2003
|
+
right.addWidget(self.spectrum_map, 1)
|
|
2004
|
+
grid.addLayout(right, 0, 1)
|
|
2005
|
+
grid.addLayout(_plotted("Across the beam at this plane", self.across_map), 1, 0)
|
|
2006
|
+
grid.addLayout(_plotted("Fluence at this plane", self.profile), 1, 1)
|
|
2007
|
+
self.axis_choice = Segments("Spectral axis", _AXES, session.options.axis)
|
|
2008
|
+
self.axis_choice.chosen.connect(lambda axis: session.set_options(axis=axis))
|
|
2009
|
+
self.scale_choice = Segments(
|
|
2010
|
+
"Fluence scale", (("dB", "dB"), ("linear", "Linear")), self._scale
|
|
2011
|
+
)
|
|
2012
|
+
self.scale_choice.chosen.connect(self._scale_chosen)
|
|
2013
|
+
self.fluence_floor = LabelledSlider("Fluence floor", -50, -5, -30, " dB")
|
|
2014
|
+
self.fluence_floor.moved.connect(self._fluence_floor_moved)
|
|
2015
|
+
self.floor = LabelledSlider(
|
|
2016
|
+
"Spectrum floor", -80, -10, int(session.options.floor), " dB"
|
|
2017
|
+
)
|
|
2018
|
+
self.floor.moved.connect(self._floor_moved)
|
|
2019
|
+
self.controls = control_panel(
|
|
2020
|
+
self.axis_choice, self.scale_choice, self.fluence_floor, self.floor
|
|
2021
|
+
)
|
|
2022
|
+
self._z = np.zeros(0)
|
|
2023
|
+
self._r = np.zeros(0)
|
|
2024
|
+
self._flu = np.zeros((0, 0))
|
|
2025
|
+
self._spec = np.zeros((0, 0))
|
|
2026
|
+
self._x = np.zeros(0)
|
|
2027
|
+
self._reach = 0.0
|
|
2028
|
+
self._spectral_view = (0.0, 1.0)
|
|
2029
|
+
|
|
2030
|
+
def forget(self) -> None:
|
|
2031
|
+
"""Drop what was read, as another file opens."""
|
|
2032
|
+
self._data = None
|
|
2033
|
+
|
|
2034
|
+
def clear(self) -> None:
|
|
2035
|
+
"""Start empty, for a new run."""
|
|
2036
|
+
self._data = None
|
|
2037
|
+
self.rows = []
|
|
2038
|
+
self.extent = None
|
|
2039
|
+
self.shown = 0
|
|
2040
|
+
self.following = True
|
|
2041
|
+
self._live = True
|
|
2042
|
+
self._flu = np.zeros((0, 0))
|
|
2043
|
+
for plot in (self.fluence_map, self.spectrum_map, self.across_map):
|
|
2044
|
+
plot.say("") # the stage covers them while the run starts
|
|
2045
|
+
self.profile.set_data(np.zeros(0), [np.zeros(0)])
|
|
2046
|
+
|
|
2047
|
+
def refresh(self) -> None:
|
|
2048
|
+
"""Read the file back; a run going draws from its rows."""
|
|
2049
|
+
session = self.session
|
|
2050
|
+
if session.path is None or self._live:
|
|
2051
|
+
self._draw_maps()
|
|
2052
|
+
return
|
|
2053
|
+
if self._data is None or self._data["axis"] != session.options.axis:
|
|
2054
|
+
if not self.rows:
|
|
2055
|
+
self.fluence_map.say("Reading…")
|
|
2056
|
+
self.spectrum_map.say("Reading…")
|
|
2057
|
+
session.ask(
|
|
2058
|
+
"beam_overview",
|
|
2059
|
+
{"path": session.path, "axis": session.options.axis},
|
|
2060
|
+
self._read_back,
|
|
2061
|
+
key="page-beam-overview",
|
|
2062
|
+
failed=self._refused,
|
|
2063
|
+
)
|
|
2064
|
+
return
|
|
2065
|
+
self._draw_maps()
|
|
2066
|
+
|
|
2067
|
+
def _read_back(self, value: Mapping[str, Any]) -> None:
|
|
2068
|
+
"""Take what the file holds.
|
|
2069
|
+
|
|
2070
|
+
Parameters
|
|
2071
|
+
----------
|
|
2072
|
+
value : Mapping
|
|
2073
|
+
The kernel's ``beam_overview`` reply.
|
|
2074
|
+
"""
|
|
2075
|
+
self._data = value
|
|
2076
|
+
self._draw_maps()
|
|
2077
|
+
|
|
2078
|
+
def _refused(self, reason: str) -> None:
|
|
2079
|
+
"""Say why there is nothing to draw.
|
|
2080
|
+
|
|
2081
|
+
Parameters
|
|
2082
|
+
----------
|
|
2083
|
+
reason : str
|
|
2084
|
+
The reason solprop gave.
|
|
2085
|
+
"""
|
|
2086
|
+
self.fluence_map.say(reason)
|
|
2087
|
+
|
|
2088
|
+
def _gather(self) -> bool:
|
|
2089
|
+
"""Take the maps' data from the file, or from a run's rows so far.
|
|
2090
|
+
|
|
2091
|
+
Returns
|
|
2092
|
+
-------
|
|
2093
|
+
bool
|
|
2094
|
+
Whether there is anything to draw.
|
|
2095
|
+
"""
|
|
2096
|
+
axis = self.session.options.axis
|
|
2097
|
+
if self._data is not None and not self._live:
|
|
2098
|
+
self._z = np.asarray(self._data["z"], float)
|
|
2099
|
+
self._r = np.asarray(self._data["r"], float) * 1e6
|
|
2100
|
+
self._flu = np.asarray(self._data["fluence"], float) * 1e-4
|
|
2101
|
+
self._x = np.asarray(self._data["x"], float) * _AXIS_SCALE[axis]
|
|
2102
|
+
self._spec = decibels(np.maximum(self._data["on_axis"], 0.0))
|
|
2103
|
+
self.spectrum_title.setText("On-axis spectrum along z")
|
|
2104
|
+
return self._z.size > 0
|
|
2105
|
+
rows = [row for row in self.rows if "profile" in row]
|
|
2106
|
+
if not rows or axis not in self.spectra:
|
|
2107
|
+
return False
|
|
2108
|
+
self._z = np.array([float(row["z"]) for row in rows])
|
|
2109
|
+
self._r = np.asarray(rows[0]["profile"]["x"], float) * 1e6
|
|
2110
|
+
self._flu = (
|
|
2111
|
+
np.array([np.asarray(r["profile"]["y"], float) for r in rows]) * 1e-4
|
|
2112
|
+
)
|
|
2113
|
+
self._x = self.spectra[axis] * _AXIS_SCALE[axis]
|
|
2114
|
+
self._spec = decibels(
|
|
2115
|
+
np.array([np.asarray(r["density"][axis], float) for r in rows])
|
|
2116
|
+
)
|
|
2117
|
+
self.spectrum_title.setText("Beam spectrum along z")
|
|
2118
|
+
return True
|
|
2119
|
+
|
|
2120
|
+
def _draw_maps(self) -> None:
|
|
2121
|
+
"""Draw the fluence and the spectrum along z."""
|
|
2122
|
+
if not self._gather():
|
|
2123
|
+
return
|
|
2124
|
+
options = self.session.options
|
|
2125
|
+
z = self._z
|
|
2126
|
+
reach = self.extent[1] if self.extent and self._live else float(z[-1])
|
|
2127
|
+
name, factor = length_unit(reach or 1.0)
|
|
2128
|
+
self._unit = (name, factor)
|
|
2129
|
+
self._reach = beam_reach(self._r, self._flu)
|
|
2130
|
+
rows, first, step = even_rows(z)
|
|
2131
|
+
y, mirrored = mirrored_rows(self._r, self._flu[rows], self._reach)
|
|
2132
|
+
x_low = (first - step / 2) * factor
|
|
2133
|
+
width = step * rows.size * factor
|
|
2134
|
+
view = (float(z[0]) * factor, max(reach, float(z[-1])) * factor)
|
|
2135
|
+
self.fluence_map.set_xlabel(f"z ({name})")
|
|
2136
|
+
self.spectrum_map.set_ylabel(f"z ({name})")
|
|
2137
|
+
self.spectrum_map.set_xlabel(_AXIS_LABEL[options.axis])
|
|
2138
|
+
self.across_map.set_xlabel(_AXIS_LABEL[options.axis])
|
|
2139
|
+
self._mirrored = mirrored.T
|
|
2140
|
+
self._y = y
|
|
2141
|
+
self._fluence_rect = (x_low, float(y[0]), width, float(y[-1] - y[0]))
|
|
2142
|
+
self._fluence_view = (view, (float(y[0]), float(y[-1])))
|
|
2143
|
+
self._show_fluence()
|
|
2144
|
+
x = self._x
|
|
2145
|
+
lit = x[(self._spec > options.floor).any(axis=0)]
|
|
2146
|
+
span = (
|
|
2147
|
+
(float(lit[0]), float(lit[-1])) if lit.size else (float(x[0]), float(x[-1]))
|
|
2148
|
+
)
|
|
2149
|
+
margin = 0.05 * (span[1] - span[0])
|
|
2150
|
+
self._spectral_view = (span[0] - margin, span[1] + margin)
|
|
2151
|
+
self.spectrum_map.show_map(
|
|
2152
|
+
self._spec[rows],
|
|
2153
|
+
(float(x[0]), x_low, float(x[-1] - x[0]), width),
|
|
2154
|
+
(self._spectral_view, view),
|
|
2155
|
+
(options.floor, 0.0),
|
|
2156
|
+
)
|
|
2157
|
+
self.profile.set_view(
|
|
2158
|
+
(0.0, self._reach), (0.0, float(np.nanmax(self._flu)) * 1.05 or 1.0)
|
|
2159
|
+
)
|
|
2160
|
+
self._draw_plane()
|
|
2161
|
+
|
|
2162
|
+
def _show_fluence(self) -> None:
|
|
2163
|
+
"""Draw the fluence map on the scale chosen."""
|
|
2164
|
+
data = self._mirrored
|
|
2165
|
+
top = float(np.nanmax(data)) or 1.0
|
|
2166
|
+
linear = self._scale == "linear"
|
|
2167
|
+
self.fluence_map.show_map(
|
|
2168
|
+
data if linear else decibels(np.maximum(data, 0.0)),
|
|
2169
|
+
self._fluence_rect,
|
|
2170
|
+
self._fluence_view,
|
|
2171
|
+
(0.0, top) if linear else (self._fluence_floor, 0.0),
|
|
2172
|
+
)
|
|
2173
|
+
|
|
2174
|
+
def _draw_plane(self) -> None:
|
|
2175
|
+
"""Draw the plane selected, and mark it on the maps."""
|
|
2176
|
+
if self._flu.size == 0:
|
|
2177
|
+
return
|
|
2178
|
+
at = min(self.shown, self._flu.shape[0] - 1)
|
|
2179
|
+
z = float(self._z[at]) * self._unit[1]
|
|
2180
|
+
self.fluence_map.set_mark(z)
|
|
2181
|
+
self.spectrum_map.set_mark(z)
|
|
2182
|
+
self.profile.set_data(self._r, [self._flu[at]])
|
|
2183
|
+
session = self.session
|
|
2184
|
+
if self._live or session.path is None or not session.planes:
|
|
2185
|
+
self.across_map.say("Shown when the run has finished.")
|
|
2186
|
+
return
|
|
2187
|
+
session.ask(
|
|
2188
|
+
"beam_plane",
|
|
2189
|
+
{
|
|
2190
|
+
"path": session.path,
|
|
2191
|
+
"index": session.index,
|
|
2192
|
+
"axis": session.options.axis,
|
|
2193
|
+
},
|
|
2194
|
+
self._show_across,
|
|
2195
|
+
key="page-beam-across",
|
|
2196
|
+
failed=self.across_map.say,
|
|
2197
|
+
)
|
|
2198
|
+
|
|
2199
|
+
def _show_across(self, value: Mapping[str, Any]) -> None:
|
|
2200
|
+
"""Draw the plane's spectrum across the beam.
|
|
2201
|
+
|
|
2202
|
+
Parameters
|
|
2203
|
+
----------
|
|
2204
|
+
value : Mapping
|
|
2205
|
+
The kernel's ``beam_plane`` reply.
|
|
2206
|
+
"""
|
|
2207
|
+
axis = str(value["axis"])
|
|
2208
|
+
x = np.asarray(value["x"], float) * _AXIS_SCALE[axis]
|
|
2209
|
+
r = np.asarray(value["r"], float) * 1e6
|
|
2210
|
+
image = np.maximum(np.asarray(value["spectrum"], float), 0.0)
|
|
2211
|
+
reach = self._reach or float(r[-1])
|
|
2212
|
+
y, rows = mirrored_rows(r, image.T, reach)
|
|
2213
|
+
half = y >= 0
|
|
2214
|
+
self.across_map.show_map(
|
|
2215
|
+
decibels(rows[:, half].T),
|
|
2216
|
+
(float(x[0]), 0.0, float(x[-1] - x[0]), reach),
|
|
2217
|
+
(self._spectral_view, (0.0, reach)),
|
|
2218
|
+
(self.session.options.floor, 0.0),
|
|
2219
|
+
)
|
|
2220
|
+
|
|
2221
|
+
def _scale_chosen(self, value: object) -> None:
|
|
2222
|
+
"""Take the fluence's scale.
|
|
2223
|
+
|
|
2224
|
+
Parameters
|
|
2225
|
+
----------
|
|
2226
|
+
value : object
|
|
2227
|
+
``"dB"`` or ``"linear"``.
|
|
2228
|
+
"""
|
|
2229
|
+
self._scale = str(value)
|
|
2230
|
+
unit = "dB" if self._scale == "dB" else "J/cm²"
|
|
2231
|
+
self.fluence_map.bar.axis.setLabel(unit)
|
|
2232
|
+
if self._flu.size:
|
|
2233
|
+
self._show_fluence()
|
|
2234
|
+
|
|
2235
|
+
def _fluence_floor_moved(self, value: int) -> None:
|
|
2236
|
+
"""Move the fluence's floor, at no cost in the data.
|
|
2237
|
+
|
|
2238
|
+
Parameters
|
|
2239
|
+
----------
|
|
2240
|
+
value : int
|
|
2241
|
+
The floor, dB.
|
|
2242
|
+
"""
|
|
2243
|
+
self._fluence_floor = float(value)
|
|
2244
|
+
if self._scale == "dB":
|
|
2245
|
+
self.fluence_map.set_levels((float(value), 0.0))
|
|
2246
|
+
|
|
2247
|
+
def _floor_moved(self, value: int) -> None:
|
|
2248
|
+
"""Move the spectrum's floor, at no cost in the data.
|
|
2249
|
+
|
|
2250
|
+
Parameters
|
|
2251
|
+
----------
|
|
2252
|
+
value : int
|
|
2253
|
+
The floor, dB.
|
|
2254
|
+
"""
|
|
2255
|
+
self.session.options = replace(self.session.options, floor=float(value))
|
|
2256
|
+
self.spectrum_map.set_levels((float(value), 0.0))
|
|
2257
|
+
self.across_map.set_levels((float(value), 0.0))
|
|
2258
|
+
|
|
2259
|
+
def _read_fluence(self, x: float, y: float) -> str:
|
|
2260
|
+
"""Say what is at a point of the fluence map.
|
|
2261
|
+
|
|
2262
|
+
Parameters
|
|
2263
|
+
----------
|
|
2264
|
+
x : float
|
|
2265
|
+
The position along z, in the map's unit.
|
|
2266
|
+
y : float
|
|
2267
|
+
The radius, µm.
|
|
2268
|
+
|
|
2269
|
+
Returns
|
|
2270
|
+
-------
|
|
2271
|
+
str
|
|
2272
|
+
The readout.
|
|
2273
|
+
"""
|
|
2274
|
+
if self._flu.size == 0:
|
|
2275
|
+
return ""
|
|
2276
|
+
z = self._z * self._unit[1]
|
|
2277
|
+
row = int(np.argmin(np.abs(z - x)))
|
|
2278
|
+
at = int(np.argmin(np.abs(self._r - abs(y))))
|
|
2279
|
+
text = f"{x:.3g} {self._unit[0]}, {abs(y):.3g} µm"
|
|
2280
|
+
return f"{text}: {self._flu[row, at]:.3g} J/cm²"
|
|
2281
|
+
|
|
2282
|
+
def data(self) -> tuple[list[str], np.ndarray] | None:
|
|
2283
|
+
"""Return the plane's fluence, as columns.
|
|
2284
|
+
|
|
2285
|
+
Returns
|
|
2286
|
+
-------
|
|
2287
|
+
tuple or None
|
|
2288
|
+
The radius and the fluence, in the columns' units.
|
|
2289
|
+
"""
|
|
2290
|
+
if self._flu.size == 0:
|
|
2291
|
+
return None
|
|
2292
|
+
at = min(self.shown, self._flu.shape[0] - 1)
|
|
2293
|
+
return ["r (um)", "fluence (J/cm2)"], np.column_stack((self._r, self._flu[at]))
|
|
2294
|
+
|
|
2295
|
+
def figure(self) -> dict[str, object] | None:
|
|
2296
|
+
"""Say that solprop's plots do not draw this page.
|
|
2297
|
+
|
|
2298
|
+
Returns
|
|
2299
|
+
-------
|
|
2300
|
+
None
|
|
2301
|
+
No figure: solprop has no plot of a beam's maps.
|
|
2302
|
+
"""
|
|
2303
|
+
return None
|
|
2304
|
+
|
|
2305
|
+
def python(self) -> str | None:
|
|
2306
|
+
"""Return the page's snippet.
|
|
2307
|
+
|
|
2308
|
+
Returns
|
|
2309
|
+
-------
|
|
2310
|
+
str
|
|
2311
|
+
Its key.
|
|
2312
|
+
"""
|
|
2313
|
+
return "beam_overview"
|
|
2314
|
+
|
|
2315
|
+
|
|
2316
|
+
class BeamPlanePage(PageView):
|
|
2317
|
+
"""One plane across the beam: in time, in its spectrum, and its fluence.
|
|
2318
|
+
|
|
2319
|
+
Parameters
|
|
2320
|
+
----------
|
|
2321
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
2322
|
+
The open file.
|
|
2323
|
+
"""
|
|
2324
|
+
|
|
2325
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
2326
|
+
"""Make the maps and the profile."""
|
|
2327
|
+
super().__init__(session)
|
|
2328
|
+
self.in_time = MapPlot(
|
|
2329
|
+
xlabel="Time (fs)", ylabel="r (µm)", colours="inferno", unit="10¹² W/cm²"
|
|
2330
|
+
)
|
|
2331
|
+
self.in_spectrum = MapPlot(
|
|
2332
|
+
xlabel=_AXIS_LABEL["wavelength"],
|
|
2333
|
+
ylabel="r (µm)",
|
|
2334
|
+
colours="viridis",
|
|
2335
|
+
unit="dB",
|
|
2336
|
+
)
|
|
2337
|
+
self.profile = LinePlot(xlabel="r (µm)", ylabel="Fluence (J/cm²)", unit="J/cm²")
|
|
2338
|
+
self._last: Mapping[str, Any] | None = None
|
|
2339
|
+
self._reach = 0.0
|
|
2340
|
+
self._half_time = 0.0
|
|
2341
|
+
grid = QGridLayout(self)
|
|
2342
|
+
grid.setContentsMargins(0, 0, 0, 0)
|
|
2343
|
+
grid.setHorizontalSpacing(14)
|
|
2344
|
+
grid.setVerticalSpacing(10)
|
|
2345
|
+
grid.setRowStretch(0, 3)
|
|
2346
|
+
grid.setRowStretch(1, 2)
|
|
2347
|
+
grid.addLayout(_plotted("Across the beam, in time", self.in_time), 0, 0)
|
|
2348
|
+
grid.addLayout(
|
|
2349
|
+
_plotted("Across the beam, in its spectrum", self.in_spectrum), 0, 1
|
|
2350
|
+
)
|
|
2351
|
+
grid.addLayout(_plotted("Fluence", self.profile), 1, 0, 1, 2)
|
|
2352
|
+
self.axis_choice = Segments("Spectral axis", _AXES, session.options.axis)
|
|
2353
|
+
self.axis_choice.chosen.connect(lambda axis: session.set_options(axis=axis))
|
|
2354
|
+
self.floor = LabelledSlider(
|
|
2355
|
+
"Floor", -80, -10, int(session.options.floor), " dB"
|
|
2356
|
+
)
|
|
2357
|
+
self.floor.moved.connect(
|
|
2358
|
+
lambda value: self.in_spectrum.set_levels((float(value), 0.0))
|
|
2359
|
+
)
|
|
2360
|
+
self.reach = LabelledSlider("Radius shown", 10, 5000, 500, " µm")
|
|
2361
|
+
self.reach.moved.connect(self._reach_moved)
|
|
2362
|
+
self.time_range = LabelledSlider("Time range", 5, 500, 60, " fs")
|
|
2363
|
+
self.time_range.moved.connect(self._window_moved)
|
|
2364
|
+
self.controls = control_panel(
|
|
2365
|
+
self.axis_choice, self.floor, self.reach, self.time_range
|
|
2366
|
+
)
|
|
2367
|
+
|
|
2368
|
+
def refresh(self) -> None:
|
|
2369
|
+
"""Ask for the plane selected."""
|
|
2370
|
+
session = self.session
|
|
2371
|
+
if session.path is None or not session.planes:
|
|
2372
|
+
return
|
|
2373
|
+
session.ask(
|
|
2374
|
+
"beam_plane",
|
|
2375
|
+
{
|
|
2376
|
+
"path": session.path,
|
|
2377
|
+
"index": session.index,
|
|
2378
|
+
"axis": session.options.axis,
|
|
2379
|
+
},
|
|
2380
|
+
self._show,
|
|
2381
|
+
key="page-beam-plane",
|
|
2382
|
+
failed=self.in_time.say,
|
|
2383
|
+
)
|
|
2384
|
+
|
|
2385
|
+
def _show(self, value: Mapping[str, Any]) -> None:
|
|
2386
|
+
"""Draw a plane.
|
|
2387
|
+
|
|
2388
|
+
Parameters
|
|
2389
|
+
----------
|
|
2390
|
+
value : Mapping
|
|
2391
|
+
The kernel's ``beam_plane`` reply.
|
|
2392
|
+
"""
|
|
2393
|
+
self._last = value
|
|
2394
|
+
axis = str(value["axis"])
|
|
2395
|
+
r = np.asarray(value["r"], float) * 1e6
|
|
2396
|
+
t = np.asarray(value["t"], float) * _FS
|
|
2397
|
+
fluence = np.asarray(value["fluence"], float) * 1e-4
|
|
2398
|
+
if self._reach <= 0:
|
|
2399
|
+
self._reach = beam_reach(r, fluence[None, :])
|
|
2400
|
+
self.reach.set_range(10, max(round(float(r[-1])), 11))
|
|
2401
|
+
self.reach.set_value(round(self._reach))
|
|
2402
|
+
intensity = np.maximum(np.asarray(value["intensity"], float), 0.0) * 1e-16
|
|
2403
|
+
if self._half_time <= 0:
|
|
2404
|
+
self._half_time = pulse_window(t, intensity.max(axis=0))
|
|
2405
|
+
self.time_range.set_range(1, max(round(float(np.abs(t).max())), 2))
|
|
2406
|
+
self.time_range.set_value(round(self._half_time))
|
|
2407
|
+
reach = self._reach
|
|
2408
|
+
y, image = mirrored_rows(r, intensity.T, reach)
|
|
2409
|
+
self.in_time.show_map(
|
|
2410
|
+
image.T,
|
|
2411
|
+
(float(t[0]), float(y[0]), float(t[-1] - t[0]), float(y[-1] - y[0])),
|
|
2412
|
+
((-self._half_time, self._half_time), (float(y[0]), float(y[-1]))),
|
|
2413
|
+
(0.0, float(image.max()) or 1.0),
|
|
2414
|
+
)
|
|
2415
|
+
x = np.asarray(value["x"], float) * _AXIS_SCALE[axis]
|
|
2416
|
+
spectrum = np.maximum(np.asarray(value["spectrum"], float), 0.0)
|
|
2417
|
+
y, rows = mirrored_rows(r, spectrum.T, reach)
|
|
2418
|
+
self.in_spectrum.set_xlabel(_AXIS_LABEL[axis])
|
|
2419
|
+
self.in_spectrum.show_map(
|
|
2420
|
+
decibels(rows.T),
|
|
2421
|
+
(float(x[0]), float(y[0]), float(x[-1] - x[0]), float(y[-1] - y[0])),
|
|
2422
|
+
((float(x[0]), float(x[-1])), (float(y[0]), float(y[-1]))),
|
|
2423
|
+
(float(self.floor.slider.value()), 0.0),
|
|
2424
|
+
)
|
|
2425
|
+
self.profile.set_data(r, [fluence])
|
|
2426
|
+
self.profile.set_view((0.0, reach), (0.0, float(fluence.max()) * 1.05 or 1.0))
|
|
2427
|
+
|
|
2428
|
+
def _reach_moved(self, value: int) -> None:
|
|
2429
|
+
"""Show another radius.
|
|
2430
|
+
|
|
2431
|
+
Parameters
|
|
2432
|
+
----------
|
|
2433
|
+
value : int
|
|
2434
|
+
The radius, µm.
|
|
2435
|
+
"""
|
|
2436
|
+
self._reach = float(value)
|
|
2437
|
+
if self._last is not None:
|
|
2438
|
+
self._show(self._last)
|
|
2439
|
+
|
|
2440
|
+
def _window_moved(self, value: int) -> None:
|
|
2441
|
+
"""Show another time range, at no cost in the data.
|
|
2442
|
+
|
|
2443
|
+
Parameters
|
|
2444
|
+
----------
|
|
2445
|
+
value : int
|
|
2446
|
+
The half-width, fs.
|
|
2447
|
+
"""
|
|
2448
|
+
self._half_time = float(value)
|
|
2449
|
+
self.in_time.box.setXRange(-value, value, padding=0)
|
|
2450
|
+
|
|
2451
|
+
def data(self) -> tuple[list[str], np.ndarray] | None:
|
|
2452
|
+
"""Return the plane's fluence, as columns.
|
|
2453
|
+
|
|
2454
|
+
Returns
|
|
2455
|
+
-------
|
|
2456
|
+
tuple or None
|
|
2457
|
+
The radius and the fluence, in the columns' units.
|
|
2458
|
+
"""
|
|
2459
|
+
if self.profile.xs.size == 0:
|
|
2460
|
+
return None
|
|
2461
|
+
return ["r (um)", "fluence (J/cm2)"], np.column_stack(
|
|
2462
|
+
(self.profile.xs, self.profile.ys[0])
|
|
2463
|
+
)
|
|
2464
|
+
|
|
2465
|
+
def python(self) -> str | None:
|
|
2466
|
+
"""Return the page's snippet.
|
|
2467
|
+
|
|
2468
|
+
Returns
|
|
2469
|
+
-------
|
|
2470
|
+
str
|
|
2471
|
+
Its key.
|
|
2472
|
+
"""
|
|
2473
|
+
return "beam_plane"
|
|
2474
|
+
|
|
2475
|
+
|
|
2476
|
+
class OnAxisPage(PageView):
|
|
2477
|
+
"""One plane on the beam's axis: its pulse, its spectrum and its spectrogram.
|
|
2478
|
+
|
|
2479
|
+
Parameters
|
|
2480
|
+
----------
|
|
2481
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
2482
|
+
The open file.
|
|
2483
|
+
"""
|
|
2484
|
+
|
|
2485
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
2486
|
+
"""Make the plots and the gate."""
|
|
2487
|
+
super().__init__(session)
|
|
2488
|
+
self.pulse = LinePlot(xlabel="Time (fs)", ylabel="Intensity", unit="")
|
|
2489
|
+
self.spectrum = LinePlot(
|
|
2490
|
+
xlabel=_AXIS_LABEL["wavelength"], ylabel="dB", unit="dB"
|
|
2491
|
+
)
|
|
2492
|
+
self.map = MapPlot(
|
|
2493
|
+
xlabel="Time (fs)",
|
|
2494
|
+
ylabel=_AXIS_LABEL["wavelength"],
|
|
2495
|
+
colours="viridis",
|
|
2496
|
+
unit="dB",
|
|
2497
|
+
)
|
|
2498
|
+
grid = QGridLayout(self)
|
|
2499
|
+
grid.setContentsMargins(0, 0, 0, 0)
|
|
2500
|
+
grid.setHorizontalSpacing(14)
|
|
2501
|
+
grid.setVerticalSpacing(10)
|
|
2502
|
+
grid.setRowStretch(0, 1)
|
|
2503
|
+
grid.setRowStretch(1, 1)
|
|
2504
|
+
grid.setColumnStretch(0, 1)
|
|
2505
|
+
grid.setColumnStretch(1, 1)
|
|
2506
|
+
grid.addLayout(_plotted("Pulse on the axis", self.pulse), 0, 0)
|
|
2507
|
+
grid.addLayout(_plotted("Spectrum on the axis", self.spectrum), 1, 0)
|
|
2508
|
+
grid.addLayout(_plotted("Spectrogram on the axis", self.map), 0, 1, 2, 1)
|
|
2509
|
+
self.axis_choice = Segments("Spectral axis", _AXES, session.options.axis)
|
|
2510
|
+
self.axis_choice.chosen.connect(lambda axis: session.set_options(axis=axis))
|
|
2511
|
+
self.floor = LabelledSlider(
|
|
2512
|
+
"Floor", -80, -10, int(session.options.floor), " dB"
|
|
2513
|
+
)
|
|
2514
|
+
self.floor.moved.connect(lambda v: self.map.set_levels((float(v), 0.0)))
|
|
2515
|
+
self.gate = LabelledSlider("Gate", 1, 200, 20, " fs")
|
|
2516
|
+
self.gate.moved.connect(
|
|
2517
|
+
lambda v: session.set_options(gate_fwhm=float(v) * 1e-15)
|
|
2518
|
+
)
|
|
2519
|
+
self.controls = control_panel(self.axis_choice, self.floor, self.gate)
|
|
2520
|
+
|
|
2521
|
+
def refresh(self) -> None:
|
|
2522
|
+
"""Ask for the plane selected."""
|
|
2523
|
+
session = self.session
|
|
2524
|
+
if session.path is None or not session.planes:
|
|
2525
|
+
return
|
|
2526
|
+
session.ask(
|
|
2527
|
+
"beam_on_axis",
|
|
2528
|
+
{
|
|
2529
|
+
"path": session.path,
|
|
2530
|
+
"index": session.index,
|
|
2531
|
+
"axis": session.options.axis,
|
|
2532
|
+
"gate_fwhm": session.options.gate_fwhm,
|
|
2533
|
+
"positions": session.options.positions,
|
|
2534
|
+
},
|
|
2535
|
+
self._show,
|
|
2536
|
+
key="page-beam-axis",
|
|
2537
|
+
failed=self.map.say,
|
|
2538
|
+
)
|
|
2539
|
+
|
|
2540
|
+
def _show(self, value: Mapping[str, Any]) -> None:
|
|
2541
|
+
"""Draw a plane on the axis.
|
|
2542
|
+
|
|
2543
|
+
Parameters
|
|
2544
|
+
----------
|
|
2545
|
+
value : Mapping
|
|
2546
|
+
The kernel's ``beam_on_axis`` reply.
|
|
2547
|
+
"""
|
|
2548
|
+
axis = str(value["axis"])
|
|
2549
|
+
t = np.asarray(value["t"], float) * _FS
|
|
2550
|
+
power = np.asarray(value["power"], float)
|
|
2551
|
+
unit, scale = scaled_unit(power, "W/m²")
|
|
2552
|
+
self.pulse.set_ylabel(f"Intensity ({unit})")
|
|
2553
|
+
self.pulse.unit = unit
|
|
2554
|
+
self.pulse.set_data(t, [power * scale])
|
|
2555
|
+
half = pulse_window(t, np.maximum(power, 0.0))
|
|
2556
|
+
self.pulse.set_view(
|
|
2557
|
+
(-half, half), (0.0, float(power.max()) * scale * 1.05 or 1.0)
|
|
2558
|
+
)
|
|
2559
|
+
x = np.asarray(value["x"], float) * _AXIS_SCALE[axis]
|
|
2560
|
+
floor = float(self.floor.slider.value())
|
|
2561
|
+
self.spectrum.set_xlabel(_AXIS_LABEL[axis])
|
|
2562
|
+
self.spectrum.set_data(x, [decibels(np.maximum(value["spectrum"], 0.0))])
|
|
2563
|
+
drawn = value["spectrogram"]
|
|
2564
|
+
map_x = np.asarray(drawn["x"], float) * _AXIS_SCALE[axis]
|
|
2565
|
+
map_t = np.asarray(drawn["t"], float) * _FS
|
|
2566
|
+
self.spectrum.set_view((float(map_x[0]), float(map_x[-1])), (floor, 3.0))
|
|
2567
|
+
self.map.set_ylabel(_AXIS_LABEL[axis])
|
|
2568
|
+
self.map.show_map(
|
|
2569
|
+
decibels(np.asarray(drawn["values"], float)),
|
|
2570
|
+
(
|
|
2571
|
+
float(map_t[0]),
|
|
2572
|
+
float(map_x[0]),
|
|
2573
|
+
float(map_t[-1] - map_t[0]),
|
|
2574
|
+
float(map_x[-1] - map_x[0]),
|
|
2575
|
+
),
|
|
2576
|
+
((-half * 2, half * 2), (float(map_x[0]), float(map_x[-1]))),
|
|
2577
|
+
(floor, 0.0),
|
|
2578
|
+
)
|
|
2579
|
+
self.gate.set_value(round(float(drawn["gate_fwhm"]) * _FS))
|
|
2580
|
+
self.note.setText(f"Gate {float(drawn['gate_fwhm']) * _FS:.3g} fs")
|
|
2581
|
+
|
|
2582
|
+
def python(self) -> str | None:
|
|
2583
|
+
"""Return the page's snippet.
|
|
2584
|
+
|
|
2585
|
+
Returns
|
|
2586
|
+
-------
|
|
2587
|
+
str
|
|
2588
|
+
Its key.
|
|
2589
|
+
"""
|
|
2590
|
+
return "on_axis"
|
|
2591
|
+
|
|
2592
|
+
|
|
2593
|
+
class FarFieldPage(PageView):
|
|
2594
|
+
"""One plane's far field: angle against wavelength, where conical emission shows.
|
|
2595
|
+
|
|
2596
|
+
Parameters
|
|
2597
|
+
----------
|
|
2598
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
2599
|
+
The open file.
|
|
2600
|
+
"""
|
|
2601
|
+
|
|
2602
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
2603
|
+
"""Make the map and its controls."""
|
|
2604
|
+
super().__init__(session)
|
|
2605
|
+
self.map = MapPlot(
|
|
2606
|
+
xlabel=_AXIS_LABEL["wavelength"],
|
|
2607
|
+
ylabel="Angle (mrad)",
|
|
2608
|
+
colours="viridis",
|
|
2609
|
+
unit="dB",
|
|
2610
|
+
)
|
|
2611
|
+
self._angles = np.zeros(0)
|
|
2612
|
+
self._x = np.zeros(0)
|
|
2613
|
+
self._db = np.zeros((0, 0))
|
|
2614
|
+
self.map.reader = self._read
|
|
2615
|
+
column = QVBoxLayout(self)
|
|
2616
|
+
column.setContentsMargins(0, 0, 0, 0)
|
|
2617
|
+
column.setSpacing(6)
|
|
2618
|
+
column.addWidget(self.note)
|
|
2619
|
+
column.addWidget(self.map, 1)
|
|
2620
|
+
self.axis_choice = Segments("Spectral axis", _AXES, session.options.axis)
|
|
2621
|
+
self.axis_choice.chosen.connect(lambda axis: session.set_options(axis=axis))
|
|
2622
|
+
self.floor = LabelledSlider(
|
|
2623
|
+
"Floor", -80, -10, int(session.options.floor), " dB"
|
|
2624
|
+
)
|
|
2625
|
+
self.floor.moved.connect(lambda v: self.map.set_levels((float(v), 0.0)))
|
|
2626
|
+
self.range = LabelledSlider("Angle shown", 1, 500, 50, " mrad")
|
|
2627
|
+
self.range.moved.connect(lambda v: self.map.box.setYRange(0, v, padding=0))
|
|
2628
|
+
self.controls = control_panel(self.axis_choice, self.floor, self.range)
|
|
2629
|
+
self.note.setText("Energy per solid angle, the angle being outside the medium.")
|
|
2630
|
+
|
|
2631
|
+
def refresh(self) -> None:
|
|
2632
|
+
"""Ask for the plane selected's far field."""
|
|
2633
|
+
session = self.session
|
|
2634
|
+
if session.path is None or not session.planes:
|
|
2635
|
+
return
|
|
2636
|
+
session.ask(
|
|
2637
|
+
"beam_far_field",
|
|
2638
|
+
{
|
|
2639
|
+
"path": session.path,
|
|
2640
|
+
"index": session.index,
|
|
2641
|
+
"axis": session.options.axis,
|
|
2642
|
+
},
|
|
2643
|
+
self._show,
|
|
2644
|
+
key="page-beam-far",
|
|
2645
|
+
failed=self.map.say,
|
|
2646
|
+
)
|
|
2647
|
+
|
|
2648
|
+
def _show(self, value: Mapping[str, Any]) -> None:
|
|
2649
|
+
"""Draw a far field.
|
|
2650
|
+
|
|
2651
|
+
Parameters
|
|
2652
|
+
----------
|
|
2653
|
+
value : Mapping
|
|
2654
|
+
The kernel's ``beam_far_field`` reply.
|
|
2655
|
+
"""
|
|
2656
|
+
axis = str(value["axis"])
|
|
2657
|
+
self._angles = np.asarray(value["theta"], float) * 1e3
|
|
2658
|
+
self._x = np.asarray(value["x"], float) * _AXIS_SCALE[axis]
|
|
2659
|
+
self._db = decibels(np.asarray(value["values"], float))
|
|
2660
|
+
x, theta = self._x, self._angles
|
|
2661
|
+
floor = float(self.floor.slider.value())
|
|
2662
|
+
lit = (self._db > floor).any(axis=1)
|
|
2663
|
+
reach = float(theta[lit].max()) * 1.1 if lit.any() else float(theta[-1])
|
|
2664
|
+
reach = min(max(reach, float(theta[1])), float(theta[-1]))
|
|
2665
|
+
self.range.set_range(1, max(round(float(theta[-1])), 2))
|
|
2666
|
+
self.range.set_value(round(reach))
|
|
2667
|
+
self.map.set_xlabel(_AXIS_LABEL[axis])
|
|
2668
|
+
self.map.show_map(
|
|
2669
|
+
self._db,
|
|
2670
|
+
(float(x[0]), 0.0, float(x[-1] - x[0]), float(theta[-1])),
|
|
2671
|
+
((float(x[0]), float(x[-1])), (0.0, reach)),
|
|
2672
|
+
(floor, 0.0),
|
|
2673
|
+
)
|
|
2674
|
+
|
|
2675
|
+
def _read(self, x: float, y: float) -> str:
|
|
2676
|
+
"""Say what is at a point of the map.
|
|
2677
|
+
|
|
2678
|
+
Parameters
|
|
2679
|
+
----------
|
|
2680
|
+
x : float
|
|
2681
|
+
The position on the spectral axis.
|
|
2682
|
+
y : float
|
|
2683
|
+
The angle, mrad.
|
|
2684
|
+
|
|
2685
|
+
Returns
|
|
2686
|
+
-------
|
|
2687
|
+
str
|
|
2688
|
+
The readout.
|
|
2689
|
+
"""
|
|
2690
|
+
if self._db.size == 0:
|
|
2691
|
+
return ""
|
|
2692
|
+
column = int(np.clip(np.searchsorted(self._x, x), 0, self._x.size - 1))
|
|
2693
|
+
row = int(np.clip(np.searchsorted(self._angles, y), 0, self._angles.size - 1))
|
|
2694
|
+
unit = _AXIS_UNIT[self.session.options.axis]
|
|
2695
|
+
return f"{x:.4g} {unit}, {y:.3g} mrad: {self._db[row, column]:.1f} dB"
|
|
2696
|
+
|
|
2697
|
+
def python(self) -> str | None:
|
|
2698
|
+
"""Return the page's snippet.
|
|
2699
|
+
|
|
2700
|
+
Returns
|
|
2701
|
+
-------
|
|
2702
|
+
str
|
|
2703
|
+
Its key.
|
|
2704
|
+
"""
|
|
2705
|
+
return "far_field"
|
|
2706
|
+
|
|
2707
|
+
|
|
2708
|
+
class FluencePage(PageView):
|
|
2709
|
+
"""A Cartesian beam's fluence across x and y at the plane, and through its middle.
|
|
2710
|
+
|
|
2711
|
+
Parameters
|
|
2712
|
+
----------
|
|
2713
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
2714
|
+
The open file.
|
|
2715
|
+
"""
|
|
2716
|
+
|
|
2717
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
2718
|
+
"""Make the map and the two profiles."""
|
|
2719
|
+
super().__init__(session)
|
|
2720
|
+
self.map = MapPlot(
|
|
2721
|
+
xlabel="x (mm)", ylabel="y (mm)", colours="inferno", unit="J/cm²"
|
|
2722
|
+
)
|
|
2723
|
+
# A round beam is drawn round.
|
|
2724
|
+
self.map.box.setAspectLocked(lock=True, ratio=1)
|
|
2725
|
+
self.profiles = LinePlot(
|
|
2726
|
+
xlabel="Position (mm)",
|
|
2727
|
+
ylabel="Fluence (J/cm²)",
|
|
2728
|
+
names=["along x, through y = 0", "along y, through x = 0"],
|
|
2729
|
+
unit="J/cm²",
|
|
2730
|
+
)
|
|
2731
|
+
self._last: Mapping[str, Any] | None = None
|
|
2732
|
+
grid = QGridLayout(self)
|
|
2733
|
+
grid.setContentsMargins(0, 0, 0, 0)
|
|
2734
|
+
grid.setHorizontalSpacing(14)
|
|
2735
|
+
grid.setRowStretch(0, 1)
|
|
2736
|
+
grid.setColumnStretch(0, 1)
|
|
2737
|
+
grid.setColumnStretch(1, 1)
|
|
2738
|
+
grid.addLayout(_plotted("Fluence across the beam", self.map), 0, 0)
|
|
2739
|
+
grid.addLayout(_plotted("Through its middle", self.profiles), 0, 1)
|
|
2740
|
+
|
|
2741
|
+
def refresh(self) -> None:
|
|
2742
|
+
"""Ask for the plane selected."""
|
|
2743
|
+
session = self.session
|
|
2744
|
+
if session.path is None or not session.planes:
|
|
2745
|
+
return
|
|
2746
|
+
session.ask(
|
|
2747
|
+
"beam_fluence",
|
|
2748
|
+
{"path": session.path, "index": session.index},
|
|
2749
|
+
self._show,
|
|
2750
|
+
key="page-beam-fluence",
|
|
2751
|
+
failed=self.map.say,
|
|
2752
|
+
)
|
|
2753
|
+
|
|
2754
|
+
def _show(self, value: Mapping[str, Any]) -> None:
|
|
2755
|
+
"""Draw a plane's fluence.
|
|
2756
|
+
|
|
2757
|
+
Parameters
|
|
2758
|
+
----------
|
|
2759
|
+
value : Mapping
|
|
2760
|
+
The kernel's ``beam_fluence`` reply.
|
|
2761
|
+
"""
|
|
2762
|
+
self._last = value
|
|
2763
|
+
x = np.asarray(value["x"], float) * 1e3
|
|
2764
|
+
y = np.asarray(value["y"], float) * 1e3
|
|
2765
|
+
fluence = np.asarray(value["fluence"], float)
|
|
2766
|
+
unit, scale = scaled_unit(fluence, "J/m²")
|
|
2767
|
+
shown = fluence * scale
|
|
2768
|
+
self.map.set_unit(unit)
|
|
2769
|
+
self.profiles.set_ylabel(f"Fluence ({unit})")
|
|
2770
|
+
self.profiles.unit = unit
|
|
2771
|
+
dx, dy = float(np.diff(x[:2])[0]), float(np.diff(y[:2])[0])
|
|
2772
|
+
self.map.show_map(
|
|
2773
|
+
shown,
|
|
2774
|
+
(float(x[0]) - dx / 2, float(y[0]) - dy / 2, x.size * dx, y.size * dy),
|
|
2775
|
+
((float(x[0]), float(x[-1])), (float(y[0]), float(y[-1]))),
|
|
2776
|
+
(0.0, float(shown.max()) or 1.0),
|
|
2777
|
+
)
|
|
2778
|
+
middle_x = shown[int(np.argmin(np.abs(y))), :]
|
|
2779
|
+
middle_y = shown[:, int(np.argmin(np.abs(x)))]
|
|
2780
|
+
# Two axes on one: x and y are each drawn over their own positions.
|
|
2781
|
+
positions = np.union1d(x, y)
|
|
2782
|
+
self.profiles.set_data(
|
|
2783
|
+
positions,
|
|
2784
|
+
[
|
|
2785
|
+
np.interp(positions, x, middle_x, left=np.nan, right=np.nan),
|
|
2786
|
+
np.interp(positions, y, middle_y, left=np.nan, right=np.nan),
|
|
2787
|
+
],
|
|
2788
|
+
)
|
|
2789
|
+
self.profiles.fit()
|
|
2790
|
+
self.note.setText(
|
|
2791
|
+
f"Energy {si(float(fluence.sum()) * dx * dy * 1e-6, 'J', digits=3)} "
|
|
2792
|
+
f"across the grid at z = {float(value['z']) * 1e3:.4g} mm."
|
|
2793
|
+
)
|
|
2794
|
+
|
|
2795
|
+
def data(self) -> tuple[list[str], np.ndarray] | None:
|
|
2796
|
+
"""Return the plane's fluence, a row per y.
|
|
2797
|
+
|
|
2798
|
+
Returns
|
|
2799
|
+
-------
|
|
2800
|
+
tuple or None
|
|
2801
|
+
``y (mm)`` and a column per x, in J/m²; ``None`` before a plane is read.
|
|
2802
|
+
"""
|
|
2803
|
+
if self._last is None:
|
|
2804
|
+
return None
|
|
2805
|
+
x = np.asarray(self._last["x"], float) * 1e3
|
|
2806
|
+
y = np.asarray(self._last["y"], float) * 1e3
|
|
2807
|
+
fluence = np.asarray(self._last["fluence"], float)
|
|
2808
|
+
names = ["y (mm)"] + [f"x = {value:.4g} mm (J/m²)" for value in x]
|
|
2809
|
+
return names, np.column_stack((y, fluence))
|
|
2810
|
+
|
|
2811
|
+
|
|
2812
|
+
class LineFluencePage(PageView):
|
|
2813
|
+
"""A line beam's fluence across x along z, and at the plane.
|
|
2814
|
+
|
|
2815
|
+
Parameters
|
|
2816
|
+
----------
|
|
2817
|
+
session : solprop_gui.ui.analysis.AnalysisSession
|
|
2818
|
+
The open file.
|
|
2819
|
+
"""
|
|
2820
|
+
|
|
2821
|
+
def __init__(self, session: AnalysisSession) -> None:
|
|
2822
|
+
"""Make the map and the profile."""
|
|
2823
|
+
super().__init__(session)
|
|
2824
|
+
self.map = MapPlot(xlabel="x (mm)", ylabel="z", colours="inferno", unit="J/cm²")
|
|
2825
|
+
self.map.set_along("y")
|
|
2826
|
+
self.map.plane_at.connect(self._picked)
|
|
2827
|
+
self.profile = LinePlot(xlabel="x (mm)", ylabel="Fluence", unit="")
|
|
2828
|
+
self._data: Mapping[str, Any] | None = None
|
|
2829
|
+
self._unit = ("m", 1.0)
|
|
2830
|
+
grid = QGridLayout(self)
|
|
2831
|
+
grid.setContentsMargins(0, 0, 0, 0)
|
|
2832
|
+
grid.setHorizontalSpacing(14)
|
|
2833
|
+
grid.setColumnStretch(0, 1)
|
|
2834
|
+
grid.setColumnStretch(1, 1)
|
|
2835
|
+
grid.addLayout(_plotted("Fluence across the beam, along z", self.map), 0, 0)
|
|
2836
|
+
grid.addLayout(_plotted("At this plane", self.profile), 0, 1)
|
|
2837
|
+
|
|
2838
|
+
def refresh(self) -> None:
|
|
2839
|
+
"""Ask for every plane's fluence, once a file is open; then draw the plane."""
|
|
2840
|
+
session = self.session
|
|
2841
|
+
if session.path is None or not session.planes:
|
|
2842
|
+
return
|
|
2843
|
+
if self._data is not None and self._data.get("path") == session.path:
|
|
2844
|
+
self._draw_plane()
|
|
2845
|
+
return
|
|
2846
|
+
session.ask(
|
|
2847
|
+
"beam_line",
|
|
2848
|
+
{"path": session.path},
|
|
2849
|
+
self._show,
|
|
2850
|
+
key="page-beam-line",
|
|
2851
|
+
failed=self.map.say,
|
|
2852
|
+
)
|
|
2853
|
+
|
|
2854
|
+
def _show(self, value: Mapping[str, Any]) -> None:
|
|
2855
|
+
"""Draw the map, and the plane.
|
|
2856
|
+
|
|
2857
|
+
Parameters
|
|
2858
|
+
----------
|
|
2859
|
+
value : Mapping
|
|
2860
|
+
The kernel's ``beam_line`` reply.
|
|
2861
|
+
"""
|
|
2862
|
+
self._data = {**value, "path": self.session.path}
|
|
2863
|
+
x = np.asarray(value["x"], float) * 1e3
|
|
2864
|
+
z = np.asarray(value["z"], float)
|
|
2865
|
+
fluence = np.asarray(value["fluence"], float)
|
|
2866
|
+
unit, scale = scaled_unit(fluence, "J/m²")
|
|
2867
|
+
name, factor = length_unit(float(z[-1]) or 1.0)
|
|
2868
|
+
self._unit = (name, factor)
|
|
2869
|
+
rows, first, step = even_rows(z)
|
|
2870
|
+
shown = fluence[rows] * scale
|
|
2871
|
+
dx = float(np.diff(x[:2])[0])
|
|
2872
|
+
self.map.set_unit(unit)
|
|
2873
|
+
self.map.set_ylabel(f"z ({name})")
|
|
2874
|
+
self.map.show_map(
|
|
2875
|
+
shown,
|
|
2876
|
+
(
|
|
2877
|
+
float(x[0]) - dx / 2,
|
|
2878
|
+
(first - step / 2) * factor,
|
|
2879
|
+
x.size * dx,
|
|
2880
|
+
step * rows.size * factor,
|
|
2881
|
+
),
|
|
2882
|
+
(
|
|
2883
|
+
(float(x[0]), float(x[-1])),
|
|
2884
|
+
(float(z[0]) * factor, float(z[-1]) * factor),
|
|
2885
|
+
),
|
|
2886
|
+
(0.0, float(shown.max()) or 1.0),
|
|
2887
|
+
)
|
|
2888
|
+
self.profile.set_ylabel(f"Fluence ({unit})")
|
|
2889
|
+
self.profile.unit = unit
|
|
2890
|
+
self._draw_plane()
|
|
2891
|
+
|
|
2892
|
+
def forget(self) -> None:
|
|
2893
|
+
"""Drop what was read, as another file opens."""
|
|
2894
|
+
self._data = None
|
|
2895
|
+
|
|
2896
|
+
def _draw_plane(self) -> None:
|
|
2897
|
+
"""Draw the plane the scrubber is on, and mark it on the map."""
|
|
2898
|
+
if self._data is None:
|
|
2899
|
+
return
|
|
2900
|
+
x = np.asarray(self._data["x"], float) * 1e3
|
|
2901
|
+
z = np.asarray(self._data["z"], float)
|
|
2902
|
+
fluence = np.asarray(self._data["fluence"], float)
|
|
2903
|
+
_unit, scale = scaled_unit(fluence, "J/m²")
|
|
2904
|
+
at = min(self.session.index, fluence.shape[0] - 1)
|
|
2905
|
+
self.map.set_mark(float(z[at]) * self._unit[1])
|
|
2906
|
+
self.profile.set_data(x, [fluence[at] * scale])
|
|
2907
|
+
self.profile.set_view(
|
|
2908
|
+
(float(x[0]), float(x[-1])),
|
|
2909
|
+
(0.0, float(fluence.max()) * scale * 1.05 or 1.0),
|
|
2910
|
+
)
|
|
2911
|
+
self.note.setText(f"{fluence.shape[0]} planes; drawn at z = {z[at]:.4g} m.")
|
|
2912
|
+
|
|
2913
|
+
def _picked(self, value: float) -> None:
|
|
2914
|
+
"""Take a plane picked on the map.
|
|
2915
|
+
|
|
2916
|
+
Parameters
|
|
2917
|
+
----------
|
|
2918
|
+
value : float
|
|
2919
|
+
The position, in the map's unit.
|
|
2920
|
+
"""
|
|
2921
|
+
self.session.move_near(value / self._unit[1])
|
|
2922
|
+
|
|
2923
|
+
def data(self) -> tuple[list[str], np.ndarray] | None:
|
|
2924
|
+
"""Return the fluence at the plane, as columns.
|
|
2925
|
+
|
|
2926
|
+
Returns
|
|
2927
|
+
-------
|
|
2928
|
+
tuple or None
|
|
2929
|
+
``x (mm)`` and the fluence in J/m²; ``None`` before the file is read.
|
|
2930
|
+
"""
|
|
2931
|
+
if self._data is None:
|
|
2932
|
+
return None
|
|
2933
|
+
fluence = np.asarray(self._data["fluence"], float)
|
|
2934
|
+
at = min(self.session.index, fluence.shape[0] - 1)
|
|
2935
|
+
x = np.asarray(self._data["x"], float) * 1e3
|
|
2936
|
+
return ["x (mm)", "fluence (J/m²)"], np.column_stack((x, fluence[at]))
|
|
2937
|
+
|
|
2938
|
+
|
|
2939
|
+
PAGE_VIEWS: dict[str, Callable[[AnalysisSession], PageView]] = {
|
|
2940
|
+
"overview": OverviewPage,
|
|
2941
|
+
"plane": PlanePage,
|
|
2942
|
+
"spectrogram": SpectrogramPage,
|
|
2943
|
+
"along": AlongPage,
|
|
2944
|
+
"modes": ModesPage,
|
|
2945
|
+
"compress": CompressPage,
|
|
2946
|
+
"health": HealthPage,
|
|
2947
|
+
"beam_overview": BeamOverviewPage,
|
|
2948
|
+
"beam_plane": BeamPlanePage,
|
|
2949
|
+
"on_axis": OnAxisPage,
|
|
2950
|
+
"far_field": FarFieldPage,
|
|
2951
|
+
"fluence_xy": FluencePage,
|
|
2952
|
+
"fluence_xz": LineFluencePage,
|
|
2953
|
+
}
|
|
2954
|
+
"""The page each key of a class's rail shows."""
|