Prevent napari crash when checking orientation on large datasets#272
Prevent napari crash when checking orientation on large datasets#272Prathiba-G wants to merge 3 commits into
Conversation
Prevents napari crashes when rendering projections of 3D volumes >500M voxels or >2GB memory. Shows Qt warning dialog; cancels if user selects No. Closes #issue-number (if applicable)
for more information, see https://pre-commit.ci
alessandrofelder
left a comment
There was a problem hiding this comment.
We appreciate you contributing @Prathiba-G and apologies for taking so long to get back to you.
I can see your thinking here, and the implementation is reasonable.
I made some suggestions for improvements.
| num_voxels = np.prod(data.shape) | ||
| bytes_per_voxel = data.dtype.itemsize | ||
| estimated_gb = num_voxels * bytes_per_voxel / 1e9 | ||
| if num_voxels > 500_000_000 or estimated_gb > 2.0: |
There was a problem hiding this comment.
What was your thinking behind these numbers? Maybe we need just the estimated_gb? Either way, we should have a comment explaining the reasoning to developers reading this code.
| msg = QMessageBox() | ||
| msg.setIcon(QMessageBox.Warning) | ||
| msg.setText( | ||
| "This dataset is very large and may cause napari to crash when rendered in 3D." |
There was a problem hiding this comment.
The error message should contain info about the estimated size of the dataset, to make it less vague.
| bytes_per_voxel = data.dtype.itemsize | ||
| estimated_gb = num_voxels * bytes_per_voxel / 1e9 | ||
| if num_voxels > 500_000_000 or estimated_gb > 2.0: | ||
| msg = QMessageBox() |
There was a problem hiding this comment.
could this use display_warning from https://github.com/neuroinformatics-unit/qt-niu/blob/main/qt_niu/dialog.py for maintainability and consistent look-and-feel?
We would need to add qt-niu as a dependency.
What does this PR do?
Adds a safeguard to prevent napari from crashing when the "Check orientation" feature is used on large datasets.
Changes made
Why is this needed?
Large datasets can exceed memory limits when rendered in 3D, causing napari to crash.
Testing