unwrap: Warn about singleton dimensions in 3D arrays.

This commit is contained in:
Jostein Bø Fløystad
2013-11-22 10:45:06 +01:00
parent 781ead2c9f
commit 27c13a1193
2 changed files with 12 additions and 2 deletions
+8 -2
View File
@@ -70,7 +70,10 @@ def check_wrap_around(ndim, axis):
index_first = tuple([0] * ndim)
index_last = tuple([-1 if n == axis else 0 for n in range(ndim)])
# unwrap the image without wrap around
image_unwrap_no_wrap_around = unwrap_phase(image_wrapped)
with warnings.catch_warnings():
# We do not want warnings about length 1 dimensions
warnings.simplefilter("ignore")
image_unwrap_no_wrap_around = unwrap_phase(image_wrapped)
print('endpoints without wrap_around:',
image_unwrap_no_wrap_around[index_first],
image_unwrap_no_wrap_around[index_last])
@@ -79,7 +82,10 @@ def check_wrap_around(ndim, axis):
- image_unwrap_no_wrap_around[index_last]) > np.pi
# unwrap the image with wrap around
wrap_around = [n == axis for n in range(ndim)]
image_unwrap_wrap_around = unwrap_phase(image_wrapped, wrap_around)
with warnings.catch_warnings():
# We do not want warnings about length 1 dimensions
warnings.simplefilter("ignore")
image_unwrap_wrap_around = unwrap_phase(image_wrapped, wrap_around)
print('endpoints with wrap_around:',
image_unwrap_wrap_around[index_first],
image_unwrap_wrap_around[index_last])
+4
View File
@@ -1,4 +1,5 @@
import numpy as np
import warnings
from ._unwrap_2d import unwrap_2d
from ._unwrap_3d import unwrap_3d
@@ -53,6 +54,9 @@ def unwrap_phase(image, wrap_around=False):
else:
raise ValueError('wrap_around must be a bool or a sequence with '
'length equal to the dimensionality of image')
if image.ndim == 3 and 1 in image.shape:
warnings.warn('image is 3D and has a length 1 dimension; consider '
'using a 2D array to use the 2D unwrapping algorithm')
if np.ma.isMaskedArray(image):
mask = np.require(image.mask, np.uint8, ['C'])