Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recon Slice Naming #2207

Merged
merged 6 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release_notes/next/feature-2206-recon_file_naming
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#2206: Improve output naming for reconstructed slices and volumes
2 changes: 1 addition & 1 deletion mantidimaging/core/reconstruct/cil_recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,6 @@ def full(images: ImageStack,

def allowed_recon_kwargs() -> dict[str, list[str]]:
return {
'CIL: PDHG-TV':
'CIL_PDHG-TV':
JackEAllen marked this conversation as resolved.
Show resolved Hide resolved
['alpha', 'num_iter', 'non_negative', 'stochastic', 'projections_per_subset', 'regularisation_percent']
}
19 changes: 17 additions & 2 deletions mantidimaging/gui/windows/recon/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def _on_stack_reconstruct_slice_done(self, task: TaskWorkerThread):
slice_idx = self._get_slice_index(None)
if images is not None:
assert self.model.images is not None
images.name = "Recon"
images.name = self.create_recon_output_filename("Recon_Slice")
self._replace_inf_nan(images) # pyqtgraph workaround
self.view.show_recon_volume(images, self.model.stack_id)
images.record_operation('AstraRecon.single_sino',
Expand Down Expand Up @@ -349,7 +349,7 @@ def _on_volume_recon_done(self, task) -> None:
try:
self._replace_inf_nan(task.result) # pyqtgraph workaround
assert self.model.images is not None
task.result.name = "Recon"
task.result.name = self.create_recon_output_filename("Recon_Vol")
self.view.show_recon_volume(task.result, self.model.stack_id)
finally:
self.view.set_recon_buttons_enabled(True)
Expand Down Expand Up @@ -468,3 +468,18 @@ def _replace_inf_nan(images: ImageStack) -> None:
:param images: The ImageStack object.
"""
images.data[np.isinf(images.data)] = np.nan

def create_recon_output_filename(self, prefix: str) -> str:
"""
Takes a naming prefix and creates a descriptive recon output
filename based on algorithm and filter if filter kwargs used in recon

:param prefix: The filename prefix to add more detail about format
:return: The formatted filename
"""
recon_name = self.view.recon_params().algorithm
filter_name = self.view.recon_params().filter_name \
if "filter_name" in self.allowed_recon_kwargs[recon_name] else None

algorithm_name = f"{prefix}_{recon_name}"
return f"{algorithm_name}_{filter_name}" if filter_name else algorithm_name
9 changes: 8 additions & 1 deletion mantidimaging/gui/windows/recon/test/presenter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ def test_on_stack_reconstruct_slice_done(self):
test_data = ImageStack(np.ndarray(shape=(200, 250), dtype=np.float32))
test_data.record_operation = mock.Mock()
task_mock = mock.Mock(result=test_data, error=None)
recon_params = ReconstructionParameters("gridrec", "ram-lak", 10)
self.view.recon_params.return_value = recon_params
self.presenter._get_slice_index = mock.Mock(return_value=7)

self.presenter._on_stack_reconstruct_slice_done(task_mock)

self.view.show_recon_volume.assert_called_once()
Expand Down Expand Up @@ -416,6 +417,8 @@ def test_infs_removed_from_recon_volume(self):
task = mock.Mock()
task.error = None
task.result.data = np.array([np.inf, -np.inf])
recon_params = ReconstructionParameters("gridrec", "ram-lak", 10)
self.view.recon_params.return_value = recon_params

self.presenter._on_volume_recon_done(task)
assert not np.isinf(self.view.show_recon_volume.call_args[0][0].data).any()
Expand All @@ -424,6 +427,8 @@ def test_infs_removed_from_recon_slice(self):
task = mock.Mock()
task.error = None
task.result.data = np.array([np.inf, -np.inf])
recon_params = ReconstructionParameters("gridrec", "ram-lak", 10)
self.view.recon_params.return_value = recon_params

self.presenter._on_stack_reconstruct_slice_done(task)
assert not np.isinf(self.view.show_recon_volume.call_args[0][0].data).any()
Expand All @@ -433,6 +438,8 @@ def test_on_volume_recon_done_enables_buttons(self, _, error):
task = mock.Mock()
task.error = error
task.result.data = np.ones((5, 10, 10))
recon_params = ReconstructionParameters("gridrec", "ram-lak", 10)
self.view.recon_params.return_value = recon_params

self.presenter._on_volume_recon_done(task)
self.view.set_recon_buttons_enabled.assert_called_once_with(True)
Expand Down
2 changes: 1 addition & 1 deletion mantidimaging/gui/windows/recon/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, main_window: MainWindowView):

self.algorithmName.insertItem(1, "FBP_CUDA")
self.algorithmName.insertItem(2, "SIRT_CUDA")
self.algorithmName.insertItem(3, "CIL: PDHG-TV")
self.algorithmName.insertItem(3, "CIL_PDHG-TV")
JackEAllen marked this conversation as resolved.
Show resolved Hide resolved
self.algorithmName.setCurrentIndex(1)
if not CudaChecker().cuda_is_present():
self.algorithmName.model().item(1).setEnabled(False)
Expand Down