pytdo 0.2.2.2__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.
- pytdo/__init__.py +46 -0
- pytdo/__main__.py +15 -0
- pytdo/assets/config_default.toml +81 -0
- pytdo/config/__init__.py +6 -0
- pytdo/config/_config.py +26 -0
- pytdo/config/_types.py +16 -0
- pytdo/config/models.py +63 -0
- pytdo/gui/__init__.py +20 -0
- pytdo/gui/_core.py +509 -0
- pytdo/gui/_workers.py +86 -0
- pytdo/gui/widgets/__init__.py +8 -0
- pytdo/gui/widgets/_configuration_tab.py +20 -0
- pytdo/gui/widgets/_graphs.py +241 -0
- pytdo/gui/widgets/_main_buttons.py +72 -0
- pytdo/gui/widgets/_param_content.py +120 -0
- pytdo/processors/__init__.py +5 -0
- pytdo/processors/_tdo.py +997 -0
- pytdo/processors/_types.py +22 -0
- pytdo/py.typed +0 -0
- pytdo/sp.py +267 -0
- pytdo-0.2.2.2.dist-info/METADATA +101 -0
- pytdo-0.2.2.2.dist-info/RECORD +24 -0
- pytdo-0.2.2.2.dist-info/WHEEL +4 -0
- pytdo-0.2.2.2.dist-info/entry_points.txt +3 -0
pytdo/gui/_core.py
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
"""Application for TDO analysis."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from PyQt6 import QtWidgets
|
|
6
|
+
from PyQt6.QtCore import pyqtSignal, pyqtSlot
|
|
7
|
+
from pyuson import gui
|
|
8
|
+
|
|
9
|
+
from . import widgets
|
|
10
|
+
from ._workers import DataWorker
|
|
11
|
+
|
|
12
|
+
ICON_PATH = str(Path(__file__).parent / "assets" / "icon.png")
|
|
13
|
+
REGEXP_EXPID_SEPARATORS = r"[_-]"
|
|
14
|
+
PROGRAM_NAME = "pytdo" # to get the relevant logger
|
|
15
|
+
OUT_FORMAT = (".txt", ".csv", ".tsv", ".out")
|
|
16
|
+
LOG_LEVEL = "INFO"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class MainWindow(gui.BaseMainWindow):
|
|
20
|
+
sig_worker_extract = pyqtSignal()
|
|
21
|
+
sig_worker_removebg = pyqtSignal()
|
|
22
|
+
sig_worker_fft = pyqtSignal()
|
|
23
|
+
sig_worker_tdocsv = pyqtSignal(str)
|
|
24
|
+
sig_worker_rescsv = pyqtSignal(str)
|
|
25
|
+
sig_worker_loadcsv = pyqtSignal(str)
|
|
26
|
+
|
|
27
|
+
wbatch: gui.widgets.BatchProcessingWidget
|
|
28
|
+
wbuttons: widgets.MainButtonsWidget
|
|
29
|
+
wconfiguration: widgets.ConfigurationWidget
|
|
30
|
+
wfiles: gui.widgets.FileBrowserWidget
|
|
31
|
+
wplots: widgets.GraphsWidget
|
|
32
|
+
worker: DataWorker
|
|
33
|
+
|
|
34
|
+
def __init__(self):
|
|
35
|
+
# Register the widgets
|
|
36
|
+
self._type_wbatch = gui.widgets.BatchProcessingWidget
|
|
37
|
+
self._type_wbuttons = widgets.MainButtonsWidget
|
|
38
|
+
self._type_wconfiguration = widgets.ConfigurationWidget
|
|
39
|
+
self._type_wfiles = gui.widgets.FileBrowserWidget
|
|
40
|
+
self._type_wplots = widgets.GraphsWidget
|
|
41
|
+
self._param_content = widgets.ParamContent
|
|
42
|
+
self._type_worker = DataWorker
|
|
43
|
+
|
|
44
|
+
super().__init__()
|
|
45
|
+
|
|
46
|
+
# Initialize window
|
|
47
|
+
self.setGeometry(300, 300, 900, 450)
|
|
48
|
+
self.setWindowTitle("TDO Analyzer")
|
|
49
|
+
|
|
50
|
+
def init_parameter_tree(self):
|
|
51
|
+
super().init_parameter_tree()
|
|
52
|
+
|
|
53
|
+
# Connect
|
|
54
|
+
self.wconfiguration.sig_syncroi_changed.connect(self.syncroi_changed)
|
|
55
|
+
|
|
56
|
+
def init_buttons(self):
|
|
57
|
+
super().init_buttons()
|
|
58
|
+
|
|
59
|
+
# Connect
|
|
60
|
+
self.wbuttons.sig_extract.connect(self.extract_tdo)
|
|
61
|
+
self.wbuttons.sig_removebg.connect(self.remove_background)
|
|
62
|
+
self.wbuttons.sig_fft.connect(self.fft)
|
|
63
|
+
self.wbuttons.sig_tdocsv.connect(self.save_tdo_csv)
|
|
64
|
+
self.wbuttons.sig_rescsv.connect(self.save_results_csv)
|
|
65
|
+
|
|
66
|
+
def init_plots(self):
|
|
67
|
+
super().init_plots()
|
|
68
|
+
|
|
69
|
+
# Connect ROIs
|
|
70
|
+
self.wplots.sig_roi1_changed.connect(self.roi1_changed)
|
|
71
|
+
self.wplots.sig_roi2_changed.connect(self.roi2_changed)
|
|
72
|
+
self.wconfiguration.settings_parameters.child(
|
|
73
|
+
"poly_window"
|
|
74
|
+
).sigValueChanged.connect(self.update_roi_from_poly)
|
|
75
|
+
self.wconfiguration.settings_parameters.child(
|
|
76
|
+
"fft_window"
|
|
77
|
+
).sigValueChanged.connect(self.update_roi_from_fft)
|
|
78
|
+
|
|
79
|
+
def init_log(self):
|
|
80
|
+
super().init_log(PROGRAM_NAME, log_level=LOG_LEVEL)
|
|
81
|
+
|
|
82
|
+
def connect_worker(self):
|
|
83
|
+
super().connect_worker()
|
|
84
|
+
|
|
85
|
+
# Extract signal
|
|
86
|
+
self.sig_worker_extract.connect(self.worker.extract_tdo)
|
|
87
|
+
self.worker.sig_extract_finished.connect(self.extract_tdo_finished)
|
|
88
|
+
|
|
89
|
+
# Remove background
|
|
90
|
+
self.sig_worker_removebg.connect(self.worker.remove_background)
|
|
91
|
+
self.worker.sig_removebg_finished.connect(self.remove_background_finished)
|
|
92
|
+
|
|
93
|
+
# FFT
|
|
94
|
+
self.sig_worker_fft.connect(self.worker.fft)
|
|
95
|
+
self.worker.sig_fft_finished.connect(self.fft_finished)
|
|
96
|
+
|
|
97
|
+
# Save TDO signal as CSV
|
|
98
|
+
self.sig_worker_tdocsv.connect(self.worker.save_tdo_csv)
|
|
99
|
+
self.worker.sig_tdocsv_finished.connect(self.save_tdo_csv_finished)
|
|
100
|
+
|
|
101
|
+
# Save results as CSV
|
|
102
|
+
self.sig_worker_rescsv.connect(self.worker.save_results_csv)
|
|
103
|
+
self.worker.sig_rescsv_finished.connect(self.save_results_csv_finished)
|
|
104
|
+
|
|
105
|
+
# Load from CSV
|
|
106
|
+
self.sig_worker_loadcsv.connect(self.worker.load_csv_file)
|
|
107
|
+
self.worker.sig_load_csv_finished.connect(self.load_csv_file_finished)
|
|
108
|
+
|
|
109
|
+
@pyqtSlot()
|
|
110
|
+
def extract_tdo(self):
|
|
111
|
+
if not self.check_data_loaded():
|
|
112
|
+
return
|
|
113
|
+
self.disable_buttons()
|
|
114
|
+
self.sig_worker_extract.emit()
|
|
115
|
+
|
|
116
|
+
@pyqtSlot()
|
|
117
|
+
def align_field_finished(self):
|
|
118
|
+
self.ind_bup = self.worker.proc.inds_inc
|
|
119
|
+
self.ind_bdown = self.worker.proc.inds_dec
|
|
120
|
+
|
|
121
|
+
@pyqtSlot()
|
|
122
|
+
def extract_tdo_finished(self):
|
|
123
|
+
self.align_field_finished()
|
|
124
|
+
self.plot_tdo()
|
|
125
|
+
|
|
126
|
+
# Clear plots since source signal was changed
|
|
127
|
+
self.wplots.tdo_field.clearPlots()
|
|
128
|
+
self.wplots.tdo_inverse_field.clearPlots()
|
|
129
|
+
self.wplots.fft.clearPlots()
|
|
130
|
+
|
|
131
|
+
self.enable_buttons()
|
|
132
|
+
|
|
133
|
+
@pyqtSlot()
|
|
134
|
+
def remove_background(self):
|
|
135
|
+
if not self.check_tdo_extracted():
|
|
136
|
+
self.logger.error("TDO signal was not extracted.")
|
|
137
|
+
return
|
|
138
|
+
self.disable_buttons()
|
|
139
|
+
self.sig_worker_removebg.emit()
|
|
140
|
+
|
|
141
|
+
@pyqtSlot()
|
|
142
|
+
def remove_background_finished(self):
|
|
143
|
+
self.plot_tdo_detrended()
|
|
144
|
+
self.enable_buttons()
|
|
145
|
+
|
|
146
|
+
@pyqtSlot()
|
|
147
|
+
def fft(self):
|
|
148
|
+
if not self.check_data_loaded():
|
|
149
|
+
return
|
|
150
|
+
self.disable_buttons()
|
|
151
|
+
self.sig_worker_fft.emit()
|
|
152
|
+
|
|
153
|
+
@pyqtSlot()
|
|
154
|
+
def fft_finished(self):
|
|
155
|
+
self.plot_fft()
|
|
156
|
+
self.enable_buttons()
|
|
157
|
+
|
|
158
|
+
@pyqtSlot()
|
|
159
|
+
def save_tdo_csv(self):
|
|
160
|
+
"""Save extracted TDO signal as CSV."""
|
|
161
|
+
if not self.check_data_loaded():
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
self.disable_buttons()
|
|
165
|
+
|
|
166
|
+
default_fname = self.worker.proc.get_csv_filename(suffix="-tdo")
|
|
167
|
+
fname, _ = QtWidgets.QFileDialog.getSaveFileName(
|
|
168
|
+
self,
|
|
169
|
+
"Save TDO signals as...",
|
|
170
|
+
default_fname,
|
|
171
|
+
"Text files (*.txt, *.csv, *.tsv, *.out)",
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
if fname:
|
|
175
|
+
self.sig_worker_tdocsv.emit(fname)
|
|
176
|
+
else:
|
|
177
|
+
self.logger.error("[GUI] Invalid output file name for CSV file.")
|
|
178
|
+
self.save_tdo_csv_finished()
|
|
179
|
+
|
|
180
|
+
@pyqtSlot()
|
|
181
|
+
def save_tdo_csv_finished(self):
|
|
182
|
+
self.enable_buttons()
|
|
183
|
+
|
|
184
|
+
@pyqtSlot()
|
|
185
|
+
def save_results_csv(self):
|
|
186
|
+
"""Save final results as CSV."""
|
|
187
|
+
if not self.check_data_loaded():
|
|
188
|
+
return
|
|
189
|
+
|
|
190
|
+
self.disable_buttons()
|
|
191
|
+
|
|
192
|
+
default_fname = self.worker.proc.get_csv_filename(suffix="-results")
|
|
193
|
+
fname, _ = QtWidgets.QFileDialog.getSaveFileName(
|
|
194
|
+
self,
|
|
195
|
+
"Save TDO signals as...",
|
|
196
|
+
default_fname,
|
|
197
|
+
"Text files (*.txt, *.csv, *.tsv)",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
if fname:
|
|
201
|
+
self.sig_worker_rescsv.emit(fname)
|
|
202
|
+
else:
|
|
203
|
+
self.logger.error("[GUI] Invalid output file name for CSV file.")
|
|
204
|
+
self.save_tdo_csv_finished()
|
|
205
|
+
|
|
206
|
+
@pyqtSlot()
|
|
207
|
+
def save_results_csv_finished(self):
|
|
208
|
+
self.enable_buttons()
|
|
209
|
+
|
|
210
|
+
def load_csv_file(self, file_path: str):
|
|
211
|
+
if not self.check_config_loaded():
|
|
212
|
+
self.logger.error(
|
|
213
|
+
"Can't load a CSV file without loading a configuration file first."
|
|
214
|
+
)
|
|
215
|
+
return
|
|
216
|
+
|
|
217
|
+
self.disable_buttons()
|
|
218
|
+
self.sig_worker_loadcsv.emit(file_path)
|
|
219
|
+
|
|
220
|
+
@pyqtSlot()
|
|
221
|
+
def load_csv_file_finished(self):
|
|
222
|
+
self.extract_tdo_finished()
|
|
223
|
+
self.remove_background_finished()
|
|
224
|
+
self.fft_finished()
|
|
225
|
+
|
|
226
|
+
@pyqtSlot()
|
|
227
|
+
def batch_process(self):
|
|
228
|
+
self.logger.warning("Not implemented.")
|
|
229
|
+
|
|
230
|
+
@pyqtSlot()
|
|
231
|
+
def roi1_changed(self):
|
|
232
|
+
# Get time range
|
|
233
|
+
xmin, xmax = self.wplots.roi.getRegion()
|
|
234
|
+
|
|
235
|
+
# Check the ROI was changed since it was created
|
|
236
|
+
if (xmin, xmax) == (0, 1):
|
|
237
|
+
return
|
|
238
|
+
|
|
239
|
+
# Update parameter in the tree if the region was changed from the graph
|
|
240
|
+
if self.flag_do_update_roi:
|
|
241
|
+
self.flag_do_update_roi = False
|
|
242
|
+
self.wconfiguration.settings_parameters["poly_window"] = (
|
|
243
|
+
self.wconfiguration.get_numbers_from_text([xmin, xmax])
|
|
244
|
+
)
|
|
245
|
+
self.flag_do_update_roi = True
|
|
246
|
+
|
|
247
|
+
self.remove_background()
|
|
248
|
+
|
|
249
|
+
@pyqtSlot()
|
|
250
|
+
def roi2_changed(self):
|
|
251
|
+
# Get time range
|
|
252
|
+
xmin, xmax = self.wplots.roi2.getRegion()
|
|
253
|
+
|
|
254
|
+
# Check the ROI was changed since it was created
|
|
255
|
+
if (xmin, xmax) == (0, 1):
|
|
256
|
+
return
|
|
257
|
+
|
|
258
|
+
# Update parameter in the tree if the region was changed from the graph
|
|
259
|
+
if self.flag_do_update_roi:
|
|
260
|
+
self.flag_do_update_roi = False
|
|
261
|
+
self.wconfiguration.settings_parameters["fft_window"] = (
|
|
262
|
+
self.wconfiguration.get_numbers_from_text([xmin, xmax])
|
|
263
|
+
)
|
|
264
|
+
self.flag_do_update_roi = True
|
|
265
|
+
|
|
266
|
+
@pyqtSlot()
|
|
267
|
+
def update_roi_from_poly(self):
|
|
268
|
+
"""
|
|
269
|
+
Update the ROI in the graph from "Fit: field window" in the parameter tree.
|
|
270
|
+
|
|
271
|
+
Use `flag_do_update_roi` to check if the change is done programatically or from
|
|
272
|
+
the user.
|
|
273
|
+
In the first case, this function is ignored.
|
|
274
|
+
In the second case, the ROI in the graph is updated and computation is
|
|
275
|
+
triggered.
|
|
276
|
+
"""
|
|
277
|
+
if self.flag_do_update_roi:
|
|
278
|
+
# ROI changed from the tree, update the ROI in the graph
|
|
279
|
+
new_region = self.wconfiguration.get_numbers_from_text(
|
|
280
|
+
self.wconfiguration.settings_parameters["poly_window"]
|
|
281
|
+
)
|
|
282
|
+
if len(new_region) != 2:
|
|
283
|
+
self.logger.error(f"[GUI] Invalid analysis window : {new_region}")
|
|
284
|
+
return
|
|
285
|
+
elif new_region[0] >= new_region[1]:
|
|
286
|
+
self.logger.error(f"[GUI] Invalid analysis window : {new_region}")
|
|
287
|
+
return
|
|
288
|
+
|
|
289
|
+
# Update ROI, without recomputing
|
|
290
|
+
self.flag_do_update_roi = False
|
|
291
|
+
self.wplots.roi.setRegion(new_region)
|
|
292
|
+
self.flag_do_update_roi = True
|
|
293
|
+
else:
|
|
294
|
+
return
|
|
295
|
+
|
|
296
|
+
@pyqtSlot()
|
|
297
|
+
def update_roi_from_fft(self):
|
|
298
|
+
"""
|
|
299
|
+
Update the ROI in the graph from "FFT: field window" in the parameter tree.
|
|
300
|
+
|
|
301
|
+
Use `flag_do_update_roi` to check if the change is done programatically or from
|
|
302
|
+
the user.
|
|
303
|
+
In the first case, this function is ignored.
|
|
304
|
+
In the second case, the ROI in the graph is updated and computation is
|
|
305
|
+
triggered.
|
|
306
|
+
"""
|
|
307
|
+
if self.flag_do_update_roi:
|
|
308
|
+
# ROI changed from the tree, update the ROI in the graph
|
|
309
|
+
new_region = self.wconfiguration.get_numbers_from_text(
|
|
310
|
+
self.wconfiguration.settings_parameters["fft_window"]
|
|
311
|
+
)
|
|
312
|
+
if len(new_region) != 2:
|
|
313
|
+
self.logger.error(f"[GUI] Invalid analysis window : {new_region}")
|
|
314
|
+
return
|
|
315
|
+
elif new_region[0] >= new_region[1]:
|
|
316
|
+
self.logger.error(f"[GUI] Invalid analysis window : {new_region}")
|
|
317
|
+
return
|
|
318
|
+
|
|
319
|
+
# Update ROI, without recomputing
|
|
320
|
+
self.flag_do_update_roi = False
|
|
321
|
+
self.wplots.roi.setRegion(new_region)
|
|
322
|
+
self.flag_do_update_roi = True
|
|
323
|
+
else:
|
|
324
|
+
return
|
|
325
|
+
|
|
326
|
+
def plot_tdo(self):
|
|
327
|
+
"""Plot TDO signal versus field and time."""
|
|
328
|
+
if not self.check_field_aligned():
|
|
329
|
+
self.worker.align_field()
|
|
330
|
+
|
|
331
|
+
## TDO signal versus field
|
|
332
|
+
self.wplots.sig_field.clearPlots()
|
|
333
|
+
self.wplots.sig_field.setAutoVisible(y=True)
|
|
334
|
+
|
|
335
|
+
# Decreasing magnetic field
|
|
336
|
+
self.wplots.sig_field.plot(
|
|
337
|
+
self.worker.proc.get_data_processed("magfield")[self.ind_bdown],
|
|
338
|
+
self.worker.proc.get_data_processed(self.worker.proc._tdo_name)[
|
|
339
|
+
self.ind_bdown
|
|
340
|
+
],
|
|
341
|
+
pen=self.wplots.pen_bdown,
|
|
342
|
+
name="B down",
|
|
343
|
+
)
|
|
344
|
+
# Increasing magnetic field
|
|
345
|
+
self.wplots.sig_field.plot(
|
|
346
|
+
self.worker.proc.get_data_processed("magfield")[self.ind_bup],
|
|
347
|
+
self.worker.proc.get_data_processed(self.worker.proc._tdo_name)[
|
|
348
|
+
self.ind_bup
|
|
349
|
+
],
|
|
350
|
+
pen=self.wplots.pen_bup,
|
|
351
|
+
name="B up",
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
## TDO signal versus time
|
|
355
|
+
self.wplots.sig_time.clearPlots()
|
|
356
|
+
self.wplots.sig_time.setAutoVisible(y=True)
|
|
357
|
+
|
|
358
|
+
# Decreasing magnetic field
|
|
359
|
+
self.wplots.sig_time.plot(
|
|
360
|
+
self.worker.proc.get_data_processed("time_exp")[self.ind_bdown],
|
|
361
|
+
self.worker.proc.get_data_processed(self.worker.proc._tdo_name)[
|
|
362
|
+
self.ind_bdown
|
|
363
|
+
],
|
|
364
|
+
pen=self.wplots.pen_bdown,
|
|
365
|
+
name="B down",
|
|
366
|
+
)
|
|
367
|
+
# Increasing magnetic field
|
|
368
|
+
self.wplots.sig_time.plot(
|
|
369
|
+
self.worker.proc.get_data_processed("time_exp")[self.ind_bup],
|
|
370
|
+
self.worker.proc.get_data_processed(self.worker.proc._tdo_name)[
|
|
371
|
+
self.ind_bup
|
|
372
|
+
],
|
|
373
|
+
pen=self.wplots.pen_bup,
|
|
374
|
+
name="B up",
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
def plot_tdo_detrended(self):
|
|
378
|
+
"""Plot TDO signal with background removed."""
|
|
379
|
+
# Get parameters
|
|
380
|
+
offset = self.worker.proc.cfg.settings.offset
|
|
381
|
+
lower_b, upper_b = self.worker.proc.cfg.settings.fft_window
|
|
382
|
+
|
|
383
|
+
# Sync fit and FFT windows
|
|
384
|
+
if lower_b == -1:
|
|
385
|
+
lower_b = self.worker.proc.cfg.settings.poly_window[0]
|
|
386
|
+
if upper_b == -1:
|
|
387
|
+
upper_b = self.worker.proc.cfg.settings.poly_window[1]
|
|
388
|
+
|
|
389
|
+
## TDO detrended versus field
|
|
390
|
+
self.wplots.tdo_field.clearPlots()
|
|
391
|
+
self.wplots.tdo_field.setAutoVisible(y=True)
|
|
392
|
+
self.wplots.sig_field.clearPlots()
|
|
393
|
+
self.plot_tdo()
|
|
394
|
+
|
|
395
|
+
# Decreasing magnetic field
|
|
396
|
+
if self.worker.proc.get_data_processed(
|
|
397
|
+
self.worker.proc._tdo_det_dec_name, checkonly=True
|
|
398
|
+
):
|
|
399
|
+
self.wplots.tdo_field.plot(
|
|
400
|
+
self.worker.proc.get_data_processed("magfield")[self.ind_bdown],
|
|
401
|
+
self.worker.proc.get_data_processed(self.worker.proc._tdo_det_dec_name)
|
|
402
|
+
- offset / 2,
|
|
403
|
+
pen=self.wplots.pen_bdown,
|
|
404
|
+
name="B down",
|
|
405
|
+
)
|
|
406
|
+
# Increasing magnetic field
|
|
407
|
+
if self.worker.proc.get_data_processed(
|
|
408
|
+
self.worker.proc._tdo_det_inc_name, checkonly=True
|
|
409
|
+
):
|
|
410
|
+
self.wplots.tdo_field.plot(
|
|
411
|
+
self.worker.proc.get_data_processed("magfield")[self.ind_bup],
|
|
412
|
+
self.worker.proc.get_data_processed(self.worker.proc._tdo_det_inc_name)
|
|
413
|
+
+ offset / 2,
|
|
414
|
+
pen=self.wplots.pen_bup,
|
|
415
|
+
name="B up",
|
|
416
|
+
)
|
|
417
|
+
self.wplots.tdo_field.setXRange(lower_b, upper_b, padding=0.05)
|
|
418
|
+
|
|
419
|
+
# Fit decreasing magnetic field
|
|
420
|
+
if self.worker.proc.get_data_processed(
|
|
421
|
+
self.worker.proc._tdo_name + "_fit_dec", checkonly=True
|
|
422
|
+
):
|
|
423
|
+
self.wplots.sig_field.plot(
|
|
424
|
+
self.worker.proc.get_data_processed("magfield")[self.ind_bdown],
|
|
425
|
+
self.worker.proc.get_data_processed(
|
|
426
|
+
self.worker.proc._tdo_name + "_fit_dec"
|
|
427
|
+
),
|
|
428
|
+
pen=self.wplots.pen_fitdown,
|
|
429
|
+
name="Fit B down",
|
|
430
|
+
)
|
|
431
|
+
# Fit increasing magnetic field
|
|
432
|
+
if self.worker.proc.get_data_processed(
|
|
433
|
+
self.worker.proc._tdo_name + "_fit_inc", checkonly=True
|
|
434
|
+
):
|
|
435
|
+
self.wplots.sig_field.plot(
|
|
436
|
+
self.worker.proc.get_data_processed("magfield")[self.ind_bup],
|
|
437
|
+
self.worker.proc.get_data_processed(
|
|
438
|
+
self.worker.proc._tdo_name + "_fit_inc"
|
|
439
|
+
),
|
|
440
|
+
pen=self.wplots.pen_fitbup,
|
|
441
|
+
name="Fit B up",
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
## TDO detrended versus 1/B
|
|
445
|
+
self.wplots.tdo_inverse_field.clearPlots()
|
|
446
|
+
self.wplots.tdo_inverse_field.setAutoVisible(y=True)
|
|
447
|
+
|
|
448
|
+
# Decreasing magnetic field
|
|
449
|
+
if self.worker.proc.get_data_processed(
|
|
450
|
+
self.worker.proc._tdo_inv_dec_name, checkonly=True
|
|
451
|
+
):
|
|
452
|
+
self.wplots.tdo_inverse_field.plot(
|
|
453
|
+
self.worker.proc.get_data_processed("magfield_inverse_dec"),
|
|
454
|
+
self.worker.proc.get_data_processed(self.worker.proc._tdo_inv_dec_name)
|
|
455
|
+
- offset / 2,
|
|
456
|
+
pen=self.wplots.pen_bdown,
|
|
457
|
+
name="B down",
|
|
458
|
+
)
|
|
459
|
+
# Increasing magnetic field
|
|
460
|
+
if self.worker.proc.get_data_processed(
|
|
461
|
+
self.worker.proc._tdo_inv_inc_name, checkonly=True
|
|
462
|
+
):
|
|
463
|
+
self.wplots.tdo_inverse_field.plot(
|
|
464
|
+
self.worker.proc.get_data_processed("magfield_inverse_inc"),
|
|
465
|
+
self.worker.proc.get_data_processed(self.worker.proc._tdo_inv_inc_name)
|
|
466
|
+
+ offset / 2,
|
|
467
|
+
pen=self.wplots.pen_bup,
|
|
468
|
+
name="B up",
|
|
469
|
+
)
|
|
470
|
+
self.wplots.tdo_inverse_field.setXRange(1 / upper_b, 1 / lower_b, padding=0.05)
|
|
471
|
+
|
|
472
|
+
def plot_fft(self):
|
|
473
|
+
"""Plot FFT in 1/B."""
|
|
474
|
+
self.wplots.fft.clearPlots()
|
|
475
|
+
|
|
476
|
+
# Decreasing magnetic field
|
|
477
|
+
if self.worker.proc.get_data_processed("fft_dec", checkonly=True):
|
|
478
|
+
self.wplots.fft.plot(
|
|
479
|
+
self.worker.proc.get_data_processed("bfreq_dec"),
|
|
480
|
+
self.worker.proc.get_data_processed("fft_dec"),
|
|
481
|
+
pen=self.wplots.pen_bdown,
|
|
482
|
+
name="B down",
|
|
483
|
+
)
|
|
484
|
+
# Increasing magnetic field
|
|
485
|
+
if self.worker.proc.get_data_processed("fft_inc", checkonly=True):
|
|
486
|
+
self.wplots.fft.plot(
|
|
487
|
+
self.worker.proc.get_data_processed("bfreq_inc"),
|
|
488
|
+
self.worker.proc.get_data_processed("fft_inc"),
|
|
489
|
+
pen=self.wplots.pen_bup,
|
|
490
|
+
name="B up",
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
def syncroi_changed(self):
|
|
494
|
+
"""Update fit and FFT windows sync. status."""
|
|
495
|
+
self.wplots._sync_roi = self.wconfiguration.syncroi_parameter.value()
|
|
496
|
+
|
|
497
|
+
def check_tdo_extracted(self) -> bool:
|
|
498
|
+
if not self.check_data_loaded():
|
|
499
|
+
return False
|
|
500
|
+
return self.worker.proc._check_barycenters_computed()
|
|
501
|
+
|
|
502
|
+
def dropEvent(self, e):
|
|
503
|
+
for url in e.mimeData().urls():
|
|
504
|
+
file_path = url.toLocalFile()
|
|
505
|
+
if file_path.endswith(OUT_FORMAT):
|
|
506
|
+
self.load_csv_file(file_path)
|
|
507
|
+
return
|
|
508
|
+
|
|
509
|
+
super().dropEvent(e)
|
pytdo/gui/_workers.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Worker class."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from PyQt6.QtCore import QObject, pyqtSignal, pyqtSlot
|
|
6
|
+
|
|
7
|
+
from ..processors import TDOProcessor
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DataWorker(QObject):
|
|
11
|
+
sig_load_finished = pyqtSignal()
|
|
12
|
+
sig_extract_finished = pyqtSignal()
|
|
13
|
+
sig_align_finished = pyqtSignal()
|
|
14
|
+
sig_removebg_finished = pyqtSignal()
|
|
15
|
+
sig_fft_finished = pyqtSignal()
|
|
16
|
+
sig_batch_progress = pyqtSignal(int)
|
|
17
|
+
sig_batch_finished = pyqtSignal()
|
|
18
|
+
sig_tdocsv_finished = pyqtSignal()
|
|
19
|
+
sig_rescsv_finished = pyqtSignal()
|
|
20
|
+
sig_save_nexus_finished = pyqtSignal()
|
|
21
|
+
sig_load_csv_finished = pyqtSignal()
|
|
22
|
+
|
|
23
|
+
def __init__(self, *args, **kwargs):
|
|
24
|
+
super().__init__()
|
|
25
|
+
|
|
26
|
+
self.proc = TDOProcessor(*args, **kwargs)
|
|
27
|
+
if self.proc.is_nexus_file:
|
|
28
|
+
self.is_dataloaded = True
|
|
29
|
+
else:
|
|
30
|
+
self.is_dataloaded = False
|
|
31
|
+
|
|
32
|
+
@pyqtSlot()
|
|
33
|
+
def load_data(self):
|
|
34
|
+
"""Load data."""
|
|
35
|
+
self.proc.load_oscillo()
|
|
36
|
+
self.is_dataloaded = True
|
|
37
|
+
self.sig_load_finished.emit()
|
|
38
|
+
|
|
39
|
+
@pyqtSlot()
|
|
40
|
+
def extract_tdo(self):
|
|
41
|
+
"""Extract TDO signal."""
|
|
42
|
+
self.proc.extract_tdo()
|
|
43
|
+
self.sig_extract_finished.emit()
|
|
44
|
+
|
|
45
|
+
def align_field(self):
|
|
46
|
+
self.proc.align_field()
|
|
47
|
+
self.sig_align_finished.emit()
|
|
48
|
+
|
|
49
|
+
@pyqtSlot()
|
|
50
|
+
def remove_background(self):
|
|
51
|
+
"""Remove background and oversample in 1/B."""
|
|
52
|
+
self.proc.remove_background()
|
|
53
|
+
self.sig_removebg_finished.emit()
|
|
54
|
+
|
|
55
|
+
@pyqtSlot()
|
|
56
|
+
def fft(self):
|
|
57
|
+
"""FFT in 1/B."""
|
|
58
|
+
self.proc.fft_inverse_field()
|
|
59
|
+
self.sig_fft_finished.emit()
|
|
60
|
+
|
|
61
|
+
@pyqtSlot()
|
|
62
|
+
def batch_process(self):
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
@pyqtSlot(str)
|
|
66
|
+
def save_tdo_csv(self, fname: str | Path):
|
|
67
|
+
"""Save TDO signal as CSV."""
|
|
68
|
+
self.proc.save_tdo_csv(filename=fname)
|
|
69
|
+
self.sig_tdocsv_finished.emit()
|
|
70
|
+
|
|
71
|
+
@pyqtSlot(str)
|
|
72
|
+
def save_results_csv(self, fname: str | Path):
|
|
73
|
+
"""Save results as CSV."""
|
|
74
|
+
self.proc.save_results_csv(filename_prefix=fname)
|
|
75
|
+
self.sig_rescsv_finished.emit()
|
|
76
|
+
|
|
77
|
+
@pyqtSlot(str)
|
|
78
|
+
def save_as_nexus(self, fname: str | Path):
|
|
79
|
+
"""Save data as NeXus."""
|
|
80
|
+
self.proc.save(filename=fname)
|
|
81
|
+
self.sig_save_nexus_finished.emit()
|
|
82
|
+
|
|
83
|
+
@pyqtSlot(str)
|
|
84
|
+
def load_csv_file(self, fname: str):
|
|
85
|
+
self.proc.load_csv(fname)
|
|
86
|
+
self.sig_load_csv_finished.emit()
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Custom widgets and UI components."""
|
|
2
|
+
|
|
3
|
+
from ._configuration_tab import ConfigurationWidget
|
|
4
|
+
from ._graphs import GraphsWidget
|
|
5
|
+
from ._main_buttons import MainButtonsWidget
|
|
6
|
+
from ._param_content import ParamContent
|
|
7
|
+
|
|
8
|
+
__all__ = ["ConfigurationWidget", "MainButtonsWidget", "GraphsWidget", "ParamContent"]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from PyQt6.QtCore import pyqtSignal
|
|
2
|
+
from pyqtgraph.parametertree import Parameter
|
|
3
|
+
from pyuson import gui
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ConfigurationWidget(gui.widgets.BaseConfigurationWidget):
|
|
7
|
+
sig_syncroi_changed = pyqtSignal()
|
|
8
|
+
|
|
9
|
+
def __init__(self, param_content: type):
|
|
10
|
+
super().__init__(param_content)
|
|
11
|
+
|
|
12
|
+
self.syncroi_parameter = Parameter.create(
|
|
13
|
+
name="syncroi",
|
|
14
|
+
type="bool",
|
|
15
|
+
value=True,
|
|
16
|
+
title="Sync. fit and FFT field-window",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
self.syncroi_parameter.sigValueChanged.connect(self.sig_syncroi_changed.emit)
|
|
20
|
+
self.host_parameters.addChild(self.syncroi_parameter)
|