Skip to content

Commit

Permalink
Merge pull request #20 from nqrduck/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
jupfi authored May 27, 2024
2 parents 6124ee8 + 9b1052b commit b5d5559
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.0.6 (27-05-2024)

- Added fitting functions to the measurement module (`dca1c6816f0697ca3c6827fd07a0236a3189b922`).

## Version 0.0.5 (20-05-2024)

- Fixed measurement dialog not showing in wayland (`f5705e4efcbaf1aa0efd558b1ec1dacf42a53944`)
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,41 @@ A module for the [nqrduck](https://github.com/nqrduck/nqrduck) project. This mod
## Installation

### Requirements

Dependencies are handled via the pyproject.toml file.

### Setup

To install the module you need the NQRduck core. You can find the installation instructions for the NQRduck core [here](https://github.com/nqrduck/nqrduck).

Ideally you should install the module in a virtual environment. You can create a virtual environment by running the following command in the terminal:

```bash
python -m venv nqrduck
# Activate the virtual environment
. nqrduck/bin/activate
```

You can install this module and the dependencies by running the following command in the terminal while the virtual environment is activated and you are in the root directory of this module:

```bash
pip install .
```

Alternatively, you can install the module and the dependencies by running the following command in the terminal while the virtual environment is activated:

```bash
pip install nqrduck-measurement
```

## Usage

The module is used with the [Spectrometer](https://github.com/nqrduck/nqrduck-spectrometer) module. However you need to use an actual submodule of the spectrometer module like:

- [nqrduck-spectrometer-limenqr](https://github.com/nqrduck/nqrduck-spectrometer-limenqr) A module used for magnetic resonance experiments with the LimeSDR (USB or Mini 2.0).
- [nqrduck-spectrometer-simulator](https://github.com/nqrduck/nqrduck-spectrometer-simulator) A module used for simulating magnetic resonance experiments.

The pulse sequence and spectrometer settings can be adjusted using the 'Spectrometer' tab.
The pulse sequence and spectrometer settings can be adjusted using the 'Spectrometer' tab.

<img src="https://github.com/nqrduck/nqrduck-measurement/raw/0b28ae6b33230c6ca9eda85bd18de7cbcade27d1/docs/img/measurement_ui_labeled_v2.png" alt="drawing" width="800">

Expand All @@ -42,8 +48,12 @@ The pulse sequence and spectrometer settings can be adjusted using the 'Spectrom
- c.) The 'Measurement Plot'. Here the measured data is displayed. One can switch time and frequency domain plots.
- d.) The import and export buttons for the measurement data.

You can then remove the folder of the virtual environment.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

## Contributing

If you're interested in contributing to the project, start by checking out our [nqrduck-module template](https://github.com/nqrduck/nqrduck-module). To contribute to existing modules, please first open an issue in the respective module repository to discuss your ideas or report bugs.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ allow-direct-references = true

[project]
name = "nqrduck-measurement"
version = "0.0.5"
version = "0.0.6"
authors = [
{ name="jupfi", email="[email protected]" },
]
Expand Down
32 changes: 31 additions & 1 deletion src/nqrduck_measurement/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
from PyQt6.QtCore import pyqtSlot, pyqtSignal
from PyQt6.QtWidgets import QApplication
from .signalprocessing_options import Apodization
from .signalprocessing_options import Apodization, Fitting
from nqrduck.module.module_controller import ModuleController
from nqrduck_spectrometer.measurement import Measurement

Expand Down Expand Up @@ -231,6 +231,36 @@ def show_apodization_dialog(self) -> None:

self.module.model.displayed_measurement = apodized_measurement
self.module.model.add_measurement(apodized_measurement)

def show_fitting_dialog(self) -> None:
"""Show fitting dialog."""
logger.debug("Showing fitting dialog.")
# First we check if there is a measurement.
if not self.module.model.displayed_measurement:
logger.debug("No measurement to fit.")
self.module.nqrduck_signal.emit(
"notification", ["Error", "No measurement to fit."]
)
return

measurement = self.module.model.displayed_measurement

dialog = Fitting(measurement, parent=self.module.view)
result = dialog.exec()

logger.debug("Dialog result: %s", result)
if not result:
return

fit = dialog.get_fit()[1]

logger.debug("Fitting function: %s", fit)

measurement.add_fit(fit)

self.module.view.update_displayed_measurement()

dialog.deleteLater()

@pyqtSlot()
def change_displayed_measurement(self, measurement=None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/nqrduck_measurement/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MeasurementModel(ModuleModel):

FILE_EXTENSION = "meas"
# This constants are used to determine which view is currently displayed.
FFT_VIEW = "fft"
FFT_VIEW = "frequency"
TIME_VIEW = "time"

displayed_measurement_changed = pyqtSignal(Measurement)
Expand Down
46 changes: 43 additions & 3 deletions src/nqrduck_measurement/signalprocessing_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import logging
import sympy
from nqrduck_spectrometer.measurement import Measurement
from nqrduck_spectrometer.measurement import Measurement, Fit, T2StarFit, LorentzianFit
from nqrduck.helpers.functions import Function, GaussianFunction, CustomFunction
from nqrduck.helpers.formbuilder import DuckFormBuilder, DuckFormFunctionSelectionField
from nqrduck.helpers.formbuilder import (
DuckFormBuilder,
DuckFormFunctionSelectionField,
DuckFormDropdownField,
)

logger = logging.getLogger(__name__)

Expand All @@ -23,7 +27,6 @@ def __init__(self) -> None:

self.add_parameter(Function.Parameter("T2star (microseconds)", "T2star", 10))


class Apodization(DuckFormBuilder):
"""Apodization parameter.
Expand Down Expand Up @@ -51,6 +54,8 @@ def __init__(self, measurement: Measurement, parent=None) -> None:
duration=self.duration,
parent=parent,
default_function=0,
view_mode="time",
mode_selection=0,
)

self.add_field(function_selection_field)
Expand All @@ -62,3 +67,38 @@ def get_function(self) -> Function:
Function: The selected function.
"""
return self.get_values()[0]


class Fitting(DuckFormBuilder):
"""Fitting parameter.
This parameter is used to apply fitting functions to the signal.
The fitting functions are used to reduce the noise in the signal.
"""

def __init__(self, measurement: Measurement, parent=None) -> None:
"""Fitting parameter."""
super().__init__("Fitting", parent=parent)

self.measurement = measurement

fits = {}
fits["T2*"] = T2StarFit(self.measurement)
fits["Lorentzian"] = LorentzianFit(self.measurement)

selection_field = DuckFormDropdownField(
text=None,
tooltip=None,
options=fits,
default_option=0,
)

self.add_field(selection_field)

def get_fit(self) -> Fit:
"""Get the selected fit.
Returns:
Fit: The selected fit.
"""
return self.get_values()[0]
Loading

0 comments on commit b5d5559

Please sign in to comment.