Skip to content

Commit 2f461be

Browse files
committed
FIX: Avoid/suppress expected warnings
1 parent f0ab879 commit 2f461be

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

nibabel/casting.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
casting. Others work round numpy casting to and from python ints
55
"""
66

7+
import warnings
78
from numbers import Integral
89
from platform import processor, machine
910

@@ -349,8 +350,9 @@ def _check_maxexp(np_type, maxexp):
349350
dt = np.dtype(np_type)
350351
np_type = dt.type
351352
two = np_type(2).reshape((1,)) # to avoid upcasting
352-
return (np.isfinite(two ** (maxexp - 1)) and
353-
not np.isfinite(two ** maxexp))
353+
with warnings.catch_warnings():
354+
warnings.simplefilter("ignore", RuntimeWarning) # Expected overflow warning
355+
return np.isfinite(two ** (maxexp - 1)) and not np.isfinite(two ** maxexp)
354356

355357

356358
def as_int(x, check=True):

nibabel/processing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,10 @@ def smooth_image(img,
300300
fwhm = np.zeros((n_dim,))
301301
fwhm[:3] = fwhm_scalar
302302
# Voxel sizes
303-
RZS = img.affine[:-1, :n_dim]
303+
RZS = img.affine[:, :n_dim]
304304
vox = np.sqrt(np.sum(RZS ** 2, 0))
305+
# Avoid divisions by zero for 4+D images
306+
vox[3:] = 1
305307
# Smoothing in terms of voxels
306308
vox_fwhm = fwhm / vox
307309
vox_sd = fwhm2sigma(vox_fwhm)

0 commit comments

Comments
 (0)