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/__init__.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The TDO package.
|
|
3
|
+
|
|
4
|
+
Implements classes and functions to process TDO experiments.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import nexusformat.nexus as nx
|
|
11
|
+
from rich.logging import RichHandler
|
|
12
|
+
|
|
13
|
+
from . import config, gui, sp
|
|
14
|
+
from .processors import TDOProcessor
|
|
15
|
+
|
|
16
|
+
__all__ = ["config", "TDOProcessor", "sp", "gui"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Setup logging
|
|
20
|
+
APPDIR = Path.home() / ".pytdo"
|
|
21
|
+
APPDIR.mkdir(parents=True, exist_ok=True)
|
|
22
|
+
|
|
23
|
+
fmt = "{asctime}.{msecs:3g} [{levelname}] : {message}"
|
|
24
|
+
logger = logging.getLogger(__name__)
|
|
25
|
+
logger.setLevel("DEBUG")
|
|
26
|
+
|
|
27
|
+
console_handler = RichHandler(log_time_format="%H:%M:%S.%f")
|
|
28
|
+
console_handler.setLevel("DEBUG")
|
|
29
|
+
|
|
30
|
+
file_handler = logging.FileHandler(
|
|
31
|
+
APPDIR / "processors.log", mode="a", encoding="utf-8"
|
|
32
|
+
)
|
|
33
|
+
file_handler.setLevel("INFO")
|
|
34
|
+
|
|
35
|
+
file_formatter = logging.Formatter(
|
|
36
|
+
fmt,
|
|
37
|
+
style="{",
|
|
38
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
39
|
+
)
|
|
40
|
+
file_handler.setFormatter(file_formatter)
|
|
41
|
+
|
|
42
|
+
logger.addHandler(console_handler)
|
|
43
|
+
logger.addHandler(file_handler)
|
|
44
|
+
|
|
45
|
+
# Configure NeXus
|
|
46
|
+
nx.nxsetconfig(compression=None, encoding="utf-8", lock=0, memory=8000, recursive=True)
|
pytdo/__main__.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# This configuration file specifies the default values if they are not filled in the
|
|
2
|
+
# per-experiment config.toml file.
|
|
3
|
+
|
|
4
|
+
expid = ""
|
|
5
|
+
data_directory = "." # path or "."
|
|
6
|
+
|
|
7
|
+
[files]
|
|
8
|
+
[files.pickup]
|
|
9
|
+
# Pickup coil binary file
|
|
10
|
+
ext = ".pu"
|
|
11
|
+
header = 2
|
|
12
|
+
precision = 4 # number of bytes/element
|
|
13
|
+
endian = "<" # endian, ">" for big-endian, "<" for little-endian
|
|
14
|
+
order = "F" # order style in the binary file, "F" for Fortran, "C" for C
|
|
15
|
+
[files.oscillo]
|
|
16
|
+
# Oscilloscope binary file
|
|
17
|
+
ext = ".tdo"
|
|
18
|
+
header = 2
|
|
19
|
+
precision = 4 # number of bytes/element
|
|
20
|
+
endian = "<" # endian, ">" for big-endian, "<" for little-endian
|
|
21
|
+
order = "F" # order style in the binary file, "F" for Fortran, "C" for C
|
|
22
|
+
|
|
23
|
+
[measurements]
|
|
24
|
+
# Measurements settings
|
|
25
|
+
# Link a physical measurement to a channel of the oscilloscope
|
|
26
|
+
# For oscillo data saved with LabVIEW, they correspond to the columns in the file (0-based)
|
|
27
|
+
signal = 0
|
|
28
|
+
|
|
29
|
+
# Parameters are values that should be fixed once and for all for a given experiment
|
|
30
|
+
[parameters]
|
|
31
|
+
pickup_surface = 1 # surface of the pickup coil (m²)
|
|
32
|
+
|
|
33
|
+
pickup_number = 1 # number of pickup(s) used and save in the pickup bin file
|
|
34
|
+
pickup_index = 0 # index of the pickup to use for analysis, 0-based
|
|
35
|
+
|
|
36
|
+
# Settings are analysis-specific and can be changed afterwards
|
|
37
|
+
[settings]
|
|
38
|
+
# Settings for TDO signal extraction from raw data
|
|
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
|
|
43
|
+
spectro_nperseg = 1024 # spectrogram : number of points per segment
|
|
44
|
+
spectro_win_size = 4096 # spectrogram : fft window size
|
|
45
|
+
spectro_noverlap = -1 # size of windows overlap, set to -1 to be nperseg / 2
|
|
46
|
+
|
|
47
|
+
# Settings for TDO signal analysis
|
|
48
|
+
poly_window = [60, 84] # field-range in which to do the polynomial fit
|
|
49
|
+
poly_deg = 3 # polynomial degree
|
|
50
|
+
npoints_interp_inverse = 100000 # number of points for interpolation in 1/B
|
|
51
|
+
fft_window = [-1, -1] # field-range in which to do the FFT, set to [-1, -1] to use the same as poly_window
|
|
52
|
+
fft_pad_mult = 100 # multiplier of signal size to adjust 0-padding size for FFT
|
|
53
|
+
max_bfreq = 70000 # maximum B-frequency (in T) to plot and save
|
|
54
|
+
|
|
55
|
+
# Settings for display/plotting
|
|
56
|
+
offset = 1000 # offset B up/down curves to see them better
|
|
57
|
+
|
|
58
|
+
[metadata]
|
|
59
|
+
# Parameters on how to handle binary files headers
|
|
60
|
+
[metadata.index_map]
|
|
61
|
+
# map a metadata to its index in the header (0-based)
|
|
62
|
+
samplerate = 0
|
|
63
|
+
temperature = 1
|
|
64
|
+
[metadata.conversion_map]
|
|
65
|
+
# determine whether conversion to numeric is required
|
|
66
|
+
samplerate = true
|
|
67
|
+
temperature = true
|
|
68
|
+
|
|
69
|
+
[nx]
|
|
70
|
+
# NeXus file consolidation
|
|
71
|
+
|
|
72
|
+
[nexus]
|
|
73
|
+
[nexus.groups]
|
|
74
|
+
# NeXus groups attributes
|
|
75
|
+
root = {name = ""}
|
|
76
|
+
# processed/analysis
|
|
77
|
+
analysis = {}
|
|
78
|
+
# data
|
|
79
|
+
data = {}
|
|
80
|
+
[nexus.datasets]
|
|
81
|
+
# NeXus datasets attributes
|
pytdo/config/__init__.py
ADDED
pytdo/config/_config.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from pyuson.config import BaseConfig
|
|
5
|
+
|
|
6
|
+
from ._types import tConfig
|
|
7
|
+
from .models import TDOConfiguration
|
|
8
|
+
|
|
9
|
+
CONFIG_DEFAULT = Path(__file__).parent.parent / "assets" / "config_default.toml"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Config(tConfig, BaseConfig):
|
|
13
|
+
def __init__(
|
|
14
|
+
self,
|
|
15
|
+
user_file: str | Path | None = None,
|
|
16
|
+
default_file: str | Path | None = None,
|
|
17
|
+
**overrides: Any,
|
|
18
|
+
) -> None:
|
|
19
|
+
if not default_file:
|
|
20
|
+
default_file = CONFIG_DEFAULT
|
|
21
|
+
|
|
22
|
+
super().__init__(TDOConfiguration, user_file, default_file, **overrides)
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def loads(cls, json_data: str | bytes, **kwargs) -> "Config":
|
|
26
|
+
return super()._loads(TDOConfiguration, json_data, **kwargs)
|
pytdo/config/_types.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from pyuson.config.models import BinaryFile
|
|
4
|
+
|
|
5
|
+
from .models import Metadata, Nexus, Parameters, Settings
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class tConfig:
|
|
9
|
+
|
|
10
|
+
files: dict[str, BinaryFile]
|
|
11
|
+
parameters: Parameters
|
|
12
|
+
settings: Settings
|
|
13
|
+
metadata: Metadata
|
|
14
|
+
|
|
15
|
+
nx: dict[str, dict[str, Any]]
|
|
16
|
+
nexus: Nexus
|
pytdo/config/models.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Pydantic models for configuration."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, ConfigDict
|
|
8
|
+
from pyuson.config.models import BinaryFile, Metadata, Nexus
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Parameters(BaseModel):
|
|
12
|
+
"""Parameters section, things related to experiment itself."""
|
|
13
|
+
|
|
14
|
+
pickup_surface: float
|
|
15
|
+
pickup_number: int
|
|
16
|
+
pickup_index: int
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Settings(BaseModel):
|
|
20
|
+
"""Settings for signal extraction, analysis and plotting."""
|
|
21
|
+
|
|
22
|
+
# Extraction
|
|
23
|
+
max_time: float
|
|
24
|
+
noise_window: Sequence[float]
|
|
25
|
+
spectro_nperseg: int
|
|
26
|
+
spectro_win_size: int
|
|
27
|
+
spectro_noverlap: int
|
|
28
|
+
barycenters_fwindow: float
|
|
29
|
+
barycenters_fast: bool
|
|
30
|
+
|
|
31
|
+
# Analysis
|
|
32
|
+
poly_window: Sequence[float]
|
|
33
|
+
poly_deg: int
|
|
34
|
+
npoints_interp_inverse: int
|
|
35
|
+
fft_window: Sequence[float]
|
|
36
|
+
fft_pad_mult: int
|
|
37
|
+
max_bfreq: float
|
|
38
|
+
|
|
39
|
+
# Display
|
|
40
|
+
offset: float
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class TDOConfiguration(BaseModel):
|
|
44
|
+
"""A model specialized for TDO experiments."""
|
|
45
|
+
|
|
46
|
+
expid: str
|
|
47
|
+
data_directory: Path
|
|
48
|
+
|
|
49
|
+
filenames: dict[str, str | Path] = dict()
|
|
50
|
+
|
|
51
|
+
files: dict[str, BinaryFile]
|
|
52
|
+
|
|
53
|
+
measurements: dict[str, int]
|
|
54
|
+
|
|
55
|
+
parameters: Parameters
|
|
56
|
+
settings: Settings
|
|
57
|
+
|
|
58
|
+
metadata: Metadata
|
|
59
|
+
|
|
60
|
+
nx: dict[str, dict[str, Any]]
|
|
61
|
+
nexus: Nexus
|
|
62
|
+
|
|
63
|
+
model_config = ConfigDict(validate_assignment=True)
|
pytdo/gui/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Graphical user interface module."""
|
|
2
|
+
|
|
3
|
+
from PyQt6 import QtWidgets
|
|
4
|
+
|
|
5
|
+
from ._core import MainWindow
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def run(exec: bool = True):
|
|
9
|
+
"""
|
|
10
|
+
Build and run the GUI.
|
|
11
|
+
|
|
12
|
+
Set `exec=False` in an interactive prompt to interact with the GUI from the shell.
|
|
13
|
+
"""
|
|
14
|
+
app = QtWidgets.QApplication([])
|
|
15
|
+
win = MainWindow()
|
|
16
|
+
win.show()
|
|
17
|
+
if exec:
|
|
18
|
+
app.exec()
|
|
19
|
+
else:
|
|
20
|
+
return win
|