pytdo 0.2.7__tar.gz → 0.2.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pytdo
3
- Version: 0.2.7
3
+ Version: 0.2.9
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>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pytdo"
3
- version = "0.2.7"
3
+ version = "0.2.9"
4
4
  description = "Add your description here"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -545,6 +545,18 @@ class MainWindow(gui.BaseMainWindow):
545
545
  self.wconfiguration.settings_parameters["spectro_nperseg"] / fs
546
546
  )
547
547
 
548
+ @pyqtSlot(bool, str)
549
+ def select_file_in_browser(self, is_toml: bool, filepath: str):
550
+ """
551
+ Select a file and set it as a configuration file or a new experiment ID.
552
+
553
+ Callback for when the user double-click on a file in the "Files" tab.
554
+ """
555
+ if filepath.endswith(".csv"):
556
+ self.load_csv_file(filepath)
557
+ else:
558
+ super().select_file_in_browser(is_toml, filepath)
559
+
548
560
  def check_tdo_extracted(self) -> bool:
549
561
  if not self.check_data_loaded():
550
562
  return False
@@ -10,6 +10,21 @@ class GraphsWidget(gui.widgets.BaseGraphsWidget):
10
10
  """
11
11
  The graphs area with all the plots.
12
12
 
13
+ There are two tabs, one with :
14
+ - dB/dt
15
+ - B(t)
16
+ - TDO(t)
17
+ - TDO(B)
18
+ The other with :
19
+ - B(t)
20
+ - TDO(B)
21
+ - TDO_detrended(B)
22
+ - TDO_detrended(1/B)
23
+ - FFT
24
+
25
+ Since B(t) and TDO(B) are re-used, placeholders plots are created. They are replaced
26
+ when the tab is selected.
27
+
13
28
  Signals
14
29
  -------
15
30
  sig_roi1_changed : emits when the draggable field-window moved in tdo(B).
@@ -21,59 +36,87 @@ class GraphsWidget(gui.widgets.BaseGraphsWidget):
21
36
 
22
37
  def __init__(self):
23
38
  super().__init__()
24
-
25
39
  # Flags
26
40
  self._sync_roi = False
27
41
 
28
- # Create empty canvases in tabs
29
- field_tab = self.create_field_plot()
30
- signal_tab = self.create_signal_plot()
31
- tdo_tab = self.create_tdo_plot()
32
- fft_tab = self.create_fft_plot()
33
-
34
- self.customize_axis()
42
+ # Create layouts
43
+ widget1 = self.create_first_tab()
44
+ widget2 = self.create_second_tab()
35
45
 
36
- self.init_coordinates_on_hover()
46
+ # Create the tabs
47
+ tab = QtWidgets.QTabWidget(self)
48
+ tab.addTab(widget1, "TDO")
49
+ tab.addTab(widget2, "Oscillations")
50
+ tab.currentChanged.connect(self.move_plots) # replace placeholders
37
51
 
38
- # Create a main splitter for rows (vertical)
39
- main_splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Vertical)
52
+ layout = QtWidgets.QVBoxLayout(self)
53
+ layout.addWidget(tab)
54
+ self.setLayout(layout)
40
55
 
41
- # Create a top splitter for the first row (horizontal)
42
- top_splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Horizontal)
43
- top_splitter.addWidget(field_tab)
44
- top_splitter.addWidget(signal_tab)
45
- top_splitter.setStretchFactor(0, 1) # field_tab stretch factor
46
- # signal_tab spans 3 columns
47
- top_splitter.setStretchFactor(1, 3)
56
+ # Apply axes style
57
+ self.customize_axis()
58
+ self.init_coordinates_on_hover()
48
59
 
49
- # Create a bottom splitter for the second row (horizontal)
60
+ def create_first_tab(self) -> QtWidgets.QSplitter:
61
+ """Create the tab with the magnetic field and TDO signal."""
62
+ # Create the plots
63
+ self.create_field_plot()
64
+ self.create_signal_plot()
65
+
66
+ # Create splitter for the top row
67
+ self.tab1_top_splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Horizontal)
68
+ self.tab1_top_splitter.addWidget(self.dfield)
69
+ self.tab1_top_splitter.addWidget(self.field)
70
+ self.tab1_top_splitter.addWidget(self.sig_time)
71
+
72
+ # Create splitter for the bottom row
73
+ self.tab1_main_splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Vertical)
74
+ self.tab1_main_splitter.addWidget(self.tab1_top_splitter)
75
+ self.tab1_main_splitter.addWidget(self.sig_field)
76
+
77
+ # Adjust ratios
78
+ self.tab1_main_splitter.setStretchFactor(0, 1)
79
+ self.tab1_main_splitter.setStretchFactor(1, 2)
80
+
81
+ return self.tab1_main_splitter
82
+
83
+ def create_second_tab(self) -> QtWidgets.QSplitter:
84
+ """Create the tab with the detrended TDO signals and the FFT."""
85
+ self.create_tdo_plot()
86
+ self.create_fft_plot()
87
+
88
+ # Create splitter for the top row
89
+ self.tab2_top_splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Horizontal)
90
+ # Add the placeholders plots, they will be replaced when the tab is shown
91
+ self.tab2_top_splitter.addWidget(self._v2field)
92
+ self.tab2_top_splitter.addWidget(self._v2sig_field)
93
+
94
+ # Create splitter for the bottom row
50
95
  bottom_splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Horizontal)
51
- bottom_splitter.addWidget(tdo_tab)
52
- bottom_splitter.addWidget(fft_tab)
53
- # tdo_tab spans 2 columns
54
- bottom_splitter.setStretchFactor(0, 2)
55
- # fft_tab spans 2 columns
56
- bottom_splitter.setStretchFactor(1, 2)
57
-
58
- # Add the top and bottom splitters to the main splitter
59
- main_splitter.addWidget(top_splitter)
60
- main_splitter.addWidget(bottom_splitter)
61
- main_splitter.setStretchFactor(0, 1) # top row stretch factor
62
- main_splitter.setStretchFactor(1, 1) # bottom row stretch factor
63
-
64
- # Set the main splitter as the central widget
65
- layout = QtWidgets.QVBoxLayout()
66
- layout.addWidget(main_splitter)
67
- self.setLayout(layout)
96
+ bottom_splitter.addWidget(self.tdo_field)
97
+ bottom_splitter.addWidget(self.tdo_inverse_field)
98
+ bottom_splitter.addWidget(self.fft)
68
99
 
69
- def create_field_plot(self) -> QtWidgets.QTabWidget:
70
- tab = QtWidgets.QTabWidget(self)
100
+ # Create main splitter
101
+ self.tab2_main_splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Vertical)
102
+ self.tab2_main_splitter.addWidget(self.tab2_top_splitter)
103
+ self.tab2_main_splitter.addWidget(bottom_splitter)
104
+
105
+ return self.tab2_main_splitter
71
106
 
107
+ def create_field_plot(self) -> None:
72
108
  # magnetic field (integrated)
73
109
  self.field = pg.PlotWidget(title="Magnetic field")
74
110
  self.field.setLabel("bottom", "time (s)")
75
111
  self.field.setLabel("left", "field (T)")
76
112
  self._plots_list.add(self.field)
113
+ # magnetic field (placeholders)
114
+ self._v1field = pg.PlotWidget(title="Magnetic field")
115
+ self._v1field.setLabel("bottom", "time (s)")
116
+ self._v1field.setLabel("left", "field (T)")
117
+ self._v2field = pg.PlotWidget(title="Magnetic field")
118
+ self._v2field.setLabel("bottom", "time (s)")
119
+ self._v2field.setLabel("left", "field (T)")
77
120
 
78
121
  # pickup coil voltage (measured)
79
122
  self.dfield = pg.PlotWidget(title="Pickup")
@@ -81,20 +124,15 @@ class GraphsWidget(gui.widgets.BaseGraphsWidget):
81
124
  self.dfield.setLabel("left", "pickup (V)")
82
125
  self._plots_list.add(self.dfield)
83
126
 
84
- tab.addTab(self.field, "B(t)")
85
- tab.addTab(self.dfield, "Pickup")
86
-
87
- return tab
88
-
89
- def create_signal_plot(self) -> QtWidgets.QTabWidget:
90
- tab = QtWidgets.QTabWidget(self)
91
-
127
+ def create_signal_plot(self):
92
128
  # TDO signal versus field
93
129
  self.sig_field = pg.PlotWidget(title="Signal versus field")
94
130
  self.sig_field.setLabel("bottom", "field (T)")
95
131
  self.sig_field.setLabel("left", "TDO frequency (Hz)")
96
132
  # Field-window selector
97
- self.roi = pg.LinearRegionItem(brush=pg.mkBrush("#0000ff1a"), pen=self.pen_fitbounds)
133
+ self.roi = pg.LinearRegionItem(
134
+ brush=pg.mkBrush("#0000ff1a"), pen=self.pen_fitbounds
135
+ )
98
136
  self.roi.hoverEvent = lambda *args, **kwargs: None # disable mouse drag
99
137
  self.roi.mouseDragEvent = lambda *args, **kwargs: None # disable mouse drag
100
138
  self.sig_field.addItem(self.roi, ignoreBounds=True)
@@ -102,27 +140,30 @@ class GraphsWidget(gui.widgets.BaseGraphsWidget):
102
140
  self.sig_field.getPlotItem().addLegend()
103
141
  self._plots_list.add(self.sig_field)
104
142
 
143
+ # TDO signal versus field (placeholders)
144
+ self._v1sig_field = pg.PlotWidget(title="Signal versus field")
145
+ self._v1sig_field.setLabel("bottom", "field (T)")
146
+ self._v1sig_field.setLabel("left", "TDO frequency (Hz)")
147
+ self._v2sig_field = pg.PlotWidget(title="Signal versus field")
148
+ self._v2sig_field.setLabel("bottom", "field (T)")
149
+ self._v2sig_field.setLabel("left", "TDO frequency (Hz)")
150
+
105
151
  # TDO signal versus time
106
152
  self.sig_time = pg.PlotWidget(title="Signal versus time")
107
153
  self.sig_time.setLabel("bottom", "time (s)")
108
154
  self.sig_time.setLabel("left", "TDO frequency (Hz)")
109
155
  self._plots_list.add(self.sig_time)
110
156
 
111
- tab.addTab(self.sig_field, "TDO(B)")
112
- tab.addTab(self.sig_time, "TDO(t)")
113
-
114
- return tab
115
-
116
- def create_tdo_plot(self) -> QtWidgets.QTabWidget:
117
- tab = QtWidgets.QTabWidget(self)
118
-
157
+ def create_tdo_plot(self):
119
158
  # vs field
120
159
  self.tdo_field = pg.PlotWidget(title="Oscillatory part versus field")
121
160
  self.tdo_field.setLabel("bottom", "field (T)")
122
161
  self.tdo_field.setLabel("left", "TDO detrended")
123
162
  self.tdo_field.getPlotItem().addLegend()
124
163
  # Field-window selector for FFT range
125
- self.roi2 = pg.LinearRegionItem(brush=pg.mkBrush("#0000ff1a"))
164
+ self.roi2 = pg.LinearRegionItem(
165
+ brush=pg.mkBrush("#0000ff1a"), pen=self.pen_fftbounds
166
+ )
126
167
  self.roi2.hoverEvent = lambda *args, **kwargs: None # disable mouse drag
127
168
  self.roi2.mouseDragEvent = lambda *args, **kwargs: None # disable mouse drag
128
169
  self.tdo_field.addItem(self.roi2, ignoreBounds=True)
@@ -140,14 +181,7 @@ class GraphsWidget(gui.widgets.BaseGraphsWidget):
140
181
  self.tdo_inverse_field.setLabel("left", "TDO detrended")
141
182
  self._plots_list.add(self.tdo_inverse_field)
142
183
 
143
- tab.addTab(self.tdo_field, "TDO detrended(B)")
144
- tab.addTab(self.tdo_inverse_field, "TDO detrended(1/B)")
145
-
146
- return tab
147
-
148
- def create_fft_plot(self) -> QtWidgets.QTabWidget:
149
- tab = QtWidgets.QTabWidget(self)
150
-
184
+ def create_fft_plot(self):
151
185
  # vs field
152
186
  self.fft = pg.PlotWidget(title="Fourier transform")
153
187
  self.fft.setLabel("bottom", "B-frequency (T)")
@@ -155,10 +189,6 @@ class GraphsWidget(gui.widgets.BaseGraphsWidget):
155
189
  self.fft.getPlotItem().addLegend()
156
190
  self._plots_list.add(self.fft)
157
191
 
158
- tab.addTab(self.fft, "FFT")
159
-
160
- return tab
161
-
162
192
  def customize_axis(self):
163
193
  """Set a right axis and show the grid, for all the plots."""
164
194
  for plot in self._plots_list:
@@ -166,16 +196,17 @@ class GraphsWidget(gui.widgets.BaseGraphsWidget):
166
196
  plot.getAxis("right").setTicks([])
167
197
  plot.showGrid(y=True)
168
198
 
169
-
170
199
  def init_plot_style(self):
171
200
  """Set up PyQtGraph line styles."""
172
201
  w0 = 1
202
+ w1 = 2
173
203
  self.pen_field = pg.mkPen("#c7c7c7", width=w0)
174
204
  self.pen_bup = pg.mkPen("#2ca02cff", width=w0)
175
205
  self.pen_bdown = pg.mkPen("#d62728ff", width=w0)
176
206
  self.pen_fitbup = pg.mkPen("#2ca02cb1", width=w0)
177
207
  self.pen_fitdown = pg.mkPen("#d62728b1", width=w0)
178
- self.pen_fitbounds = pg.mkPen("#7477ed99", width=w0)
208
+ self.pen_fitbounds = pg.mkPen("#7477ed99", width=w1)
209
+ self.pen_fftbounds = pg.mkPen("#eddd86ff", width=w1)
179
210
 
180
211
  @pyqtSlot()
181
212
  def roi1_changed(self):
@@ -214,3 +245,19 @@ class GraphsWidget(gui.widgets.BaseGraphsWidget):
214
245
  """Disable moving ROIs."""
215
246
  self.roi.setMovable(False)
216
247
  self.roi2.setMovable(False)
248
+
249
+ @pyqtSlot(int)
250
+ def move_plots(self, index: int):
251
+ """Move plots from one tab to another, because a widget can't be copied."""
252
+ if index == 0:
253
+ # First tab
254
+ self.tab2_top_splitter.replaceWidget(0, self._v2field)
255
+ self.tab2_top_splitter.replaceWidget(1, self._v2sig_field)
256
+ self.tab1_top_splitter.replaceWidget(1, self.field)
257
+ self.tab1_main_splitter.replaceWidget(1, self.sig_field)
258
+ elif index == 1:
259
+ # Second tab
260
+ self.tab1_top_splitter.replaceWidget(1, self._v1field)
261
+ self.tab1_main_splitter.replaceWidget(1, self._v1sig_field)
262
+ self.tab2_top_splitter.replaceWidget(0, self.field)
263
+ self.tab2_top_splitter.replaceWidget(1, self.sig_field)
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