thzdaq-api 0.0.6b3__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.
- thzdaq_api/__init__.py +1 -0
- thzdaq_api/analysis.py +62 -0
- thzdaq_api/approvals.py +87 -0
- thzdaq_api/assistant/agents.md +202 -0
- thzdaq_api/assistant/assistant.md +23 -0
- thzdaq_api/assistant/hints.md +15 -0
- thzdaq_api/atomic.py +79 -0
- thzdaq_api/catalog.py +131 -0
- thzdaq_api/console.py +70 -0
- thzdaq_api/custom.py +326 -0
- thzdaq_api/daemon.py +183 -0
- thzdaq_api/data.py +55 -0
- thzdaq_api/declare.py +193 -0
- thzdaq_api/declaring.py +125 -0
- thzdaq_api/devices.py +307 -0
- thzdaq_api/errors.py +47 -0
- thzdaq_api/events.py +224 -0
- thzdaq_api/examples/hot_cold.py +67 -0
- thzdaq_api/examples/hot_cold_grid.py +74 -0
- thzdaq_api/examples/iv_analysis.py +34 -0
- thzdaq_api/examples/map.py +42 -0
- thzdaq_api/examples/monitor.py +35 -0
- thzdaq_api/examples/raw_instrument.py +37 -0
- thzdaq_api/examples/sweep.py +38 -0
- thzdaq_api/examples.py +79 -0
- thzdaq_api/guides.py +61 -0
- thzdaq_api/host.py +494 -0
- thzdaq_api/interpreters.py +422 -0
- thzdaq_api/kernel.py +137 -0
- thzdaq_api/lab.py +562 -0
- thzdaq_api/lanes.py +170 -0
- thzdaq_api/leases.py +29 -0
- thzdaq_api/lock.py +65 -0
- thzdaq_api/measurement_file.py +459 -0
- thzdaq_api/measurements.py +433 -0
- thzdaq_api/operation.py +52 -0
- thzdaq_api/origins.py +86 -0
- thzdaq_api/present.py +376 -0
- thzdaq_api/procedures.py +124 -0
- thzdaq_api/raw.py +272 -0
- thzdaq_api/remote.py +267 -0
- thzdaq_api/rights.py +81 -0
- thzdaq_api/script.py +382 -0
- thzdaq_api/scripts.py +133 -0
- thzdaq_api/sessions.py +176 -0
- thzdaq_api/station.py +192 -0
- thzdaq_api/terminal.py +66 -0
- thzdaq_api/tools.py +275 -0
- thzdaq_api/transport.py +93 -0
- thzdaq_api/ui.py +152 -0
- thzdaq_api/windows.py +192 -0
- thzdaq_api/wire.py +35 -0
- thzdaq_api/workspace.py +239 -0
- thzdaq_api-0.0.6b3.dist-info/METADATA +30 -0
- thzdaq_api-0.0.6b3.dist-info/RECORD +57 -0
- thzdaq_api-0.0.6b3.dist-info/WHEEL +4 -0
- thzdaq_api-0.0.6b3.dist-info/licenses/LICENSE +21 -0
thzdaq_api/present.py
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"""What an agent and the assistant read back: short text, values with their
|
|
2
|
+
units, no arrays (the answers of the tools, thzdaq_api.tools).
|
|
3
|
+
|
|
4
|
+
Values travel in SI (power in dBm); each is shown with the prefix that keeps
|
|
5
|
+
it from 1 to 999 ("2.3 mV"), as the daemon reads it back when it is typed.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Iterable, Mapping, Optional, Sequence, Tuple
|
|
9
|
+
|
|
10
|
+
from thzdaq_api.approvals import UserAnswer
|
|
11
|
+
from thzdaq_api.custom import CustomCheck, CustomLibrary, CustomText
|
|
12
|
+
from thzdaq_api.daemon import DaemonStatus
|
|
13
|
+
from thzdaq_api.devices import (
|
|
14
|
+
ActionInfo,
|
|
15
|
+
ActionResult,
|
|
16
|
+
DeviceDescription,
|
|
17
|
+
DeviceInfo,
|
|
18
|
+
Prefix,
|
|
19
|
+
QuantityInfo,
|
|
20
|
+
RawReply,
|
|
21
|
+
Trace,
|
|
22
|
+
Value,
|
|
23
|
+
shown,
|
|
24
|
+
)
|
|
25
|
+
from thzdaq_api.errors import LabError
|
|
26
|
+
from thzdaq_api.measurement_file import RUNNING
|
|
27
|
+
from thzdaq_api.measurements import (
|
|
28
|
+
ColumnSummary,
|
|
29
|
+
MeasurementSummary,
|
|
30
|
+
ParameterInfo,
|
|
31
|
+
ProcedureInfo,
|
|
32
|
+
ProcedureSummary,
|
|
33
|
+
RunInfo,
|
|
34
|
+
)
|
|
35
|
+
from thzdaq_api.station import ConnectionInfo
|
|
36
|
+
from thzdaq_api.ui import FieldState, FormState, WindowState
|
|
37
|
+
|
|
38
|
+
NOTHING = "none"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def failure(error: LabError) -> str:
|
|
42
|
+
"""A refused or failed call as the model reads it: its code, what went
|
|
43
|
+
wrong and what to do instead (a person's words when they refused)."""
|
|
44
|
+
return f"{error.code.value}: {error}"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def lines(found: Iterable[str]) -> str:
|
|
48
|
+
return "\n".join(found) or NOTHING
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def devices(found: Sequence[DeviceInfo]) -> str:
|
|
52
|
+
return lines(
|
|
53
|
+
f"{d.ref}: {d.title} ({d.type} on {d.instrument}; {', '.join(d.capabilities)})"
|
|
54
|
+
for d in found
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def span(
|
|
59
|
+
low: Optional[float],
|
|
60
|
+
high: Optional[float],
|
|
61
|
+
unit: str,
|
|
62
|
+
prefixes: Sequence[Prefix],
|
|
63
|
+
) -> str:
|
|
64
|
+
""" "-30 mV..30 mV"; empty when neither end is known."""
|
|
65
|
+
if low is None and high is None:
|
|
66
|
+
return ""
|
|
67
|
+
return f"{shown(low, unit, prefixes)}..{shown(high, unit, prefixes)}"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def quantity(q: QuantityInfo) -> str:
|
|
71
|
+
def value(found: Optional[float]) -> str:
|
|
72
|
+
return shown(found, q.unit, q.prefixes)
|
|
73
|
+
|
|
74
|
+
text = f"{q.key}: {q.label}"
|
|
75
|
+
if q.kind != "float":
|
|
76
|
+
text += f" ({q.kind}{': ' + ', '.join(q.choices) if q.choices else ''})"
|
|
77
|
+
if not q.settable:
|
|
78
|
+
return text + "; read only"
|
|
79
|
+
text += "; settable"
|
|
80
|
+
taken = span(q.minimum, q.maximum, q.unit, q.prefixes)
|
|
81
|
+
if taken:
|
|
82
|
+
text += f" {taken}"
|
|
83
|
+
usual = span(q.warn_minimum, q.warn_maximum, q.unit, q.prefixes)
|
|
84
|
+
if usual:
|
|
85
|
+
text += f", a person is asked beyond {usual}"
|
|
86
|
+
if q.step is not None:
|
|
87
|
+
rate = f" at {value(q.rate)}/s" if q.rate is not None else ""
|
|
88
|
+
text += f", in steps of {value(q.step)}{rate}"
|
|
89
|
+
if q.danger:
|
|
90
|
+
text += f"; DANGER: {q.danger}"
|
|
91
|
+
return text
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def action(a: ActionInfo) -> str:
|
|
95
|
+
arguments = ", ".join(
|
|
96
|
+
f"{arg.key}{': ' + arg.unit if arg.unit else ''}"
|
|
97
|
+
+ (
|
|
98
|
+
""
|
|
99
|
+
if arg.default is None
|
|
100
|
+
else f" = {shown(arg.default, arg.unit, arg.prefixes)}"
|
|
101
|
+
)
|
|
102
|
+
for arg in a.arguments
|
|
103
|
+
)
|
|
104
|
+
text = f"{a.key}({arguments}): {a.title}"
|
|
105
|
+
if a.help:
|
|
106
|
+
text += f". {a.help}"
|
|
107
|
+
if not a.changes:
|
|
108
|
+
text += " (a read)"
|
|
109
|
+
if a.danger:
|
|
110
|
+
text += f"; DANGER: {a.danger}"
|
|
111
|
+
return text
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def description(d: DeviceDescription) -> str:
|
|
115
|
+
device = d.device
|
|
116
|
+
parts = [
|
|
117
|
+
f"{device.ref}: {device.title} ({device.type} on {device.instrument})",
|
|
118
|
+
"quantities (key: title, unit):",
|
|
119
|
+
*(f" {quantity(q)}" for q in d.quantities),
|
|
120
|
+
]
|
|
121
|
+
if d.actions:
|
|
122
|
+
parts += ["actions (call_action):", *(f" {action(a)}" for a in d.actions)]
|
|
123
|
+
if d.settings:
|
|
124
|
+
parts += ["settings in the profile:", *(f" {quantity(q)}" for q in d.settings)]
|
|
125
|
+
return "\n".join(parts)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def values(ref: str, found: Mapping[str, Value], description: DeviceDescription) -> str:
|
|
129
|
+
known = {q.key: q for q in description.quantities}
|
|
130
|
+
|
|
131
|
+
def value(key: str, given: Value) -> str:
|
|
132
|
+
q = known.get(key)
|
|
133
|
+
return shown(given, q.unit, q.prefixes) if q else shown(given)
|
|
134
|
+
|
|
135
|
+
return f"{ref}: " + ", ".join(f"{k} = {value(k, v)}" for k, v in found.items())
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def trace(found: Trace) -> str:
|
|
139
|
+
"""A trace by its ends and its peak: the agent reads the file for more."""
|
|
140
|
+
points = len(found.frequency)
|
|
141
|
+
if not points:
|
|
142
|
+
return "an empty trace"
|
|
143
|
+
peak = max(range(points), key=lambda i: found.values[i])
|
|
144
|
+
label = found.label()
|
|
145
|
+
return (
|
|
146
|
+
f"{found.parameter + ' ' if found.parameter else ''}trace of {points} points, "
|
|
147
|
+
f"{shown(found.frequency[0], 'Hz')}..{shown(found.frequency[-1], 'Hz')}; "
|
|
148
|
+
f"{label} from {min(found.values):.4g} to {found.values[peak]:.4g}, "
|
|
149
|
+
f"peak at {shown(found.frequency[peak], 'Hz')}"
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def action_result(done: ActionResult) -> str:
|
|
154
|
+
result = done.result
|
|
155
|
+
told = trace(result) if isinstance(result, Trace) else shown(result)
|
|
156
|
+
return f"{done.ref} {done.action}: {told}"
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def raw(reply: RawReply) -> str:
|
|
160
|
+
if reply.answer is not None:
|
|
161
|
+
return f"{reply.instrument} {reply.command}: {reply.answer}"
|
|
162
|
+
return f"{reply.instrument} {reply.command}: sent; read again"
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def connections(found: Sequence[ConnectionInfo]) -> str:
|
|
166
|
+
def state(c: ConnectionInfo) -> str:
|
|
167
|
+
return "broken" if c.broken else "open" if c.open else "closed"
|
|
168
|
+
|
|
169
|
+
return lines(
|
|
170
|
+
f"{c.label}: {state(c)}, for {', '.join(c.instruments)}" for c in found
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def last_line(error: str) -> str:
|
|
175
|
+
"""An error with its traceback, in a line: its last."""
|
|
176
|
+
told = error.strip().splitlines()
|
|
177
|
+
return told[-1] if told else error
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def procedures(found: Sequence[ProcedureSummary]) -> str:
|
|
181
|
+
return lines(
|
|
182
|
+
f"{p.name}: {p.title}. {p.description}"
|
|
183
|
+
+ (f" Not described: {last_line(p.error)}" if p.error else "")
|
|
184
|
+
for p in found
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def library(found: CustomLibrary) -> str:
|
|
189
|
+
"""The bench's own measurements: run each as its procedure."""
|
|
190
|
+
head = f"library {found.folder}:"
|
|
191
|
+
if not found.measurements:
|
|
192
|
+
return f"{head} no measurement of its own yet; write_custom adds one"
|
|
193
|
+
return "\n".join(
|
|
194
|
+
[head]
|
|
195
|
+
+ [
|
|
196
|
+
f" {m.name}: {m.procedure}, {m.title}"
|
|
197
|
+
+ (f"; not described: {last_line(m.error)}" if m.error else "")
|
|
198
|
+
for m in found.measurements
|
|
199
|
+
]
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def custom_text(found: CustomText) -> str:
|
|
204
|
+
return f"{found.info.path} ({found.info.procedure}):\n{found.text}"
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def check(found: CustomCheck) -> str:
|
|
208
|
+
"""Its problems by line, then the form it describes."""
|
|
209
|
+
parts = [
|
|
210
|
+
f"line {p.line} ({p.kind}): {p.text}" if p.line else f"({p.kind}) {p.text}"
|
|
211
|
+
for p in found.problems
|
|
212
|
+
] or ["no problems found"]
|
|
213
|
+
info = found.procedure
|
|
214
|
+
if info is not None:
|
|
215
|
+
parts += [f"{info.name}: {info.title}", "parameters:"]
|
|
216
|
+
parts += [f" {parameter(p)}" for p in info.parameters] or [" none"]
|
|
217
|
+
slots = ", ".join(f"{s.name} ({s.title})" for s in info.slots)
|
|
218
|
+
parts.append(f"slots: {slots or NOTHING}")
|
|
219
|
+
return "\n".join(parts)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def parameter(p: ParameterInfo) -> str:
|
|
223
|
+
unit = p.display_unit or p.unit
|
|
224
|
+
text = f"{p.name}: {p.label}, {p.kind}{', ' + unit if unit else ''}"
|
|
225
|
+
if p.required:
|
|
226
|
+
text += ", required"
|
|
227
|
+
elif p.default is not None:
|
|
228
|
+
text += f"; default {p.typed(p.default)}"
|
|
229
|
+
if p.minimum is not None or p.maximum is not None:
|
|
230
|
+
text += f"; {p.typed(p.minimum)}..{p.typed(p.maximum)}"
|
|
231
|
+
if p.choices:
|
|
232
|
+
text += f"; one of {', '.join(str(c) for c in p.choices)}"
|
|
233
|
+
if p.max_points:
|
|
234
|
+
text += f"; at most {p.max_points} points"
|
|
235
|
+
if p.shown_if:
|
|
236
|
+
text += f"; used only when {p.used_when()}"
|
|
237
|
+
if p.help:
|
|
238
|
+
text += f". {p.help}"
|
|
239
|
+
return text
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def procedure(info: ProcedureInfo, bench: Sequence[DeviceInfo]) -> str:
|
|
243
|
+
steps = f"{info.steps} steps" if info.steps else "no end of its own: cancel it"
|
|
244
|
+
parts = [
|
|
245
|
+
f"{info.title} ({info.name}): {steps}",
|
|
246
|
+
info.description,
|
|
247
|
+
"parameters (pass them in typed, in the units shown; a sweep "
|
|
248
|
+
"start:stop:points, a list comma separated):",
|
|
249
|
+
*(f" {parameter(p)}" for p in info.parameters),
|
|
250
|
+
"devices (slot: the devices that suit it):",
|
|
251
|
+
*(
|
|
252
|
+
f" {s.name}: {', '.join(d.ref for d in s.candidates(bench)) or NOTHING}"
|
|
253
|
+
for s in info.slots
|
|
254
|
+
),
|
|
255
|
+
]
|
|
256
|
+
if info.plots:
|
|
257
|
+
parts.append(f"plots: {', '.join(p.title for p in info.plots)}")
|
|
258
|
+
if info.guide:
|
|
259
|
+
parts.append(f"how to measure: {info.guide}")
|
|
260
|
+
return "\n".join(parts)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def run(found: RunInfo) -> str:
|
|
264
|
+
done = f"{found.done}/{found.total}" if found.total else f"{found.done}"
|
|
265
|
+
used = ", ".join(f"{slot}={ref}" for slot, ref in found.devices.items())
|
|
266
|
+
parts = [
|
|
267
|
+
f"#{found.id} {found.title} ({found.procedure}): {found.status}, "
|
|
268
|
+
f"{done} steps; {used}; by {found.origin}"
|
|
269
|
+
]
|
|
270
|
+
if found.error:
|
|
271
|
+
parts.append(f"error: {found.error}")
|
|
272
|
+
if found.path:
|
|
273
|
+
parts.append(f"file: {found.path}")
|
|
274
|
+
if found.status == RUNNING and found.id:
|
|
275
|
+
parts.append(f"still running: wait_measurement(id={found.id}) again")
|
|
276
|
+
return "\n".join(parts)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def runs(found: Sequence[RunInfo]) -> str:
|
|
280
|
+
return lines(run(r).splitlines()[0] for r in found)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def column(c: ColumnSummary) -> str:
|
|
284
|
+
told = span(c.minimum, c.maximum, c.unit, c.prefixes)
|
|
285
|
+
return f"{c.key} ({c.label}) {told}".rstrip() if told else f"{c.key} ({c.label})"
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def summary(found: MeasurementSummary) -> str:
|
|
289
|
+
parts = [run(found.run)]
|
|
290
|
+
for table in found.tables:
|
|
291
|
+
parts.append(f"table {table.name} ({table.title or table.name}): "
|
|
292
|
+
f"{table.records} records") # fmt: skip
|
|
293
|
+
parts += [f" {column(c)}" for c in table.columns]
|
|
294
|
+
if found.results:
|
|
295
|
+
parts.append(
|
|
296
|
+
"results: "
|
|
297
|
+
+ ", ".join(f"{k} = {shown(v)}" for k, v in found.results.items())
|
|
298
|
+
)
|
|
299
|
+
if found.series:
|
|
300
|
+
parts.append(
|
|
301
|
+
"in the file: "
|
|
302
|
+
+ ", ".join(f"{k} ({n} values)" for k, n in found.series.items())
|
|
303
|
+
)
|
|
304
|
+
return "\n".join(parts)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def answer(found: UserAnswer) -> str:
|
|
308
|
+
if found.pending or found.answer is None:
|
|
309
|
+
return f"question #{found.id} still waits: wait_answer(id={found.id})"
|
|
310
|
+
given = found.answer
|
|
311
|
+
parts: Tuple[str, ...] = (
|
|
312
|
+
f"answered by {given.by}" if given.allowed else f"declined by {given.by}",
|
|
313
|
+
f"choice: {given.choice}" if given.choice else "",
|
|
314
|
+
f"words: {given.text}" if given.text else "",
|
|
315
|
+
)
|
|
316
|
+
return "; ".join(p for p in parts if p)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def status(found: DaemonStatus) -> str:
|
|
320
|
+
process = found.process
|
|
321
|
+
parts = [
|
|
322
|
+
f"daemon {process.app_version} (pid {process.pid}"
|
|
323
|
+
f"{', simulators' if process.simulate else ''}), profile {found.station}"
|
|
324
|
+
+ (f" ({found.path})" if found.path else ""),
|
|
325
|
+
"open: " + (", ".join(found.opened) or NOTHING),
|
|
326
|
+
"clients: " + (", ".join(c.origin for c in found.clients) or NOTHING),
|
|
327
|
+
"running: " + (runs(found.runs) if found.runs else NOTHING),
|
|
328
|
+
]
|
|
329
|
+
if found.problems:
|
|
330
|
+
parts.append("problems: " + "; ".join(found.problems))
|
|
331
|
+
return "\n".join(parts)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def window(found: WindowState) -> str:
|
|
335
|
+
"""A window by the names ui_open and ui_highlight take."""
|
|
336
|
+
others = [w for w in found.windows if w != found.window]
|
|
337
|
+
parts = [
|
|
338
|
+
f"window {found.window}: {found.title}"
|
|
339
|
+
+ (f" (other windows: {', '.join(others)})" if others else ""),
|
|
340
|
+
"docks (name: title, front/behind/closed):",
|
|
341
|
+
*(f" {d.name}: {d.title}, {d.state}" for d in found.docks),
|
|
342
|
+
"bar on top: "
|
|
343
|
+
+ ", ".join(
|
|
344
|
+
f"{c.name} {c.title}" + ("" if c.enabled else " (disabled)")
|
|
345
|
+
for c in found.controls
|
|
346
|
+
),
|
|
347
|
+
form(found.measurement) if found.measurement else "measurement: none chosen",
|
|
348
|
+
"running: " + (", ".join(found.running) or NOTHING),
|
|
349
|
+
]
|
|
350
|
+
return "\n".join(parts)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def form(found: FormState) -> str:
|
|
354
|
+
"""The measurement chosen in the bar on top and its fields."""
|
|
355
|
+
state = ["form open" if found.open else "form closed"]
|
|
356
|
+
state += [f"{section} folded" for section in found.folded]
|
|
357
|
+
state += ["running"] if found.running else []
|
|
358
|
+
parts = [f"measurement {found.procedure}: {found.title} ({', '.join(state)})"]
|
|
359
|
+
parts += [f" {field(f)}" for f in found.fields] or [" no fields"]
|
|
360
|
+
return "\n".join(parts)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def field(found: FieldState) -> str:
|
|
364
|
+
value = f"{found.value} {found.unit}".strip() or "--"
|
|
365
|
+
text = f"{found.name} ({found.kind} {found.label}): {value}"
|
|
366
|
+
if found.choices:
|
|
367
|
+
text += f" [{', '.join(found.choices)}]"
|
|
368
|
+
return text if found.used else f"{text}; not used with these values"
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def opened(place: str) -> str:
|
|
372
|
+
return f"{place} is shown in the window"
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def highlighted(anchor: str) -> str:
|
|
376
|
+
return f"{anchor} is highlighted; it goes when the person acts there"
|
thzdaq_api/procedures.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""Names of the built-in procedures: clients start a procedure by its name, and the
|
|
2
|
+
core's procedure classes take their names from here.
|
|
3
|
+
|
|
4
|
+
A name is "<group>.<procedure>"; the group sorts procedures in menus. The
|
|
5
|
+
monitor's rules of what is watched and where it is drawn are here too: the
|
|
6
|
+
monitor applies them, and a client choosing what to watch or plotting what a
|
|
7
|
+
device dock reads applies the same ones.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from typing import Any, Iterable, List, Optional, Tuple
|
|
11
|
+
|
|
12
|
+
SIS = "sis"
|
|
13
|
+
IF = "if"
|
|
14
|
+
TWO_SB = "two_sb"
|
|
15
|
+
MONITOR = "monitor"
|
|
16
|
+
|
|
17
|
+
# "<group>.<what is measured>_vs_<what is changed>"
|
|
18
|
+
CURRENT_VS_VOLTAGE = f"{SIS}.current_vs_voltage"
|
|
19
|
+
POWER_VS_VOLTAGE = f"{SIS}.power_vs_voltage"
|
|
20
|
+
NOISE_TEMPERATURE_VS_VOLTAGE = f"{SIS}.noise_temperature_vs_voltage"
|
|
21
|
+
CURRENT_VS_COIL_CURRENT = f"{SIS}.current_vs_coil_current"
|
|
22
|
+
DEMAGNETIZATION = f"{SIS}.demagnetization"
|
|
23
|
+
REFLECTION_VS_FREQUENCY = f"{SIS}.reflection_vs_frequency"
|
|
24
|
+
CURRENT_VS_GRID_ANGLE = f"{SIS}.current_vs_grid_angle"
|
|
25
|
+
AMPLIFIER_NOISE_VS_VOLTAGE = f"{IF}.amplifier_noise_vs_voltage"
|
|
26
|
+
NOISE_TEMPERATURE_VS_FREQUENCY = f"{IF}.noise_temperature_vs_frequency"
|
|
27
|
+
POWER_VS_FREQUENCY = f"{IF}.power_vs_frequency"
|
|
28
|
+
TWO_SB_IF_BALANCE = f"{TWO_SB}.if_balance"
|
|
29
|
+
TWO_SB_LO_RF_BALANCE = f"{TWO_SB}.lo_rf_balance"
|
|
30
|
+
TWO_SB_SIDEBAND_RATIO = f"{TWO_SB}.sideband_ratio"
|
|
31
|
+
TWO_SB_NOISE_TEMPERATURE = f"{TWO_SB}.noise_temperature"
|
|
32
|
+
TWO_SB_BIAS_OPTIMIZATION = f"{TWO_SB}.bias_optimization"
|
|
33
|
+
MONITOR_VALUES_VS_TIME = f"{MONITOR}.values_vs_time"
|
|
34
|
+
|
|
35
|
+
# Names procedures had before (old -> current): files measured then, saved
|
|
36
|
+
# forms, commands and scripts that still use them
|
|
37
|
+
RENAMED = {
|
|
38
|
+
f"{SIS}.iv_curve": CURRENT_VS_VOLTAGE,
|
|
39
|
+
f"{SIS}.pv_curve": POWER_VS_VOLTAGE,
|
|
40
|
+
f"{SIS}.y_factor_voltage": NOISE_TEMPERATURE_VS_VOLTAGE,
|
|
41
|
+
f"{SIS}.cl_curve": CURRENT_VS_COIL_CURRENT,
|
|
42
|
+
f"{SIS}.demagnetize": DEMAGNETIZATION,
|
|
43
|
+
f"{SIS}.reflection": REFLECTION_VS_FREQUENCY,
|
|
44
|
+
f"{SIS}.shot_noise": AMPLIFIER_NOISE_VS_VOLTAGE,
|
|
45
|
+
f"{IF}.hot_cold": NOISE_TEMPERATURE_VS_FREQUENCY,
|
|
46
|
+
f"{TWO_SB}.pump_balance": TWO_SB_LO_RF_BALANCE,
|
|
47
|
+
f"{TWO_SB}.srr": TWO_SB_SIDEBAND_RATIO,
|
|
48
|
+
f"{TWO_SB}.tn": TWO_SB_NOISE_TEMPERATURE,
|
|
49
|
+
f"{TWO_SB}.optimization": TWO_SB_BIAS_OPTIMIZATION,
|
|
50
|
+
"grid.current_angle": CURRENT_VS_GRID_ANGLE,
|
|
51
|
+
"grid.current_vs_angle": CURRENT_VS_GRID_ANGLE,
|
|
52
|
+
f"{MONITOR}.time": MONITOR_VALUES_VS_TIME,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def current_name(name: str) -> str:
|
|
57
|
+
"""The name a procedure has now: sis.iv_curve -> sis.current_vs_voltage;
|
|
58
|
+
a current or unknown name stays as it is."""
|
|
59
|
+
return RENAMED.get(name, name)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def former_names(name: str) -> List[str]:
|
|
63
|
+
"""The names the procedure had before: sis.current_vs_voltage -> [sis.iv_curve]."""
|
|
64
|
+
return [old for old, new in RENAMED.items() if new == name]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def group_of(name: str) -> str:
|
|
68
|
+
"""sis.current_vs_voltage -> sis"""
|
|
69
|
+
return name.split(".", 1)[0]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# What the monitor watches: "<ref>" or "<ref>/<quantity key>"; a column's source too
|
|
73
|
+
KEY_SEPARATOR = "/"
|
|
74
|
+
|
|
75
|
+
# The time graph of each unit
|
|
76
|
+
UNIT_PLOTS = {
|
|
77
|
+
"dBm": "P-t",
|
|
78
|
+
"K": "T-t",
|
|
79
|
+
"V": "V-t",
|
|
80
|
+
"A": "I-t",
|
|
81
|
+
"Pa": "p-t",
|
|
82
|
+
"Hz": "f-t",
|
|
83
|
+
}
|
|
84
|
+
COIL_PLOT = "Coil-t" # mA of a coil, not the µA of a SIS on I-t
|
|
85
|
+
OTHER_PLOT = "Value-t"
|
|
86
|
+
COIL_KEYS = ("current_set", "coil_current")
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def split_entry(entry: str) -> Tuple[str, Optional[str]]:
|
|
90
|
+
""" "sis_bias_1/voltage" -> ("sis_bias_1", "voltage"); "power_meter_1" -> (ref, None)."""
|
|
91
|
+
ref, _, key = entry.partition(KEY_SEPARATOR)
|
|
92
|
+
return ref, key or None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def entry(ref: str, key: str) -> str:
|
|
96
|
+
"""("sis_bias_1", "voltage") -> "sis_bias_1/voltage": a quantity of a device
|
|
97
|
+
in one text, as the monitor watches it and a column names its source."""
|
|
98
|
+
return f"{ref}{KEY_SEPARATOR}{key}"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# The rules take quantities as described (instruments' Quantity, or QuantityInfo)
|
|
102
|
+
def monitor_quantities(quantities: Iterable[Any]) -> List[Any]:
|
|
103
|
+
"""Quantities worth watching: numeric readings, not configuration."""
|
|
104
|
+
return [
|
|
105
|
+
q
|
|
106
|
+
for q in quantities
|
|
107
|
+
if q.readable and q.kind in ("float", "int") and not q.persistent
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def default_quantities(quantities: Iterable[Any]) -> List[Any]:
|
|
112
|
+
"""Read when a device is watched without a choice: measured values with a
|
|
113
|
+
unit, or the readable setpoints when nothing is measured (a SIS coil
|
|
114
|
+
current). A value without a unit (the NRX reading in its display unit) can
|
|
115
|
+
be chosen by hand."""
|
|
116
|
+
candidates = [q for q in monitor_quantities(quantities) if q.unit]
|
|
117
|
+
return [q for q in candidates if not q.settable] or candidates
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def plot_for(quantity: Any) -> str:
|
|
121
|
+
"""The time graph of a quantity, by its unit."""
|
|
122
|
+
if quantity.unit == "A" and quantity.key in COIL_KEYS:
|
|
123
|
+
return COIL_PLOT
|
|
124
|
+
return UNIT_PLOTS.get(quantity.unit, OTHER_PLOT)
|