mlgidGUI 0.4.1__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.
- mlgidGUI/__init__.py +52 -0
- mlgidGUI/__main__.py +7 -0
- mlgidGUI/__version.py +1 -0
- mlgidGUI/app/__init__.py +8 -0
- mlgidGUI/app/actions_stack.py +1 -0
- mlgidGUI/app/app.py +67 -0
- mlgidGUI/app/cif_rois/__init__.py +0 -0
- mlgidGUI/app/cif_rois/cif_peaks_calculation.py +57 -0
- mlgidGUI/app/cif_rois/cif_simulation/__init__.py +0 -0
- mlgidGUI/app/cif_rois/cif_simulation/data/__init__.py +0 -0
- mlgidGUI/app/cif_rois/cif_simulation/data/atoms.py +15 -0
- mlgidGUI/app/cif_rois/cif_simulation/data/export_database.py +28 -0
- mlgidGUI/app/cif_rois/cif_simulation/experiment.py +57 -0
- mlgidGUI/app/cif_rois/cif_simulation/giwaxs_sim.py +286 -0
- mlgidGUI/app/cif_rois/cif_simulation/int_sim.py +105 -0
- mlgidGUI/app/cif_rois/cif_simulation/possible_directions.py +20 -0
- mlgidGUI/app/cif_rois/cif_simulation/q_sim.py +159 -0
- mlgidGUI/app/data_manager/__init__.py +4 -0
- mlgidGUI/app/data_manager/data_manager.py +164 -0
- mlgidGUI/app/data_manager/import_from_h5.py +68 -0
- mlgidGUI/app/data_manager/load_data.py +78 -0
- mlgidGUI/app/data_manager/pascal/__init__.py +2 -0
- mlgidGUI/app/data_manager/pascal/annotation_fabric.py +59 -0
- mlgidGUI/app/data_manager/pascal/draw_objects.py +119 -0
- mlgidGUI/app/data_manager/pascal/exceptions.py +6 -0
- mlgidGUI/app/data_manager/pascal/format_convertor.py +127 -0
- mlgidGUI/app/data_manager/pascal/pascal_annotation.py +85 -0
- mlgidGUI/app/data_manager/pascal/protocol_implementations.py +28 -0
- mlgidGUI/app/data_manager/pascal/protocols.py +47 -0
- mlgidGUI/app/data_manager/pascal/utils.py +64 -0
- mlgidGUI/app/data_manager/save_dataset.py +57 -0
- mlgidGUI/app/data_manager/save_h5.py +178 -0
- mlgidGUI/app/data_manager/saving_parameters.py +88 -0
- mlgidGUI/app/debug_tracker.py +129 -0
- mlgidGUI/app/edf_reader.py +135 -0
- mlgidGUI/app/file_manager/__init__.py +201 -0
- mlgidGUI/app/file_manager/config_manager.py +76 -0
- mlgidGUI/app/file_manager/keys.py +542 -0
- mlgidGUI/app/file_manager/npy_file_manager.py +17 -0
- mlgidGUI/app/file_manager/object_file_manager.py +77 -0
- mlgidGUI/app/file_manager/project_structure.py +169 -0
- mlgidGUI/app/file_manager/read_fits.py +76 -0
- mlgidGUI/app/file_manager/read_geometry.py +54 -0
- mlgidGUI/app/file_manager/read_images.py +31 -0
- mlgidGUI/app/file_manager/read_meta_roi.py +40 -0
- mlgidGUI/app/file_manager/read_polar_images.py +22 -0
- mlgidGUI/app/file_manager/read_radial_profile.py +6 -0
- mlgidGUI/app/file_manager/read_roi_data.py +39 -0
- mlgidGUI/app/fitting/__init__.py +5 -0
- mlgidGUI/app/fitting/background.py +92 -0
- mlgidGUI/app/fitting/fit.py +128 -0
- mlgidGUI/app/fitting/fit_holder.py +273 -0
- mlgidGUI/app/fitting/fit_object.py +247 -0
- mlgidGUI/app/fitting/functions.py +107 -0
- mlgidGUI/app/fitting/range_strategy.py +14 -0
- mlgidGUI/app/fitting/utils.py +17 -0
- mlgidGUI/app/geometry.py +236 -0
- mlgidGUI/app/geometry_holder.py +131 -0
- mlgidGUI/app/image_holder.py +200 -0
- mlgidGUI/app/image_processing.py +23 -0
- mlgidGUI/app/polar_image.py +96 -0
- mlgidGUI/app/profiles/__init__.py +5 -0
- mlgidGUI/app/profiles/angular_profile.py +20 -0
- mlgidGUI/app/profiles/basic_profile.py +169 -0
- mlgidGUI/app/profiles/radial_profile.py +38 -0
- mlgidGUI/app/read_image.py +21 -0
- mlgidGUI/app/rois/__init__.py +4 -0
- mlgidGUI/app/rois/new_roi_dict.py +670 -0
- mlgidGUI/app/rois/roi.py +194 -0
- mlgidGUI/app/rois/roi_colors.py +76 -0
- mlgidGUI/app/rois/roi_data.py +177 -0
- mlgidGUI/app/rois/roi_dict.py +466 -0
- mlgidGUI/app/rois/roi_meta_data.py +149 -0
- mlgidGUI/app/structures/__init__.py +6 -0
- mlgidGUI/app/structures/crystal_ring.py +19 -0
- mlgidGUI/app/structures/crystals_holders.py +144 -0
- mlgidGUI/app/structures/custom_crystal.py +45 -0
- mlgidGUI/app/structures/get_ring_list.py +89 -0
- mlgidGUI/app/transformations.py +82 -0
- mlgidGUI/app/update/__init__.py +3 -0
- mlgidGUI/app/update/check_version.py +51 -0
- mlgidGUI/app/update/launch_program.py +15 -0
- mlgidGUI/app/update/script_update.py +64 -0
- mlgidGUI/app/utils.py +124 -0
- mlgidGUI/gui/__init__.py +3 -0
- mlgidGUI/gui/background_tasks.py +41 -0
- mlgidGUI/gui/background_update.py +87 -0
- mlgidGUI/gui/basic_widgets/__init__.py +12 -0
- mlgidGUI/gui/basic_widgets/buttons.py +144 -0
- mlgidGUI/gui/basic_widgets/labels.py +51 -0
- mlgidGUI/gui/basic_widgets/mouse_events.py +119 -0
- mlgidGUI/gui/basic_widgets/path_line.py +162 -0
- mlgidGUI/gui/basic_widgets/plots_1d.py +365 -0
- mlgidGUI/gui/basic_widgets/plots_2d.py +224 -0
- mlgidGUI/gui/basic_widgets/popups.py +164 -0
- mlgidGUI/gui/basic_widgets/progress_bar.py +127 -0
- mlgidGUI/gui/basic_widgets/setup_widgets.py +138 -0
- mlgidGUI/gui/basic_widgets/sliders.py +616 -0
- mlgidGUI/gui/basic_widgets/spinner.py +65 -0
- mlgidGUI/gui/basic_widgets/toolbars.py +19 -0
- mlgidGUI/gui/debug_widgets.py +388 -0
- mlgidGUI/gui/dock_area.py +115 -0
- mlgidGUI/gui/exception_message.py +42 -0
- mlgidGUI/gui/fitting/__init__.py +2 -0
- mlgidGUI/gui/fitting/fit_widget.py +966 -0
- mlgidGUI/gui/fitting/inplace_fit.py +536 -0
- mlgidGUI/gui/fitting/selected_fit_widget.py +286 -0
- mlgidGUI/gui/gui_main.py +349 -0
- mlgidGUI/gui/image_viewer.py +323 -0
- mlgidGUI/gui/init_window.py +170 -0
- mlgidGUI/gui/load_window/__init__.py +2 -0
- mlgidGUI/gui/load_window/load_folder.py +61 -0
- mlgidGUI/gui/load_window/load_h5.py +73 -0
- mlgidGUI/gui/notifications.py +68 -0
- mlgidGUI/gui/polar_image_viewer.py +153 -0
- mlgidGUI/gui/profiles/__init__.py +1 -0
- mlgidGUI/gui/profiles/angular_profile_widget.py +62 -0
- mlgidGUI/gui/profiles/radial_profile_widget.py +164 -0
- mlgidGUI/gui/project_manager/__init__.py +17 -0
- mlgidGUI/gui/project_manager/cif_files_widget.py +196 -0
- mlgidGUI/gui/project_manager/cif_results.py +146 -0
- mlgidGUI/gui/project_manager/metadata_widget.py +15 -0
- mlgidGUI/gui/project_manager/project_viewer.py +151 -0
- mlgidGUI/gui/project_manager/roi_widget.py +171 -0
- mlgidGUI/gui/roi_widgets/__init__.py +6 -0
- mlgidGUI/gui/roi_widgets/abstract_roi_holder.py +189 -0
- mlgidGUI/gui/roi_widgets/abstract_roi_widget.py +111 -0
- mlgidGUI/gui/roi_widgets/cif_file_widget.py +16 -0
- mlgidGUI/gui/roi_widgets/cif_peak_widget.py +43 -0
- mlgidGUI/gui/roi_widgets/confidence_level_widget.py +105 -0
- mlgidGUI/gui/roi_widgets/roi_1d_widget.py +136 -0
- mlgidGUI/gui/roi_widgets/roi_2d_rect_widget.py +98 -0
- mlgidGUI/gui/roi_widgets/roi_2d_ring_widget.py +203 -0
- mlgidGUI/gui/roi_widgets/rois_context_menu.py +150 -0
- mlgidGUI/gui/roi_widgets/select_roi_color_widget.py +58 -0
- mlgidGUI/gui/save_window/__init__.py +152 -0
- mlgidGUI/gui/save_window/format_box.py +33 -0
- mlgidGUI/gui/save_window/num_selected_widget.py +45 -0
- mlgidGUI/gui/save_window/options_widgets.py +105 -0
- mlgidGUI/gui/save_window/save_mode_box.py +30 -0
- mlgidGUI/gui/save_window/select_images.py +198 -0
- mlgidGUI/gui/tools.py +179 -0
- mlgidGUI/static/__init__.py +0 -0
- mlgidGUI/static/icons/__init__.py +0 -0
- mlgidGUI/static/icons/add.png +0 -0
- mlgidGUI/static/icons/add_yellow.png +0 -0
- mlgidGUI/static/icons/angular_profile.png +0 -0
- mlgidGUI/static/icons/arrow.png +0 -0
- mlgidGUI/static/icons/baseline.png +0 -0
- mlgidGUI/static/icons/center.png +0 -0
- mlgidGUI/static/icons/confirm.png +0 -0
- mlgidGUI/static/icons/control_widget.png +0 -0
- mlgidGUI/static/icons/data.png +0 -0
- mlgidGUI/static/icons/delete.png +0 -0
- mlgidGUI/static/icons/delete_yellow.png +0 -0
- mlgidGUI/static/icons/error.png +0 -0
- mlgidGUI/static/icons/find.png +0 -0
- mlgidGUI/static/icons/fit.png +0 -0
- mlgidGUI/static/icons/fix_all.png +0 -0
- mlgidGUI/static/icons/flip_horizontal.png +0 -0
- mlgidGUI/static/icons/flip_vertical.png +0 -0
- mlgidGUI/static/icons/folder.png +0 -0
- mlgidGUI/static/icons/fromfullscreen.png +0 -0
- mlgidGUI/static/icons/h5_folder.png +0 -0
- mlgidGUI/static/icons/h5_group_folder.png +0 -0
- mlgidGUI/static/icons/info.png +0 -0
- mlgidGUI/static/icons/interpolate.png +0 -0
- mlgidGUI/static/icons/item.png +0 -0
- mlgidGUI/static/icons/properties.png +0 -0
- mlgidGUI/static/icons/radial_profile.png +0 -0
- mlgidGUI/static/icons/roi_item.png +0 -0
- mlgidGUI/static/icons/rotate.png +0 -0
- mlgidGUI/static/icons/rotate_image.png +0 -0
- mlgidGUI/static/icons/rotate_right.png +0 -0
- mlgidGUI/static/icons/setup.png +0 -0
- mlgidGUI/static/icons/setup_white.png +0 -0
- mlgidGUI/static/icons/tofullscreen.png +0 -0
- mlgidGUI/static/icons/unfix_all.png +0 -0
- mlgidGUI/static/icons/update.png +0 -0
- mlgidGUI/static/icons/update_suggested.png +0 -0
- mlgidGUI/static/icons/window_icon.png +0 -0
- mlgidGUI/static/icons/window_icon_256.png +0 -0
- mlgidGUI/utils/__init__.py +1 -0
- mlgidGUI/utils/project2h5.py +11 -0
- mlgidgui-0.4.1.dist-info/METADATA +119 -0
- mlgidgui-0.4.1.dist-info/RECORD +202 -0
- mlgidgui-0.4.1.dist-info/WHEEL +5 -0
- mlgidgui-0.4.1.dist-info/entry_points.txt +5 -0
- mlgidgui-0.4.1.dist-info/licenses/LICENSE +674 -0
- mlgidgui-0.4.1.dist-info/top_level.txt +4 -0
- tests/__init__.py +0 -0
- tests/conftest.py +1 -0
- tests/fixures/__init__.py +2 -0
- tests/fixures/projects.py +102 -0
- tests/func/__init__.py +1 -0
- tests/func/test_loading_state.py +21 -0
- tests/func/test_parse_project_data.py +23 -0
- tests/func/test_save.py +62 -0
- tests/unit/__init__.py +0 -0
- tests/unit/rois/__init__.py +0 -0
- tests/unit/rois/test_basic_operations.py +18 -0
- tests/unit/test_add_data.py +33 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Dict
|
|
3
|
+
from enum import Enum
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from PyQt5.QtWidgets import (QWidget, QGridLayout, QPushButton,
|
|
7
|
+
QLabel, QFrame, QSplitter,
|
|
8
|
+
QScrollArea, QSizePolicy)
|
|
9
|
+
from PyQt5.QtGui import QColor
|
|
10
|
+
from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QObject
|
|
11
|
+
|
|
12
|
+
from ..roi_widgets.roi_1d_widget import Roi1D
|
|
13
|
+
from ..roi_widgets.confidence_level_widget import ConfidenceOptionsList
|
|
14
|
+
from ..roi_widgets.cif_file_widget import CIFFileWidget
|
|
15
|
+
from ..roi_widgets import AbstractRoiWidget, AbstractRoiHolder
|
|
16
|
+
from ...app.fitting import (
|
|
17
|
+
Fit,
|
|
18
|
+
FittingType,
|
|
19
|
+
BackgroundType,
|
|
20
|
+
)
|
|
21
|
+
from ...app.fitting.fit_holder import FitHolder
|
|
22
|
+
from ...app.rois.roi_data import Roi
|
|
23
|
+
from ...app import App
|
|
24
|
+
from ..tools import get_pen
|
|
25
|
+
from ..basic_widgets import (
|
|
26
|
+
Custom1DPlot,
|
|
27
|
+
ParametersSlider,
|
|
28
|
+
LabeledSlider
|
|
29
|
+
)
|
|
30
|
+
class DummyRoiWidget(AbstractRoiWidget):
|
|
31
|
+
def move_roi(self):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
def send_move(self):
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
def set_color(self, color):
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class RoiFitWidget(AbstractRoiHolder, QWidget):
|
|
42
|
+
def __init__(self, parent=None):
|
|
43
|
+
self.app = App()
|
|
44
|
+
QWidget.__init__(self, parent)
|
|
45
|
+
self._init_ui()
|
|
46
|
+
self.fit_holder = FitHolder()
|
|
47
|
+
AbstractRoiHolder.__init__(self, 'RoiFitWidget')
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def selected_fit(self):
|
|
51
|
+
return self.fit_holder.fit
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def selected_roi(self):
|
|
55
|
+
fit = self.selected_fit
|
|
56
|
+
if not fit:
|
|
57
|
+
return
|
|
58
|
+
return fit.roi
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def selected_key(self):
|
|
62
|
+
roi = self.selected_roi
|
|
63
|
+
if not roi:
|
|
64
|
+
return
|
|
65
|
+
return roi.key
|
|
66
|
+
|
|
67
|
+
def _update_data(self):
|
|
68
|
+
self.fit_holder.update_data()
|
|
69
|
+
self._update()
|
|
70
|
+
|
|
71
|
+
def _init_ui(self):
|
|
72
|
+
self.fit_plot = FitPlot(self)
|
|
73
|
+
self.sliders_widget = SlidersWidget(parent=self)
|
|
74
|
+
self.next_roi_btn = QPushButton('Next ROI', self)
|
|
75
|
+
self.prev_roi_btn = QPushButton('Previous ROI', self)
|
|
76
|
+
self.fit_current_button = QPushButton(CurrentFitButtonStatus.fit.value, self)
|
|
77
|
+
self.auto_range_btn = QPushButton('Auto range', self)
|
|
78
|
+
self.update_params_by_range_btn = QPushButton('Update params by range', self)
|
|
79
|
+
self.cif_widget = CIFFileWidget()
|
|
80
|
+
self.auto_fit_btn = QPushButton('Fit all peaks', self)
|
|
81
|
+
self.confidence_list = ConfidenceOptionsList('Not set', self, horizontal=True)
|
|
82
|
+
self.update_bounds_btn = QPushButton('Default range', self)
|
|
83
|
+
|
|
84
|
+
q_scroll_area = QScrollArea(self)
|
|
85
|
+
q_scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
|
|
86
|
+
q_scroll_area.setWidgetResizable(True)
|
|
87
|
+
q_scroll_area.setGeometry(0, 0, 300, 400)
|
|
88
|
+
|
|
89
|
+
options_widget = QWidget(self)
|
|
90
|
+
q_scroll_area.setWidget(options_widget)
|
|
91
|
+
|
|
92
|
+
options_widget.setSizePolicy(
|
|
93
|
+
QSizePolicy.Expanding, QSizePolicy.Expanding
|
|
94
|
+
)
|
|
95
|
+
scroll_layout = QGridLayout(options_widget)
|
|
96
|
+
|
|
97
|
+
scroll_layout.addWidget(self.auto_fit_btn, 0, 0, 1, 2)
|
|
98
|
+
scroll_layout.addWidget(self.prev_roi_btn, 1, 0)
|
|
99
|
+
scroll_layout.addWidget(self.next_roi_btn, 1, 1)
|
|
100
|
+
scroll_layout.addWidget(self.fit_current_button, 2, 0, 1, 2)
|
|
101
|
+
scroll_layout.addWidget(self.update_bounds_btn, 3, 0, 1, 1)
|
|
102
|
+
scroll_layout.addWidget(self.auto_range_btn, 3, 1, 1, 1)
|
|
103
|
+
scroll_layout.addWidget(self.update_params_by_range_btn, 4, 0, 1, 2)
|
|
104
|
+
scroll_layout.addWidget(self.cif_widget, 5, 0, 1, 2)
|
|
105
|
+
scroll_layout.addWidget(self.confidence_list, 6, 0, 1, 2)
|
|
106
|
+
scroll_layout.addWidget(self.sliders_widget, 7, 0, 1, 2)
|
|
107
|
+
|
|
108
|
+
q_splitter_h2 = QSplitter(orientation=Qt.Vertical, parent=self)
|
|
109
|
+
q_splitter_h2.addWidget(self.fit_plot)
|
|
110
|
+
q_splitter_h2.addWidget(q_scroll_area)
|
|
111
|
+
q_splitter_h2.setSizes((500, 300))
|
|
112
|
+
|
|
113
|
+
layout = QGridLayout(self)
|
|
114
|
+
layout.addWidget(q_splitter_h2)
|
|
115
|
+
|
|
116
|
+
def _delete_roi_widget(self, roi_widget) -> None:
|
|
117
|
+
self._update()
|
|
118
|
+
|
|
119
|
+
def _make_roi_widget(self, roi: Roi) -> AbstractRoiWidget:
|
|
120
|
+
return DummyRoiWidget(roi)
|
|
121
|
+
|
|
122
|
+
def _init_connect(self):
|
|
123
|
+
self.app.image_holder.sigPolarImageChanged.connect(self._update_data)
|
|
124
|
+
self.app.image_holder.sigEmptyImage.connect(self._clear)
|
|
125
|
+
self.app.geometry_holder.sigScaleChanged.connect(self._update_data)
|
|
126
|
+
|
|
127
|
+
self.app.roi_dict.sig_roi_moved.connect(self._update_move)
|
|
128
|
+
self.app.roi_dict.sig_selected.connect(self._update)
|
|
129
|
+
self.app.roi_dict.sig_one_selected.connect(self._update)
|
|
130
|
+
self.app.roi_dict.sig_fixed.connect(self._fix)
|
|
131
|
+
self.app.roi_dict.sig_unfixed.connect(self._unfix)
|
|
132
|
+
self.app.roi_dict.sigConfLevelChanged.connect(self._change_confidence)
|
|
133
|
+
|
|
134
|
+
self.next_roi_btn.clicked.connect(self.app.roi_dict.select_next)
|
|
135
|
+
self.prev_roi_btn.clicked.connect(self.app.roi_dict.select_previous)
|
|
136
|
+
self.fit_current_button.clicked.connect(self._fit_current_clicked)
|
|
137
|
+
self.update_bounds_btn.clicked.connect(self._update_bounds_clicked)
|
|
138
|
+
self.update_params_by_range_btn.clicked.connect(self._update_params_by_range_clicked)
|
|
139
|
+
self.cif_widget.line_edit.textEdited.connect(self._cif_file_changed)
|
|
140
|
+
self.auto_fit_btn.clicked.connect(self._autofit_clicked)
|
|
141
|
+
self.auto_range_btn.clicked.connect(self._autorange_clicked)
|
|
142
|
+
self.fit_plot.sigRangeUpdated.connect(self._range_changed)
|
|
143
|
+
self.sliders_widget.sigValueChanged.connect(self._sliders_moved)
|
|
144
|
+
self.confidence_list.sigConfidenceChanged.connect(self._confidence_changed)
|
|
145
|
+
|
|
146
|
+
def _change_confidence(self):
|
|
147
|
+
if self.selected_fit:
|
|
148
|
+
self.confidence_list.set_level(self.selected_roi.confidence_level)
|
|
149
|
+
|
|
150
|
+
def _confidence_changed(self, level: float):
|
|
151
|
+
if self.selected_fit:
|
|
152
|
+
self.app.roi_dict.change_conf_level(self.selected_key, level)
|
|
153
|
+
|
|
154
|
+
def _cif_file_changed(self, cif_name: str):
|
|
155
|
+
try:
|
|
156
|
+
cif_name = str(cif_name)
|
|
157
|
+
except (ValueError, TypeError):
|
|
158
|
+
cif_name = 'input not valid'
|
|
159
|
+
if self.selected_fit:
|
|
160
|
+
self.app.roi_dict.change_cif_file(self.selected_key, cif_name)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _update_params_by_range_clicked(self):
|
|
164
|
+
if not self.selected_fit:
|
|
165
|
+
return
|
|
166
|
+
self.fit_holder.set_roi_from_range()
|
|
167
|
+
self._set_fit()
|
|
168
|
+
self._emit_move_roi()
|
|
169
|
+
|
|
170
|
+
def _autorange_clicked(self):
|
|
171
|
+
if not self.selected_fit:
|
|
172
|
+
return
|
|
173
|
+
self.fit_holder.set_auto_range()
|
|
174
|
+
self._set_fit()
|
|
175
|
+
self._emit_move_roi()
|
|
176
|
+
|
|
177
|
+
def _autofit_clicked(self):
|
|
178
|
+
for roi in self.app.roi_dict.values():
|
|
179
|
+
if roi.movable:
|
|
180
|
+
fit = self.fit_holder.set_auto_range(roi)
|
|
181
|
+
fit.do_fit()
|
|
182
|
+
self.app.roi_dict.move_roi(roi.key, self._name)
|
|
183
|
+
self.app.roi_dict.fix_roi(roi.key)
|
|
184
|
+
if roi.key == self.selected_key:
|
|
185
|
+
self.fit_holder.fit = fit
|
|
186
|
+
self._set_fit()
|
|
187
|
+
|
|
188
|
+
def _update_bounds_clicked(self):
|
|
189
|
+
fit = self.selected_fit
|
|
190
|
+
if not fit:
|
|
191
|
+
return
|
|
192
|
+
fit = self.fit_holder.set_default_bounds(fit.roi)
|
|
193
|
+
self.fit_plot.set_fit(fit)
|
|
194
|
+
self.sliders_widget.set_fit(fit)
|
|
195
|
+
self._emit_move_roi()
|
|
196
|
+
|
|
197
|
+
def _sliders_moved(self):
|
|
198
|
+
self.fit_holder.update_fit_data(update_bounds=False)
|
|
199
|
+
self.fit_plot.update_plot()
|
|
200
|
+
self._emit_move_roi()
|
|
201
|
+
|
|
202
|
+
def _range_changed(self):
|
|
203
|
+
self.fit_holder.update_fit_data(update_r_range=False)
|
|
204
|
+
self.fit_plot.update_plot(update_range=False)
|
|
205
|
+
self._emit_move_roi()
|
|
206
|
+
|
|
207
|
+
def _emit_move_roi(self):
|
|
208
|
+
if self.selected_fit:
|
|
209
|
+
self.app.roi_dict.move_roi(self.selected_roi.key, self._name)
|
|
210
|
+
|
|
211
|
+
@pyqtSlot(name='currentFitButtonClicked')
|
|
212
|
+
def _fit_current_clicked(self):
|
|
213
|
+
if self.selected_fit:
|
|
214
|
+
if self.fit_current_button.text() == CurrentFitButtonStatus.fit.value:
|
|
215
|
+
self._fit()
|
|
216
|
+
else:
|
|
217
|
+
self._emit_unfix()
|
|
218
|
+
|
|
219
|
+
def _emit_fix(self):
|
|
220
|
+
self.app.roi_dict.fix_roi(self.selected_key)
|
|
221
|
+
|
|
222
|
+
def _emit_unfix(self):
|
|
223
|
+
self.app.roi_dict.unfix_roi(self.selected_key)
|
|
224
|
+
|
|
225
|
+
def _fit(self):
|
|
226
|
+
if not self.selected_fit:
|
|
227
|
+
return
|
|
228
|
+
self.selected_fit.do_fit()
|
|
229
|
+
self.selected_fit.set_roi_from_params()
|
|
230
|
+
self.fit_plot.update_plot()
|
|
231
|
+
self.sliders_widget.update_values()
|
|
232
|
+
self._emit_move_roi()
|
|
233
|
+
self._emit_fix()
|
|
234
|
+
|
|
235
|
+
def _fix(self):
|
|
236
|
+
self.sliders_widget.setEnabled(False)
|
|
237
|
+
self.update_bounds_btn.setEnabled(False)
|
|
238
|
+
self.auto_range_btn.setEnabled(False)
|
|
239
|
+
self.update_params_by_range_btn.setEnabled(False)
|
|
240
|
+
self.fit_current_button.setText(CurrentFitButtonStatus.unfix.value)
|
|
241
|
+
|
|
242
|
+
def _unfix(self):
|
|
243
|
+
self.sliders_widget.setEnabled(True)
|
|
244
|
+
self.update_bounds_btn.setEnabled(True)
|
|
245
|
+
self.auto_range_btn.setEnabled(True)
|
|
246
|
+
self.update_params_by_range_btn.setEnabled(True)
|
|
247
|
+
self.fit_current_button.setText(CurrentFitButtonStatus.fit.value)
|
|
248
|
+
|
|
249
|
+
def _update_move(self, keys, name):
|
|
250
|
+
if name != self._name:
|
|
251
|
+
self._update()
|
|
252
|
+
|
|
253
|
+
def _update(self):
|
|
254
|
+
selected_rois = self.app.roi_dict.selected_rois
|
|
255
|
+
if len(selected_rois) == 1:
|
|
256
|
+
selected_roi = selected_rois[0]
|
|
257
|
+
key = selected_roi.key
|
|
258
|
+
self.cif_widget.line_edit.setText(str(selected_roi.cif_file))
|
|
259
|
+
if key == self.selected_key:
|
|
260
|
+
self.fit_holder.update_fit_data(update_r_range=selected_roi.movable)
|
|
261
|
+
else:
|
|
262
|
+
self.fit_holder.new_fit(selected_roi)
|
|
263
|
+
|
|
264
|
+
self._set_fit()
|
|
265
|
+
|
|
266
|
+
else:
|
|
267
|
+
self._clear()
|
|
268
|
+
|
|
269
|
+
def _set_fit(self):
|
|
270
|
+
self.fit_plot.set_fit(self.selected_fit)
|
|
271
|
+
self.sliders_widget.set_fit(self.selected_fit)
|
|
272
|
+
self.confidence_list.set_level(self.selected_roi.confidence_level)
|
|
273
|
+
if self.selected_roi.movable:
|
|
274
|
+
self._unfix()
|
|
275
|
+
else:
|
|
276
|
+
self._fix()
|
|
277
|
+
|
|
278
|
+
def _clear(self):
|
|
279
|
+
self.fit_holder.remove_fit()
|
|
280
|
+
self.sliders_widget.remove_fit()
|
|
281
|
+
self.fit_plot.remove_fit()
|
|
282
|
+
self._fix()
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
# class ControlsWidget(QWidget):
|
|
286
|
+
# def __init__(self, parent=None):
|
|
287
|
+
# super().__init__(parent)
|
|
288
|
+
# self._init_ui()
|
|
289
|
+
#
|
|
290
|
+
# def _init_ui(self):
|
|
291
|
+
# self.functions_box = QComboBox(self)
|
|
292
|
+
# self.background_box = QComboBox(self)
|
|
293
|
+
#
|
|
294
|
+
# self.range_factor_slider = LabeledSlider('Y range factor', (0, 10), parent=self, decimals=2)
|
|
295
|
+
# self.fit_current_button = QPushButton(CurrentFitButtonStatus.fit.value)
|
|
296
|
+
# self.fit_current_button.clicked.connect(self._fit_current_clicked)
|
|
297
|
+
# self.update_data_button = QPushButton('Update fit')
|
|
298
|
+
# self.update_data_button.clicked.connect(self._update_data_button_clicked)
|
|
299
|
+
#
|
|
300
|
+
# self.functions_box.currentTextChanged.connect(self._change_function)
|
|
301
|
+
# self.background_box.currentTextChanged.connect(self._change_background)
|
|
302
|
+
# self.range_strategies_box.currentTextChanged.connect(self._change_range_strategy)
|
|
303
|
+
#
|
|
304
|
+
# self.functions_box.addItem('Fitting functions')
|
|
305
|
+
# for t in FittingType:
|
|
306
|
+
# self.functions_box.addItem(t.value)
|
|
307
|
+
# self.background_box.addItem('Backgrounds')
|
|
308
|
+
# for t in BackgroundType:
|
|
309
|
+
# self.background_box.addItem(t.value)
|
|
310
|
+
#
|
|
311
|
+
# def _connect(self):
|
|
312
|
+
# self.fit_current_button.clicked.connect(self._fit_current_clicked)
|
|
313
|
+
# self.range_factor_slider.valueChanged.connect(self._on_range_slider_moved)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
class CurrentFitButtonStatus(Enum):
|
|
317
|
+
fit = 'Fit roi'
|
|
318
|
+
unfix = 'Unfix'
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
class FitPlot(Custom1DPlot):
|
|
322
|
+
sigRangeUpdated = pyqtSignal()
|
|
323
|
+
|
|
324
|
+
log = logging.getLogger(__name__)
|
|
325
|
+
|
|
326
|
+
def __init__(self, parent=None):
|
|
327
|
+
super().__init__(parent=parent)
|
|
328
|
+
self.fit: Fit = None
|
|
329
|
+
self.fit_plot = self.plot_item.plot()
|
|
330
|
+
self.profile_plot = self.plot_item.plot()
|
|
331
|
+
self.background_plot = self.plot_item.plot()
|
|
332
|
+
self.fit_plot.setPen(get_pen(color='red', style=Qt.DashDotDotLine, width=4))
|
|
333
|
+
self.background_plot.setPen(get_pen(color='blue', style=Qt.DashDotDotLine, width=4))
|
|
334
|
+
self.profile_plot.setPen(get_pen(color='white', style=Qt.DashDotDotLine, width=2))
|
|
335
|
+
|
|
336
|
+
self.range_roi: Roi = Roi(radius=0, width=1, key=-1)
|
|
337
|
+
self.range_widget: Roi1D = Roi1D(self.range_roi, enable_context=False)
|
|
338
|
+
self.range_widget.set_color(QColor(255, 255, 255, 50))
|
|
339
|
+
|
|
340
|
+
self.range_widget.sigRoiMoved.connect(self._range_updated)
|
|
341
|
+
|
|
342
|
+
self.plot_item.addItem(self.range_widget)
|
|
343
|
+
|
|
344
|
+
self.plot_item.setTitle('Fit')
|
|
345
|
+
self.plot_item.getAxis('bottom').setLabel('|Q|', color='white', font_size='large')
|
|
346
|
+
self.plot_item.getAxis('left').setLabel('Intensity', color='white', font_size='large')
|
|
347
|
+
|
|
348
|
+
def _update_range(self):
|
|
349
|
+
if not self.fit:
|
|
350
|
+
return
|
|
351
|
+
r1, r2 = self.fit.r_range
|
|
352
|
+
self.range_roi.radius = (r1 + r2) / 2
|
|
353
|
+
self.range_roi.width = r2 - r1
|
|
354
|
+
self.range_widget.move_roi()
|
|
355
|
+
|
|
356
|
+
def _range_updated(self):
|
|
357
|
+
r, w = self.range_roi.radius, self.range_roi.width
|
|
358
|
+
self.fit.r_range = r - w / 2, r + w / 2
|
|
359
|
+
self.sigRangeUpdated.emit()
|
|
360
|
+
|
|
361
|
+
def set_fit(self, fit: Fit):
|
|
362
|
+
self.fit = fit
|
|
363
|
+
self.update_plot()
|
|
364
|
+
|
|
365
|
+
def update_plot(self, update_range: bool = True):
|
|
366
|
+
if not self.fit:
|
|
367
|
+
return
|
|
368
|
+
try:
|
|
369
|
+
self.range_widget.show()
|
|
370
|
+
self.profile_plot.setData(self.fit.x_profile, self.fit.y_profile)
|
|
371
|
+
self.plot.setData(self.fit.x, self.fit.y)
|
|
372
|
+
self.fit_plot.setData(self.fit.x, self.fit.init_curve)
|
|
373
|
+
if self.fit.background_curve is not None:
|
|
374
|
+
self.background_plot.setData(self.fit.x, self.fit.background_curve)
|
|
375
|
+
else:
|
|
376
|
+
self.background_plot.clear()
|
|
377
|
+
if update_range:
|
|
378
|
+
self._update_range()
|
|
379
|
+
self._set_range()
|
|
380
|
+
|
|
381
|
+
except Exception as err:
|
|
382
|
+
self.log.exception(err)
|
|
383
|
+
self.clear_plot()
|
|
384
|
+
|
|
385
|
+
def _set_range(self, pad: float = 0.4):
|
|
386
|
+
if not self.fit:
|
|
387
|
+
return
|
|
388
|
+
y_min, y_max = np.nanmin(self.fit.y), np.nanmax(self.fit.y)
|
|
389
|
+
for curve in (self.fit.init_curve, self.fit.fitting_curve, self.fit.background_curve):
|
|
390
|
+
if curve is not None:
|
|
391
|
+
y_min = min(y_min, np.nanmin(curve))
|
|
392
|
+
y_max = max(y_max, np.nanmax(curve))
|
|
393
|
+
|
|
394
|
+
dx = np.nanmax(self.fit.x) - np.nanmin(self.fit.x)
|
|
395
|
+
dy = y_max - y_min
|
|
396
|
+
self.plot_item.setRange(
|
|
397
|
+
xRange=[np.nanmin(self.fit.x) - dx * pad, np.nanmax(self.fit.x) + dx * pad],
|
|
398
|
+
yRange=[y_min - dy * pad, y_max + dy * pad]
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
def remove_fit(self):
|
|
402
|
+
self.fit = None
|
|
403
|
+
self.clear_plot()
|
|
404
|
+
|
|
405
|
+
def clear_plot(self):
|
|
406
|
+
self.plot.clear()
|
|
407
|
+
self.fit_plot.clear()
|
|
408
|
+
self.background_plot.clear()
|
|
409
|
+
self.profile_plot.clear()
|
|
410
|
+
self.range_widget.hide()
|
|
411
|
+
self.update()
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
class SliderWithLabels(QFrame):
|
|
415
|
+
def __init__(self, slider: ParametersSlider, label: QLabel, parent=None):
|
|
416
|
+
super().__init__(parent=parent)
|
|
417
|
+
self.slider = slider
|
|
418
|
+
self.label = label
|
|
419
|
+
self._init_ui()
|
|
420
|
+
|
|
421
|
+
def _init_ui(self):
|
|
422
|
+
layout = QGridLayout(self)
|
|
423
|
+
layout.addWidget(self.label, 0, 0, alignment=Qt.AlignHCenter)
|
|
424
|
+
layout.addWidget(self.slider, 1, 0)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
class SlidersWidget(QWidget):
|
|
428
|
+
sigValueChanged = pyqtSignal()
|
|
429
|
+
DEFAULT_LABEL = 'lower bound; init value; upper bound'
|
|
430
|
+
|
|
431
|
+
log = logging.getLogger(__name__)
|
|
432
|
+
|
|
433
|
+
def __init__(self, param_names: tuple = (), parent=None):
|
|
434
|
+
super().__init__(parent=parent)
|
|
435
|
+
self.fit: Fit = None
|
|
436
|
+
self.param_names = param_names
|
|
437
|
+
|
|
438
|
+
self._sliders: Dict[int, ParametersSlider] = {}
|
|
439
|
+
self._labels: Dict[int, QLabel] = {}
|
|
440
|
+
self._param_labels: Dict[int, QLabel] = {}
|
|
441
|
+
|
|
442
|
+
self._init_ui()
|
|
443
|
+
|
|
444
|
+
def _init_ui(self):
|
|
445
|
+
self._layout = QGridLayout(self)
|
|
446
|
+
|
|
447
|
+
for i, param_name in enumerate(self.param_names):
|
|
448
|
+
self._add_parameter(i, param_name)
|
|
449
|
+
|
|
450
|
+
def set_fit(self, fit: Fit):
|
|
451
|
+
self.fit = fit
|
|
452
|
+
if self.fit is None:
|
|
453
|
+
self.remove_fit()
|
|
454
|
+
return
|
|
455
|
+
self.set_param_names(fit.param_names)
|
|
456
|
+
self.update_values()
|
|
457
|
+
|
|
458
|
+
def _add_parameter(self, i: int, param_name: str):
|
|
459
|
+
self._param_labels[i] = pl = QLabel(param_name)
|
|
460
|
+
self._sliders[i] = sl = ParametersSlider()
|
|
461
|
+
self._labels[i] = ll = QLabel(self.DEFAULT_LABEL)
|
|
462
|
+
self._layout.addWidget(pl, i, 0, alignment=Qt.AlignCenter)
|
|
463
|
+
self._layout.addWidget(SliderWithLabels(sl, ll, self), i, 1)
|
|
464
|
+
sl.sigLowerValueChanged.connect(lambda x, idx=i: self._send_value(x, 0, idx))
|
|
465
|
+
sl.sigMiddleValueChanged.connect(lambda x, idx=i: self._send_value(x, 1, idx))
|
|
466
|
+
sl.sigUpperValueChanged.connect(lambda x, idx=i: self._send_value(x, 2, idx))
|
|
467
|
+
|
|
468
|
+
if App().debug_tracker:
|
|
469
|
+
App().debug_tracker.add_object(pl)
|
|
470
|
+
App().debug_tracker.add_object(sl)
|
|
471
|
+
App().debug_tracker.add_object(ll)
|
|
472
|
+
|
|
473
|
+
def _remove_parameter(self, i: int):
|
|
474
|
+
pl = self._param_labels.pop(i)
|
|
475
|
+
sl = self._sliders.pop(i)
|
|
476
|
+
ll = self._labels.pop(i)
|
|
477
|
+
self._layout.removeWidget(pl)
|
|
478
|
+
self._layout.removeWidget(sl)
|
|
479
|
+
self._layout.removeWidget(ll)
|
|
480
|
+
pl.deleteLater()
|
|
481
|
+
sl.deleteLater()
|
|
482
|
+
ll.deleteLater()
|
|
483
|
+
|
|
484
|
+
def set_param_names(self, param_names: tuple):
|
|
485
|
+
if param_names == self.param_names:
|
|
486
|
+
return
|
|
487
|
+
|
|
488
|
+
i = 0
|
|
489
|
+
for i, name in enumerate(param_names):
|
|
490
|
+
if i == len(self._param_labels):
|
|
491
|
+
self._add_parameter(i, name)
|
|
492
|
+
else:
|
|
493
|
+
self._param_labels[i].setText(name)
|
|
494
|
+
|
|
495
|
+
if i < len(self.param_names) - 1:
|
|
496
|
+
for j in range(i + 1, len(self.param_names)):
|
|
497
|
+
self._remove_parameter(j)
|
|
498
|
+
|
|
499
|
+
self.param_names = param_names
|
|
500
|
+
|
|
501
|
+
def update_values(self):
|
|
502
|
+
if not self.fit:
|
|
503
|
+
return
|
|
504
|
+
fit = self.fit
|
|
505
|
+
for idx, (l, i, u) in enumerate(zip(fit.lower_bounds, fit.init_params, fit.upper_bounds)):
|
|
506
|
+
try:
|
|
507
|
+
lu = abs(u - l) / 2
|
|
508
|
+
self._sliders[idx].setValues(l, i, u, new_range=(l - lu, u + lu))
|
|
509
|
+
except ValueError as err:
|
|
510
|
+
self.log.error(f'{self._param_labels[idx].text()} received wrong values.')
|
|
511
|
+
self.log.exception(err)
|
|
512
|
+
self._update_label(idx, l, i, u)
|
|
513
|
+
|
|
514
|
+
def _update_label(self, idx: int, l: float, i: float, u: float):
|
|
515
|
+
self._labels[idx].setText(f'lower bound = {l:0.3f}; init value = {i:0.3f}; upper bound = {u:0.3f}')
|
|
516
|
+
|
|
517
|
+
def _send_value(self, value: float, place: int, idx: int):
|
|
518
|
+
if not self.fit:
|
|
519
|
+
return
|
|
520
|
+
if place == 0:
|
|
521
|
+
params = self.fit.lower_bounds
|
|
522
|
+
elif place == 1:
|
|
523
|
+
params = self.fit.init_params
|
|
524
|
+
else:
|
|
525
|
+
params = self.fit.upper_bounds
|
|
526
|
+
params[idx] = value
|
|
527
|
+
|
|
528
|
+
self._update_label(
|
|
529
|
+
idx, self.fit.lower_bounds[idx], self.fit.init_params[idx], self.fit.upper_bounds[idx])
|
|
530
|
+
|
|
531
|
+
self.sigValueChanged.emit()
|
|
532
|
+
|
|
533
|
+
def remove_fit(self):
|
|
534
|
+
self.fit = None
|
|
535
|
+
for l in self._labels.values():
|
|
536
|
+
l.setText(self.DEFAULT_LABEL)
|