pytdo 0.2.2.2__tar.gz → 0.2.4__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.
Files changed (24) hide show
  1. {pytdo-0.2.2.2 → pytdo-0.2.4}/PKG-INFO +2 -2
  2. {pytdo-0.2.2.2 → pytdo-0.2.4}/pyproject.toml +2 -2
  3. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/assets/config_default.toml +6 -3
  4. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/config/models.py +4 -1
  5. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/gui/_core.py +45 -0
  6. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/gui/_workers.py +7 -0
  7. pytdo-0.2.4/src/pytdo/gui/widgets/_configuration_tab.py +58 -0
  8. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/gui/widgets/_param_content.py +29 -19
  9. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/processors/_tdo.py +62 -14
  10. pytdo-0.2.2.2/src/pytdo/gui/widgets/_configuration_tab.py +0 -20
  11. {pytdo-0.2.2.2 → pytdo-0.2.4}/README.md +0 -0
  12. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/__init__.py +0 -0
  13. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/__main__.py +0 -0
  14. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/config/__init__.py +0 -0
  15. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/config/_config.py +0 -0
  16. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/config/_types.py +0 -0
  17. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/gui/__init__.py +0 -0
  18. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/gui/widgets/__init__.py +0 -0
  19. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/gui/widgets/_graphs.py +0 -0
  20. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/gui/widgets/_main_buttons.py +0 -0
  21. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/processors/__init__.py +0 -0
  22. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/processors/_types.py +0 -0
  23. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/py.typed +0 -0
  24. {pytdo-0.2.2.2 → pytdo-0.2.4}/src/pytdo/sp.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pytdo
3
- Version: 0.2.2.2
3
+ Version: 0.2.4
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.0
13
+ Requires-Dist: pyuson>=0.7.1
14
14
  Requires-Python: >=3.12
15
15
  Description-Content-Type: text/markdown
16
16
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pytdo"
3
- version = "0.2.2.2"
3
+ version = "0.2.4"
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.0",
17
+ "pyuson>=0.7.1",
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
- barycenters_fwindow = 732421.875 # half size of the window to use around frequency maxima in spectrogram
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
- noise_window: Sequence[float]
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,10 @@ 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)
55
60
 
56
61
  def init_buttons(self):
57
62
  super().init_buttons()
@@ -86,6 +91,13 @@ class MainWindow(gui.BaseMainWindow):
86
91
  self.sig_worker_extract.connect(self.worker.extract_tdo)
87
92
  self.worker.sig_extract_finished.connect(self.extract_tdo_finished)
88
93
 
94
+ # Time offset
95
+ self.sig_worker_offset.connect(self.worker.time_offset)
96
+ self.worker.sig_offset_finished.connect(self.time_offset_finished)
97
+
98
+ # Field aligned
99
+ self.worker.sig_align_finished.connect(self.align_field_finished)
100
+
89
101
  # Remove background
90
102
  self.sig_worker_removebg.connect(self.worker.remove_background)
91
103
  self.worker.sig_removebg_finished.connect(self.remove_background_finished)
@@ -115,6 +127,7 @@ class MainWindow(gui.BaseMainWindow):
115
127
 
116
128
  @pyqtSlot()
117
129
  def align_field_finished(self):
130
+ self.plot_field()
118
131
  self.ind_bup = self.worker.proc.inds_inc
119
132
  self.ind_bdown = self.worker.proc.inds_dec
120
133
 
@@ -130,6 +143,22 @@ class MainWindow(gui.BaseMainWindow):
130
143
 
131
144
  self.enable_buttons()
132
145
 
146
+ @pyqtSlot()
147
+ def apply_time_offset(self):
148
+ if not self.check_data_loaded():
149
+ return
150
+ self.disable_buttons()
151
+ self.sig_worker_offset.emit()
152
+
153
+ @pyqtSlot()
154
+ def time_offset_finished(self):
155
+ self.align_field_finished()
156
+ self.plot_tdo()
157
+ self.wplots.tdo_field.clearPlots()
158
+ self.wplots.tdo_inverse_field.clearPlots()
159
+ self.wplots.fft.clearPlots()
160
+ self.enable_buttons()
161
+
133
162
  @pyqtSlot()
134
163
  def remove_background(self):
135
164
  if not self.check_tdo_extracted():
@@ -152,6 +181,7 @@ class MainWindow(gui.BaseMainWindow):
152
181
 
153
182
  @pyqtSlot()
154
183
  def fft_finished(self):
184
+ self.plot_tdo_detrended()
155
185
  self.plot_fft()
156
186
  self.enable_buttons()
157
187
 
@@ -490,10 +520,25 @@ class MainWindow(gui.BaseMainWindow):
490
520
  name="B up",
491
521
  )
492
522
 
523
+ @pyqtSlot()
493
524
  def syncroi_changed(self):
494
525
  """Update fit and FFT windows sync. status."""
495
526
  self.wplots._sync_roi = self.wconfiguration.syncroi_parameter.value()
496
527
 
528
+ @pyqtSlot()
529
+ def update_spectro_time_window(self):
530
+ """Update the spectro. nperseg setting expressed in time."""
531
+ if not self.check_data_loaded():
532
+ return
533
+ if "fs_signal" not in self.worker.proc.metadata:
534
+ return
535
+ else:
536
+ fs = self.worker.proc.metadata["fs_signal"]
537
+
538
+ self.wconfiguration.host_parameters["spectro_time_window"] = (
539
+ self.wconfiguration.settings_parameters["spectro_nperseg"] / fs
540
+ )
541
+
497
542
  def check_tdo_extracted(self) -> bool:
498
543
  if not self.check_data_loaded():
499
544
  return False
@@ -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,58 @@
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
+ """
16
+
17
+ sig_syncroi_changed = pyqtSignal()
18
+ sig_timeoffset_changed = pyqtSignal()
19
+ sig_spectro_nperseg_changed = pyqtSignal()
20
+
21
+ def __init__(self, param_content: type):
22
+ super().__init__(param_content)
23
+
24
+ self.add_extra_parameters()
25
+ self.connect_extras()
26
+
27
+ def add_extra_parameters(self):
28
+ """Add extra parameters used only in the GUI."""
29
+ # Sync ROIs parameter
30
+ self.syncroi_parameter = Parameter.create(
31
+ name="syncroi",
32
+ type="bool",
33
+ value=True,
34
+ title="Sync. fit and FFT field-window",
35
+ )
36
+ self.host_parameters.addChild(self.syncroi_parameter)
37
+
38
+ # Show nperseg parameter in µs
39
+ nperseg = Parameter.create(
40
+ name="spectro_time_window",
41
+ type="float",
42
+ readonly=True,
43
+ value=1024 / 100e6,
44
+ suffix="s",
45
+ siPrefix=True,
46
+ title="Spectro: time window (n/persegment)"
47
+ )
48
+ self.host_parameters.addChild(nperseg)
49
+
50
+ def connect_extras(self):
51
+ """Extra connections."""
52
+ self.syncroi_parameter.sigValueChanged.connect(self.sig_syncroi_changed.emit)
53
+ self.settings_parameters.child("time_offset").sigValueChanged.connect(
54
+ self.sig_timeoffset_changed.emit
55
+ )
56
+ self.settings_parameters.child("spectro_nperseg").sigValueChanged.connect(
57
+ self.sig_spectro_nperseg_changed.emit
58
+ )
@@ -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=[2, np.inf],
34
+ limits=[0, np.inf],
52
35
  value=1024,
53
- step=1024,
36
+ step=512,
54
37
  title="Spectro: n/segment",
55
38
  ),
56
39
  dict(
@@ -69,6 +52,33 @@ class ParamContent(BaseParamContent):
69
52
  step=512,
70
53
  title="Spectro: n overlap",
71
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",
81
+ ),
72
82
  dict(name="poly_window", type="str", value="", title="Fit: field window"),
73
83
  dict(
74
84
  name="poly_deg",
@@ -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
  """
@@ -381,19 +385,29 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
381
385
  fast=self.cfg.settings.barycenters_fast,
382
386
  ),
383
387
  )
384
- # Corresponding time vector (start at 0)
385
- time_tdo = self.get_data_processed("spectro_t")
386
- self.set_data_processed("time_exp", time_tdo - time_tdo[0])
388
+ # Corresponding time vector
389
+ self.apply_time_offset()
387
390
 
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
391
  logger.info("TDO signal extracted.")
394
392
 
395
393
  return self
396
394
 
395
+ def apply_time_offset(self) -> Self:
396
+ """Apply offset on the experiment time vector."""
397
+ if not self.get_data_processed("spectro_t", checkonly=True):
398
+ logger.warning("Spectrogram was not computed.")
399
+ return self
400
+
401
+ logger.info("Applying offset on time vector...")
402
+ time_tdo = self.get_data_processed("spectro_t")
403
+ self.set_data_processed("time_exp", time_tdo - self.cfg.settings.time_offset)
404
+ self.align_field()
405
+ logger.info(
406
+ f"Applied a {self.cfg.settings.time_offset * 1e6}µs PU/TDO time offset"
407
+ )
408
+
409
+ return self
410
+
397
411
  def align_field(self) -> Self:
398
412
  """Align magnetic field on the `time_exp` vector."""
399
413
  if not self._check_field_computed():
@@ -417,6 +431,9 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
417
431
  # Get the up / down indices
418
432
  self.get_up_down_indices()
419
433
 
434
+ # Remove previously-computed values based on this TDO signal
435
+ self._remove_data_changed()
436
+
420
437
  return self
421
438
 
422
439
  def get_up_down_indices(self) -> Self:
@@ -445,6 +462,14 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
445
462
  b1, b2 = self.cfg.settings.poly_window
446
463
  deg = self.cfg.settings.poly_deg
447
464
 
465
+ # Checks
466
+ maxfield = self.get_data_processed("magfield").max()
467
+ if b1 > maxfield:
468
+ logger.error(
469
+ f"Field window lower bound is {b1}T but max field is {maxfield}T"
470
+ )
471
+ return self
472
+
448
473
  # Fit and detrend
449
474
  logger.info(
450
475
  f"Fitting (degree : {deg}) and detrending TDO signal in {b1, b2}T..."
@@ -480,6 +505,9 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
480
505
  # Checks
481
506
  if not self._check_tdo_detrended():
482
507
  self.detrend_polyfit()
508
+ if not self._check_tdo_detrended():
509
+ logger.error("TDO signal could not be detrended, check messages above")
510
+ return self
483
511
 
484
512
  # Get parameters
485
513
  b1, b2 = self.cfg.settings.fft_window
@@ -565,7 +593,7 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
565
593
 
566
594
  def extract_tdo(self) -> Self:
567
595
  """Helper function that does everything required to extract the TDO signal."""
568
- self.compute_spectrogram().find_barycenters().align_field()
596
+ self.compute_spectrogram().find_barycenters()
569
597
 
570
598
  return self
571
599
 
@@ -619,6 +647,19 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
619
647
 
620
648
  return self
621
649
 
650
+ def _remove_data_changed(self):
651
+ """Remove data that was computed but the data it relied on changed."""
652
+ self.remove_data_processed(self._tdo_name + "_fit_inc")
653
+ self.remove_data_processed(self._tdo_name + "_fit_dec")
654
+ self.remove_data_processed(self._tdo_det_inc_name)
655
+ self.remove_data_processed(self._tdo_det_dec_name)
656
+ self.remove_data_processed(self._tdo_inv_inc_name)
657
+ self.remove_data_processed(self._tdo_inv_dec_name)
658
+ self.remove_data_processed("bfreq_inc")
659
+ self.remove_data_processed("bfreq_dec")
660
+ self.remove_data_processed("fft_inc")
661
+ self.remove_data_processed("fft_dec")
662
+
622
663
  def _get_result_names_list(self, ud: Literal["inc", "dec"]):
623
664
  """
624
665
  Generate the list of things to save.
@@ -719,6 +760,7 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
719
760
  return
720
761
 
721
762
  logger.info(f"Reading data from {filepath.name}...")
763
+ self._reinit()
722
764
  status = reader(filepath, sep=delimiter)
723
765
  if not status:
724
766
  logger.error(f"Failed to read {filepath.name}, check messages above")
@@ -782,9 +824,6 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
782
824
  )
783
825
  self.set_data_processed("magfield_time", self.get_data_processed("time_exp"))
784
826
 
785
- # Get the up / down indices
786
- self.get_up_down_indices()
787
-
788
827
  return True
789
828
 
790
829
  def _load_csv_legacy_results(self, filepath: Path, sep: str = ",") -> bool:
@@ -995,3 +1034,12 @@ class TDOProcessor(tTDOProcessor, BaseProcessor):
995
1034
  return self.get_data_processed(
996
1035
  self._tdo_inv_inc_name, checkonly=True
997
1036
  ) and self.get_data_processed(self._tdo_inv_dec_name, checkonly=True)
1037
+
1038
+ def _reinit(self):
1039
+ """Clear data and initialize objects."""
1040
+ self._init()
1041
+
1042
+ self.inds_inc = slice(-1)
1043
+ self.inds_dec = slice(-1)
1044
+
1045
+ 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