Skip to content

Commit

Permalink
Avoid DeprecationWarnings when importing scipy.ndimage filter functio…
Browse files Browse the repository at this point in the history
…ns (#261)
  • Loading branch information
fbunt authored May 11, 2022
1 parent 890933e commit 58b9aa0
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 70 deletions.
30 changes: 15 additions & 15 deletions dask_image/dispatch/_dispatch_ndfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# ================== convolve ==================
@dispatch_convolve.register(np.ndarray)
def numpy_convolve(*args, **kwargs):
return scipy.ndimage.filters.convolve
return scipy.ndimage.convolve


@dispatch_convolve.register_lazy("cupy")
Expand All @@ -62,7 +62,7 @@ def cupy_convolve(*args, **kwargs):
# ================== correlate ==================
@dispatch_correlate.register(np.ndarray)
def numpy_correlate(*args, **kwargs):
return scipy.ndimage.filters.correlate
return scipy.ndimage.correlate


@dispatch_correlate.register_lazy("cupy")
Expand All @@ -78,7 +78,7 @@ def cupy_correlate(*args, **kwargs):
# ================== laplace ==================
@dispatch_laplace.register(np.ndarray)
def numpy_laplace(*args, **kwargs):
return scipy.ndimage.filters.laplace
return scipy.ndimage.laplace


@dispatch_laplace.register_lazy("cupy")
Expand All @@ -94,7 +94,7 @@ def cupy_laplace(*args, **kwargs):
# ================== prewitt ==================
@dispatch_prewitt.register(np.ndarray)
def numpy_prewitt(*args, **kwargs):
return scipy.ndimage.filters.prewitt
return scipy.ndimage.prewitt


@dispatch_prewitt.register_lazy("cupy")
Expand All @@ -110,7 +110,7 @@ def cupy_prewitt(*args, **kwargs):
# ================== sobel ==================
@dispatch_sobel.register(np.ndarray)
def numpy_sobel(*args, **kwargs):
return scipy.ndimage.filters.sobel
return scipy.ndimage.sobel


@dispatch_sobel.register_lazy("cupy")
Expand All @@ -126,7 +126,7 @@ def cupy_sobel(*args, **kwargs):
# ================== gaussian_filter ==================
@dispatch_gaussian_filter.register(np.ndarray)
def numpy_gaussian_filter(*args, **kwargs):
return scipy.ndimage.filters.gaussian_filter
return scipy.ndimage.gaussian_filter


@dispatch_gaussian_filter.register_lazy("cupy")
Expand All @@ -142,7 +142,7 @@ def cupy_gaussian_filter(*args, **kwargs):
# ================== gaussian_gradient_magnitude ==================
@dispatch_gaussian_gradient_magnitude.register(np.ndarray)
def numpy_gaussian_gradient_magnitude(*args, **kwargs):
return scipy.ndimage.filters.gaussian_gradient_magnitude
return scipy.ndimage.gaussian_gradient_magnitude


@dispatch_gaussian_gradient_magnitude.register_lazy("cupy")
Expand All @@ -158,7 +158,7 @@ def cupy_gaussian_gradient_magnitude(*args, **kwargs):
# ================== gaussian_laplace ==================
@dispatch_gaussian_laplace.register(np.ndarray)
def numpy_gaussian_laplace(*args, **kwargs):
return scipy.ndimage.filters.gaussian_laplace
return scipy.ndimage.gaussian_laplace


@dispatch_gaussian_laplace.register_lazy("cupy")
Expand All @@ -174,7 +174,7 @@ def cupy_gaussian_laplace(*args, **kwargs):
# ================== generic_filter ==================
@dispatch_generic_filter.register(np.ndarray)
def numpy_generic_filter(*args, **kwargs):
return scipy.ndimage.filters.generic_filter
return scipy.ndimage.generic_filter


@dispatch_generic_filter.register_lazy("cupy")
Expand All @@ -190,7 +190,7 @@ def cupy_generic_filter(*args, **kwargs):
# ================== minimum_filter ==================
@dispatch_minimum_filter.register(np.ndarray)
def numpy_minimum_filter(*args, **kwargs):
return scipy.ndimage.filters.minimum_filter
return scipy.ndimage.minimum_filter


@dispatch_minimum_filter.register_lazy("cupy")
Expand All @@ -206,7 +206,7 @@ def cupy_minimum_filter(*args, **kwargs):
# ================== median_filter ==================
@dispatch_median_filter.register(np.ndarray)
def numpy_median_filter(*args, **kwargs):
return scipy.ndimage.filters.median_filter
return scipy.ndimage.median_filter


@dispatch_median_filter.register_lazy("cupy")
Expand All @@ -222,7 +222,7 @@ def cupy_median_filter(*args, **kwargs):
# ================== maximum_filter ==================
@dispatch_maximum_filter.register(np.ndarray)
def numpy_maximum_filter(*args, **kwargs):
return scipy.ndimage.filters.maximum_filter
return scipy.ndimage.maximum_filter


@dispatch_maximum_filter.register_lazy("cupy")
Expand All @@ -238,7 +238,7 @@ def cupy_maximum_filter(*args, **kwargs):
# ================== rank_filter ==================
@dispatch_rank_filter.register(np.ndarray)
def numpy_rank_filter(*args, **kwargs):
return scipy.ndimage.filters.rank_filter
return scipy.ndimage.rank_filter


@dispatch_rank_filter.register_lazy("cupy")
Expand All @@ -254,7 +254,7 @@ def cupy_rank_filter(*args, **kwargs):
# ================== percentile_filter ==================
@dispatch_percentile_filter.register(np.ndarray)
def numpy_percentile_filter(*args, **kwargs):
return scipy.ndimage.filters.percentile_filter
return scipy.ndimage.percentile_filter


@dispatch_percentile_filter.register_lazy("cupy")
Expand All @@ -270,7 +270,7 @@ def cupy_percentile_filter(*args, **kwargs):
# ================== uniform_filter ==================
@dispatch_uniform_filter.register(np.ndarray)
def numpy_uniform_filter(*args, **kwargs):
return scipy.ndimage.filters.uniform_filter
return scipy.ndimage.uniform_filter


@dispatch_uniform_filter.register_lazy("cupy")
Expand Down
4 changes: 2 additions & 2 deletions dask_image/ndfilters/_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
]


@_utils._update_wrapper(scipy.ndimage.filters.convolve)
@_utils._update_wrapper(scipy.ndimage.convolve)
def convolve(image, weights, mode="reflect", cval=0.0, origin=0):
check_arraytypes_compatible(image, weights)

Expand All @@ -39,7 +39,7 @@ def convolve(image, weights, mode="reflect", cval=0.0, origin=0):
return result


@_utils._update_wrapper(scipy.ndimage.filters.correlate)
@_utils._update_wrapper(scipy.ndimage.correlate)
def correlate(image, weights, mode="reflect", cval=0.0, origin=0):
check_arraytypes_compatible(image, weights)

Expand Down
2 changes: 1 addition & 1 deletion dask_image/ndfilters/_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]


@_utils._update_wrapper(scipy.ndimage.filters.laplace)
@_utils._update_wrapper(scipy.ndimage.laplace)
def laplace(image, mode='reflect', cval=0.0):
result = image.map_overlap(
dispatch_laplace(image),
Expand Down
4 changes: 2 additions & 2 deletions dask_image/ndfilters/_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _validate_axis(ndim, axis):
raise ValueError("The axis is out of range.")


@_utils._update_wrapper(scipy.ndimage.filters.prewitt)
@_utils._update_wrapper(scipy.ndimage.prewitt)
def prewitt(image, axis=-1, mode='reflect', cval=0.0):
_validate_axis(image.ndim, axis)

Expand All @@ -39,7 +39,7 @@ def prewitt(image, axis=-1, mode='reflect', cval=0.0):
return result


@_utils._update_wrapper(scipy.ndimage.filters.sobel)
@_utils._update_wrapper(scipy.ndimage.sobel)
def sobel(image, axis=-1, mode='reflect', cval=0.0):
_validate_axis(image.ndim, axis)

Expand Down
6 changes: 3 additions & 3 deletions dask_image/ndfilters/_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _get_border(image, sigma, truncate):
return half_shape


@_utils._update_wrapper(scipy.ndimage.filters.gaussian_filter)
@_utils._update_wrapper(scipy.ndimage.gaussian_filter)
def gaussian_filter(image,
sigma,
order=0,
Expand Down Expand Up @@ -98,7 +98,7 @@ def gaussian(image,
truncate=truncate)


@_utils._update_wrapper(scipy.ndimage.filters.gaussian_gradient_magnitude)
@_utils._update_wrapper(scipy.ndimage.gaussian_gradient_magnitude)
def gaussian_gradient_magnitude(image,
sigma,
mode='reflect',
Expand Down Expand Up @@ -126,7 +126,7 @@ def gaussian_gradient_magnitude(image,
return result


@_utils._update_wrapper(scipy.ndimage.filters.gaussian_laplace)
@_utils._update_wrapper(scipy.ndimage.gaussian_laplace)
def gaussian_laplace(image,
sigma,
mode='reflect',
Expand Down
2 changes: 1 addition & 1 deletion dask_image/ndfilters/_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]


@_utils._update_wrapper(scipy.ndimage.filters.generic_filter)
@_utils._update_wrapper(scipy.ndimage.generic_filter)
def generic_filter(image,
function,
size=None,
Expand Down
10 changes: 5 additions & 5 deletions dask_image/ndfilters/_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
]


@_utils._update_wrapper(scipy.ndimage.filters.minimum_filter)
@_utils._update_wrapper(scipy.ndimage.minimum_filter)
def minimum_filter(image,
size=None,
footprint=None,
Expand All @@ -45,7 +45,7 @@ def minimum_filter(image,
return result


@_utils._update_wrapper(scipy.ndimage.filters.median_filter)
@_utils._update_wrapper(scipy.ndimage.median_filter)
def median_filter(image,
size=None,
footprint=None,
Expand All @@ -72,7 +72,7 @@ def median_filter(image,
return result


@_utils._update_wrapper(scipy.ndimage.filters.maximum_filter)
@_utils._update_wrapper(scipy.ndimage.maximum_filter)
def maximum_filter(image,
size=None,
footprint=None,
Expand All @@ -99,7 +99,7 @@ def maximum_filter(image,
return result


@_utils._update_wrapper(scipy.ndimage.filters.rank_filter)
@_utils._update_wrapper(scipy.ndimage.rank_filter)
def rank_filter(image,
rank,
size=None,
Expand Down Expand Up @@ -128,7 +128,7 @@ def rank_filter(image,
return result


@_utils._update_wrapper(scipy.ndimage.filters.percentile_filter)
@_utils._update_wrapper(scipy.ndimage.percentile_filter)
def percentile_filter(image,
percentile,
size=None,
Expand Down
2 changes: 1 addition & 1 deletion dask_image/ndfilters/_smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
gaussian_filter = gaussian_filter


@_utils._update_wrapper(scipy.ndimage.filters.uniform_filter)
@_utils._update_wrapper(scipy.ndimage.uniform_filter)
def uniform_filter(image,
size=3,
mode='reflect',
Expand Down
1 change: 1 addition & 0 deletions environment_doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
- pip==20.2.4
- wheel==0.35.1
- sphinx==3.2.1
- jinja2<3.1
- dask==2.8.1
- numpy==1.15.4
- pims==0.4.1
Expand Down
12 changes: 6 additions & 6 deletions tests/test_dask_image/test_ndfilters/test__conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def test_convolutions_comprehensions(da_func):
@pytest.mark.parametrize(
"sp_func, da_func",
[
(scipy.ndimage.filters.convolve, dask_image.ndfilters.convolve),
(scipy.ndimage.filters.correlate, dask_image.ndfilters.correlate),
(scipy.ndimage.convolve, dask_image.ndfilters.convolve),
(scipy.ndimage.correlate, dask_image.ndfilters.correlate),
]
)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -117,8 +117,8 @@ def test_convolutions_identity(sp_func,
@pytest.mark.parametrize(
"sp_func, da_func",
[
(scipy.ndimage.filters.convolve, dask_image.ndfilters.convolve),
(scipy.ndimage.filters.correlate, dask_image.ndfilters.correlate),
(scipy.ndimage.convolve, dask_image.ndfilters.convolve),
(scipy.ndimage.correlate, dask_image.ndfilters.correlate),
]
)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -157,8 +157,8 @@ def test_convolutions_compare(sp_func,
@pytest.mark.parametrize(
"sp_func, da_func",
[
(scipy.ndimage.filters.convolve, dask_image.ndfilters.convolve),
(scipy.ndimage.filters.correlate, dask_image.ndfilters.correlate),
(scipy.ndimage.convolve, dask_image.ndfilters.convolve),
(scipy.ndimage.correlate, dask_image.ndfilters.correlate),
]
)
@pytest.mark.parametrize(
Expand Down
3 changes: 1 addition & 2 deletions tests/test_dask_image/test_ndfilters/test__diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ def test_laplace_compare():
d = da.from_array(a, chunks=(5, 5, 6))

da.utils.assert_eq(
scipy.ndimage.filters.laplace(a),
dask_image.ndfilters.laplace(d)
scipy.ndimage.laplace(a), dask_image.ndfilters.laplace(d)
)
4 changes: 2 additions & 2 deletions tests/test_dask_image/test_ndfilters/test__edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def test_edge_comprehensions(da_func):
@pytest.mark.parametrize(
"da_func, sp_func",
[
(dask_image.ndfilters.prewitt, scipy.ndimage.filters.prewitt),
(dask_image.ndfilters.sobel, scipy.ndimage.filters.sobel),
(dask_image.ndfilters.prewitt, scipy.ndimage.prewitt),
(dask_image.ndfilters.sobel, scipy.ndimage.sobel),
]
)
def test_edge_func_compare(da_func, sp_func, axis):
Expand Down
15 changes: 5 additions & 10 deletions tests/test_dask_image/test_ndfilters/test__gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def test_gaussian_filters_params(da_func, err_type, sigma, truncate):
)
@pytest.mark.parametrize(
"sp_func, da_func",
[
(scipy.ndimage.filters.gaussian_filter, dask_image.ndfilters.gaussian_filter), # noqa: E501
]
[(scipy.ndimage.gaussian_filter, dask_image.ndfilters.gaussian_filter)]
)
def test_gaussian_filters_identity(sp_func, da_func, order, sigma, truncate):
a = np.arange(140.0).reshape(10, 14)
Expand Down Expand Up @@ -131,11 +129,10 @@ def test_gaussian_filter_comprehensions(da_func):
@pytest.mark.parametrize(
"sp_func, da_func",
[
(scipy.ndimage.filters.gaussian_filter,
dask_image.ndfilters.gaussian_filter),
(scipy.ndimage.filters.gaussian_gradient_magnitude,
(scipy.ndimage.gaussian_filter, dask_image.ndfilters.gaussian_filter),
(scipy.ndimage.gaussian_gradient_magnitude,
dask_image.ndfilters.gaussian_gradient_magnitude),
(scipy.ndimage.filters.gaussian_laplace,
(scipy.ndimage.gaussian_laplace,
dask_image.ndfilters.gaussian_laplace),
]
)
Expand Down Expand Up @@ -175,9 +172,7 @@ def test_gaussian_filters_compare(sp_func, da_func, sigma, truncate):
)
@pytest.mark.parametrize(
"sp_func, da_func",
[
(scipy.ndimage.filters.gaussian_filter, dask_image.ndfilters.gaussian_filter), # noqa: E501
]
[(scipy.ndimage.gaussian_filter, dask_image.ndfilters.gaussian_filter)]
)
def test_gaussian_derivative_filters_compare(sp_func, da_func,
order, sigma, truncate):
Expand Down
8 changes: 2 additions & 6 deletions tests/test_dask_image/test_ndfilters/test__generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ def test_generic_filter_shape_type(da_func):

@pytest.mark.parametrize(
"sp_func, da_func",
[
(scipy.ndimage.filters.generic_filter, dask_image.ndfilters.generic_filter), # noqa: E501
],
[(scipy.ndimage.generic_filter, dask_image.ndfilters.generic_filter)],
)
@pytest.mark.parametrize(
"function, size, footprint",
Expand Down Expand Up @@ -112,9 +110,7 @@ def test_generic_filter_comprehensions(da_func):

@pytest.mark.parametrize(
"sp_func, da_func",
[
(scipy.ndimage.filters.generic_filter, dask_image.ndfilters.generic_filter), # noqa: E501
],
[(scipy.ndimage.generic_filter, dask_image.ndfilters.generic_filter)],
)
@pytest.mark.parametrize(
"function, size, footprint, origin",
Expand Down
Loading

0 comments on commit 58b9aa0

Please sign in to comment.