-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_analyser.py
More file actions
170 lines (152 loc) · 6.23 KB
/
Copy pathtest_analyser.py
File metadata and controls
170 lines (152 loc) · 6.23 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from __future__ import annotations
import pytest
from murfey.client.analyser import Analyser
from murfey.client.contexts.atlas import AtlasContext
from murfey.client.contexts.clem import CLEMContext
from murfey.client.contexts.fib import FIBContext
from murfey.client.contexts.spa import SPAContext
from murfey.client.contexts.spa_metadata import SPAMetadataContext
from murfey.client.contexts.sxt import SXTContext
from murfey.client.contexts.tomo import TomographyContext
from murfey.client.contexts.tomo_metadata import TomographyMetadataContext
from murfey.util.models import ProcessingParametersSPA, ProcessingParametersTomo
example_files = [
# Tomography
["visit/Position_1_001_0.0_20250715_012434_fractions.tiff", TomographyContext],
["visit/Position_1_2_002_3.0_20250715_012434_Fractions.mrc", TomographyContext],
["visit/Position_1_2_003_6.0_20250715_012434_EER.eer", TomographyContext],
["visit/name1_004_9.0_20250715_012434_fractions.tiff", TomographyContext],
["visit/Position_1_[30.0].tiff", TomographyContext],
["visit/Position_1.mdoc", TomographyContext],
["visit/name1_2.mdoc", TomographyContext],
# Tomography metadata
["visit/Session.dm", TomographyMetadataContext],
["visit/SearchMaps/SearchMap.xml", TomographyMetadataContext],
["visit/Batch/BatchPositionsList.xml", TomographyMetadataContext],
["visit/Thumbnails/file.mrc", TomographyMetadataContext],
# SPA
["visit/FoilHole_01234_fractions.tiff", SPAContext],
["visit/FoilHole_01234_EER.eer", SPAContext],
# SPA metadata
["atlas/atlas.mrc", AtlasContext],
["visit/EpuSession.dm", SPAMetadataContext],
["visit/Metadata/GridSquare.dm", SPAMetadataContext],
# CLEM LIF file
["visit/images/test_file.lif", CLEMContext],
# CLEM TIFF files
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12--Z02--C01.tif",
CLEMContext,
],
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12_Lng_LVCC--Z02--C01.tif",
CLEMContext,
],
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Series001--Z00--C00.tif",
CLEMContext,
],
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Series001_Lng_LVCC--Z00--C00.tif",
CLEMContext,
],
# CLEM TIFF file accompanying metadata
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Metadata/Position 12.xlif",
CLEMContext,
],
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Metadata/Position 12_Lng_LVCC.xlif",
CLEMContext,
],
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12/Metadata/Position 12_histo.xlif",
CLEMContext,
],
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12/Metadata/Position 12_Lng_LVCC_histo.xlif",
CLEMContext,
],
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Metadata/Series001.xlif",
CLEMContext,
],
[
"visit/images/2024_03_14_12_34_56--Project001/grid1/Metadata/Series001_Lng_LVCC.xlif",
CLEMContext,
],
# FIB Autotem files
["visit/autotem/visit/ProjectData.dat", FIBContext],
["visit/autotem/visit/Sites/Lamella/SetupImages/Preparation.tif", FIBContext],
[
"visit/autotem/visit/Sites/Lamella (2)//DCImages/DCM_2026-03-09-23-45-40.926/2026-03-09-23-48-43-Finer-Milling-dc_rescan-image-.png",
FIBContext,
],
# FIB Maps files
["visit/maps/visit/EMproject.emxml", FIBContext],
[
"visit/maps/visit/LayersData/Layer/Electron Snapshot/Electron Snapshot.tiff",
FIBContext,
],
[
"visit/maps/visit/LayersData/Layer/Electron Snapshot (2)/Electron Snapshot (2).tiff",
FIBContext,
],
# Soft x-ray tomography
["visit/tomo__tag_ROI10_area1_angle-60to60@1.5_1sec_251p.txrm", SXTContext],
["visit/X-ray_mosaic_ROI2.xrm", SXTContext],
]
@pytest.mark.parametrize("file_and_context", example_files)
def test_find_context(file_and_context, tmp_path):
# Unpack parametrised variables
file_name, context = file_and_context
# Pass the file to the Analyser; add environment as needed
analyser = Analyser(basepath_local=tmp_path, token="")
# Check that the results are as expected
assert analyser._find_context(tmp_path / file_name)
assert isinstance(analyser._context, context)
# Checks for the specific workflow contexts
if isinstance(analyser._context, TomographyContext):
assert analyser.parameters_model == ProcessingParametersTomo
if isinstance(analyser._context, SPAContext):
assert analyser.parameters_model == ProcessingParametersSPA
contextless_files = [
"visit/Position_1_gain.tiff",
"visit/FoilHole_01234_gain.tiff",
"visit/file_1.mrc",
"visit/FoilHole_01234.mrc",
"visit/FoilHole_01234.jpg",
"visit/FoilHole_01234.xml",
"visit/images/test_file.lifext",
"visit/images/2024_03_14_12_34_56--Project001/Project001.xlef",
"visit/images/2024_03_14_12_34_56--Project001/Project001.xlef.lock",
"visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12/Position 12_histo.lof",
"visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12/Series001_histo.lof",
]
@pytest.mark.parametrize("bad_file", contextless_files)
def test_ignore_contextless_files(bad_file, tmp_path):
analyser = Analyser(tmp_path, "")
assert not analyser._find_context(tmp_path / bad_file)
assert not analyser._context
def test_analyser_setup_and_stopping(tmp_path):
analyser = Analyser(tmp_path, "")
assert analyser.queue.empty()
analyser.start()
assert analyser.thread.is_alive()
analyser.stop()
assert analyser._halt_thread
assert not analyser.thread.is_alive()
def test_analyser_tomo_determination(tmp_path):
tomo_file = tmp_path / "Position_1_[30.0].tiff"
analyser = Analyser(tmp_path, "")
analyser.start()
analyser.queue.put(tomo_file)
analyser.stop()
assert analyser._context._acquisition_software == "tomo"
def test_analyser_epu_determination(tmp_path):
tomo_file = tmp_path / "FoilHole_12345_Data_6789_Fractions.tiff"
analyser = Analyser(tmp_path, "")
analyser.start()
analyser.queue.put(tomo_file)
analyser.stop()
assert analyser._context._acquisition_software == "epu"