diff --git a/README.md b/README.md index 431d3c2..15d12e8 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ [![Documentation Status](https://img.shields.io/badge/docs-passing-4a4c4c1.svg)](https://comic.github.io/evalutils/) [![Code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black) -evalutils helps challenge administrators easily create evaluation -containers for grand-challenge.org. +evalutils contains useful functions for evaluating machine learning models in the context of medical imaging. - Free software: MIT license - Documentation: . @@ -19,7 +18,5 @@ containers for grand-challenge.org. ## Getting Started -[evalutils](https://github.com/comic/evalutils) requires Python 3.9 or -above, and can be installed from `pip`. -Please see the [Getting Started](https://comic.github.io/evalutils/usage.html) -documentation for more details. +[evalutils](https://github.com/comic/evalutils) requires Python 3.9 or above, and can be installed from `pip`. +Please see the [Getting Started](https://comic.github.io/evalutils/usage.html) documentation for more details. diff --git a/pyproject.toml b/pyproject.toml index cdcd189..e4cc3ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,8 +56,6 @@ markers = [ ] filterwarnings = [ "error", - "ignore:.*The default dtype for empty Series will be 'object' instead of 'float64' in a future version.*", - "ignore:.*Use pandas.concat instead\\.:FutureWarning", ] [tool.tox] diff --git a/tests/test_stats.py b/tests/test_stats.py index 1dff498..a268227 100644 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -1,9 +1,7 @@ import numpy as np import pytest -import scipy.ndimage as ndimage import SimpleITK import sklearn -from numpy.testing import assert_array_almost_equal from scipy.ndimage import generate_binary_structure import evalutils.stats as stats @@ -429,188 +427,3 @@ def test_cm_functions(a, b, classes): assert not np.allclose(r3, r4) assert not np.allclose(r1, r5) assert not np.allclose(r3, r5) - - -# The following code is modified from the SciPy test suite -# -# Copyright (C) 2003-2005 Peter J. Verveer -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# 3. The name of the author may not be used to endorse or promote -# products derived from this software without specific prior -# written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS -# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -INTEGER_TYPES = [ - np.int8, - np.uint8, - np.int16, - np.uint16, - np.int32, - np.uint32, - np.int64, - np.uint64, -] - -FLOAT_TYPES = [np.float32, np.float64] - -TYPES = INTEGER_TYPES + FLOAT_TYPES - - -@pytest.mark.parametrize("type_", TYPES) -def test_distance_transform_edt01(type_): - # euclidean distance transform (edt) - data = np.array( - [ - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - ], - type_, - ) - out, ft = stats.distance_transform_edt_float32(data, return_indices=True) - bf = ndimage.distance_transform_bf(data, "euclidean") - assert_array_almost_equal(bf, out) - - dt = ft - np.indices(ft.shape[1:], dtype=ft.dtype) - dt = dt.astype(np.float64) - np.multiply(dt, dt, dt) - dt = np.add.reduce(dt, axis=0) - np.sqrt(dt, dt) - - assert_array_almost_equal(bf, dt) - - -@pytest.mark.parametrize("type_", TYPES) -def test_distance_transform_edt02(type_): - data = np.array( - [ - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - ], - type_, - ) - tdt, tft = stats.distance_transform_edt_float32(data, return_indices=True) - dts = [] - fts = [] - dt = np.zeros(data.shape, dtype=np.float32) - stats.distance_transform_edt_float32(data, distances=dt) - dts.append(dt) - ft = stats.distance_transform_edt_float32( - data, return_distances=0, return_indices=True - ) - fts.append(ft) - ft = np.indices(data.shape, dtype=np.int32) - stats.distance_transform_edt_float32( - data, return_distances=False, return_indices=True, indices=ft - ) - fts.append(ft) - dt, ft = stats.distance_transform_edt_float32(data, return_indices=True) - dts.append(dt) - fts.append(ft) - dt = np.zeros(data.shape, dtype=np.float32) - ft = stats.distance_transform_edt_float32( - data, distances=dt, return_indices=True - ) - dts.append(dt) - fts.append(ft) - ft = np.indices(data.shape, dtype=np.int32) - dt = stats.distance_transform_edt_float32( - data, return_indices=True, indices=ft - ) - dts.append(dt) - fts.append(ft) - dt = np.zeros(data.shape, dtype=np.float32) - ft = np.indices(data.shape, dtype=np.int32) - stats.distance_transform_edt_float32( - data, distances=dt, return_indices=True, indices=ft - ) - dts.append(dt) - fts.append(ft) - for dt in dts: - assert_array_almost_equal(tdt, dt) - for ft in fts: - assert_array_almost_equal(tft, ft) - - -@pytest.mark.parametrize("type_", TYPES) -def test_distance_transform_edt03(type_): - data = np.array( - [ - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - ], - type_, - ) - ref = ndimage.distance_transform_bf(data, "euclidean", sampling=[2, 2]) - out = stats.distance_transform_edt_float32(data, sampling=[2, 2]) - assert_array_almost_equal(ref, out) - - -@pytest.mark.parametrize("type_", TYPES) -def test_distance_transform_edt4(type_): - data = np.array( - [ - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - ], - type_, - ) - ref = ndimage.distance_transform_bf(data, "euclidean", sampling=[2, 1]) - out = stats.distance_transform_edt_float32(data, sampling=[2, 1]) - assert_array_almost_equal(ref, out) - - -def test_distance_transform_edt5(): - # Ticket #954 regression test - out = stats.distance_transform_edt_float32(False) - assert_array_almost_equal(out, [0.0])