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