mosamatic2 2.0.2__py3-none-any.whl → 2.0.4__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.

Potentially problematic release.


This version of mosamatic2 might be problematic. Click here for more details.

Files changed (60) hide show
  1. mosamatic2/app.py +4 -0
  2. mosamatic2/cli.py +34 -0
  3. mosamatic2/commands/__init__.py +0 -0
  4. mosamatic2/commands/calculatescores.py +73 -0
  5. mosamatic2/commands/createpngsfromsegmentations.py +65 -0
  6. mosamatic2/commands/dicom2nifti.py +46 -0
  7. mosamatic2/commands/rescaledicomimages.py +54 -0
  8. mosamatic2/commands/segmentmusclefatl3tensorflow.py +55 -0
  9. mosamatic2/constants.py +6 -3
  10. mosamatic2/core/data/__init__.py +5 -0
  11. mosamatic2/core/data/dicomimage.py +18 -0
  12. mosamatic2/core/data/dicomimageseries.py +26 -0
  13. mosamatic2/core/data/dixonseries.py +22 -0
  14. mosamatic2/core/data/filedata.py +26 -0
  15. mosamatic2/core/data/multidicomimage.py +30 -0
  16. mosamatic2/core/managers/logmanager.py +0 -2
  17. mosamatic2/core/pipelines/__init__.py +1 -0
  18. mosamatic2/core/pipelines/defaultpipeline.py +79 -0
  19. mosamatic2/core/pipelines/pipeline.py +14 -0
  20. mosamatic2/core/tasks/__init__.py +5 -0
  21. mosamatic2/core/tasks/calculatescorestask/__init__.py +0 -0
  22. mosamatic2/core/tasks/calculatescorestask/calculatescorestask.py +149 -0
  23. mosamatic2/core/tasks/createpngsfromsegmentationstask/__init__.py +0 -0
  24. mosamatic2/core/tasks/createpngsfromsegmentationstask/createpngsfromsegmentationstask.py +52 -0
  25. mosamatic2/core/tasks/dicom2niftitask/__init__.py +0 -0
  26. mosamatic2/core/tasks/dicom2niftitask/dicom2niftitask.py +24 -0
  27. mosamatic2/core/tasks/rescaledicomimagestask/__init__.py +0 -0
  28. mosamatic2/core/tasks/rescaledicomimagestask/rescaledicomimagestask.py +64 -0
  29. mosamatic2/core/tasks/segmentmusclefatl3tensorflowtask/__init__.py +0 -0
  30. mosamatic2/core/tasks/segmentmusclefatl3tensorflowtask/paramloader.py +39 -0
  31. mosamatic2/core/tasks/segmentmusclefatl3tensorflowtask/segmentmusclefatl3tensorflowtask.py +121 -0
  32. mosamatic2/core/tasks/task.py +50 -0
  33. mosamatic2/core/utils.py +316 -0
  34. mosamatic2/server.py +112 -1
  35. mosamatic2/ui/mainwindow.py +150 -1
  36. mosamatic2/ui/resources/VERSION +1 -1
  37. mosamatic2/ui/widgets/dialogs/__init__.py +0 -0
  38. mosamatic2/ui/widgets/dialogs/dialog.py +16 -0
  39. mosamatic2/ui/widgets/dialogs/helpdialog.py +9 -0
  40. mosamatic2/ui/widgets/panels/__init__.py +0 -0
  41. mosamatic2/ui/widgets/panels/defaultpanel.py +31 -0
  42. mosamatic2/ui/widgets/panels/logpanel.py +65 -0
  43. mosamatic2/ui/widgets/panels/mainpanel.py +82 -0
  44. mosamatic2/ui/widgets/panels/pipelines/__init__.py +0 -0
  45. mosamatic2/ui/widgets/panels/pipelines/defaultpipelinepanel.py +299 -0
  46. mosamatic2/ui/widgets/panels/stackedpanel.py +22 -0
  47. mosamatic2/ui/widgets/panels/taskpanel.py +6 -0
  48. mosamatic2/ui/widgets/panels/tasks/__init__.py +0 -0
  49. mosamatic2/ui/widgets/panels/tasks/calculatescorestaskpanel.py +215 -0
  50. mosamatic2/ui/widgets/panels/tasks/createpngsfromsegmentationstaskpanel.py +186 -0
  51. mosamatic2/ui/widgets/panels/tasks/dicom2niftitaskpanel.py +183 -0
  52. mosamatic2/ui/widgets/panels/tasks/rescaledicomimagestaskpanel.py +184 -0
  53. mosamatic2/ui/widgets/panels/tasks/segmentmusclefatl3tensorflowtaskpanel.py +216 -0
  54. mosamatic2/ui/widgets/panels/tasks/selectslicefromscantaskpanel.py +184 -0
  55. mosamatic2/ui/worker.py +29 -0
  56. {mosamatic2-2.0.2.dist-info → mosamatic2-2.0.4.dist-info}/METADATA +6 -2
  57. mosamatic2-2.0.4.dist-info/RECORD +74 -0
  58. {mosamatic2-2.0.2.dist-info → mosamatic2-2.0.4.dist-info}/entry_points.txt +1 -0
  59. mosamatic2-2.0.2.dist-info/RECORD +0 -26
  60. {mosamatic2-2.0.2.dist-info → mosamatic2-2.0.4.dist-info}/WHEEL +0 -0
@@ -0,0 +1,184 @@
1
+ import os
2
+
3
+ from PySide6.QtWidgets import (
4
+ QLineEdit,
5
+ QCheckBox,
6
+ QSpinBox,
7
+ QHBoxLayout,
8
+ QVBoxLayout,
9
+ QFormLayout,
10
+ QPushButton,
11
+ QFileDialog,
12
+ QMessageBox,
13
+ )
14
+ from PySide6.QtCore import (
15
+ QThread,
16
+ Slot,
17
+ )
18
+
19
+ from mosamatic2.core.managers.logmanager import LogManager
20
+ from mosamatic2.ui.widgets.panels.taskpanel import TaskPanel
21
+ from mosamatic2.ui.settings import Settings
22
+ from mosamatic2.ui.utils import is_macos
23
+ from mosamatic2.ui.worker import Worker
24
+ from mosamatic2.core.tasks import RescaleDicomImagesTask
25
+
26
+ LOG = LogManager()
27
+
28
+ PANEL_TITLE = 'RescaleDicomImagesTask'
29
+ PANEL_NAME = 'rescaledicomfilestaskpanel'
30
+
31
+
32
+ class RescaleDicomImagesTaskPanel(TaskPanel):
33
+ def __init__(self):
34
+ super(RescaleDicomImagesTaskPanel, self).__init__()
35
+ self.set_title(PANEL_TITLE)
36
+ self._images_dir_line_edit = None
37
+ self._images_dir_select_button = None
38
+ self._output_dir_line_edit = None
39
+ self._output_dir_select_button = None
40
+ self._overwrite_checkbox = None
41
+ self._form_layout = None
42
+ self._run_task_button = None
43
+ self._settings = None
44
+ self._task = None
45
+ self._worker = None
46
+ self._thread = None
47
+ self.init_layout()
48
+
49
+ def images_dir_line_edit(self):
50
+ if not self._images_dir_line_edit:
51
+ self._images_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/images_dir'))
52
+ return self._images_dir_line_edit
53
+
54
+ def images_dir_select_button(self):
55
+ if not self._images_dir_select_button:
56
+ self._images_dir_select_button = QPushButton('Select')
57
+ self._images_dir_select_button.clicked.connect(self.handle_images_dir_select_button)
58
+ return self._images_dir_select_button
59
+
60
+ def output_dir_line_edit(self):
61
+ if not self._output_dir_line_edit:
62
+ self._output_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/output_dir'))
63
+ return self._output_dir_line_edit
64
+
65
+ def output_dir_select_button(self):
66
+ if not self._output_dir_select_button:
67
+ self._output_dir_select_button = QPushButton('Select')
68
+ self._output_dir_select_button.clicked.connect(self.handle_output_dir_select_button)
69
+ return self._output_dir_select_button
70
+
71
+ def overwrite_checkbox(self):
72
+ if not self._overwrite_checkbox:
73
+ self._overwrite_checkbox = QCheckBox('')
74
+ self._overwrite_checkbox.setChecked(self.settings().get_bool(f'{PANEL_NAME}/overwrite', True))
75
+ return self._overwrite_checkbox
76
+
77
+ def form_layout(self):
78
+ if not self._form_layout:
79
+ self._form_layout = QFormLayout()
80
+ if is_macos():
81
+ self._form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
82
+ return self._form_layout
83
+
84
+ def run_task_button(self):
85
+ if not self._run_task_button:
86
+ self._run_task_button = QPushButton('Run task')
87
+ self._run_task_button.clicked.connect(self.handle_run_task_button)
88
+ return self._run_task_button
89
+
90
+ def settings(self):
91
+ if not self._settings:
92
+ self._settings = Settings()
93
+ return self._settings
94
+
95
+ def init_layout(self):
96
+ images_dir_layout = QHBoxLayout()
97
+ images_dir_layout.addWidget(self.images_dir_line_edit())
98
+ images_dir_layout.addWidget(self.images_dir_select_button())
99
+ output_dir_layout = QHBoxLayout()
100
+ output_dir_layout.addWidget(self.output_dir_line_edit())
101
+ output_dir_layout.addWidget(self.output_dir_select_button())
102
+ self.form_layout().addRow('Images directory', images_dir_layout)
103
+ self.form_layout().addRow('Output directory', output_dir_layout)
104
+ self.form_layout().addRow('Overwrite', self.overwrite_checkbox())
105
+ layout = QVBoxLayout()
106
+ layout.addLayout(self.form_layout())
107
+ layout.addWidget(self.run_task_button())
108
+ self.setLayout(layout)
109
+ self.setObjectName(PANEL_NAME)
110
+
111
+ def handle_images_dir_select_button(self):
112
+ last_directory = self.settings().get('last_directory')
113
+ directory = QFileDialog.getExistingDirectory(dir=last_directory)
114
+ if directory:
115
+ self.images_dir_line_edit().setText(directory)
116
+ self.settings().set('last_directory', directory)
117
+
118
+ def handle_output_dir_select_button(self):
119
+ last_directory = self.settings().get('last_directory')
120
+ directory = QFileDialog.getExistingDirectory(dir=last_directory)
121
+ if directory:
122
+ self.output_dir_line_edit().setText(directory)
123
+ self.settings().set('last_directory', directory)
124
+
125
+ def handle_run_task_button(self):
126
+ errors = self.check_inputs_and_parameters()
127
+ if len(errors) > 0:
128
+ error_message = 'Following errors were encountered:\n'
129
+ for error in errors:
130
+ error_message += f' - {error}\n'
131
+ QMessageBox.information(self, 'Error', error_message)
132
+ else:
133
+ LOG.info('Running task...')
134
+ self.run_task_button().setEnabled(False)
135
+ self.save_inputs_and_parameters()
136
+ self._task = RescaleDicomImagesTask(
137
+ inputs={'images': self.images_dir_line_edit().text()},
138
+ params={'target_size': 512},
139
+ output=self.output_dir_line_edit().text(),
140
+ overwrite=self.overwrite_checkbox().isChecked(),
141
+ )
142
+ self._worker = Worker(self._task)
143
+ self._thread = QThread()
144
+ self._worker.moveToThread(self._thread)
145
+ self._thread.started.connect(self._worker.run)
146
+ self._worker.progress.connect(self.handle_progress)
147
+ self._worker.status.connect(self.handle_status)
148
+ self._worker.finished.connect(self.handle_finished)
149
+ self._worker.finished.connect(self._thread.quit)
150
+ self._worker.finished.connect(self._worker.deleteLater)
151
+ self._thread.finished.connect(self._thread.deleteLater)
152
+ self._thread.start()
153
+
154
+ @Slot(int)
155
+ def handle_progress(self, progress):
156
+ LOG.info(f'Progress: {progress} / 100%')
157
+
158
+ @Slot(str)
159
+ def handle_status(self, status):
160
+ LOG.info(f'Status: {status}')
161
+
162
+ @Slot()
163
+ def handle_finished(self):
164
+ LOG.info(f'Output saved in {self._task.output()}')
165
+ self.run_task_button().setEnabled(True)
166
+
167
+ # HELPERS
168
+
169
+ def check_inputs_and_parameters(self):
170
+ errors = []
171
+ if self.images_dir_line_edit().text() == '':
172
+ errors.append('Empty images directory path')
173
+ if not os.path.isdir(self.images_dir_line_edit().text()):
174
+ errors.append('Images directory does not exist')
175
+ if self.output_dir_line_edit().text() == '':
176
+ errors.append('Empty output directory path')
177
+ if os.path.isdir(self.output_dir_line_edit().text()) and not self.overwrite_checkbox().isChecked():
178
+ errors.append('Output directory exists but overwrite=False. Please remove output directory first')
179
+ return errors
180
+
181
+ def save_inputs_and_parameters(self):
182
+ self.settings().set(f'{PANEL_NAME}/images_dir', self.images_dir_line_edit().text())
183
+ self.settings().set(f'{PANEL_NAME}/output_dir', self.output_dir_line_edit().text())
184
+ self.settings().set(f'{PANEL_NAME}/overwrite', self.overwrite_checkbox().isChecked())
@@ -0,0 +1,216 @@
1
+ import os
2
+
3
+ from PySide6.QtWidgets import (
4
+ QLineEdit,
5
+ QCheckBox,
6
+ QHBoxLayout,
7
+ QVBoxLayout,
8
+ QFormLayout,
9
+ QPushButton,
10
+ QFileDialog,
11
+ QMessageBox,
12
+ )
13
+ from PySide6.QtCore import (
14
+ QThread,
15
+ Slot,
16
+ )
17
+
18
+ from mosamatic2.core.managers.logmanager import LogManager
19
+ from mosamatic2.ui.widgets.panels.taskpanel import TaskPanel
20
+ from mosamatic2.ui.settings import Settings
21
+ from mosamatic2.ui.utils import is_macos
22
+ from mosamatic2.ui.worker import Worker
23
+ from mosamatic2.core.tasks import SegmentMuscleFatL3TensorFlowTask
24
+
25
+ LOG = LogManager()
26
+
27
+ PANEL_TITLE = 'SegmentMuscleFatL3TensorFlowTask (TensorFlow)'
28
+ PANEL_NAME = 'segmentmusclefatl3tensorflowtaskpanel'
29
+
30
+
31
+ class SegmentMuscleFatL3TensorFlowTaskPanel(TaskPanel):
32
+ def __init__(self):
33
+ super(SegmentMuscleFatL3TensorFlowTaskPanel, self).__init__()
34
+ self.set_title(PANEL_TITLE)
35
+ self._images_dir_line_edit = None
36
+ self._images_dir_select_button = None
37
+ self._model_files_dir_line_edit = None
38
+ self._model_files_dir_select_button = None
39
+ self._output_dir_line_edit = None
40
+ self._output_dir_select_button = None
41
+ self._overwrite_checkbox = None
42
+ self._form_layout = None
43
+ self._run_task_button = None
44
+ self._settings = None
45
+ self._task = None
46
+ self._worker = None
47
+ self._thread = None
48
+ self.init_layout()
49
+
50
+ def images_dir_line_edit(self):
51
+ if not self._images_dir_line_edit:
52
+ self._images_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/images_dir'))
53
+ return self._images_dir_line_edit
54
+
55
+ def images_dir_select_button(self):
56
+ if not self._images_dir_select_button:
57
+ self._images_dir_select_button = QPushButton('Select')
58
+ self._images_dir_select_button.clicked.connect(self.handle_images_dir_select_button)
59
+ return self._images_dir_select_button
60
+
61
+ def model_files_dir_line_edit(self):
62
+ if not self._model_files_dir_line_edit:
63
+ self._model_files_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/model_files_dir'))
64
+ return self._model_files_dir_line_edit
65
+
66
+ def model_files_dir_select_button(self):
67
+ if not self._model_files_dir_select_button:
68
+ self._model_files_dir_select_button = QPushButton('Select')
69
+ self._model_files_dir_select_button.clicked.connect(self.handle_model_files_dir_select_button)
70
+ return self._model_files_dir_select_button
71
+
72
+ def output_dir_line_edit(self):
73
+ if not self._output_dir_line_edit:
74
+ self._output_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/output_dir'))
75
+ return self._output_dir_line_edit
76
+
77
+ def output_dir_select_button(self):
78
+ if not self._output_dir_select_button:
79
+ self._output_dir_select_button = QPushButton('Select')
80
+ self._output_dir_select_button.clicked.connect(self.handle_output_dir_select_button)
81
+ return self._output_dir_select_button
82
+
83
+ def overwrite_checkbox(self):
84
+ if not self._overwrite_checkbox:
85
+ self._overwrite_checkbox = QCheckBox('')
86
+ self._overwrite_checkbox.setChecked(self.settings().get_bool(f'{PANEL_NAME}/overwrite', True))
87
+ return self._overwrite_checkbox
88
+
89
+ def form_layout(self):
90
+ if not self._form_layout:
91
+ self._form_layout = QFormLayout()
92
+ if is_macos():
93
+ self._form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
94
+ return self._form_layout
95
+
96
+ def run_task_button(self):
97
+ if not self._run_task_button:
98
+ self._run_task_button = QPushButton('Run task')
99
+ self._run_task_button.clicked.connect(self.handle_run_task_button)
100
+ return self._run_task_button
101
+
102
+ def settings(self):
103
+ if not self._settings:
104
+ self._settings = Settings()
105
+ return self._settings
106
+
107
+ def init_layout(self):
108
+ images_dir_layout = QHBoxLayout()
109
+ images_dir_layout.addWidget(self.images_dir_line_edit())
110
+ images_dir_layout.addWidget(self.images_dir_select_button())
111
+ model_files_dir_layout = QHBoxLayout()
112
+ model_files_dir_layout.addWidget(self.model_files_dir_line_edit())
113
+ model_files_dir_layout.addWidget(self.model_files_dir_select_button())
114
+ output_dir_layout = QHBoxLayout()
115
+ output_dir_layout.addWidget(self.output_dir_line_edit())
116
+ output_dir_layout.addWidget(self.output_dir_select_button())
117
+ self.form_layout().addRow('Images directory', images_dir_layout)
118
+ self.form_layout().addRow('Model files directory', model_files_dir_layout)
119
+ self.form_layout().addRow('Output directory', output_dir_layout)
120
+ self.form_layout().addRow('Overwrite', self.overwrite_checkbox())
121
+ layout = QVBoxLayout()
122
+ layout.addLayout(self.form_layout())
123
+ layout.addWidget(self.run_task_button())
124
+ self.setLayout(layout)
125
+ self.setObjectName(PANEL_NAME)
126
+
127
+ def handle_images_dir_select_button(self):
128
+ last_directory = self.settings().get('last_directory')
129
+ directory = QFileDialog.getExistingDirectory(dir=last_directory)
130
+ if directory:
131
+ self.images_dir_line_edit().setText(directory)
132
+ self.settings().set('last_directory', directory)
133
+
134
+ def handle_model_files_dir_select_button(self):
135
+ last_directory = self.settings().get('last_directory')
136
+ directory = QFileDialog.getExistingDirectory(dir=last_directory)
137
+ if directory:
138
+ self.model_files_dir_line_edit().setText(directory)
139
+ self.settings().set('last_directory', directory)
140
+
141
+ def handle_output_dir_select_button(self):
142
+ last_directory = self.settings().get('last_directory')
143
+ directory = QFileDialog.getExistingDirectory(dir=last_directory)
144
+ if directory:
145
+ self.output_dir_line_edit().setText(directory)
146
+ self.settings().set('last_directory', directory)
147
+
148
+ def handle_run_task_button(self):
149
+ errors = self.check_inputs_and_parameters()
150
+ if len(errors) > 0:
151
+ error_message = 'Following errors were encountered:\n'
152
+ for error in errors:
153
+ error_message += f' - {error}\n'
154
+ QMessageBox.information(self, 'Error', error_message)
155
+ else:
156
+ LOG.info('Running task...')
157
+ self.run_task_button().setEnabled(False)
158
+ self.save_inputs_and_parameters()
159
+ self._task = SegmentMuscleFatL3TensorFlowTask(
160
+ inputs={
161
+ 'images': self.images_dir_line_edit().text(),
162
+ 'model_files': self.model_files_dir_line_edit().text(),
163
+ },
164
+ params={'model_version': 1.0},
165
+ output=self.output_dir_line_edit().text(),
166
+ overwrite=self.overwrite_checkbox().isChecked(),
167
+ )
168
+ self._worker = Worker(self._task)
169
+ self._thread = QThread()
170
+ self._worker.moveToThread(self._thread)
171
+ self._thread.started.connect(self._worker.run)
172
+ self._worker.progress.connect(self.handle_progress)
173
+ self._worker.status.connect(self.handle_status)
174
+ self._worker.finished.connect(self.handle_finished)
175
+ self._worker.finished.connect(self._thread.quit)
176
+ self._worker.finished.connect(self._worker.deleteLater)
177
+ self._thread.finished.connect(self._thread.deleteLater)
178
+ self._thread.start()
179
+
180
+ @Slot(int)
181
+ def handle_progress(self, progress):
182
+ LOG.info(f'Progress: {progress} / 100%')
183
+
184
+ @Slot(str)
185
+ def handle_status(self, status):
186
+ LOG.info(f'Status: {status}')
187
+
188
+ @Slot()
189
+ def handle_finished(self):
190
+ self.run_task_button().setEnabled(True)
191
+
192
+ # HELPERS
193
+
194
+ def check_inputs_and_parameters(self):
195
+ errors = []
196
+ if self.images_dir_line_edit().text() == '':
197
+ errors.append('Empty images directory path')
198
+ if not os.path.isdir(self.images_dir_line_edit().text()):
199
+ errors.append('Images directory does not exist')
200
+ if self.model_files_dir_line_edit().text() == '':
201
+ errors.append('Empty model files directory path')
202
+ if not os.path.isdir(self.model_files_dir_line_edit().text()):
203
+ errors.append('Model files directory does not exist')
204
+ if len(os.listdir(self.model_files_dir_line_edit().text())) != 3:
205
+ errors.append('Model files directory should ONLY contain "model-1.1.zip", "contour_model-1.1.zip" and "params-1.1.json", nothing else!')
206
+ if self.output_dir_line_edit().text() == '':
207
+ errors.append('Empty output directory path')
208
+ if os.path.isdir(self.output_dir_line_edit().text()) and not self.overwrite_checkbox().isChecked():
209
+ errors.append('Output directory exists but overwrite=False. Please remove output directory first')
210
+ return errors
211
+
212
+ def save_inputs_and_parameters(self):
213
+ self.settings().set(f'{PANEL_NAME}/images_dir', self.images_dir_line_edit().text())
214
+ self.settings().set(f'{PANEL_NAME}/model_files_dir', self.model_files_dir_line_edit().text())
215
+ self.settings().set(f'{PANEL_NAME}/output_dir', self.output_dir_line_edit().text())
216
+ self.settings().set(f'{PANEL_NAME}/overwrite', self.overwrite_checkbox().isChecked())
@@ -0,0 +1,184 @@
1
+ import os
2
+
3
+ from PySide6.QtWidgets import (
4
+ QLineEdit,
5
+ QCheckBox,
6
+ QSpinBox,
7
+ QHBoxLayout,
8
+ QVBoxLayout,
9
+ QFormLayout,
10
+ QPushButton,
11
+ QFileDialog,
12
+ QMessageBox,
13
+ )
14
+ from PySide6.QtCore import (
15
+ QThread,
16
+ Slot,
17
+ )
18
+
19
+ from mosamaticdesktop.core.utils.logmanager import LogManager
20
+ from mosamaticdesktop.ui.panels.taskpanel import TaskPanel
21
+ from mosamaticdesktop.ui.settings import Settings
22
+ from mosamaticdesktop.ui.utils import is_macos
23
+ from mosamaticdesktop.ui.worker import Worker
24
+
25
+ from mosamatic.tasks import SelectSliceFromScanTask
26
+
27
+ LOG = LogManager()
28
+
29
+ PANEL_TITLE = 'Automatically select L3 or T4 slice from full CT scan'
30
+ PANEL_NAME = 'selectslicefromscantaskpanel'
31
+
32
+
33
+ class SelectSliceFromScanTaskPanel(TaskPanel):
34
+ def __init__(self):
35
+ super(SelectSliceFromScanTaskPanel, self).__init__()
36
+ self.set_title(PANEL_TITLE)
37
+ self._scans_dir_line_edit = None
38
+ self._scans_dir_select_button = None
39
+ self._output_dir_line_edit = None
40
+ self._output_dir_select_button = None
41
+ self._overwrite_checkbox = None
42
+ self._form_layout = None
43
+ self._run_task_button = None
44
+ self._settings = None
45
+ self._task = None
46
+ self._worker = None
47
+ self._thread = None
48
+ self.init_layout()
49
+
50
+ def scans_dir_line_edit(self):
51
+ if not self._scans_dir_line_edit:
52
+ self._scans_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/scans_dir'))
53
+ return self._scans_dir_line_edit
54
+
55
+ def scans_dir_select_button(self):
56
+ if not self._scans_dir_select_button:
57
+ self._scans_dir_select_button = QPushButton('Select')
58
+ self._scans_dir_select_button.clicked.connect(self.handle_scans_dir_select_button)
59
+ return self._scans_dir_select_button
60
+
61
+ def output_dir_line_edit(self):
62
+ if not self._output_dir_line_edit:
63
+ self._output_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/output_dir'))
64
+ return self._output_dir_line_edit
65
+
66
+ def output_dir_select_button(self):
67
+ if not self._output_dir_select_button:
68
+ self._output_dir_select_button = QPushButton('Select')
69
+ self._output_dir_select_button.clicked.connect(self.handle_output_dir_select_button)
70
+ return self._output_dir_select_button
71
+
72
+ def overwrite_checkbox(self):
73
+ if not self._overwrite_checkbox:
74
+ self._overwrite_checkbox = QCheckBox('')
75
+ self._overwrite_checkbox.setChecked(self.settings().get_bool(f'{PANEL_NAME}/overwrite', True))
76
+ return self._overwrite_checkbox
77
+
78
+ def form_layout(self):
79
+ if not self._form_layout:
80
+ self._form_layout = QFormLayout()
81
+ if is_macos():
82
+ self._form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
83
+ return self._form_layout
84
+
85
+ def run_task_button(self):
86
+ if not self._run_task_button:
87
+ self._run_task_button = QPushButton('Run task')
88
+ self._run_task_button.clicked.connect(self.handle_run_task_button)
89
+ return self._run_task_button
90
+
91
+ def settings(self):
92
+ if not self._settings:
93
+ self._settings = Settings()
94
+ return self._settings
95
+
96
+ def init_layout(self):
97
+ scans_dir_layout = QHBoxLayout()
98
+ scans_dir_layout.addWidget(self.scans_dir_line_edit())
99
+ scans_dir_layout.addWidget(self.scans_dir_select_button())
100
+ output_dir_layout = QHBoxLayout()
101
+ output_dir_layout.addWidget(self.output_dir_line_edit())
102
+ output_dir_layout.addWidget(self.output_dir_select_button())
103
+ self.form_layout().addRow('Scans directory', scans_dir_layout)
104
+ self.form_layout().addRow('Output directory', output_dir_layout)
105
+ self.form_layout().addRow('Overwrite', self.overwrite_checkbox())
106
+ layout = QVBoxLayout()
107
+ layout.addLayout(self.form_layout())
108
+ layout.addWidget(self.run_task_button())
109
+ self.setLayout(layout)
110
+ self.setObjectName(PANEL_NAME)
111
+
112
+ def handle_scans_dir_select_button(self):
113
+ last_directory = self.settings().get('last_directory')
114
+ directory = QFileDialog.getExistingDirectory(dir=last_directory)
115
+ if directory:
116
+ self.scans_dir_line_edit().setText(directory)
117
+ self.settings().set('last_directory', directory)
118
+
119
+ def handle_output_dir_select_button(self):
120
+ last_directory = self.settings().get('last_directory')
121
+ directory = QFileDialog.getExistingDirectory(dir=last_directory)
122
+ if directory:
123
+ self.output_dir_line_edit().setText(directory)
124
+ self.settings().set('last_directory', directory)
125
+
126
+ def handle_run_task_button(self):
127
+ errors = self.check_inputs_and_parameters()
128
+ if len(errors) > 0:
129
+ error_message = 'Following errors were encountered:\n'
130
+ for error in errors:
131
+ error_message += f' - {error}\n'
132
+ QMessageBox.information(self, 'Error', error_message)
133
+ else:
134
+ LOG.info('Running task...')
135
+ self.run_task_button().setEnabled(False)
136
+ self.save_inputs_and_parameters()
137
+ self._task = SelectSliceFromScanTask(
138
+ self.scans_dir_line_edit().text(),
139
+ self.output_dir_line_edit().text(),
140
+ 'vertebrae_L3',
141
+ self.overwrite_checkbox().isChecked()
142
+ )
143
+ self._worker = Worker(self._task)
144
+ self._thread = QThread()
145
+ self._worker.moveToThread(self._thread)
146
+ self._thread.started.connect(self._worker.run)
147
+ self._worker.progress.connect(self.handle_progress)
148
+ self._worker.status.connect(self.handle_status)
149
+ self._worker.finished.connect(self.handle_finished)
150
+ self._worker.finished.connect(self._thread.quit)
151
+ self._worker.finished.connect(self._worker.deleteLater)
152
+ self._thread.finished.connect(self._thread.deleteLater)
153
+ self._thread.start()
154
+
155
+ @Slot(int)
156
+ def handle_progress(self, progress):
157
+ LOG.info(f'Progress: {progress} / 100%')
158
+
159
+ @Slot(str)
160
+ def handle_status(self, status):
161
+ LOG.info(f'Status: {status}')
162
+
163
+ @Slot()
164
+ def handle_finished(self):
165
+ self.run_task_button().setEnabled(True)
166
+
167
+ # HELPERS
168
+
169
+ def check_inputs_and_parameters(self):
170
+ errors = []
171
+ if self.scans_dir_line_edit().text() == '':
172
+ errors.append('Empty scans directory path')
173
+ if not os.path.isdir(self.scans_dir_line_edit().text()):
174
+ errors.append('Scans directory does not exist')
175
+ if self.output_dir_line_edit().text() == '':
176
+ errors.append('Empty output directory path')
177
+ if os.path.isdir(self.output_dir_line_edit().text()) and not self.overwrite_checkbox().isChecked():
178
+ errors.append('Output directory exists but overwrite=False. Please remove output directory first')
179
+ return errors
180
+
181
+ def save_inputs_and_parameters(self):
182
+ self.settings().set(f'{PANEL_NAME}/scans_dir', self.scans_dir_line_edit().text())
183
+ self.settings().set(f'{PANEL_NAME}/output_dir', self.output_dir_line_edit().text())
184
+ self.settings().set(f'{PANEL_NAME}/overwrite', self.overwrite_checkbox().isChecked())
@@ -0,0 +1,29 @@
1
+ import traceback
2
+ from PySide6.QtCore import (
3
+ QObject,
4
+ Signal,
5
+ )
6
+ from mosamatic2.core.managers.logmanager import LogManager
7
+
8
+ LOG = LogManager()
9
+
10
+
11
+ class Worker(QObject):
12
+ progress = Signal(int)
13
+ status = Signal(str)
14
+ finished = Signal()
15
+
16
+ def __init__(self, task):
17
+ super(Worker, self).__init__()
18
+ self._task = task
19
+
20
+ def run(self):
21
+ try:
22
+ self.status.emit('started')
23
+ self._task.run()
24
+ self.status.emit('done')
25
+ self.finished.emit()
26
+ except Exception as e:
27
+ self.status.emit('failed')
28
+ LOG.error(traceback.format_exc())
29
+ self.finished.emit()
@@ -1,12 +1,15 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mosamatic2
3
- Version: 2.0.2
3
+ Version: 2.0.4
4
4
  Summary:
5
5
  Author: Ralph Brecheisen
6
6
  Author-email: r.brecheisen@maastrichtuniversity.nl
7
7
  Requires-Python: >=3.11,<3.12
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.11
10
+ Requires-Dist: antspyx (>=0.5.4)
11
+ Requires-Dist: dicom2nifti (>=2.6.2)
12
+ Requires-Dist: flask (>=3.1.2)
10
13
  Requires-Dist: nibabel (>=5.3.2)
11
14
  Requires-Dist: numpy (>=1.26.4)
12
15
  Requires-Dist: openpyxl (>=3.1.5)
@@ -21,7 +24,8 @@ Requires-Dist: tensorboard (==2.15.2)
21
24
  Requires-Dist: tensorboard-data-server (==0.7.2)
22
25
  Requires-Dist: tensorflow (==2.15.*) ; platform_system == "Linux"
23
26
  Requires-Dist: tensorflow-intel (==2.15.0) ; platform_system == "Windows"
24
- Requires-Dist: tensorflow-io-gcs-filesystem (==0.31.0)
27
+ Requires-Dist: tensorflow-io-gcs-filesystem (==0.31.0) ; platform_system == "Windows"
28
+ Requires-Dist: tensorflow-io-gcs-filesystem (>=0.31.0) ; platform_system == "Darwin" and platform_machine == "arm64"
25
29
  Requires-Dist: tensorflow-macos (==2.15.0) ; platform_system == "Darwin" and platform_machine == "arm64"
26
30
  Requires-Dist: torch (>=2.8.0)
27
31
  Requires-Dist: torchvision (>=0.23.0)