From 75692191fc7763feea35ee2c439a04d42d357f9b Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 27 Feb 2024 09:19:58 -0500 Subject: [PATCH 1/2] Make "Calculated shape" more "correct" (do show shape) and informative --- nibabel/nicom/dicomwrappers.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index 5ff4f3305..7e8f7201a 100755 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -565,8 +565,11 @@ def image_shape(self): ns_unique = [len(np.unique(row)) for row in self._frame_indices.T] shape = (rows, cols) + tuple(ns_unique) n_vols = np.prod(shape[3:]) - if n_frames != n_vols * shape[2]: - raise WrapperError('Calculated shape does not match number of frames.') + n_frames_calc = n_vols * shape[2] + if n_frames != n_frames_calc: + raise WrapperError( + f'Calculated # of frames ({n_frames_calc}={n_vols}*{shape[2]}) of shape {shape} does not ' + f'match NumberOfFrames {n_frames}.') return tuple(shape) @one_time From d063b95a83bc2fba49d083a96235e60b3a0035c1 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Wed, 28 Feb 2024 09:40:14 -0500 Subject: [PATCH 2/2] STY: blue/flake8 --- nibabel/nicom/dicomwrappers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index 7e8f7201a..a5ea550d8 100755 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -568,8 +568,9 @@ def image_shape(self): n_frames_calc = n_vols * shape[2] if n_frames != n_frames_calc: raise WrapperError( - f'Calculated # of frames ({n_frames_calc}={n_vols}*{shape[2]}) of shape {shape} does not ' - f'match NumberOfFrames {n_frames}.') + f'Calculated # of frames ({n_frames_calc}={n_vols}*{shape[2]}) ' + f'of shape {shape} does not match NumberOfFrames {n_frames}.' + ) return tuple(shape) @one_time