Skip to content

Commit

Permalink
BUG: Fix error handling for image/mask mismatch
Browse files Browse the repository at this point in the history
In `imageoperations.checkMask` and error is thrown if the image and mask do not align or contain tolerance errors. The error message is caught and parsed to provide users with a more insightful message providing potential solutions. However, this was done by evaluating the `message` attribute of the RunTimeError thrown by SimpleITK. This attribute is present in python 2, but not in python 3.
Instead, use `args[0]` attribute, which contains the message, and is present in both python 2 and 3.
  • Loading branch information
JoostJM committed Nov 15, 2017
1 parent 6ac3bb8 commit 0257217
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Expand Up @@ -11,6 +11,7 @@ Bug fixes

- Ensure PyKwalify has a log handler, which is needed when parameter file validation fails.
(`#309 <https://github.com/Radiomics/pyradiomics/pull/309>`_)
- Fix bug in error handling in :py:func:`~radiomics.imageoperations.checkMask` (compatibility issue between python 2 and 3).

Tests
#####
Expand Down
4 changes: 2 additions & 2 deletions radiomics/imageoperations.py
Expand Up @@ -234,11 +234,11 @@ def checkMask(imageNode, maskNode, **kwargs):
except RuntimeError as e:
# If correctMask = True, try to resample the mask to the image geometry, otherwise return None ("fail")
if not kwargs.get('correctMask', False):
if "Both images for LabelStatisticsImageFilter don't match type or dimension!" in e.message:
if "Both images for LabelStatisticsImageFilter don't match type or dimension!" in e.args[0]:
logger.error('Image/Mask datatype or size mismatch. Potential solution: enable correctMask, see '
'Documentation:Usage:Customizing the Extraction:Settings:correctMask for more information')
logger.debug('Additional information on error.', exc_info=True)
elif "Inputs do not occupy the same physical space!" in e.message:
elif "Inputs do not occupy the same physical space!" in e.args[0]:
logger.error('Image/Mask geometry mismatch. Potential solution: increase tolerance using geometryTolerance, '
'see Documentation:Usage:Customizing the Extraction:Settings:geometryTolerance for more '
'information')
Expand Down

0 comments on commit 0257217

Please sign in to comment.