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.
Files changed (202) hide show
  1. mlgidGUI/__init__.py +52 -0
  2. mlgidGUI/__main__.py +7 -0
  3. mlgidGUI/__version.py +1 -0
  4. mlgidGUI/app/__init__.py +8 -0
  5. mlgidGUI/app/actions_stack.py +1 -0
  6. mlgidGUI/app/app.py +67 -0
  7. mlgidGUI/app/cif_rois/__init__.py +0 -0
  8. mlgidGUI/app/cif_rois/cif_peaks_calculation.py +57 -0
  9. mlgidGUI/app/cif_rois/cif_simulation/__init__.py +0 -0
  10. mlgidGUI/app/cif_rois/cif_simulation/data/__init__.py +0 -0
  11. mlgidGUI/app/cif_rois/cif_simulation/data/atoms.py +15 -0
  12. mlgidGUI/app/cif_rois/cif_simulation/data/export_database.py +28 -0
  13. mlgidGUI/app/cif_rois/cif_simulation/experiment.py +57 -0
  14. mlgidGUI/app/cif_rois/cif_simulation/giwaxs_sim.py +286 -0
  15. mlgidGUI/app/cif_rois/cif_simulation/int_sim.py +105 -0
  16. mlgidGUI/app/cif_rois/cif_simulation/possible_directions.py +20 -0
  17. mlgidGUI/app/cif_rois/cif_simulation/q_sim.py +159 -0
  18. mlgidGUI/app/data_manager/__init__.py +4 -0
  19. mlgidGUI/app/data_manager/data_manager.py +164 -0
  20. mlgidGUI/app/data_manager/import_from_h5.py +68 -0
  21. mlgidGUI/app/data_manager/load_data.py +78 -0
  22. mlgidGUI/app/data_manager/pascal/__init__.py +2 -0
  23. mlgidGUI/app/data_manager/pascal/annotation_fabric.py +59 -0
  24. mlgidGUI/app/data_manager/pascal/draw_objects.py +119 -0
  25. mlgidGUI/app/data_manager/pascal/exceptions.py +6 -0
  26. mlgidGUI/app/data_manager/pascal/format_convertor.py +127 -0
  27. mlgidGUI/app/data_manager/pascal/pascal_annotation.py +85 -0
  28. mlgidGUI/app/data_manager/pascal/protocol_implementations.py +28 -0
  29. mlgidGUI/app/data_manager/pascal/protocols.py +47 -0
  30. mlgidGUI/app/data_manager/pascal/utils.py +64 -0
  31. mlgidGUI/app/data_manager/save_dataset.py +57 -0
  32. mlgidGUI/app/data_manager/save_h5.py +178 -0
  33. mlgidGUI/app/data_manager/saving_parameters.py +88 -0
  34. mlgidGUI/app/debug_tracker.py +129 -0
  35. mlgidGUI/app/edf_reader.py +135 -0
  36. mlgidGUI/app/file_manager/__init__.py +201 -0
  37. mlgidGUI/app/file_manager/config_manager.py +76 -0
  38. mlgidGUI/app/file_manager/keys.py +542 -0
  39. mlgidGUI/app/file_manager/npy_file_manager.py +17 -0
  40. mlgidGUI/app/file_manager/object_file_manager.py +77 -0
  41. mlgidGUI/app/file_manager/project_structure.py +169 -0
  42. mlgidGUI/app/file_manager/read_fits.py +76 -0
  43. mlgidGUI/app/file_manager/read_geometry.py +54 -0
  44. mlgidGUI/app/file_manager/read_images.py +31 -0
  45. mlgidGUI/app/file_manager/read_meta_roi.py +40 -0
  46. mlgidGUI/app/file_manager/read_polar_images.py +22 -0
  47. mlgidGUI/app/file_manager/read_radial_profile.py +6 -0
  48. mlgidGUI/app/file_manager/read_roi_data.py +39 -0
  49. mlgidGUI/app/fitting/__init__.py +5 -0
  50. mlgidGUI/app/fitting/background.py +92 -0
  51. mlgidGUI/app/fitting/fit.py +128 -0
  52. mlgidGUI/app/fitting/fit_holder.py +273 -0
  53. mlgidGUI/app/fitting/fit_object.py +247 -0
  54. mlgidGUI/app/fitting/functions.py +107 -0
  55. mlgidGUI/app/fitting/range_strategy.py +14 -0
  56. mlgidGUI/app/fitting/utils.py +17 -0
  57. mlgidGUI/app/geometry.py +236 -0
  58. mlgidGUI/app/geometry_holder.py +131 -0
  59. mlgidGUI/app/image_holder.py +200 -0
  60. mlgidGUI/app/image_processing.py +23 -0
  61. mlgidGUI/app/polar_image.py +96 -0
  62. mlgidGUI/app/profiles/__init__.py +5 -0
  63. mlgidGUI/app/profiles/angular_profile.py +20 -0
  64. mlgidGUI/app/profiles/basic_profile.py +169 -0
  65. mlgidGUI/app/profiles/radial_profile.py +38 -0
  66. mlgidGUI/app/read_image.py +21 -0
  67. mlgidGUI/app/rois/__init__.py +4 -0
  68. mlgidGUI/app/rois/new_roi_dict.py +670 -0
  69. mlgidGUI/app/rois/roi.py +194 -0
  70. mlgidGUI/app/rois/roi_colors.py +76 -0
  71. mlgidGUI/app/rois/roi_data.py +177 -0
  72. mlgidGUI/app/rois/roi_dict.py +466 -0
  73. mlgidGUI/app/rois/roi_meta_data.py +149 -0
  74. mlgidGUI/app/structures/__init__.py +6 -0
  75. mlgidGUI/app/structures/crystal_ring.py +19 -0
  76. mlgidGUI/app/structures/crystals_holders.py +144 -0
  77. mlgidGUI/app/structures/custom_crystal.py +45 -0
  78. mlgidGUI/app/structures/get_ring_list.py +89 -0
  79. mlgidGUI/app/transformations.py +82 -0
  80. mlgidGUI/app/update/__init__.py +3 -0
  81. mlgidGUI/app/update/check_version.py +51 -0
  82. mlgidGUI/app/update/launch_program.py +15 -0
  83. mlgidGUI/app/update/script_update.py +64 -0
  84. mlgidGUI/app/utils.py +124 -0
  85. mlgidGUI/gui/__init__.py +3 -0
  86. mlgidGUI/gui/background_tasks.py +41 -0
  87. mlgidGUI/gui/background_update.py +87 -0
  88. mlgidGUI/gui/basic_widgets/__init__.py +12 -0
  89. mlgidGUI/gui/basic_widgets/buttons.py +144 -0
  90. mlgidGUI/gui/basic_widgets/labels.py +51 -0
  91. mlgidGUI/gui/basic_widgets/mouse_events.py +119 -0
  92. mlgidGUI/gui/basic_widgets/path_line.py +162 -0
  93. mlgidGUI/gui/basic_widgets/plots_1d.py +365 -0
  94. mlgidGUI/gui/basic_widgets/plots_2d.py +224 -0
  95. mlgidGUI/gui/basic_widgets/popups.py +164 -0
  96. mlgidGUI/gui/basic_widgets/progress_bar.py +127 -0
  97. mlgidGUI/gui/basic_widgets/setup_widgets.py +138 -0
  98. mlgidGUI/gui/basic_widgets/sliders.py +616 -0
  99. mlgidGUI/gui/basic_widgets/spinner.py +65 -0
  100. mlgidGUI/gui/basic_widgets/toolbars.py +19 -0
  101. mlgidGUI/gui/debug_widgets.py +388 -0
  102. mlgidGUI/gui/dock_area.py +115 -0
  103. mlgidGUI/gui/exception_message.py +42 -0
  104. mlgidGUI/gui/fitting/__init__.py +2 -0
  105. mlgidGUI/gui/fitting/fit_widget.py +966 -0
  106. mlgidGUI/gui/fitting/inplace_fit.py +536 -0
  107. mlgidGUI/gui/fitting/selected_fit_widget.py +286 -0
  108. mlgidGUI/gui/gui_main.py +349 -0
  109. mlgidGUI/gui/image_viewer.py +323 -0
  110. mlgidGUI/gui/init_window.py +170 -0
  111. mlgidGUI/gui/load_window/__init__.py +2 -0
  112. mlgidGUI/gui/load_window/load_folder.py +61 -0
  113. mlgidGUI/gui/load_window/load_h5.py +73 -0
  114. mlgidGUI/gui/notifications.py +68 -0
  115. mlgidGUI/gui/polar_image_viewer.py +153 -0
  116. mlgidGUI/gui/profiles/__init__.py +1 -0
  117. mlgidGUI/gui/profiles/angular_profile_widget.py +62 -0
  118. mlgidGUI/gui/profiles/radial_profile_widget.py +164 -0
  119. mlgidGUI/gui/project_manager/__init__.py +17 -0
  120. mlgidGUI/gui/project_manager/cif_files_widget.py +196 -0
  121. mlgidGUI/gui/project_manager/cif_results.py +146 -0
  122. mlgidGUI/gui/project_manager/metadata_widget.py +15 -0
  123. mlgidGUI/gui/project_manager/project_viewer.py +151 -0
  124. mlgidGUI/gui/project_manager/roi_widget.py +171 -0
  125. mlgidGUI/gui/roi_widgets/__init__.py +6 -0
  126. mlgidGUI/gui/roi_widgets/abstract_roi_holder.py +189 -0
  127. mlgidGUI/gui/roi_widgets/abstract_roi_widget.py +111 -0
  128. mlgidGUI/gui/roi_widgets/cif_file_widget.py +16 -0
  129. mlgidGUI/gui/roi_widgets/cif_peak_widget.py +43 -0
  130. mlgidGUI/gui/roi_widgets/confidence_level_widget.py +105 -0
  131. mlgidGUI/gui/roi_widgets/roi_1d_widget.py +136 -0
  132. mlgidGUI/gui/roi_widgets/roi_2d_rect_widget.py +98 -0
  133. mlgidGUI/gui/roi_widgets/roi_2d_ring_widget.py +203 -0
  134. mlgidGUI/gui/roi_widgets/rois_context_menu.py +150 -0
  135. mlgidGUI/gui/roi_widgets/select_roi_color_widget.py +58 -0
  136. mlgidGUI/gui/save_window/__init__.py +152 -0
  137. mlgidGUI/gui/save_window/format_box.py +33 -0
  138. mlgidGUI/gui/save_window/num_selected_widget.py +45 -0
  139. mlgidGUI/gui/save_window/options_widgets.py +105 -0
  140. mlgidGUI/gui/save_window/save_mode_box.py +30 -0
  141. mlgidGUI/gui/save_window/select_images.py +198 -0
  142. mlgidGUI/gui/tools.py +179 -0
  143. mlgidGUI/static/__init__.py +0 -0
  144. mlgidGUI/static/icons/__init__.py +0 -0
  145. mlgidGUI/static/icons/add.png +0 -0
  146. mlgidGUI/static/icons/add_yellow.png +0 -0
  147. mlgidGUI/static/icons/angular_profile.png +0 -0
  148. mlgidGUI/static/icons/arrow.png +0 -0
  149. mlgidGUI/static/icons/baseline.png +0 -0
  150. mlgidGUI/static/icons/center.png +0 -0
  151. mlgidGUI/static/icons/confirm.png +0 -0
  152. mlgidGUI/static/icons/control_widget.png +0 -0
  153. mlgidGUI/static/icons/data.png +0 -0
  154. mlgidGUI/static/icons/delete.png +0 -0
  155. mlgidGUI/static/icons/delete_yellow.png +0 -0
  156. mlgidGUI/static/icons/error.png +0 -0
  157. mlgidGUI/static/icons/find.png +0 -0
  158. mlgidGUI/static/icons/fit.png +0 -0
  159. mlgidGUI/static/icons/fix_all.png +0 -0
  160. mlgidGUI/static/icons/flip_horizontal.png +0 -0
  161. mlgidGUI/static/icons/flip_vertical.png +0 -0
  162. mlgidGUI/static/icons/folder.png +0 -0
  163. mlgidGUI/static/icons/fromfullscreen.png +0 -0
  164. mlgidGUI/static/icons/h5_folder.png +0 -0
  165. mlgidGUI/static/icons/h5_group_folder.png +0 -0
  166. mlgidGUI/static/icons/info.png +0 -0
  167. mlgidGUI/static/icons/interpolate.png +0 -0
  168. mlgidGUI/static/icons/item.png +0 -0
  169. mlgidGUI/static/icons/properties.png +0 -0
  170. mlgidGUI/static/icons/radial_profile.png +0 -0
  171. mlgidGUI/static/icons/roi_item.png +0 -0
  172. mlgidGUI/static/icons/rotate.png +0 -0
  173. mlgidGUI/static/icons/rotate_image.png +0 -0
  174. mlgidGUI/static/icons/rotate_right.png +0 -0
  175. mlgidGUI/static/icons/setup.png +0 -0
  176. mlgidGUI/static/icons/setup_white.png +0 -0
  177. mlgidGUI/static/icons/tofullscreen.png +0 -0
  178. mlgidGUI/static/icons/unfix_all.png +0 -0
  179. mlgidGUI/static/icons/update.png +0 -0
  180. mlgidGUI/static/icons/update_suggested.png +0 -0
  181. mlgidGUI/static/icons/window_icon.png +0 -0
  182. mlgidGUI/static/icons/window_icon_256.png +0 -0
  183. mlgidGUI/utils/__init__.py +1 -0
  184. mlgidGUI/utils/project2h5.py +11 -0
  185. mlgidgui-0.4.1.dist-info/METADATA +119 -0
  186. mlgidgui-0.4.1.dist-info/RECORD +202 -0
  187. mlgidgui-0.4.1.dist-info/WHEEL +5 -0
  188. mlgidgui-0.4.1.dist-info/entry_points.txt +5 -0
  189. mlgidgui-0.4.1.dist-info/licenses/LICENSE +674 -0
  190. mlgidgui-0.4.1.dist-info/top_level.txt +4 -0
  191. tests/__init__.py +0 -0
  192. tests/conftest.py +1 -0
  193. tests/fixures/__init__.py +2 -0
  194. tests/fixures/projects.py +102 -0
  195. tests/func/__init__.py +1 -0
  196. tests/func/test_loading_state.py +21 -0
  197. tests/func/test_parse_project_data.py +23 -0
  198. tests/func/test_save.py +62 -0
  199. tests/unit/__init__.py +0 -0
  200. tests/unit/rois/__init__.py +0 -0
  201. tests/unit/rois/test_basic_operations.py +18 -0
  202. tests/unit/test_add_data.py +33 -0
@@ -0,0 +1,198 @@
1
+ from typing import Iterable, List, Dict, Any
2
+
3
+ from PyQt5.QtWidgets import (
4
+ QWidget,
5
+ QGridLayout,
6
+ QTreeWidgetItemIterator,
7
+ QPushButton,
8
+ QTreeWidget,
9
+ QTreeWidgetItem,
10
+ QSplitter,
11
+ )
12
+ from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal
13
+
14
+ from ...app import Roi, App
15
+ from ...app.file_manager import ImageKey, FolderKey
16
+ from ...app.data_manager import ImageData, ImageDataFlags
17
+ from ...gui.image_viewer import ImageViewer
18
+
19
+
20
+ class SelectImagesWindow(QWidget):
21
+ sigApplyClicked = pyqtSignal(dict)
22
+
23
+ def __init__(self, path_dict: Dict[FolderKey, List[ImageKey]], parent=None):
24
+ super().__init__(parent)
25
+ self.setWindowFlag(Qt.Window, True)
26
+ self.setWindowState(Qt.WindowMaximized)
27
+ self.setWindowModality(Qt.WindowModal)
28
+ self.setAttribute(Qt.WA_DeleteOnClose, True)
29
+
30
+ self.app = App()
31
+
32
+ self._init_ui(path_dict)
33
+ self._init_layout()
34
+ self._init_connections()
35
+
36
+ if self.app.debug_tracker:
37
+ self.app.debug_tracker.add_object(self, 'SelectImagesWindow')
38
+
39
+ def _init_ui(self, path_dict: Dict[FolderKey, List[ImageKey]]):
40
+ self._image_tree_widget = ImageTreeWidget(path_dict, self)
41
+ self._image_viewer = SimpleImageViewer(self)
42
+ self._save_button = QPushButton('Apply')
43
+ self._cancel_button = QPushButton('Cancel')
44
+
45
+ def _init_layout(self):
46
+ common_layout = QGridLayout(self)
47
+
48
+ splitter = QSplitter(Qt.Horizontal, self)
49
+ common_layout.addWidget(splitter)
50
+
51
+ left_widget = QWidget(splitter)
52
+ layout = QGridLayout(left_widget)
53
+ layout.addWidget(self._image_tree_widget, 0, 0, 1, 2)
54
+ layout.addWidget(self._save_button, 1, 0)
55
+ layout.addWidget(self._cancel_button, 1, 1)
56
+
57
+ splitter.addWidget(left_widget)
58
+ splitter.addWidget(self._image_viewer)
59
+ splitter.setSizes([200, 600])
60
+
61
+ def _init_connections(self):
62
+ self._image_tree_widget.sigImageSelected.connect(self._on_image_selected)
63
+ self._save_button.clicked.connect(self._on_save_clicked)
64
+ self._cancel_button.clicked.connect(self.close)
65
+
66
+ @pyqtSlot(object, name='imageSelected')
67
+ def _on_image_selected(self, image_key: ImageKey):
68
+ self._image_viewer.clear_rois()
69
+
70
+ image_data: ImageData = self.app.data_manager.load_image_data(
71
+ image_key, flags=ImageDataFlags.IMAGE | ImageDataFlags.ROI_DATA)
72
+ if image_data.image is not None:
73
+ self._image_viewer.set_data(image_data.image)
74
+ if image_data.roi_data:
75
+ self._image_viewer.add_rois(image_data.roi_data.values())
76
+ else:
77
+ self._image_viewer.clear_image()
78
+
79
+ @pyqtSlot(name='onSavedClicked')
80
+ def _on_save_clicked(self):
81
+ self.sigApplyClicked.emit(self._image_tree_widget.get_path_dict())
82
+ self.close()
83
+
84
+
85
+ class SimpleImageViewer(ImageViewer):
86
+ def _init_connect(self):
87
+ pass
88
+
89
+ def add_rois(self, rois: Iterable[Roi]):
90
+ for roi in rois:
91
+ self._roi_widgets[roi.key] = self._make_roi_widget(roi)
92
+
93
+ def clear_rois(self):
94
+ for key in list(self._roi_widgets.keys()):
95
+ self._delete_roi_widget(self._roi_widgets.pop(key))
96
+
97
+
98
+ class KeyItem(QTreeWidgetItem):
99
+ def __init__(self, parent, key: ImageKey or FolderKey, is_image: bool = True):
100
+ super().__init__(parent)
101
+ self.key = key
102
+ self.is_image = is_image
103
+
104
+ def setData(self, column: int, role: int, value: Any) -> None:
105
+ is_check_change: bool = (column == 0 and
106
+ role == Qt.CheckStateRole and
107
+ self.data(column, role) is not None and
108
+ self.checkState(0) != value)
109
+ super().setData(column, role, value)
110
+ if is_check_change:
111
+ if self.is_image:
112
+ self.treeWidget().sigImageChecked.emit(self.key, self.checkState(0) == Qt.Checked)
113
+ else:
114
+ self.treeWidget().sigFolderChecked.emit(self.key, self.checkState(0) == Qt.Checked)
115
+
116
+
117
+ class MyTree(QTreeWidget):
118
+ sigImageChecked = pyqtSignal(object, bool)
119
+ sigFolderChecked = pyqtSignal(object, bool)
120
+
121
+ def __init__(self, parent):
122
+ super().__init__(parent)
123
+ self.setHeaderLabel('Selected images')
124
+
125
+ def get_path_dict(self) -> Dict[FolderKey, List[ImageKey]]:
126
+ path_dict: Dict[FolderKey, List[ImageKey]] = {}
127
+
128
+ iterator = QTreeWidgetItemIterator(self, QTreeWidgetItemIterator.All)
129
+
130
+ while iterator.value():
131
+ item = iterator.value()
132
+ if item.is_image and item.checkState(0) == Qt.Checked:
133
+ folder_key = item.key.parent
134
+ if folder_key not in path_dict:
135
+ path_dict[folder_key] = []
136
+ path_dict[folder_key].append(item.key)
137
+ iterator += 1
138
+
139
+ return path_dict
140
+
141
+
142
+ class ImageTreeWidget(QWidget):
143
+ sigImageSelected = pyqtSignal(object)
144
+ sigPathDictChanged = pyqtSignal(dict)
145
+
146
+ def __init__(self, path_dict: Dict[FolderKey, List[ImageKey]], parent):
147
+ super().__init__(parent)
148
+ self.path_dict: Dict[FolderKey, List[ImageKey]] = path_dict
149
+ self._init_ui()
150
+
151
+ self.tree.itemSelectionChanged.connect(self._on_item_selected)
152
+ self.tree.sigImageChecked.connect(self._on_image_checked_status_changed)
153
+ self.tree.sigFolderChecked.connect(self._on_folder_checked_status_changed)
154
+
155
+ def _init_ui(self):
156
+ layout = QGridLayout(self)
157
+ self.tree = MyTree(self)
158
+
159
+ layout.addWidget(self.tree)
160
+
161
+ for folder_key, image_keys in self.path_dict.items():
162
+ folder_item = KeyItem(self.tree, folder_key, False)
163
+ folder_item.setText(0, folder_key.name)
164
+ folder_item.setFlags(folder_item.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable)
165
+
166
+ for image_key in image_keys:
167
+ child = KeyItem(folder_item, image_key)
168
+ child.setFlags(child.flags())
169
+ child.setText(0, image_key.name)
170
+ child.setCheckState(0, Qt.Checked)
171
+
172
+ @pyqtSlot(object, bool, name='onImageCheckedStatusChanged')
173
+ def _on_image_checked_status_changed(self, image_key: ImageKey, status: bool):
174
+ folder_key = image_key.parent
175
+ if status:
176
+ if folder_key not in self.path_dict:
177
+ self.path_dict[folder_key] = []
178
+ self.path_dict[folder_key].append(image_key)
179
+ else:
180
+ self.path_dict[folder_key].remove(image_key)
181
+ self.sigPathDictChanged.emit(self.path_dict)
182
+
183
+ @pyqtSlot(object, bool, name='onFolderCheckedStatusChanged')
184
+ def _on_folder_checked_status_changed(self, folder_key: FolderKey, status: bool):
185
+ self.path_dict = self.tree.get_path_dict()
186
+ self.sigPathDictChanged.emit(self.path_dict)
187
+
188
+ def get_path_dict(self) -> Dict[FolderKey, List[ImageKey]]:
189
+ return self.tree.get_path_dict()
190
+
191
+ @pyqtSlot(name='onItemClicked')
192
+ def _on_item_selected(self):
193
+ try:
194
+ item = self.tree.selectedItems()[0]
195
+ if item.is_image:
196
+ self.sigImageSelected.emit(item.key)
197
+ except (IndexError, AttributeError):
198
+ return
mlgidGUI/gui/tools.py ADDED
@@ -0,0 +1,179 @@
1
+ import logging
2
+ import os.path
3
+ from pathlib import Path
4
+ from itertools import count
5
+
6
+ from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QLineEdit,
7
+ QWidget, QApplication, QMessageBox,
8
+ QFileDialog)
9
+ from PyQt5.QtCore import QPropertyAnimation, Qt
10
+ from PyQt5.QtGui import QColor, QIcon, QPen
11
+
12
+ from ..app.file_manager import GLOB_IMAGE_FORMATS
13
+
14
+ ICON_PATH: Path = Path(__file__).parents[1] / 'static' / 'icons'
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ class DummySignal(object):
20
+ def __init__(self, *args, **kwargs):
21
+ pass
22
+
23
+ def connect(self, *args, **kwargs):
24
+ pass
25
+
26
+ def emit(self, *args, **kwargs):
27
+ pass
28
+
29
+ def disconnect(self, *args, **kwargs):
30
+ pass
31
+
32
+
33
+ def save_file_dialog(parent,
34
+ title: str = 'Save File',
35
+ file_format: str = 'H5 file (*.h5)',
36
+ *, exists: bool = False,
37
+ directory: str = '',
38
+ native: bool = False,
39
+ ) -> Path or None:
40
+ options = QFileDialog.Options()
41
+
42
+ if not native:
43
+ options |= QFileDialog.DontUseNativeDialog
44
+
45
+ if exists:
46
+ filename, _ = QFileDialog.getOpenFileName(parent, title, directory, file_format, options=options)
47
+ else:
48
+ filename, _ = QFileDialog.getSaveFileName(parent, title, directory, file_format, options=options)
49
+
50
+ if filename:
51
+ return Path(filename)
52
+
53
+
54
+ def get_filepath_dialog(parent, message: str = 'Open image', formats: str = GLOB_IMAGE_FORMATS) -> Path or None:
55
+ options = QFileDialog.Options()
56
+ options |= QFileDialog.DontUseNativeDialog
57
+ filepath, _ = QFileDialog.getOpenFileName(
58
+ parent, message, '',
59
+ formats, options=options)
60
+ if filepath:
61
+ return Path(filepath)
62
+
63
+ def get_new_project_folder():
64
+ new_project_path = Path('~/GIWAXSProjects').expanduser().resolve() / 'NewProject'
65
+ if not os.path.isdir(new_project_path):
66
+ return new_project_path
67
+ else:
68
+ for i in count(1):
69
+ new_project_path = Path('~/GIWAXSProjects').expanduser().resolve() / ('NewProject' + str(i))
70
+ if not os.path.isdir(new_project_path):
71
+ return new_project_path
72
+
73
+
74
+ def get_folder_filepath(parent, message: str, *, show_files: bool = True,
75
+ directory: str = '', exists: bool = True, native: bool = False,
76
+ ) -> Path or None:
77
+ options = QFileDialog.DontResolveSymlinks
78
+
79
+ if not native:
80
+ options |= QFileDialog.DontUseNativeDialog
81
+
82
+ if not show_files:
83
+ options |= QFileDialog.ShowDirsOnly
84
+
85
+ dialog = QFileDialog(parent, caption=message, directory=directory)
86
+ dialog.setFileMode(QFileDialog.Directory)
87
+ dialog.setOptions(options)
88
+
89
+ if not exists:
90
+ dialog.setAcceptMode(QFileDialog.AcceptSave)
91
+
92
+ if dialog.exec_() == QFileDialog.Accepted:
93
+ folder_path = dialog.selectedFiles()[0]
94
+
95
+ if folder_path:
96
+ return Path(folder_path)
97
+
98
+
99
+ def get_pen(width: int = 1, color: str or QColor = 'white', style=Qt.SolidLine) -> QPen:
100
+ if isinstance(color, str):
101
+ color = QColor(color)
102
+ pen = QPen(color)
103
+ pen.setStyle(style)
104
+ pen.setWidth(width)
105
+ pen.setCapStyle(Qt.RoundCap)
106
+ pen.setJoinStyle(Qt.RoundJoin)
107
+ pen.setCosmetic(True)
108
+ return pen
109
+
110
+
111
+ def show_error(err: str, *, error_title: str = 'Internal Error', info_text: str = ''):
112
+ logger.info(f'Error message shown: {error_title} - {err} {info_text}.')
113
+
114
+ mb = QMessageBox()
115
+ mb.setIcon(QMessageBox.Critical)
116
+ mb.setWindowTitle(error_title)
117
+ mb.setWindowIcon(Icon('error'))
118
+ mb.setText(err)
119
+ if info_text:
120
+ mb.setInformativeText(info_text)
121
+ mb.exec_()
122
+
123
+
124
+ def show_info(title: str, txt: str):
125
+ msg = QMessageBox()
126
+ msg.setText(txt)
127
+ msg.setWindowTitle(title)
128
+ msg.setStandardButtons(QMessageBox.Ok)
129
+ return msg.exec_()
130
+
131
+ class Icon(QIcon):
132
+ def __init__(self, name: str):
133
+ if name.find('.') == -1:
134
+ name += '.png'
135
+ name = str(ICON_PATH / name)
136
+ QIcon.__init__(self, name)
137
+
138
+
139
+ def center_widget(widget):
140
+ frame_gm = widget.frameGeometry()
141
+ screen = QApplication.desktop().screenNumber(
142
+ QApplication.desktop().cursor().pos())
143
+ center_point = QApplication.desktop().screenGeometry(
144
+ screen).center()
145
+ frame_gm.moveCenter(center_point)
146
+ widget.move(frame_gm.topLeft())
147
+
148
+
149
+ def validate_scientific_value(q_line_edit: QLineEdit,
150
+ data_type: type or None = float,
151
+ empty_possible: bool = False,
152
+ additional_conditions: tuple = ()):
153
+ text_value = q_line_edit.text().replace(',', '.')
154
+ if data_type is None:
155
+ return text_value
156
+ try:
157
+ value = data_type(text_value)
158
+ except ValueError:
159
+ if not empty_possible:
160
+ color_animation(q_line_edit)
161
+ return
162
+ for condition in additional_conditions:
163
+ if not condition(value):
164
+ return
165
+ return value
166
+
167
+
168
+ def color_animation(widget: QWidget, color=Qt.red):
169
+ effect = QGraphicsColorizeEffect(widget)
170
+ widget.setGraphicsEffect(effect)
171
+
172
+ widget.animation = QPropertyAnimation(effect, b'color')
173
+
174
+ widget.animation.setStartValue(QColor(color))
175
+ widget.animation.setEndValue(QColor(Qt.black))
176
+
177
+ widget.animation.setLoopCount(1)
178
+ widget.animation.setDuration(1500)
179
+ widget.animation.start()
File without changes
File without changes
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ from .project2h5 import convert_project_to_h5
@@ -0,0 +1,11 @@
1
+ from pathlib import Path
2
+ from mlgidGUI import App
3
+
4
+
5
+ def convert_project_to_h5(project_dir: Path, h5_file: Path, skip_unlabelled_images: bool = True):
6
+ app = App(_connect=False)
7
+ project_dir = Path(project_dir)
8
+ h5_file = Path(h5_file)
9
+
10
+ app.fm.open_project(project_dir)
11
+ app.data_manager.project2h5(h5_file, skip_empty_images=skip_unlabelled_images)
@@ -0,0 +1,119 @@
1
+ Metadata-Version: 2.4
2
+ Name: mlgidGUI
3
+ Version: 0.4.1
4
+ Summary: A GUI program for GIWAXS images analysis and annotation
5
+ Author-email: Constantin Völter <constantin.voelter@gmail.com>, Vladimir Starostin <v.starostin.m@gmail.com>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/mlgid-project/mlgidGUI
8
+ Keywords: xray,python,giwaxs,scientific-analysis
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Classifier: Topic :: Scientific/Engineering :: Physics
14
+ Classifier: Topic :: Scientific/Engineering :: Visualization
15
+ Requires-Python: >=3.12.0
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: appdirs>=1.4.4
19
+ Requires-Dist: h5py>=3.14.0
20
+ Requires-Dist: networkx>=3.5
21
+ Requires-Dist: numpy>=2.2.6
22
+ Requires-Dist: opencv-python-headless>=4.12.0.88
23
+ Requires-Dist: packaging>=25.0
24
+ Requires-Dist: pathvalidate>=3.3.1
25
+ Requires-Dist: periodictable>=2.0.2
26
+ Requires-Dist: pillow>=11.3.0
27
+ Requires-Dist: PyQt5>=5.15.11
28
+ Requires-Dist: pyqtgraph>=0.13.0
29
+ Requires-Dist: qdarkgraystyle>=2.0.0
30
+ Requires-Dist: QDarkStyle>=3.2.3
31
+ Requires-Dist: requests>=2.32.4
32
+ Requires-Dist: scipy>=1.16.1
33
+ Requires-Dist: tifffile>=2025.6.11
34
+ Requires-Dist: typing_extensions>=4.14.1
35
+ Requires-Dist: transliterate>=1.10.2
36
+ Requires-Dist: xmlobj>=1.2.2
37
+ Requires-Dist: xrayutilities>=1.7.10
38
+ Dynamic: license-file
39
+
40
+ # _mlgidGUI_
41
+ ## Project summary
42
+
43
+ _mlgidGUI_ is a graphical tool for the analysis and annotation of 2D scattering data e.g. Grazing-Incidence Wide-Angle X-ray Scattering (GIWAXS).
44
+ The resulting datasets can be used for training and testing ML models or further manual analysis.
45
+ _mlgidGUI_ is well suited for the annotation of 2D diffraction images with radial symmetry.
46
+ In particular, it focuses on grazing-incidence wide-angle scattering data analysis and its specific needs.
47
+
48
+ ## Installation
49
+
50
+ ### Recommended: Precompiled AppImage or EXE
51
+ Readily compiled packages for the x64 architecture with Windows and Unix are available at the releases page:
52
+ [https://github.com/mlgid-project/mlgidGUI/releases](https://github.com/mlgid-project/mlgidGUI/releases)
53
+
54
+ To run the program on Windows simply double click on the file and ignore the security warnings.
55
+
56
+
57
+ Follow these instructions to run the AppImage: [https://docs.appimage.org/introduction/quickstart.html](https://docs.appimage.org/introduction/quickstart.html)
58
+
59
+ ### Alternative: Installation with conda
60
+ * Install miniconda
61
+ [https://www.anaconda.com/download/success#miniconda](https://www.anaconda.com/download/success#miniconda)
62
+ * Create environment
63
+ `conda create -n mlgidGUI python=3.12 pip`
64
+ * Activate environment
65
+ `conda activate mlgidGUI`
66
+
67
+ Clone with git:
68
+
69
+ `git clone https://github.com/mlgid-project/mlgidGUI.git`
70
+
71
+ `cd ./mlgidGUI`
72
+
73
+ `pip install ./`
74
+
75
+ `python3 main.py`
76
+
77
+
78
+ ### Alternative: Installation from PyPi
79
+
80
+ `pip install mlgidGUI`
81
+ * Apply a Patch to pyqtgraph
82
+
83
+ `pip install git+https://github.com/pyqtgraph/pyqtgraph.git@6eb0bf1a928c3e8fef332bbebe8a9da3be0ab19a`
84
+
85
+ ## Usage
86
+
87
+ Import images or HDF5 files into the program, select an image in the Project Manager and begin labeling.
88
+ To add annotations, hold `Ctrl + Alt`, then click, hold, and drag the mouse over the image, similar to using a shape-drawing tool.
89
+ The key combination `Ctrl + H` can be used to hide the annotations. The annotated data can be exported as PASCAL-VOC
90
+ dataset or as an HDF5 file.
91
+
92
+ - We added a CIF file, a GIWAXS image, and an HDF5 file in the `docs\example_files` folder to provide the user with examples.
93
+ - For a short demonstration of the program usage, please refer to the [Workflow section](./docs/WORKFLOW.md).
94
+ - For a detailed guidance, please refer to the [Documentation section](./docs/DOCUMENTATION.md)
95
+
96
+
97
+ ## Papers
98
+
99
+ This project is part of our broader efforts to improve and automate GIWAXS analysis. Below is a list of related papers.
100
+
101
+ ### ML-based peak detection and structure refinement
102
+
103
+ _Tracking perovskite crystallization via deep learning-based feature detection on 2D X-ray scattering data_
104
+
105
+ V. Starostin, V. Munteanu, A. Greco, E. Kneschaurek, A. Pleli, F. Bertram, A. Gerlach, A. Hinderhofer, and F. Schreiber. npj Comput Mater 8, 101 (2022) [https://doi.org/10.1038/s41524-022-00778-8](https://doi.org/10.1038/s41524-022-00778-8)
106
+
107
+ ### Deployment at synchrotron facilities for real-time analysis
108
+
109
+ _End-to-end deep learning pipeline for real-time processing of
110
+ surface scattering data at synchrotron facilities_
111
+
112
+ V. Starostin, L. Pithan, A. Greco, V. Munteanu, A. Gerlach, A. Hinderhofer, and F. Schreiber. Synchrotron Radiation News, 35:4, 21-27 (2022) [https://doi.org/10.1080/08940886.2022.2112499](https://doi.org/10.1080/08940886.2022.2112499)
113
+
114
+ ### Benchmarking peak detection
115
+
116
+ _Benchmarking deep learning for automated peak detection on GIWAXS data_
117
+
118
+ C. Völter, V. Starostin, D. Lapkin, V. Munteanu, M. Romodin, M. Hylinski, A. Gerlach, A. Hinderhofer, F. Schreiber. Journal of Applied Crystallography (2025) accepted [https://doi.org/10.1107/S1600576725000974](https://doi.org/10.1107/S1600576725000974)
119
+