Commit ee4cbb03 authored by payno's avatar payno Committed by payno
Browse files

[test] add test for edf on flat field correction and and get_sinogram

parent 1dc31042
......@@ -37,6 +37,7 @@ from tomoscan.esrf.mock import MockEDF
from tomoscan.esrf.edfscan import EDFTomoScan
from tomoscan.scanbase import TomoScanBase
from tomoscan.scanfactory import ScanFactory
from silx.io.utils import get_data
from silx.io.url import DataUrl
import collections
import json
......@@ -311,6 +312,103 @@ class TestProjections(unittest.TestCase):
self.assertTrue(360 not in proj_angle_dict)
class TestFlatFieldCorrection(unittest.TestCase):
"""Test the flat field correction"""
def setUp(self) -> None:
self.folder = tempfile.mkdtemp()
mock = MockEDF(
scan_path=self.folder, n_radio=30, n_ini_radio=30, n_extra_radio=0, dim=20
)
mock.end_acquisition()
self.scan = EDFTomoScan(scan=self.folder)
def tearDown(self) -> None:
shutil.rmtree(self.folder)
def testFlatAndDarksSet(self):
"""Test no error is log if `normed` dark and flat are provided"""
self.scan.set_normed_flats(
{
1: numpy.random.random(20 * 20).reshape((20, 20)),
21: numpy.random.random(20 * 20).reshape((20, 20)),
}
)
self.scan.set_normed_darks({0: numpy.random.random(20 * 20).reshape((20, 20))})
projs = []
proj_indexes = []
for proj_index, proj in self.scan.projections.items():
projs.append(proj)
proj_indexes.append(proj_index)
normed_proj = self.scan.flat_field_correction(
projs=projs, proj_indexes=proj_indexes
)
self.assertEqual(len(normed_proj), len(self.scan.projections))
raw_data = get_data(projs[10])
self.assertFalse(numpy.array_equal(raw_data, normed_proj[10]))
def testNoFlatOrDarkSet(self):
"""Test an error is log if `normed` dark and flat aren't provided"""
projs = []
proj_indexes = []
for proj_index, proj in self.scan.projections.items():
projs.append(proj)
proj_indexes.append(proj_index)
with self.assertLogs("tomoscan", level="ERROR"):
normed_proj = self.scan.flat_field_correction(
projs=projs, proj_indexes=proj_indexes
)
self.assertEqual(len(normed_proj), len(self.scan.projections))
raw_data = get_data(projs[10])
self.assertTrue(numpy.array_equal(raw_data, normed_proj[10]))
class TestGetSinogram(unittest.TestCase):
"""Test the get_sinogram function"""
def setUp(self) -> None:
self.folder = tempfile.mkdtemp()
mock = MockEDF(
scan_path=self.folder, n_radio=30, n_ini_radio=30, n_extra_radio=0, dim=20
)
mock.end_acquisition()
self.scan = EDFTomoScan(scan=self.folder)
self.scan.set_normed_flats(
{
21: numpy.random.random(20 * 20).reshape((20, 20)),
1520: numpy.random.random(20 * 20).reshape((20, 20)),
}
)
self.scan.set_normed_darks({0: numpy.random.random(20 * 20).reshape((20, 20))})
def tearDown(self) -> None:
shutil.rmtree(self.folder)
def testGetSinogram1(self):
sinogram = self.scan.get_sinogram(line=12, subsampling=1)
self.assertEqual(sinogram.shape, (30, 20))
def testGetSinogram2(self):
"""Test if subsampling is negative"""
with self.assertRaises(ValueError):
self.scan.get_sinogram(line=0, subsampling=-1)
def testGetSinogram3(self):
sinogram = self.scan.get_sinogram(line=0, subsampling=3)
self.assertEqual(sinogram.shape, (10, 20))
def testGetSinogram4(self):
"""Test if line is not in the projection"""
with self.assertRaises(ValueError):
self.scan.get_sinogram(line=-1, subsampling=1)
def testGetSinogram5(self):
"""Test if line is not in the projection"""
with self.assertRaises(ValueError):
self.scan.get_sinogram(line=35, subsampling=1)
class TestScanValidatorFindFiles(unittest.TestCase):
"""Function testing the getReconstructionsPaths function is correctly
functioning"""
......@@ -512,6 +610,8 @@ def suite():
TestProjections,
TestTomoBaseHashable,
TestOriDarksFlats,
TestFlatFieldCorrection,
TestGetSinogram,
):
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui))
return test_suite
......
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