Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsmkn committed Aug 7, 2024
1 parent cf34906 commit 52bce03
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 195 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://comic.github.io/evalutils/>.
Expand All @@ -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.
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
187 changes: 0 additions & 187 deletions tests/test_stats.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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])

0 comments on commit 52bce03

Please sign in to comment.