Commit f0fa9256 authored by Henri Payno's avatar Henri Payno
Browse files

[edfconverter] improve tests

parent 9122aacb
......@@ -44,6 +44,7 @@ from nxtomomill.settings import Tomo
from tomoscan.esrf.edfscan import EDFTomoScan
from tomoscan.unitsystem import metricsystem
from tomoscan.io import HDF5File
import datetime
import fabio
import numpy
import os
......@@ -446,7 +447,6 @@ def edf_to_nx(
return nfr
# projections
import datetime
proj_indexes = sorted(proj_urls.keys())
if progress is not None:
......
......@@ -28,7 +28,6 @@ __license__ = "MIT"
__date__ = "09/10/2020"
import unittest
import shutil
import tempfile
import os
......@@ -36,45 +35,43 @@ from nxtomomill import converter
from tomoscan.esrf.mock import MockEDF
from tomoscan.esrf.hdf5scan import HDF5TomoScan
from tomoscan.esrf.edfscan import EDFTomoScan
from tomoscan import version
from nxtomomill.utils import Progress
import pytest
class TestEDFToNxConverter(unittest.TestCase):
def setUp(self) -> None:
self.folder = tempfile.mkdtemp()
scan_path = os.path.join(self.folder, "myscan")
self.n_proj = 120
self.n_alignment_proj = 5
self.dim = 100
self.mock = MockEDF(
@pytest.mark.parametrize("progress", (None, Progress("conversion from edf")))
@pytest.mark.skipif(
condition=(version.MINOR < 7 and version.MAJOR == 0),
reason="dark_n and ref_n from EDFTomoScan where not existing",
)
def test_edf_to_nx_converter(progress):
with tempfile.TemporaryDirectory() as folder:
scan_path = os.path.join(folder, "myscan")
n_proj = 120
n_alignment_proj = 5
dim = 100
mock = MockEDF(
scan_path=scan_path,
n_radio=self.n_proj,
n_ini_radio=self.n_proj,
n_extra_radio=self.n_alignment_proj,
dim=self.dim,
n_radio=n_proj,
n_ini_radio=n_proj,
n_extra_radio=n_alignment_proj,
dim=dim,
dark_n=1,
ref_n=1,
)
self.scan = EDFTomoScan(scan_path)
self.output_file = os.path.join(self.folder, "nexus_file.nx")
scan = EDFTomoScan(scan_path)
assert scan.dark_n == 1
output_file = os.path.join(folder, "nexus_file.nx")
def tearDown(self) -> None:
shutil.rmtree(self.folder)
def test_conversion(self):
"""
Test a simple conversion from edf to nexus
"""
for progress in (None, Progress("conversion from edf")):
with self.subTest(progress=progress):
nx_file, nx_entry = converter.edf_to_nx(
scan=self.scan,
output_file=self.output_file,
scan=scan,
output_file=output_file,
file_extension=".nx",
progress=progress,
)
hdf5_scan = HDF5TomoScan(scan=nx_file, entry=nx_entry)
self.assertEqual(len(hdf5_scan.projections), self.n_proj)
self.assertEqual(
len(hdf5_scan.alignment_projections), self.n_alignment_proj
)
self.assertEqual(hdf5_scan.dim_1, self.dim)
self.assertEqual(hdf5_scan.dim_2, self.dim)
assert len(hdf5_scan.projections) == n_proj
assert len(hdf5_scan.alignment_projections) == n_alignment_proj
assert hdf5_scan.dim_1 == dim
assert hdf5_scan.dim_2 == dim
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