test_edf2nx.py 2.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/

__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "09/10/2020"


import shutil
import tempfile
import os
from nxtomomill import converter
from tomoscan.esrf.mock import MockEDF
from tomoscan.esrf.hdf5scan import HDF5TomoScan
from tomoscan.esrf.edfscan import EDFTomoScan
Henri Payno's avatar
Henri Payno committed
38
from tomoscan import version
39
from tomoscan.validator import is_valid_for_reconstruction
40
from nxtomomill.utils import Progress
Henri Payno's avatar
Henri Payno committed
41
import pytest
42
43


Henri Payno's avatar
Henri Payno committed
44
45
46
47
48
49
50
51
52
53
54
55
@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(
56
            scan_path=scan_path,
Henri Payno's avatar
Henri Payno committed
57
58
59
60
61
62
            n_radio=n_proj,
            n_ini_radio=n_proj,
            n_extra_radio=n_alignment_proj,
            dim=dim,
            dark_n=1,
            ref_n=1,
63
        )
Henri Payno's avatar
Henri Payno committed
64
65
66
        scan = EDFTomoScan(scan_path)
        assert scan.dark_n == 1
        output_file = os.path.join(folder, "nexus_file.nx")
67

Henri Payno's avatar
Henri Payno committed
68
69
70
71
72
73
74
75
76
77
78
        nx_file, nx_entry = converter.edf_to_nx(
            scan=scan,
            output_file=output_file,
            file_extension=".nx",
            progress=progress,
        )
        hdf5_scan = HDF5TomoScan(scan=nx_file, entry=nx_entry)
        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
79
        assert is_valid_for_reconstruction(hdf5_scan)