pytdo 0.2.2.2__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/PKG-INFO ADDED
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.3
2
+ Name: pytdo
3
+ Version: 0.2.2.2
4
+ Summary: Add your description here
5
+ Author: Guillaume Le Goc
6
+ Author-email: Guillaume Le Goc <guillaume.le-goc@lncmi.cnrs.fr>
7
+ Requires-Dist: matplotlib>=3.10.7
8
+ Requires-Dist: numpy>=2.3.5
9
+ Requires-Dist: rich>=14.2.0
10
+ Requires-Dist: scipy>=1.16.3
11
+ Requires-Dist: pydantic>=2.12.4
12
+ Requires-Dist: pyqt6>=6.10.0
13
+ Requires-Dist: pyuson>=0.7.0
14
+ Requires-Python: >=3.12
15
+ Description-Content-Type: text/markdown
16
+
17
+ # `pytdo`
18
+
19
+ [![Latest Release](https://gitlab.in2p3.fr/himagnetos/pytdo/-/badges/release.svg)](https://gitlab.in2p3.fr/himagnetos/pytdo/-/releases)
20
+ [![PyPI](https://img.shields.io/pypi/v/pytdo.svg)](https://pypi.org/project/pytdo/)
21
+
22
+ ## Description
23
+ `pytdo` provides a Python API to read and analyse tunnel diode oscillator experiments on samples exposed to a high magnetic field. It is bundled with a graphical user interface written with PyQt.
24
+
25
+ ## Installation
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.
29
+
30
+ To do so, install uv : https://docs.astral.sh/uv/getting-started/installation/.
31
+
32
+ Then, from the command line (PowerShell in Windows), install `pytdo` with uv :
33
+ ```
34
+ uv tool install pytdo
35
+ ```
36
+
37
+ `pytdo` will be installed along its dependencies in an isolated environment with no risks to mess up with your current tools and Python versions.
38
+
39
+ Then, launch the GUI by running `pytdo` from the command line.
40
+
41
+ To update, run : `uv tool upgrade pytdo`.
42
+
43
+ ### As a library
44
+ Installing `pytdo` as a library will allow you to use it from scripts and Jupyter notebooks (e.g. you will be able to import it with `import pytdo`).
45
+ Note that you can re-use the same environment than the one for [`pyuson`](https://gitlab.in2p3.fr/himagnetos/pyuson).
46
+
47
+ 1. Create a Python environment :
48
+
49
+ With `conda` :
50
+ ```
51
+ conda create -n pytdo-env -c conda-forge python=3.12
52
+ ```
53
+
54
+ You may replace the environment name `pytdo-env` with whatever you want.
55
+
56
+ Activate the environment with :
57
+ ```
58
+ conda activate pytdo-env
59
+ ```
60
+
61
+ 2. Install the `pytdo` package :
62
+
63
+ With `pip`, with the `pytdo-env` activated :
64
+ ```
65
+ pip install pytdo
66
+ ```
67
+
68
+ #### Updates
69
+ To upgrade `pytdo` to the latest version, simply run from the activated environment :
70
+ ```
71
+ pip install pytdo --upgrade
72
+ ```
73
+
74
+ #### Manual download
75
+ 1. Download the repository and extract it on your computer (or clone it).
76
+ 2. Create and activate a conda environment as shown above.
77
+ 3. Install the extracted repository with `pip` :
78
+ ```
79
+ pip install "/path/to/pytdo-main"
80
+ ```
81
+
82
+ Alternatively, if you wish to make modification to the source code so that your change is reflected immediately, use the editable mode :
83
+ ```
84
+ pip install -e /path/to/pytdo-main
85
+ ```
86
+
87
+ ## Usage
88
+ You can use this package through the graphical user interface, or directly from Python prompt, script or Jupyter notebook using the `Processor` classes. All this methods rely on a TOML configuration file that specifies the experiment parameters and analysis settings.
89
+
90
+ 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
+
92
+ - Run the graphical interface with `python -m pytdo` from a terminal with the `pyuson-env` environment activated. Drag & drop the configuration file in the window, load the data, extract the TDO signal and interactively choose the field-window in which the signal is detrended.
93
+ - Write your own script using the library :
94
+ ```python
95
+ import pytdo
96
+
97
+ cfg_filename = "/path/to/your/config.toml"
98
+ r = pytdo.TDOProcessor(cfg_filename)
99
+ r.extract_tdo().remove_background().fft_inverse()
100
+ r.save_results_csv()
101
+ ```
@@ -0,0 +1,85 @@
1
+ # `pytdo`
2
+
3
+ [![Latest Release](https://gitlab.in2p3.fr/himagnetos/pytdo/-/badges/release.svg)](https://gitlab.in2p3.fr/himagnetos/pytdo/-/releases)
4
+ [![PyPI](https://img.shields.io/pypi/v/pytdo.svg)](https://pypi.org/project/pytdo/)
5
+
6
+ ## Description
7
+ `pytdo` provides a Python API to read and analyse tunnel diode oscillator experiments on samples exposed to a high magnetic field. It is bundled with a graphical user interface written with PyQt.
8
+
9
+ ## Installation
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
+ Then, from the command line (PowerShell in Windows), install `pytdo` with uv :
17
+ ```
18
+ uv tool install pytdo
19
+ ```
20
+
21
+ `pytdo` will be installed along its dependencies in an isolated environment with no risks to mess up with your current tools and Python versions.
22
+
23
+ Then, launch the GUI by running `pytdo` from the command line.
24
+
25
+ To update, run : `uv tool upgrade pytdo`.
26
+
27
+ ### As a library
28
+ Installing `pytdo` as a library will allow you to use it from scripts and Jupyter notebooks (e.g. you will be able to import it with `import pytdo`).
29
+ Note that you can re-use the same environment than the one for [`pyuson`](https://gitlab.in2p3.fr/himagnetos/pyuson).
30
+
31
+ 1. Create a Python environment :
32
+
33
+ With `conda` :
34
+ ```
35
+ conda create -n pytdo-env -c conda-forge python=3.12
36
+ ```
37
+
38
+ You may replace the environment name `pytdo-env` with whatever you want.
39
+
40
+ Activate the environment with :
41
+ ```
42
+ conda activate pytdo-env
43
+ ```
44
+
45
+ 2. Install the `pytdo` package :
46
+
47
+ With `pip`, with the `pytdo-env` activated :
48
+ ```
49
+ pip install pytdo
50
+ ```
51
+
52
+ #### Updates
53
+ To upgrade `pytdo` to the latest version, simply run from the activated environment :
54
+ ```
55
+ pip install pytdo --upgrade
56
+ ```
57
+
58
+ #### Manual download
59
+ 1. Download the repository and extract it on your computer (or clone it).
60
+ 2. Create and activate a conda environment as shown above.
61
+ 3. Install the extracted repository with `pip` :
62
+ ```
63
+ pip install "/path/to/pytdo-main"
64
+ ```
65
+
66
+ Alternatively, if you wish to make modification to the source code so that your change is reflected immediately, use the editable mode :
67
+ ```
68
+ pip install -e /path/to/pytdo-main
69
+ ```
70
+
71
+ ## Usage
72
+ You can use this package through the graphical user interface, or directly from Python prompt, script or Jupyter notebook using the `Processor` classes. All this methods rely on a TOML configuration file that specifies the experiment parameters and analysis settings.
73
+
74
+ 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
+
76
+ - Run the graphical interface with `python -m pytdo` from a terminal with the `pyuson-env` environment activated. Drag & drop the configuration file in the window, load the data, extract the TDO signal and interactively choose the field-window in which the signal is detrended.
77
+ - Write your own script using the library :
78
+ ```python
79
+ import pytdo
80
+
81
+ cfg_filename = "/path/to/your/config.toml"
82
+ r = pytdo.TDOProcessor(cfg_filename)
83
+ r.extract_tdo().remove_background().fft_inverse()
84
+ r.save_results_csv()
85
+ ```
@@ -0,0 +1,53 @@
1
+ [project]
2
+ name = "pytdo"
3
+ version = "0.2.2.2"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Guillaume Le Goc", email = "guillaume.le-goc@lncmi.cnrs.fr" }
8
+ ]
9
+ requires-python = ">=3.12"
10
+ dependencies = [
11
+ "matplotlib>=3.10.7",
12
+ "numpy>=2.3.5",
13
+ "rich>=14.2.0",
14
+ "scipy>=1.16.3",
15
+ "pydantic>=2.12.4",
16
+ "pyqt6>=6.10.0",
17
+ "pyuson>=0.7.0",
18
+ ]
19
+
20
+ [project.gui-scripts]
21
+ pytdo = "pytdo:__main__.main"
22
+
23
+ [build-system]
24
+ requires = ["uv_build>=0.9.9,<0.10.0"]
25
+ build-backend = "uv_build"
26
+
27
+ [tool.ruff.lint]
28
+ ignore = ["D401"]
29
+ extend-select = [
30
+ "UP", # pyupgrade
31
+ "D", # pydocstyle
32
+ ]
33
+
34
+ [tool.ruff.lint.pydocstyle]
35
+ convention = "numpy"
36
+
37
+ [tool.ruff.lint.per-file-ignores]
38
+ "tests/*.py" = ["D103"]
39
+
40
+ [tool.mypy]
41
+ files = ["src"]
42
+ allow_redefinition_new = true
43
+ local_partial_types = true
44
+
45
+ [dependency-groups]
46
+ dev = [
47
+ "ipython>=9.7.0",
48
+ "mypy>=1.17.0",
49
+ "pytest>=8.4.2",
50
+ "pytest-cov>=7.0.0",
51
+ "ruff>=0.12.2",
52
+ "scipy-stubs>=1.16.0.2",
53
+ ]
@@ -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)
@@ -0,0 +1,15 @@
1
+ """Run the GUI when using pytdo as a module.
2
+
3
+ Usage : `python -m pytdo`
4
+ """
5
+
6
+
7
+ def main():
8
+ """Run GUI."""
9
+ from . import gui
10
+
11
+ gui.run()
12
+
13
+
14
+ if __name__ == "__main__":
15
+ main()
@@ -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
@@ -0,0 +1,6 @@
1
+ """The Config module."""
2
+
3
+ from .import models
4
+ from ._config import Config
5
+
6
+ __all__ = ["Config", "models"]
@@ -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)
@@ -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
@@ -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)
@@ -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