11import logging
2+ from math import isclose
23
34import numpy as np
45
5- from .utils import isclose
66from .exceptions import DicomImportException
77
88
@@ -180,19 +180,19 @@ def _validate_image_orientation(image_orientation):
180180 row_cosine , column_cosine , slice_cosine = _extract_cosines (image_orientation )
181181
182182 if not _almost_zero (np .dot (row_cosine , column_cosine ), 1e-4 ):
183- raise DicomImportException ("Non-orthogonal direction cosines: {}, {}" . format ( row_cosine , column_cosine ) )
183+ raise DicomImportException (f "Non-orthogonal direction cosines: { row_cosine } , { column_cosine } " )
184184 elif not _almost_zero (np .dot (row_cosine , column_cosine ), 1e-8 ):
185- logger .warning ("Direction cosines aren't quite orthogonal: {}, {}" . format ( row_cosine , column_cosine ) )
185+ logger .warning (f "Direction cosines aren't quite orthogonal: { row_cosine } , { column_cosine } " )
186186
187187 if not _almost_one (np .linalg .norm (row_cosine ), 1e-4 ):
188- raise DicomImportException ("The row direction cosine's magnitude is not 1: {}" . format ( row_cosine ) )
188+ raise DicomImportException (f "The row direction cosine's magnitude is not 1: { row_cosine } " )
189189 elif not _almost_one (np .linalg .norm (row_cosine ), 1e-8 ):
190- logger .warning ("The row direction cosine's magnitude is not quite 1: {}" . format ( row_cosine ) )
190+ logger .warning (f "The row direction cosine's magnitude is not quite 1: { row_cosine } " )
191191
192192 if not _almost_one (np .linalg .norm (column_cosine ), 1e-4 ):
193- raise DicomImportException ("The column direction cosine's magnitude is not 1: {}" . format ( column_cosine ) )
193+ raise DicomImportException (f "The column direction cosine's magnitude is not 1: { column_cosine } " )
194194 elif not _almost_one (np .linalg .norm (column_cosine ), 1e-8 ):
195- logger .warning ("The column direction cosine's magnitude is not quite 1: {}" . format ( column_cosine ) )
195+ logger .warning (f "The column direction cosine's magnitude is not quite 1: { column_cosine } " )
196196
197197
198198def _almost_zero (value , abs_tol ):
@@ -215,17 +215,18 @@ def _slice_attribute_equal(slice_datasets, property_name):
215215 for dataset in slice_datasets [1 :]:
216216 value = getattr (dataset , property_name , None )
217217 if value != initial_value :
218- msg = 'All slices must have the same value for "{}": {} != {}'
219- raise DicomImportException (msg . format ( property_name , value , initial_value ) )
218+ msg = f 'All slices must have the same value for "{ property_name } ": { value } != { initial_value } '
219+ raise DicomImportException (msg )
220220
221221
222222def _slice_ndarray_attribute_almost_equal (slice_datasets , property_name , abs_tol ):
223223 initial_value = getattr (slice_datasets [0 ], property_name , None )
224224 for dataset in slice_datasets [1 :]:
225225 value = getattr (dataset , property_name , None )
226226 if not np .allclose (value , initial_value , atol = abs_tol ):
227- msg = 'All slices must have the same value for "{}" within "{}": {} != {}'
228- raise DicomImportException (msg .format (property_name , abs_tol , value , initial_value ))
227+ msg = (f'All slices must have the same value for "{ property_name } " within "{ abs_tol } ": { value } != '
228+ f'{ initial_value } ' )
229+ raise DicomImportException (msg )
229230
230231
231232def _slice_positions (slice_datasets ):
@@ -239,8 +240,8 @@ def _check_for_missing_slices(slice_positions):
239240 slice_positions_diffs = np .diff (sorted (slice_positions ))
240241 if not np .allclose (slice_positions_diffs , slice_positions_diffs [0 ], atol = 0 , rtol = 1e-5 ):
241242 # TODO: figure out how we should handle non-even slice spacing
242- msg = "The slice spacing is non-uniform. Slice spacings:\n {}"
243- logger .warning (msg . format ( slice_positions_diffs ) )
243+ msg = f "The slice spacing is non-uniform. Slice spacings:\n { slice_positions_diffs } "
244+ logger .warning (msg )
244245
245246 if not np .allclose (slice_positions_diffs , slice_positions_diffs [0 ], atol = 0 , rtol = 1e-1 ):
246247 raise DicomImportException ('It appears there are missing slices' )
0 commit comments