pytdo 0.2.2.2__tar.gz → 0.2.5__tar.gz
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-0.2.2.2 → pytdo-0.2.5}/PKG-INFO +21 -13
- {pytdo-0.2.2.2 → pytdo-0.2.5}/README.md +21 -13
- {pytdo-0.2.2.2 → pytdo-0.2.5}/pyproject.toml +2 -2
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/assets/config_default.toml +6 -3
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/config/models.py +4 -1
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/gui/_core.py +63 -11
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/gui/_workers.py +7 -0
- pytdo-0.2.5/src/pytdo/gui/widgets/_configuration_tab.py +71 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/gui/widgets/_graphs.py +29 -68
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/gui/widgets/_param_content.py +32 -22
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/processors/_tdo.py +85 -33
- pytdo-0.2.2.2/src/pytdo/gui/widgets/_configuration_tab.py +0 -20
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/__init__.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/__main__.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/config/__init__.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/config/_config.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/config/_types.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/gui/__init__.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/gui/widgets/__init__.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/gui/widgets/_main_buttons.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/processors/__init__.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/processors/_types.py +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/py.typed +0 -0
- {pytdo-0.2.2.2 → pytdo-0.2.5}/src/pytdo/sp.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pytdo
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: Add your description here
|
|
5
5
|
Author: Guillaume Le Goc
|
|
6
6
|
Author-email: Guillaume Le Goc <guillaume.le-goc@lncmi.cnrs.fr>
|
|
@@ -10,7 +10,7 @@ Requires-Dist: rich>=14.2.0
|
|
|
10
10
|
Requires-Dist: scipy>=1.16.3
|
|
11
11
|
Requires-Dist: pydantic>=2.12.4
|
|
12
12
|
Requires-Dist: pyqt6>=6.10.0
|
|
13
|
-
Requires-Dist: pyuson>=0.7.
|
|
13
|
+
Requires-Dist: pyuson>=0.7.3
|
|
14
14
|
Requires-Python: >=3.12
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
|
|
@@ -24,12 +24,20 @@ Description-Content-Type: text/markdown
|
|
|
24
24
|
|
|
25
25
|
## Installation
|
|
26
26
|
|
|
27
|
-
### As an app
|
|
28
|
-
If you plan to just use the graphical user interface, consider installing `pytdo` as a tool managed by uv, a modern Python package manager.
|
|
27
|
+
### Method 1 : As an app
|
|
28
|
+
If you plan to just use the graphical user interface, consider installing `pytdo` as a tool managed by [uv](https://docs.astral.sh/uv/), a modern Python package manager.
|
|
29
29
|
|
|
30
|
-
To do so, install uv : https://docs.astral.sh/uv/getting-started/installation
|
|
30
|
+
To do so, install uv (see the official installation instructions : https://docs.astral.sh/uv/getting-started/installation/) :
|
|
31
|
+
- On Windows, enter the following command in PowerShell :
|
|
32
|
+
```powershell
|
|
33
|
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
34
|
+
```
|
|
35
|
+
- On Linux and MacOS, enter the following in a terminal :
|
|
36
|
+
```bash
|
|
37
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
38
|
+
```
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
Once uv is installed, from the command line (PowerShell in Windows), install `pytdo` with uv :
|
|
33
41
|
```
|
|
34
42
|
uv tool install pytdo
|
|
35
43
|
```
|
|
@@ -40,13 +48,13 @@ Then, launch the GUI by running `pytdo` from the command line.
|
|
|
40
48
|
|
|
41
49
|
To update, run : `uv tool upgrade pytdo`.
|
|
42
50
|
|
|
43
|
-
### As a library
|
|
44
|
-
Installing `pytdo` as a library will allow you to use
|
|
45
|
-
Note that you can
|
|
51
|
+
### Method 2 : As a library
|
|
52
|
+
Installing `pytdo` as a library will allow you to use the graphical user interface but also use the backend library from scripts and Jupyter notebooks (e.g. you will be able to import it with `import pytdo`).
|
|
53
|
+
Note that you can use the same environment than the one for [`pyuson`](https://gitlab.in2p3.fr/himagnetos/pyuson).
|
|
46
54
|
|
|
47
|
-
1. Create a Python environment :
|
|
48
|
-
|
|
49
|
-
With
|
|
55
|
+
1. Create a Python environment with Python 3.12 :
|
|
56
|
+
|
|
57
|
+
You can use your favorite Python environment manager. With [conda](https://conda-forge.org/miniforge/), this would be :
|
|
50
58
|
```
|
|
51
59
|
conda create -n pytdo-env -c conda-forge python=3.12
|
|
52
60
|
```
|
|
@@ -85,7 +93,7 @@ pip install -e /path/to/pytdo-main
|
|
|
85
93
|
```
|
|
86
94
|
|
|
87
95
|
## Usage
|
|
88
|
-
You can use this package through the graphical user interface, or directly from Python
|
|
96
|
+
You can use this package through the graphical user interface, or directly from the Python shell, script or Jupyter notebook using the `TDOProcessor` class. All this methods rely on a TOML configuration file that specifies the experiment parameters and analysis settings.
|
|
89
97
|
|
|
90
98
|
A template configuration file is provided in the `configs` folder. Copy-paste and edit it according to your need. Each entry of the file is commented so it should be somewhat straightforward to configure. Then :
|
|
91
99
|
|
|
@@ -8,12 +8,20 @@
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
### As an app
|
|
12
|
-
If you plan to just use the graphical user interface, consider installing `pytdo` as a tool managed by uv, a modern Python package manager.
|
|
13
|
-
|
|
14
|
-
To do so, install uv : https://docs.astral.sh/uv/getting-started/installation
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
### Method 1 : As an app
|
|
12
|
+
If you plan to just use the graphical user interface, consider installing `pytdo` as a tool managed by [uv](https://docs.astral.sh/uv/), a modern Python package manager.
|
|
13
|
+
|
|
14
|
+
To do so, install uv (see the official installation instructions : https://docs.astral.sh/uv/getting-started/installation/) :
|
|
15
|
+
- On Windows, enter the following command in PowerShell :
|
|
16
|
+
```powershell
|
|
17
|
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
18
|
+
```
|
|
19
|
+
- On Linux and MacOS, enter the following in a terminal :
|
|
20
|
+
```bash
|
|
21
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Once uv is installed, from the command line (PowerShell in Windows), install `pytdo` with uv :
|
|
17
25
|
```
|
|
18
26
|
uv tool install pytdo
|
|
19
27
|
```
|
|
@@ -24,13 +32,13 @@ Then, launch the GUI by running `pytdo` from the command line.
|
|
|
24
32
|
|
|
25
33
|
To update, run : `uv tool upgrade pytdo`.
|
|
26
34
|
|
|
27
|
-
### As a library
|
|
28
|
-
Installing `pytdo` as a library will allow you to use
|
|
29
|
-
Note that you can
|
|
30
|
-
|
|
31
|
-
1. Create a Python environment :
|
|
35
|
+
### Method 2 : As a library
|
|
36
|
+
Installing `pytdo` as a library will allow you to use the graphical user interface but also use the backend library from scripts and Jupyter notebooks (e.g. you will be able to import it with `import pytdo`).
|
|
37
|
+
Note that you can use the same environment than the one for [`pyuson`](https://gitlab.in2p3.fr/himagnetos/pyuson).
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
1. Create a Python environment with Python 3.12 :
|
|
40
|
+
|
|
41
|
+
You can use your favorite Python environment manager. With [conda](https://conda-forge.org/miniforge/), this would be :
|
|
34
42
|
```
|
|
35
43
|
conda create -n pytdo-env -c conda-forge python=3.12
|
|
36
44
|
```
|
|
@@ -69,7 +77,7 @@ pip install -e /path/to/pytdo-main
|
|
|
69
77
|
```
|
|
70
78
|
|
|
71
79
|
## Usage
|
|
72
|
-
You can use this package through the graphical user interface, or directly from Python
|
|
80
|
+
You can use this package through the graphical user interface, or directly from the Python shell, script or Jupyter notebook using the `TDOProcessor` class. All this methods rely on a TOML configuration file that specifies the experiment parameters and analysis settings.
|
|
73
81
|
|
|
74
82
|
A template configuration file is provided in the `configs` folder. Copy-paste and edit it according to your need. Each entry of the file is commented so it should be somewhat straightforward to configure. Then :
|
|
75
83
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pytdo"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.5"
|
|
4
4
|
description = "Add your description here"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -14,7 +14,7 @@ dependencies = [
|
|
|
14
14
|
"scipy>=1.16.3",
|
|
15
15
|
"pydantic>=2.12.4",
|
|
16
16
|
"pyqt6>=6.10.0",
|
|
17
|
-
"pyuson>=0.7.
|
|
17
|
+
"pyuson>=0.7.3",
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
[project.gui-scripts]
|
|
@@ -37,13 +37,16 @@ pickup_index = 0 # index of the pickup to use for analysis, 0-based
|
|
|
37
37
|
[settings]
|
|
38
38
|
# Settings for TDO signal extraction from raw data
|
|
39
39
|
max_time = 1 # crop signals until this time in seconds
|
|
40
|
-
|
|
41
|
-
barycenters_fast = true # use fast algo to find barycenters or not
|
|
42
|
-
noise_window = [0, 0.05] # noise analysis time window in seconds
|
|
40
|
+
|
|
43
41
|
spectro_nperseg = 1024 # spectrogram : number of points per segment
|
|
44
42
|
spectro_win_size = 4096 # spectrogram : fft window size
|
|
45
43
|
spectro_noverlap = -1 # size of windows overlap, set to -1 to be nperseg / 2
|
|
46
44
|
|
|
45
|
+
barycenters_fwindow = 732421.875 # half size of the window to use around frequency maxima in spectrogram
|
|
46
|
+
barycenters_fast = true # use fast algo to find barycenters or not
|
|
47
|
+
|
|
48
|
+
time_offset = 0
|
|
49
|
+
|
|
47
50
|
# Settings for TDO signal analysis
|
|
48
51
|
poly_window = [60, 84] # field-range in which to do the polynomial fit
|
|
49
52
|
poly_deg = 3 # polynomial degree
|
|
@@ -21,13 +21,16 @@ class Settings(BaseModel):
|
|
|
21
21
|
|
|
22
22
|
# Extraction
|
|
23
23
|
max_time: float
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
spectro_nperseg: int
|
|
26
26
|
spectro_win_size: int
|
|
27
27
|
spectro_noverlap: int
|
|
28
|
+
|
|
28
29
|
barycenters_fwindow: float
|
|
29
30
|
barycenters_fast: bool
|
|
30
31
|
|
|
32
|
+
time_offset: float
|
|
33
|
+
|
|
31
34
|
# Analysis
|
|
32
35
|
poly_window: Sequence[float]
|
|
33
36
|
poly_deg: int
|
|
@@ -18,6 +18,7 @@ LOG_LEVEL = "INFO"
|
|
|
18
18
|
|
|
19
19
|
class MainWindow(gui.BaseMainWindow):
|
|
20
20
|
sig_worker_extract = pyqtSignal()
|
|
21
|
+
sig_worker_offset = pyqtSignal()
|
|
21
22
|
sig_worker_removebg = pyqtSignal()
|
|
22
23
|
sig_worker_fft = pyqtSignal()
|
|
23
24
|
sig_worker_tdocsv = pyqtSignal(str)
|
|
@@ -52,6 +53,13 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
52
53
|
|
|
53
54
|
# Connect
|
|
54
55
|
self.wconfiguration.sig_syncroi_changed.connect(self.syncroi_changed)
|
|
56
|
+
self.wconfiguration.sig_spectro_nperseg_changed.connect(
|
|
57
|
+
self.update_spectro_time_window
|
|
58
|
+
)
|
|
59
|
+
self.wconfiguration.sig_timeoffset_changed.connect(self.apply_time_offset)
|
|
60
|
+
self.wconfiguration.sig_fitdeg_changed.connect(self.remove_background)
|
|
61
|
+
self.wconfiguration.sig_npoints_interp_changed.connect(self.remove_background)
|
|
62
|
+
self.wconfiguration.sig_curveoffset_changed.connect(self.plot_tdo_detrended)
|
|
55
63
|
|
|
56
64
|
def init_buttons(self):
|
|
57
65
|
super().init_buttons()
|
|
@@ -86,6 +94,13 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
86
94
|
self.sig_worker_extract.connect(self.worker.extract_tdo)
|
|
87
95
|
self.worker.sig_extract_finished.connect(self.extract_tdo_finished)
|
|
88
96
|
|
|
97
|
+
# Time offset
|
|
98
|
+
self.sig_worker_offset.connect(self.worker.time_offset)
|
|
99
|
+
self.worker.sig_offset_finished.connect(self.time_offset_finished)
|
|
100
|
+
|
|
101
|
+
# Field aligned
|
|
102
|
+
self.worker.sig_align_finished.connect(self.align_field_finished)
|
|
103
|
+
|
|
89
104
|
# Remove background
|
|
90
105
|
self.sig_worker_removebg.connect(self.worker.remove_background)
|
|
91
106
|
self.worker.sig_removebg_finished.connect(self.remove_background_finished)
|
|
@@ -115,21 +130,37 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
115
130
|
|
|
116
131
|
@pyqtSlot()
|
|
117
132
|
def align_field_finished(self):
|
|
133
|
+
self.plot_field()
|
|
118
134
|
self.ind_bup = self.worker.proc.inds_inc
|
|
119
135
|
self.ind_bdown = self.worker.proc.inds_dec
|
|
120
136
|
|
|
121
137
|
@pyqtSlot()
|
|
122
138
|
def extract_tdo_finished(self):
|
|
123
|
-
self.align_field_finished()
|
|
124
|
-
self.plot_tdo()
|
|
125
|
-
|
|
126
139
|
# Clear plots since source signal was changed
|
|
127
140
|
self.wplots.tdo_field.clearPlots()
|
|
128
141
|
self.wplots.tdo_inverse_field.clearPlots()
|
|
129
142
|
self.wplots.fft.clearPlots()
|
|
130
143
|
|
|
144
|
+
self.align_field_finished()
|
|
145
|
+
self.plot_tdo()
|
|
131
146
|
self.enable_buttons()
|
|
132
147
|
|
|
148
|
+
@pyqtSlot()
|
|
149
|
+
def apply_time_offset(self):
|
|
150
|
+
if not self.check_data_loaded():
|
|
151
|
+
return
|
|
152
|
+
self.disable_buttons()
|
|
153
|
+
self.sig_worker_offset.emit()
|
|
154
|
+
|
|
155
|
+
@pyqtSlot()
|
|
156
|
+
def time_offset_finished(self):
|
|
157
|
+
self.align_field_finished()
|
|
158
|
+
self.plot_tdo()
|
|
159
|
+
self.wplots.tdo_field.clearPlots()
|
|
160
|
+
self.wplots.tdo_inverse_field.clearPlots()
|
|
161
|
+
self.wplots.fft.clearPlots()
|
|
162
|
+
self.fft()
|
|
163
|
+
|
|
133
164
|
@pyqtSlot()
|
|
134
165
|
def remove_background(self):
|
|
135
166
|
if not self.check_tdo_extracted():
|
|
@@ -140,6 +171,7 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
140
171
|
|
|
141
172
|
@pyqtSlot()
|
|
142
173
|
def remove_background_finished(self):
|
|
174
|
+
self.wplots.fft.clearPlots()
|
|
143
175
|
self.plot_tdo_detrended()
|
|
144
176
|
self.enable_buttons()
|
|
145
177
|
|
|
@@ -152,6 +184,7 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
152
184
|
|
|
153
185
|
@pyqtSlot()
|
|
154
186
|
def fft_finished(self):
|
|
187
|
+
self.plot_tdo_detrended()
|
|
155
188
|
self.plot_fft()
|
|
156
189
|
self.enable_buttons()
|
|
157
190
|
|
|
@@ -263,6 +296,8 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
263
296
|
)
|
|
264
297
|
self.flag_do_update_roi = True
|
|
265
298
|
|
|
299
|
+
self.fft()
|
|
300
|
+
|
|
266
301
|
@pyqtSlot()
|
|
267
302
|
def update_roi_from_poly(self):
|
|
268
303
|
"""
|
|
@@ -318,7 +353,7 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
318
353
|
|
|
319
354
|
# Update ROI, without recomputing
|
|
320
355
|
self.flag_do_update_roi = False
|
|
321
|
-
self.wplots.
|
|
356
|
+
self.wplots.roi2.setRegion(new_region)
|
|
322
357
|
self.flag_do_update_roi = True
|
|
323
358
|
else:
|
|
324
359
|
return
|
|
@@ -330,7 +365,6 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
330
365
|
|
|
331
366
|
## TDO signal versus field
|
|
332
367
|
self.wplots.sig_field.clearPlots()
|
|
333
|
-
self.wplots.sig_field.setAutoVisible(y=True)
|
|
334
368
|
|
|
335
369
|
# Decreasing magnetic field
|
|
336
370
|
self.wplots.sig_field.plot(
|
|
@@ -353,7 +387,6 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
353
387
|
|
|
354
388
|
## TDO signal versus time
|
|
355
389
|
self.wplots.sig_time.clearPlots()
|
|
356
|
-
self.wplots.sig_time.setAutoVisible(y=True)
|
|
357
390
|
|
|
358
391
|
# Decreasing magnetic field
|
|
359
392
|
self.wplots.sig_time.plot(
|
|
@@ -374,8 +407,11 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
374
407
|
name="B up",
|
|
375
408
|
)
|
|
376
409
|
|
|
410
|
+
@pyqtSlot()
|
|
377
411
|
def plot_tdo_detrended(self):
|
|
378
412
|
"""Plot TDO signal with background removed."""
|
|
413
|
+
if not self.check_tdo_detrended():
|
|
414
|
+
return
|
|
379
415
|
# Get parameters
|
|
380
416
|
offset = self.worker.proc.cfg.settings.offset
|
|
381
417
|
lower_b, upper_b = self.worker.proc.cfg.settings.fft_window
|
|
@@ -388,9 +424,8 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
388
424
|
|
|
389
425
|
## TDO detrended versus field
|
|
390
426
|
self.wplots.tdo_field.clearPlots()
|
|
391
|
-
self.wplots.tdo_field.setAutoVisible(y=True)
|
|
392
427
|
self.wplots.sig_field.clearPlots()
|
|
393
|
-
self.plot_tdo()
|
|
428
|
+
self.plot_tdo() # to make sure data shown is synced
|
|
394
429
|
|
|
395
430
|
# Decreasing magnetic field
|
|
396
431
|
if self.worker.proc.get_data_processed(
|
|
@@ -414,7 +449,6 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
414
449
|
pen=self.wplots.pen_bup,
|
|
415
450
|
name="B up",
|
|
416
451
|
)
|
|
417
|
-
self.wplots.tdo_field.setXRange(lower_b, upper_b, padding=0.05)
|
|
418
452
|
|
|
419
453
|
# Fit decreasing magnetic field
|
|
420
454
|
if self.worker.proc.get_data_processed(
|
|
@@ -443,7 +477,6 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
443
477
|
|
|
444
478
|
## TDO detrended versus 1/B
|
|
445
479
|
self.wplots.tdo_inverse_field.clearPlots()
|
|
446
|
-
self.wplots.tdo_inverse_field.setAutoVisible(y=True)
|
|
447
480
|
|
|
448
481
|
# Decreasing magnetic field
|
|
449
482
|
if self.worker.proc.get_data_processed(
|
|
@@ -467,7 +500,6 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
467
500
|
pen=self.wplots.pen_bup,
|
|
468
501
|
name="B up",
|
|
469
502
|
)
|
|
470
|
-
self.wplots.tdo_inverse_field.setXRange(1 / upper_b, 1 / lower_b, padding=0.05)
|
|
471
503
|
|
|
472
504
|
def plot_fft(self):
|
|
473
505
|
"""Plot FFT in 1/B."""
|
|
@@ -490,15 +522,35 @@ class MainWindow(gui.BaseMainWindow):
|
|
|
490
522
|
name="B up",
|
|
491
523
|
)
|
|
492
524
|
|
|
525
|
+
@pyqtSlot()
|
|
493
526
|
def syncroi_changed(self):
|
|
494
527
|
"""Update fit and FFT windows sync. status."""
|
|
495
528
|
self.wplots._sync_roi = self.wconfiguration.syncroi_parameter.value()
|
|
496
529
|
|
|
530
|
+
@pyqtSlot()
|
|
531
|
+
def update_spectro_time_window(self):
|
|
532
|
+
"""Update the spectro. nperseg setting expressed in time."""
|
|
533
|
+
if not self.check_data_loaded():
|
|
534
|
+
return
|
|
535
|
+
if "fs_signal" not in self.worker.proc.metadata:
|
|
536
|
+
return
|
|
537
|
+
else:
|
|
538
|
+
fs = self.worker.proc.metadata["fs_signal"]
|
|
539
|
+
|
|
540
|
+
self.wconfiguration.host_parameters["spectro_time_window"] = (
|
|
541
|
+
self.wconfiguration.settings_parameters["spectro_nperseg"] / fs
|
|
542
|
+
)
|
|
543
|
+
|
|
497
544
|
def check_tdo_extracted(self) -> bool:
|
|
498
545
|
if not self.check_data_loaded():
|
|
499
546
|
return False
|
|
500
547
|
return self.worker.proc._check_barycenters_computed()
|
|
501
548
|
|
|
549
|
+
def check_tdo_detrended(self) -> bool:
|
|
550
|
+
if not self.check_tdo_extracted():
|
|
551
|
+
return False
|
|
552
|
+
return self.worker.proc._check_tdo_detrended()
|
|
553
|
+
|
|
502
554
|
def dropEvent(self, e):
|
|
503
555
|
for url in e.mimeData().urls():
|
|
504
556
|
file_path = url.toLocalFile()
|
|
@@ -10,6 +10,7 @@ from ..processors import TDOProcessor
|
|
|
10
10
|
class DataWorker(QObject):
|
|
11
11
|
sig_load_finished = pyqtSignal()
|
|
12
12
|
sig_extract_finished = pyqtSignal()
|
|
13
|
+
sig_offset_finished = pyqtSignal()
|
|
13
14
|
sig_align_finished = pyqtSignal()
|
|
14
15
|
sig_removebg_finished = pyqtSignal()
|
|
15
16
|
sig_fft_finished = pyqtSignal()
|
|
@@ -42,6 +43,12 @@ class DataWorker(QObject):
|
|
|
42
43
|
self.proc.extract_tdo()
|
|
43
44
|
self.sig_extract_finished.emit()
|
|
44
45
|
|
|
46
|
+
@pyqtSlot()
|
|
47
|
+
def time_offset(self):
|
|
48
|
+
"""Apply time offset on experiment time vector."""
|
|
49
|
+
self.proc.apply_time_offset()
|
|
50
|
+
self.sig_offset_finished.emit()
|
|
51
|
+
|
|
45
52
|
def align_field(self):
|
|
46
53
|
self.proc.align_field()
|
|
47
54
|
self.sig_align_finished.emit()
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
"""
|
|
8
|
+
Configuration Parameter Tree for TDO experiments.
|
|
9
|
+
|
|
10
|
+
Base : pyuson.gui.widgets.BaseConfigurationWidget
|
|
11
|
+
|
|
12
|
+
Extra signals :
|
|
13
|
+
sig_syncroi_changed : emitted when the "Sync ROI" checkbox is changed.
|
|
14
|
+
sig_timeoffset_changed : emitted when the "Time offset" parameter is changed.
|
|
15
|
+
sig_fitdeg_changed : emitted when the n points interp 1/B parameter is changed.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
sig_syncroi_changed = pyqtSignal()
|
|
19
|
+
sig_timeoffset_changed = pyqtSignal()
|
|
20
|
+
sig_spectro_nperseg_changed = pyqtSignal()
|
|
21
|
+
sig_fitdeg_changed = pyqtSignal()
|
|
22
|
+
sig_npoints_interp_changed = pyqtSignal()
|
|
23
|
+
sig_curveoffset_changed = pyqtSignal()
|
|
24
|
+
|
|
25
|
+
def __init__(self, param_content: type):
|
|
26
|
+
super().__init__(param_content)
|
|
27
|
+
|
|
28
|
+
self.add_extra_parameters()
|
|
29
|
+
self.connect_extras()
|
|
30
|
+
|
|
31
|
+
def add_extra_parameters(self):
|
|
32
|
+
"""Add extra parameters used only in the GUI."""
|
|
33
|
+
# Sync ROIs parameter
|
|
34
|
+
self.syncroi_parameter = Parameter.create(
|
|
35
|
+
name="syncroi",
|
|
36
|
+
type="bool",
|
|
37
|
+
value=False,
|
|
38
|
+
title="Sync. fit and FFT field-window",
|
|
39
|
+
)
|
|
40
|
+
self.host_parameters.addChild(self.syncroi_parameter)
|
|
41
|
+
|
|
42
|
+
# Show nperseg parameter in µs
|
|
43
|
+
nperseg = Parameter.create(
|
|
44
|
+
name="spectro_time_window",
|
|
45
|
+
type="float",
|
|
46
|
+
readonly=True,
|
|
47
|
+
value=1024 / 100e6,
|
|
48
|
+
suffix="s",
|
|
49
|
+
siPrefix=True,
|
|
50
|
+
title="Spectro: time window (n/persegment)",
|
|
51
|
+
)
|
|
52
|
+
self.host_parameters.addChild(nperseg)
|
|
53
|
+
|
|
54
|
+
def connect_extras(self):
|
|
55
|
+
"""Extra connections."""
|
|
56
|
+
self.syncroi_parameter.sigValueChanged.connect(self.sig_syncroi_changed.emit)
|
|
57
|
+
self.settings_parameters.child("time_offset").sigValueChanged.connect(
|
|
58
|
+
self.sig_timeoffset_changed.emit
|
|
59
|
+
)
|
|
60
|
+
self.settings_parameters.child("spectro_nperseg").sigValueChanged.connect(
|
|
61
|
+
self.sig_spectro_nperseg_changed.emit
|
|
62
|
+
)
|
|
63
|
+
self.settings_parameters.child("poly_deg").sigValueChanged.connect(
|
|
64
|
+
self.sig_fitdeg_changed.emit
|
|
65
|
+
)
|
|
66
|
+
self.settings_parameters.child(
|
|
67
|
+
"npoints_interp_inverse"
|
|
68
|
+
).sigValueChanged.connect(self.sig_npoints_interp_changed.emit)
|
|
69
|
+
self.settings_parameters.child("offset").sigValueChanged.connect(
|
|
70
|
+
self.sig_curveoffset_changed.emit
|
|
71
|
+
)
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import pyqtgraph as pg
|
|
4
4
|
from PyQt6 import QtWidgets
|
|
5
|
-
from PyQt6.QtCore import
|
|
5
|
+
from PyQt6.QtCore import pyqtSignal, pyqtSlot
|
|
6
|
+
from pyuson import gui
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
class GraphsWidget(
|
|
9
|
+
class GraphsWidget(gui.widgets.BaseGraphsWidget):
|
|
9
10
|
"""
|
|
10
11
|
The graphs area with all the plots.
|
|
11
12
|
|
|
@@ -22,8 +23,7 @@ class GraphsWidget(QtWidgets.QWidget):
|
|
|
22
23
|
super().__init__()
|
|
23
24
|
|
|
24
25
|
# Flags
|
|
25
|
-
self.
|
|
26
|
-
self._sync_roi = True
|
|
26
|
+
self._sync_roi = False
|
|
27
27
|
|
|
28
28
|
# Create grid
|
|
29
29
|
grid = QtWidgets.QGridLayout()
|
|
@@ -34,8 +34,7 @@ class GraphsWidget(QtWidgets.QWidget):
|
|
|
34
34
|
tdo_tab = self.create_tdo_plot()
|
|
35
35
|
fft_tab = self.create_fft_plot()
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
self.init_plot_style()
|
|
37
|
+
self.init_coordinates_on_hover()
|
|
39
38
|
|
|
40
39
|
# Add Tabs to the grid
|
|
41
40
|
grid.addWidget(field_tab, 0, 0, 1, 1)
|
|
@@ -54,16 +53,6 @@ class GraphsWidget(QtWidgets.QWidget):
|
|
|
54
53
|
# Create widget
|
|
55
54
|
self.setLayout(grid)
|
|
56
55
|
|
|
57
|
-
@property
|
|
58
|
-
def time2frame_scale(self) -> float:
|
|
59
|
-
return self._time2frame_scale
|
|
60
|
-
|
|
61
|
-
@time2frame_scale.setter
|
|
62
|
-
def time2frame_scale(self, value: float):
|
|
63
|
-
self._time2frame_scale = value
|
|
64
|
-
self.field.getAxis("top").setScale(self.time2frame_scale)
|
|
65
|
-
self.dfield.getAxis("top").setScale(self.time2frame_scale)
|
|
66
|
-
|
|
67
56
|
def create_field_plot(self) -> QtWidgets.QTabWidget:
|
|
68
57
|
tab = QtWidgets.QTabWidget(self)
|
|
69
58
|
|
|
@@ -72,12 +61,14 @@ class GraphsWidget(QtWidgets.QWidget):
|
|
|
72
61
|
self.field.setLabel("bottom", "time (s)")
|
|
73
62
|
self.field.setLabel("left", "field (T)")
|
|
74
63
|
self.field.showGrid(y=True)
|
|
64
|
+
self._plots_list.add(self.field)
|
|
75
65
|
|
|
76
66
|
# pickup coil voltage (measured)
|
|
77
67
|
self.dfield = pg.PlotWidget(title="Pickup")
|
|
78
68
|
self.dfield.setLabel("bottom", "time (s)")
|
|
79
69
|
self.dfield.setLabel("left", "pickup (V)")
|
|
80
70
|
self.dfield.showGrid(y=True)
|
|
71
|
+
self._plots_list.add(self.dfield)
|
|
81
72
|
|
|
82
73
|
tab.addTab(self.field, "B(t)")
|
|
83
74
|
tab.addTab(self.dfield, "Pickup")
|
|
@@ -92,16 +83,21 @@ class GraphsWidget(QtWidgets.QWidget):
|
|
|
92
83
|
self.sig_field.setLabel("bottom", "field (T)")
|
|
93
84
|
self.sig_field.setLabel("left", "TDO frequency (Hz)")
|
|
94
85
|
self.sig_field.showGrid(y=True)
|
|
95
|
-
|
|
86
|
+
# Field-window selector
|
|
87
|
+
self.roi = pg.LinearRegionItem(brush=pg.mkBrush("#0000ff1a"))
|
|
88
|
+
self.roi.hoverEvent = lambda *args, **kwargs: None # disable mouse drag
|
|
89
|
+
self.roi.mouseDragEvent = lambda *args, **kwargs: None # disable mouse drag
|
|
96
90
|
self.sig_field.addItem(self.roi, ignoreBounds=True)
|
|
97
91
|
self.roi.sigRegionChangeFinished.connect(self.roi1_changed)
|
|
98
92
|
self.sig_field.getPlotItem().addLegend()
|
|
93
|
+
self._plots_list.add(self.sig_field)
|
|
99
94
|
|
|
100
95
|
# TDO signal versus time
|
|
101
96
|
self.sig_time = pg.PlotWidget(title="Signal versus time")
|
|
102
97
|
self.sig_time.setLabel("bottom", "time (s)")
|
|
103
98
|
self.sig_time.setLabel("left", "TDO frequency (Hz)")
|
|
104
99
|
self.sig_time.showGrid(y=True)
|
|
100
|
+
self._plots_list.add(self.sig_time)
|
|
105
101
|
|
|
106
102
|
tab.addTab(self.sig_field, "TDO(B)")
|
|
107
103
|
tab.addTab(self.sig_time, "TDO(t)")
|
|
@@ -117,15 +113,25 @@ class GraphsWidget(QtWidgets.QWidget):
|
|
|
117
113
|
self.tdo_field.setLabel("left", "TDO detrended")
|
|
118
114
|
self.tdo_field.showGrid(y=True)
|
|
119
115
|
self.tdo_field.getPlotItem().addLegend()
|
|
120
|
-
|
|
116
|
+
# Field-window selector for FFT range
|
|
117
|
+
self.roi2 = pg.LinearRegionItem(brush=pg.mkBrush("#0000ff1a"))
|
|
118
|
+
self.roi2.hoverEvent = lambda *args, **kwargs: None # disable mouse drag
|
|
119
|
+
self.roi2.mouseDragEvent = lambda *args, **kwargs: None # disable mouse drag
|
|
121
120
|
self.tdo_field.addItem(self.roi2, ignoreBounds=True)
|
|
122
121
|
self.roi2.sigRegionChangeFinished.connect(self.roi2_changed)
|
|
122
|
+
# Vertical lines to show polynomial fit range
|
|
123
|
+
self.fit_bounds1 = pg.InfiniteLine(pen=self.pen_fitbounds, movable=False)
|
|
124
|
+
self.fit_bounds2 = pg.InfiniteLine(pen=self.pen_fitbounds, movable=False)
|
|
125
|
+
self.tdo_field.addItem(self.fit_bounds1)
|
|
126
|
+
self.tdo_field.addItem(self.fit_bounds2)
|
|
127
|
+
self._plots_list.add(self.tdo_field)
|
|
123
128
|
|
|
124
129
|
# vs 1/B
|
|
125
130
|
self.tdo_inverse_field = pg.PlotWidget(title="Oscillatory part versus 1/B")
|
|
126
131
|
self.tdo_inverse_field.setLabel("bottom", "1/B (T^-1)")
|
|
127
132
|
self.tdo_inverse_field.setLabel("left", "TDO detrended")
|
|
128
133
|
self.tdo_inverse_field.showGrid(y=True)
|
|
134
|
+
self._plots_list.add(self.tdo_inverse_field)
|
|
129
135
|
|
|
130
136
|
tab.addTab(self.tdo_field, "TDO detrended(B)")
|
|
131
137
|
tab.addTab(self.tdo_inverse_field, "TDO detrended(1/B)")
|
|
@@ -141,6 +147,7 @@ class GraphsWidget(QtWidgets.QWidget):
|
|
|
141
147
|
self.fft.setLabel("left", "magnitude")
|
|
142
148
|
self.fft.showGrid(y=True)
|
|
143
149
|
self.fft.getPlotItem().addLegend()
|
|
150
|
+
self._plots_list.add(self.fft)
|
|
144
151
|
|
|
145
152
|
tab.addTab(self.fft, "FFT")
|
|
146
153
|
|
|
@@ -154,15 +161,18 @@ class GraphsWidget(QtWidgets.QWidget):
|
|
|
154
161
|
self.pen_bdown = pg.mkPen("#d62728ff", width=w0)
|
|
155
162
|
self.pen_fitbup = pg.mkPen("#2ca02cb1", width=w0)
|
|
156
163
|
self.pen_fitdown = pg.mkPen("#d62728b1", width=w0)
|
|
164
|
+
self.pen_fitbounds = pg.mkPen("#7477ed99", width=w0)
|
|
157
165
|
|
|
158
166
|
@pyqtSlot()
|
|
159
167
|
def roi1_changed(self):
|
|
160
168
|
"""Update ROI in the TDO detrended panel when the ROI in the TDO panel moved."""
|
|
169
|
+
roi1 = self.roi.getRegion() # TDO panel
|
|
170
|
+
self.fit_bounds1.setPos(roi1[0])
|
|
171
|
+
self.fit_bounds2.setPos(roi1[1])
|
|
161
172
|
self.sig_roi1_changed.emit()
|
|
162
173
|
if not self._sync_roi:
|
|
163
174
|
return
|
|
164
175
|
|
|
165
|
-
roi1 = self.roi.getRegion() # TDO panel
|
|
166
176
|
roi2 = self.roi2.getRegion() # TDO detrend panel
|
|
167
177
|
|
|
168
178
|
if roi1 != roi2:
|
|
@@ -190,52 +200,3 @@ class GraphsWidget(QtWidgets.QWidget):
|
|
|
190
200
|
"""Disable moving ROIs."""
|
|
191
201
|
self.roi.setMovable(False)
|
|
192
202
|
self.roi2.setMovable(False)
|
|
193
|
-
|
|
194
|
-
def clear_all_plots(self):
|
|
195
|
-
"""Clear plots."""
|
|
196
|
-
self.field.clearPlots()
|
|
197
|
-
self.dfield.clearPlots()
|
|
198
|
-
self.sig_time.clearPlots()
|
|
199
|
-
self.sig_field.clearPlots()
|
|
200
|
-
self.tdo_field.clearPlots()
|
|
201
|
-
self.tdo_inverse_field.clearPlots()
|
|
202
|
-
self.fft.clearPlots()
|
|
203
|
-
|
|
204
|
-
def event(self, ev: QEvent | None):
|
|
205
|
-
"""Handle mouse selection while holding CTRL to make a ROI zoom in plots."""
|
|
206
|
-
if ev is None:
|
|
207
|
-
return super().event(None)
|
|
208
|
-
|
|
209
|
-
# Switch to rectangular zoom selection on the first Ctrl key press event
|
|
210
|
-
if ev.type() == QEvent.Type.KeyPress and ev.key() == Qt.Key.Key_Control:
|
|
211
|
-
if self._mouse_pan_mode:
|
|
212
|
-
self.switch_mouse_pan_mode(False)
|
|
213
|
-
|
|
214
|
-
# Switch back to pan mode on left click when releasing the Ctrl key
|
|
215
|
-
if ev.type() == QEvent.Type.KeyRelease and ev.key() == Qt.Key.Key_Control:
|
|
216
|
-
self.switch_mouse_pan_mode(True)
|
|
217
|
-
|
|
218
|
-
return super().event(ev)
|
|
219
|
-
|
|
220
|
-
def switch_mouse_pan_mode(self, state: bool):
|
|
221
|
-
"""
|
|
222
|
-
Switch mouse behavior from panning to ROI-zooming when holding CTRL.
|
|
223
|
-
|
|
224
|
-
Parameters
|
|
225
|
-
----------
|
|
226
|
-
state : bool
|
|
227
|
-
If True, all plots are set to pan mode, otherwise they are set in ROI-zoom
|
|
228
|
-
mode.
|
|
229
|
-
"""
|
|
230
|
-
# Get mode
|
|
231
|
-
mode = pg.ViewBox.PanMode if state else pg.ViewBox.RectMode
|
|
232
|
-
self._mouse_pan_mode = state
|
|
233
|
-
|
|
234
|
-
# Set mode
|
|
235
|
-
self.field.getPlotItem().getViewBox().setMouseMode(mode)
|
|
236
|
-
self.dfield.getPlotItem().getViewBox().setMouseMode(mode)
|
|
237
|
-
self.sig_time.getPlotItem().getViewBox().setMouseMode(mode)
|
|
238
|
-
self.sig_field.getPlotItem().getViewBox().setMouseMode(mode)
|
|
239
|
-
self.tdo_field.getPlotItem().getViewBox().setMouseMode(mode)
|
|
240
|
-
self.tdo_inverse_field.getPlotItem().getViewBox().setMouseMode(mode)
|
|
241
|
-
self.fft.getPlotItem().getViewBox().setMouseMode(mode)
|
|
@@ -28,29 +28,12 @@ class ParamContent(BaseParamContent):
|
|
|
28
28
|
siPrefix=True,
|
|
29
29
|
title="Max. time",
|
|
30
30
|
),
|
|
31
|
-
dict(
|
|
32
|
-
name="barycenters_fwindow",
|
|
33
|
-
type="float",
|
|
34
|
-
limits=[0, np.inf],
|
|
35
|
-
step=1e3,
|
|
36
|
-
value=1,
|
|
37
|
-
suffix="Hz",
|
|
38
|
-
siPrefix=True,
|
|
39
|
-
title="Barycenters: frequency window",
|
|
40
|
-
),
|
|
41
|
-
dict(
|
|
42
|
-
name="barycenters_fast",
|
|
43
|
-
type="bool",
|
|
44
|
-
limits=[True, False],
|
|
45
|
-
value=True,
|
|
46
|
-
title="Barycenters: fast algo.",
|
|
47
|
-
),
|
|
48
31
|
dict(
|
|
49
32
|
name="spectro_nperseg",
|
|
50
33
|
type="int",
|
|
51
|
-
limits=[
|
|
34
|
+
limits=[0, np.inf],
|
|
52
35
|
value=1024,
|
|
53
|
-
step=
|
|
36
|
+
step=512,
|
|
54
37
|
title="Spectro: n/segment",
|
|
55
38
|
),
|
|
56
39
|
dict(
|
|
@@ -59,7 +42,7 @@ class ParamContent(BaseParamContent):
|
|
|
59
42
|
limits=[2, np.inf],
|
|
60
43
|
value=2048,
|
|
61
44
|
step=1024,
|
|
62
|
-
title="Spectro: FFT
|
|
45
|
+
title="Spectro: FFT padding size",
|
|
63
46
|
),
|
|
64
47
|
dict(
|
|
65
48
|
name="spectro_noverlap",
|
|
@@ -67,7 +50,34 @@ class ParamContent(BaseParamContent):
|
|
|
67
50
|
limits=[-1, np.inf],
|
|
68
51
|
value=-1,
|
|
69
52
|
step=512,
|
|
70
|
-
title="Spectro: n overlap",
|
|
53
|
+
title="Spectro: n overlap (-1 : n/2)",
|
|
54
|
+
),
|
|
55
|
+
dict(
|
|
56
|
+
name="barycenters_fwindow",
|
|
57
|
+
type="float",
|
|
58
|
+
limits=[0, np.inf],
|
|
59
|
+
step=1e3,
|
|
60
|
+
value=1,
|
|
61
|
+
suffix="Hz",
|
|
62
|
+
siPrefix=True,
|
|
63
|
+
title="Barycenters: frequency window",
|
|
64
|
+
),
|
|
65
|
+
dict(
|
|
66
|
+
name="barycenters_fast",
|
|
67
|
+
type="bool",
|
|
68
|
+
limits=[True, False],
|
|
69
|
+
value=True,
|
|
70
|
+
title="Barycenters: fast algo.",
|
|
71
|
+
),
|
|
72
|
+
dict(
|
|
73
|
+
name="time_offset",
|
|
74
|
+
type="float",
|
|
75
|
+
limits=[-np.inf, np.inf],
|
|
76
|
+
suffix="s",
|
|
77
|
+
siPrefix=True,
|
|
78
|
+
value=0e-6,
|
|
79
|
+
step=0.5e-6,
|
|
80
|
+
title="TDO/Pickup time offset",
|
|
71
81
|
),
|
|
72
82
|
dict(name="poly_window", type="str", value="", title="Fit: field window"),
|
|
73
83
|
dict(
|
|
@@ -107,7 +117,7 @@ class ParamContent(BaseParamContent):
|
|
|
107
117
|
limits=[1, np.inf],
|
|
108
118
|
suffix="T",
|
|
109
119
|
siPrefix=True,
|
|
110
|
-
title="Max. B-frequency",
|
|
120
|
+
title="FFT : Max. B-frequency",
|
|
111
121
|
),
|
|
112
122
|
dict(
|
|
113
123
|
name="offset",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""TDO Processor class to analyse TDO experiments."""
|
|
2
2
|
|
|
3
|
+
import gc
|
|
3
4
|
import logging
|
|
4
5
|
from collections.abc import Callable
|
|
5
6
|
from pathlib import Path
|
|
@@ -25,7 +26,6 @@ MEAS_TO_CROP = (
|
|
|
25
26
|
|
|
26
27
|
TDO_SIGNAL_NAME = "tdo_signal" # name of the TDO signal (the frequencies barycenters)
|
|
27
28
|
PROGRAM_NAME = "pytdo"
|
|
28
|
-
OUT_FORMAT = (".csv", ".tsv", ".txt", ".out")
|
|
29
29
|
CSV_TDO_NCOLS = 3
|
|
30
30
|
CSV_RES_NCOLS = 11
|
|
31
31
|
|
|
@@ -59,9 +59,11 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
59
59
|
|
|
60
60
|
@expid.setter
|
|
61
61
|
def expid(self, value: str):
|
|
62
|
-
"""Setter for expid
|
|
62
|
+
"""Setter for `expid`."""
|
|
63
63
|
self.cfg.expid = value
|
|
64
64
|
self.cfg.build_filenames()
|
|
65
|
+
self._reinit()
|
|
66
|
+
logger.info(f"Experiment ID set to {self.expid}.")
|
|
65
67
|
|
|
66
68
|
@property
|
|
67
69
|
def data_directory(self) -> Path:
|
|
@@ -73,6 +75,8 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
73
75
|
"""Setter for `data_directory`."""
|
|
74
76
|
self.cfg.data_directory = Path(value)
|
|
75
77
|
self.cfg.build_filenames()
|
|
78
|
+
self._reinit()
|
|
79
|
+
logger.info(f"Data directory set to {self.data_directory}.")
|
|
76
80
|
|
|
77
81
|
def load_pickup(self) -> Self:
|
|
78
82
|
"""
|
|
@@ -368,32 +372,53 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
368
372
|
logger.error("Spectrogram not computed. Run `compute_spectrogram()` first")
|
|
369
373
|
return self
|
|
370
374
|
|
|
375
|
+
# Get parameters to log
|
|
376
|
+
fxx = self.get_data_processed("spectro_f")
|
|
377
|
+
freq_window = self.cfg.settings.barycenters_fwindow
|
|
378
|
+
nsamples = int(freq_window / np.mean(np.diff(fxx)))
|
|
371
379
|
logger.info(
|
|
372
|
-
"Finding spectrogram barycenters (frequency-window size : "
|
|
373
|
-
f"{
|
|
380
|
+
"Finding spectrogram barycenters (frequency-window half-size : "
|
|
381
|
+
f"{freq_window:2.3f}Hz, {nsamples} samples)..."
|
|
374
382
|
)
|
|
383
|
+
# Get barycenters
|
|
375
384
|
self.set_data_processed(
|
|
376
385
|
self._tdo_name,
|
|
377
386
|
sp.find_barycenters(
|
|
378
|
-
|
|
387
|
+
fxx,
|
|
379
388
|
self.get_data_processed("spectro_s"),
|
|
380
|
-
|
|
389
|
+
freq_window,
|
|
381
390
|
fast=self.cfg.settings.barycenters_fast,
|
|
382
391
|
),
|
|
383
392
|
)
|
|
384
|
-
# Corresponding time vector
|
|
385
|
-
|
|
386
|
-
self.set_data_processed("time_exp", time_tdo - time_tdo[0])
|
|
393
|
+
# Corresponding time vector
|
|
394
|
+
self.apply_time_offset()
|
|
387
395
|
|
|
388
|
-
# Remove previously-computed values based on this TDO signal
|
|
389
|
-
self.remove_data_processed(self._tdo_name + "_fit_inc")
|
|
390
|
-
self.remove_data_processed(self._tdo_name + "_fit_dec")
|
|
391
|
-
self.remove_data_processed(self._tdo_det_inc_name)
|
|
392
|
-
self.remove_data_processed(self._tdo_det_dec_name)
|
|
393
396
|
logger.info("TDO signal extracted.")
|
|
394
397
|
|
|
395
398
|
return self
|
|
396
399
|
|
|
400
|
+
def extract_tdo(self) -> Self:
|
|
401
|
+
"""Helper function that does everything required to extract the TDO signal."""
|
|
402
|
+
self.compute_spectrogram().find_barycenters()
|
|
403
|
+
|
|
404
|
+
return self
|
|
405
|
+
|
|
406
|
+
def apply_time_offset(self) -> Self:
|
|
407
|
+
"""Apply offset on the experiment time vector."""
|
|
408
|
+
if not self.get_data_processed("spectro_t", checkonly=True):
|
|
409
|
+
logger.warning("Spectrogram was not computed.")
|
|
410
|
+
return self
|
|
411
|
+
|
|
412
|
+
logger.info("Applying offset on time vector...")
|
|
413
|
+
time_tdo = self.get_data_processed("spectro_t")
|
|
414
|
+
self.set_data_processed("time_exp", time_tdo - self.cfg.settings.time_offset)
|
|
415
|
+
self.align_field()
|
|
416
|
+
logger.info(
|
|
417
|
+
f"Applied a {self.cfg.settings.time_offset * 1e6}µs PU/TDO time offset"
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
return self
|
|
421
|
+
|
|
397
422
|
def align_field(self) -> Self:
|
|
398
423
|
"""Align magnetic field on the `time_exp` vector."""
|
|
399
424
|
if not self._check_field_computed():
|
|
@@ -417,6 +442,9 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
417
442
|
# Get the up / down indices
|
|
418
443
|
self.get_up_down_indices()
|
|
419
444
|
|
|
445
|
+
# Remove previously-computed values based on this TDO signal
|
|
446
|
+
self._remove_data_changed()
|
|
447
|
+
|
|
420
448
|
return self
|
|
421
449
|
|
|
422
450
|
def get_up_down_indices(self) -> Self:
|
|
@@ -445,6 +473,14 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
445
473
|
b1, b2 = self.cfg.settings.poly_window
|
|
446
474
|
deg = self.cfg.settings.poly_deg
|
|
447
475
|
|
|
476
|
+
# Checks
|
|
477
|
+
maxfield = self.get_data_processed("magfield").max()
|
|
478
|
+
if b1 > maxfield:
|
|
479
|
+
logger.error(
|
|
480
|
+
f"Field window lower bound is {b1}T but max field is {maxfield}T"
|
|
481
|
+
)
|
|
482
|
+
return self
|
|
483
|
+
|
|
448
484
|
# Fit and detrend
|
|
449
485
|
logger.info(
|
|
450
486
|
f"Fitting (degree : {deg}) and detrending TDO signal in {b1, b2}T..."
|
|
@@ -480,6 +516,9 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
480
516
|
# Checks
|
|
481
517
|
if not self._check_tdo_detrended():
|
|
482
518
|
self.detrend_polyfit()
|
|
519
|
+
if not self._check_tdo_detrended():
|
|
520
|
+
logger.error("TDO signal could not be detrended, check messages above")
|
|
521
|
+
return self
|
|
483
522
|
|
|
484
523
|
# Get parameters
|
|
485
524
|
b1, b2 = self.cfg.settings.fft_window
|
|
@@ -520,15 +559,20 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
520
559
|
|
|
521
560
|
return self
|
|
522
561
|
|
|
562
|
+
def remove_background(self) -> Self:
|
|
563
|
+
"""Helper function to detrend the signal and sort signal in 1/B."""
|
|
564
|
+
self.detrend_polyfit().oversample_inverse_field()
|
|
565
|
+
|
|
566
|
+
return self
|
|
567
|
+
|
|
523
568
|
def fft_inverse_field(self) -> Self:
|
|
524
569
|
"""
|
|
525
570
|
FFT on the signal in 1/B.
|
|
526
571
|
|
|
527
572
|
The resulting "frequencies" are therefore in units of B (teslas).
|
|
528
573
|
"""
|
|
529
|
-
#
|
|
530
|
-
|
|
531
|
-
self.oversample_inverse_field()
|
|
574
|
+
# Force oversample inverese field to update parameters
|
|
575
|
+
self.oversample_inverse_field()
|
|
532
576
|
|
|
533
577
|
# FFT
|
|
534
578
|
logger.info("FFT on TDO signal in 1/B...")
|
|
@@ -563,18 +607,6 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
563
607
|
|
|
564
608
|
return self
|
|
565
609
|
|
|
566
|
-
def extract_tdo(self) -> Self:
|
|
567
|
-
"""Helper function that does everything required to extract the TDO signal."""
|
|
568
|
-
self.compute_spectrogram().find_barycenters().align_field()
|
|
569
|
-
|
|
570
|
-
return self
|
|
571
|
-
|
|
572
|
-
def remove_background(self) -> Self:
|
|
573
|
-
"""Helper function to detrend the signal and sort signal in 1/B."""
|
|
574
|
-
self.detrend_polyfit().oversample_inverse_field()
|
|
575
|
-
|
|
576
|
-
return self
|
|
577
|
-
|
|
578
610
|
def collect_arrays(self, array_names_list: list[str]) -> list[np.ndarray]:
|
|
579
611
|
"""Collect and data in `data_processed`."""
|
|
580
612
|
return [self.get_data_processed(name) for name in array_names_list]
|
|
@@ -592,7 +624,7 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
592
624
|
If the file already exists, it is overwritten.
|
|
593
625
|
"""
|
|
594
626
|
if filename is None:
|
|
595
|
-
filename = self.get_csv_filename(suffix="-
|
|
627
|
+
filename = self.get_csv_filename(suffix="-out")
|
|
596
628
|
|
|
597
629
|
logger.info("Saving extracted TDO signal...")
|
|
598
630
|
|
|
@@ -619,6 +651,19 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
619
651
|
|
|
620
652
|
return self
|
|
621
653
|
|
|
654
|
+
def _remove_data_changed(self):
|
|
655
|
+
"""Remove data that was computed but the data it relied on changed."""
|
|
656
|
+
self.remove_data_processed(self._tdo_name + "_fit_inc")
|
|
657
|
+
self.remove_data_processed(self._tdo_name + "_fit_dec")
|
|
658
|
+
self.remove_data_processed(self._tdo_det_inc_name)
|
|
659
|
+
self.remove_data_processed(self._tdo_det_dec_name)
|
|
660
|
+
self.remove_data_processed(self._tdo_inv_inc_name)
|
|
661
|
+
self.remove_data_processed(self._tdo_inv_dec_name)
|
|
662
|
+
self.remove_data_processed("bfreq_inc")
|
|
663
|
+
self.remove_data_processed("bfreq_dec")
|
|
664
|
+
self.remove_data_processed("fft_inc")
|
|
665
|
+
self.remove_data_processed("fft_dec")
|
|
666
|
+
|
|
622
667
|
def _get_result_names_list(self, ud: Literal["inc", "dec"]):
|
|
623
668
|
"""
|
|
624
669
|
Generate the list of things to save.
|
|
@@ -719,6 +764,7 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
719
764
|
return
|
|
720
765
|
|
|
721
766
|
logger.info(f"Reading data from {filepath.name}...")
|
|
767
|
+
self._reinit()
|
|
722
768
|
status = reader(filepath, sep=delimiter)
|
|
723
769
|
if not status:
|
|
724
770
|
logger.error(f"Failed to read {filepath.name}, check messages above")
|
|
@@ -782,9 +828,6 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
782
828
|
)
|
|
783
829
|
self.set_data_processed("magfield_time", self.get_data_processed("time_exp"))
|
|
784
830
|
|
|
785
|
-
# Get the up / down indices
|
|
786
|
-
self.get_up_down_indices()
|
|
787
|
-
|
|
788
831
|
return True
|
|
789
832
|
|
|
790
833
|
def _load_csv_legacy_results(self, filepath: Path, sep: str = ",") -> bool:
|
|
@@ -995,3 +1038,12 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
|
|
|
995
1038
|
return self.get_data_processed(
|
|
996
1039
|
self._tdo_inv_inc_name, checkonly=True
|
|
997
1040
|
) and self.get_data_processed(self._tdo_inv_dec_name, checkonly=True)
|
|
1041
|
+
|
|
1042
|
+
def _reinit(self):
|
|
1043
|
+
"""Clear data and initialize objects."""
|
|
1044
|
+
self._init()
|
|
1045
|
+
|
|
1046
|
+
self.inds_inc = slice(-1)
|
|
1047
|
+
self.inds_dec = slice(-1)
|
|
1048
|
+
|
|
1049
|
+
gc.collect()
|
|
@@ -1,20 +0,0 @@
|
|
|
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)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|