mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-28 22:37:50 +08:00
Allow for no exceptions to be raised and cleanup
Allow for no exceptions to be raised Add some helpful comments Remove doctest skips Remove TODO note Cleanup and skip failing doctest
This commit is contained in:
@@ -15,7 +15,7 @@ Version 0.13
|
||||
Version 0.12
|
||||
------------
|
||||
* Change `label` to mark background as 0, not -1, which is consistent with
|
||||
SciPy's labelling. Also remove doctest skip in _ccomp.pyx `label`.
|
||||
SciPy's labelling.
|
||||
* Remove `skimage.morphology.label` from `skimage.morphology.__init__`--it now
|
||||
lives in `skimage.measure.label`.
|
||||
* Remove deprecated `reverse_map` parameter of `skimage.transform.warp`
|
||||
|
||||
@@ -85,12 +85,15 @@ def expected_warnings(matching):
|
||||
Uses `all_warnings` to ensure all warnings are raised.
|
||||
Upon exiting, it checks the recorded warnings for the desired matching
|
||||
string. Raises a warning if the match was not found or an Unexpected
|
||||
warning is found.
|
||||
warning is found. You can pass an empty regex as on of the matches
|
||||
to allow for no matches: "\A\Z".
|
||||
|
||||
"""
|
||||
with all_warnings() as w:
|
||||
# enter context
|
||||
yield w
|
||||
remaining = [m for m in matching]
|
||||
# exited user context, check the recorded warnings
|
||||
remaining = [m for m in matching if not '\A\Z' in m.split('|')]
|
||||
for warn in w:
|
||||
found = False
|
||||
for match in matching:
|
||||
|
||||
@@ -117,7 +117,7 @@ def color_check(plugin, fmt='png'):
|
||||
testing.assert_allclose(img2.astype(np.uint8), r2)
|
||||
|
||||
img3 = img_as_float(img)
|
||||
with expected_warnings(['precision loss']):
|
||||
with expected_warnings(['precision loss|unclosed file']):
|
||||
r3 = roundtrip(img3, plugin, fmt)
|
||||
testing.assert_allclose(r3, img)
|
||||
|
||||
@@ -129,12 +129,12 @@ def color_check(plugin, fmt='png'):
|
||||
r4 = roundtrip(img4, plugin, fmt)
|
||||
testing.assert_allclose(r4, img4)
|
||||
else:
|
||||
with expected_warnings(['sign loss']):
|
||||
with expected_warnings(['sign loss|precision loss|unclosed file']):
|
||||
r4 = roundtrip(img4, plugin, fmt)
|
||||
testing.assert_allclose(r4, img_as_ubyte(img4))
|
||||
|
||||
img5 = img_as_uint(img)
|
||||
with expected_warnings(['precision loss']):
|
||||
with expected_warnings(['precision loss|unclosed file']):
|
||||
r5 = roundtrip(img5, plugin, fmt)
|
||||
testing.assert_allclose(r5, img)
|
||||
|
||||
@@ -154,7 +154,7 @@ def mono_check(plugin, fmt='png'):
|
||||
testing.assert_allclose(img2.astype(np.uint8), r2)
|
||||
|
||||
img3 = img_as_float(img)
|
||||
with expected_warnings(['precision loss']):
|
||||
with expected_warnings(['precision|unclosed file|\A\Z']):
|
||||
r3 = roundtrip(img3, plugin, fmt)
|
||||
if r3.dtype.kind == 'f':
|
||||
testing.assert_allclose(img3, r3)
|
||||
@@ -165,11 +165,11 @@ def mono_check(plugin, fmt='png'):
|
||||
img4 = img_as_int(img)
|
||||
if fmt.lower() in (('tif', 'tiff')):
|
||||
img4 -= 100
|
||||
with expected_warnings(['sign loss']):
|
||||
with expected_warnings(['sign loss|\A\Z']):
|
||||
r4 = roundtrip(img4, plugin, fmt)
|
||||
testing.assert_allclose(r4, img4)
|
||||
else:
|
||||
with expected_warnings(['sign loss']):
|
||||
with expected_warnings(['precision loss|sign loss|unclosed file']):
|
||||
r4 = roundtrip(img4, plugin, fmt)
|
||||
testing.assert_allclose(r4, img_as_uint(img4))
|
||||
|
||||
|
||||
@@ -163,4 +163,3 @@ def assert_nD(array, ndim, arg_name='image'):
|
||||
ndim = [ndim]
|
||||
if not array.ndim in ndim:
|
||||
raise ValueError(msg % (arg_name, '-or-'.join([str(n) for n in ndim])))
|
||||
|
||||
|
||||
+1
-1
@@ -193,7 +193,7 @@ def show():
|
||||
>>> import skimage.io as io
|
||||
|
||||
>>> for i in range(4):
|
||||
... io.imshow(np.random.rand(50, 50)) # doctest: +SKIP
|
||||
... io.imshow(np.random.rand(50, 50))
|
||||
>>> io.show() # doctest: +SKIP
|
||||
|
||||
'''
|
||||
|
||||
@@ -430,7 +430,7 @@ def label(input, neighbors=None, background=None, return_num=False,
|
||||
... [1, 1, 5],
|
||||
... [0, 0, 0]])
|
||||
|
||||
>>> print(label(x, background=0)) # doctest: +SKIP
|
||||
>>> print(label(x, background=0))
|
||||
[[ 0 -1 -1]
|
||||
[ 0 0 1]
|
||||
[-1 -1 -1]]
|
||||
|
||||
@@ -619,10 +619,10 @@ def ransac(data, model_class, min_samples, residual_threshold,
|
||||
|
||||
Estimate ellipse model using RANSAC:
|
||||
|
||||
>>> ransac_model, inliers = ransac(data, EllipseModel, 5, 3, max_trials=50) # doctest: +SKIP
|
||||
>>> ransac_model.params # doctest: +SKIP
|
||||
>>> ransac_model, inliers = ransac(data, EllipseModel, 5, 3, max_trials=50)
|
||||
>>> ransac_model.params
|
||||
array([ 20.12762373, 29.73563063, 4.81499637, 10.4743584 , 0.05217117])
|
||||
>>> inliers # doctest: +SKIP
|
||||
>>> inliers
|
||||
array([False, False, False, False, True, True, True, True, True,
|
||||
True, True, True, True, True, True, True, True, True,
|
||||
True, True, True, True, True, True, True, True, True,
|
||||
|
||||
@@ -119,9 +119,9 @@ def watershed(image, markers, connectivity=None, offset=None, mask=None):
|
||||
>>> from skimage.feature import peak_local_max
|
||||
>>> local_maxi = peak_local_max(distance, labels=image,
|
||||
... footprint=np.ones((3, 3)),
|
||||
... indices=False) # doctest: +SKIP
|
||||
>>> markers = ndimage.label(local_maxi)[0] # doctest: +SKIP
|
||||
>>> labels = watershed(-distance, markers, mask=image) # doctest: +SKIP
|
||||
... indices=False)
|
||||
>>> markers = ndimage.label(local_maxi)[0]
|
||||
>>> labels = watershed(-distance, markers, mask=image)
|
||||
|
||||
The algorithm works also for 3-D images, and can be used for example to
|
||||
separate overlapping spheres.
|
||||
|
||||
@@ -49,8 +49,8 @@ def hough_line_peaks(hspace, angles, dists, min_distance=9, min_angle=10,
|
||||
>>> rr, cc = line(0, 14, 14, 0)
|
||||
>>> img[cc, rr] = 1
|
||||
>>> hspace, angles, dists = hough_line(img)
|
||||
>>> hspace, angles, dists = hough_line_peaks(hspace, angles, dists) # doctest: +SKIP
|
||||
>>> len(angles) # doctest: +SKIP
|
||||
>>> hspace, angles, dists = hough_line_peaks(hspace, angles, dists)
|
||||
>>> len(angles)
|
||||
2
|
||||
|
||||
"""
|
||||
|
||||
@@ -30,12 +30,8 @@ def test_range():
|
||||
(img_as_uint, np.uint16),
|
||||
(img_as_ubyte, np.ubyte)]:
|
||||
|
||||
try:
|
||||
with expected_warnings(['precision loss|sign loss']):
|
||||
y = f(x)
|
||||
except ValueError as e:
|
||||
if not 'No warning raised' in str(e):
|
||||
raise
|
||||
with expected_warnings(['precision loss|sign loss|\A\Z']):
|
||||
y = f(x)
|
||||
|
||||
omin, omax = dtype_range[dt]
|
||||
|
||||
@@ -67,12 +63,8 @@ def test_range_extra_dtypes():
|
||||
imin, imax = dtype_range_extra[dtype_in]
|
||||
x = np.linspace(imin, imax, 10).astype(dtype_in)
|
||||
|
||||
try:
|
||||
with expected_warnings(['precision loss|sign loss']):
|
||||
y = convert(x, dt)
|
||||
except ValueError as e:
|
||||
if not 'No warning raised' in str(e):
|
||||
raise
|
||||
with expected_warnings(['precision loss|sign loss|\A\Z']):
|
||||
y = convert(x, dt)
|
||||
|
||||
omin, omax = dtype_range_extra[dt]
|
||||
yield (_verify_range,
|
||||
|
||||
Reference in New Issue
Block a user