Skip to content

Commit

Permalink
fix: remove ragged array in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maffettone committed Apr 5, 2024
1 parent 2795117 commit d935601
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions tests/test_image.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from csxtools.image import (rotate90, stackmean, stacksum, stackstd,
stackvar, stackstderr, images_mean, images_sum)
import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
from numpy.testing import assert_array_almost_equal, assert_array_equal

from csxtools.image import images_mean, images_sum, rotate90, stackmean, stackstd, stackstderr, stacksum, stackvar


def test_rotate90():
x = np.arange(4*20, dtype=np.float32).reshape(4, 20)
y = rotate90(np.array([x, x, x, x]), 'ccw')
x = np.arange(4 * 20, dtype=np.float32).reshape(4, 20)
y = rotate90(np.array([x, x, x, x]), "ccw")
for i in y:
assert_array_equal(i, np.rot90(x, 1))

y = rotate90(np.array([x, x, x, x]), 'cw')
y = rotate90(np.array([x, x, x, x]), "cw")
for i in y:
assert_array_equal(i, np.rot90(x, -1))

Expand Down Expand Up @@ -52,45 +52,42 @@ def test_stacksum():
x[23] = np.nan
x[40] = np.nan
m, n = stacksum(x)
assert_array_almost_equal(m, np.ones((100, 100), dtype=np.float32) * 2000,
decimal=3)
assert_array_almost_equal(m, np.ones((100, 100), dtype=np.float32) * 2000, decimal=3)
assert_array_equal(n, np.ones((100, 100), dtype=np.float32) * (1000 - 3))


def test_stackstd():
x = np.repeat(np.arange(1000, dtype=np.float32), 400).reshape(
(1000, 20, 20))
x = np.repeat(np.arange(1000, dtype=np.float32), 400).reshape((1000, 20, 20))
m, n = stackstd(x)
assert_array_almost_equal(m, np.std(x, axis=0), 2)
assert_array_equal(n, np.ones((20, 20), dtype=np.float32) * 1000.0)


def test_stackvar():
x = np.repeat(np.arange(1000, dtype=np.float32), 400).reshape(
(1000, 20, 20))
x = np.repeat(np.arange(1000, dtype=np.float32), 400).reshape((1000, 20, 20))
m, n = stackvar(x)
assert_array_almost_equal(m, np.var(x, axis=0), 0)
assert_array_equal(n, np.ones((20, 20), dtype=np.float32) * 1000.0)


def test_stackstderr():
x = np.repeat(np.arange(1000, dtype=np.float32), 400).reshape(
(1000, 20, 20))
x = np.repeat(np.arange(1000, dtype=np.float32), 400).reshape((1000, 20, 20))
m, n = stackstderr(x)
assert_array_almost_equal(m, np.std(x, axis=0) / np.sqrt(n), 3)
assert_array_equal(n, np.ones((20, 20), dtype=np.float32) * 1000.0)


def test_images_mean():
x = np.array([np.repeat(ii*np.ones(ii*100, dtype=np.float32), 400).reshape(
(ii*100, 20, 20)) for ii in range(1, 11)])
x = [
np.repeat(ii * np.ones(ii * 100, dtype=np.float32), 400).reshape((ii * 100, 20, 20)) for ii in range(1, 11)
]
m = images_mean(x)
assert_array_equal(m, np.array([np.mean(x1) for x1 in x]), 3)


def test_images_sum():
x = np.array([np.repeat(ii*np.ones(ii*100, dtype=np.float32), 400).reshape(
(ii*100, 20, 20)) for ii in range(1, 11)])
x = [
np.repeat(ii * np.ones(ii * 100, dtype=np.float32), 400).reshape((ii * 100, 20, 20)) for ii in range(1, 11)
]
m = images_sum(x)
assert_array_equal(m, np.array([np.sum(np.mean(x1, axis=0))
for x1 in x]), 3)
assert_array_equal(m, np.array([np.sum(np.mean(x1, axis=0)) for x1 in x]), 3)

0 comments on commit d935601

Please sign in to comment.