Commit 350a2bef authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Adapt test_sino_array to include four tests

parent 92f23000
......@@ -14,6 +14,8 @@ def bootstrap(request):
cls = request.cls
cls.sino = get_data("sino_refill.npy")
cls.tol = 1e-7
cls.norm_array_1D = np.arange(cls.sino.shape[-1])
cls.norm_array_2D = np.arange(cls.sino.size).reshape(cls.sino.shape)
@pytest.mark.usefixtures("bootstrap")
......@@ -45,25 +47,29 @@ class TestSinoNormalization:
assert np.max(np.abs(res - ref)) < self.tol
def test_sino_array_subtraction(self):
def test_sino_array_subtraction_and_division(self):
with pytest.raises(ValueError):
SinoNormalization(kind="subtraction", sinos_shape=self.sino.shape)
array_1D = np.arange(self.sino.shape[-1])
array_2D = np.arange(self.sino.size).reshape(self.sino.shape)
def compare_normalizations(normalization_arr):
def compare_normalizations(normalization_arr, op):
sino_normalization = SinoNormalization(
kind="subtraction", sinos_shape=self.sino.shape,
kind=op, sinos_shape=self.sino.shape,
normalization_array=normalization_arr
)
sino = self.sino.copy()
sino_normalization.normalize(sino)
ref = self.sino - normalization_arr
assert np.allclose(sino, ref)
compare_normalizations(array_1D)
compare_normalizations(array_2D)
# Perform explicit operations to compare with numpy.divide, numpy.subtract, etc
if op == "subtraction":
ref = self.sino - normalization_arr
elif op == "division":
ref = self.sino / normalization_arr
#
assert np.allclose(sino, ref), "operation=%s, normalization_array dims=%d" % (op, normalization_arr.ndim)
compare_normalizations(self.norm_array_1D, "subtraction")
compare_normalizations(self.norm_array_1D, "division")
compare_normalizations(self.norm_array_2D, "subtraction")
compare_normalizations(self.norm_array_2D, "division")
@pytest.mark.skipif(not(__has_pycuda__), reason="Need pycuda for sinogram normalization with cuda backend")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment