Skip to content

Commit b86b6cb

Browse files
committed
Update tests to avoid txrm2tiff
1 parent 1d457bf commit b86b6cb

3 files changed

Lines changed: 59 additions & 37 deletions

File tree

src/murfey/client/contexts/sxt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def register_sxt_data_collection(
6161
"source": str(self._basepath),
6262
"tag": tilt_series,
6363
"pixel_size_on_image": str(
64-
data_collection_parameters.get("pixel_size", 100) * 1e-10
64+
round(data_collection_parameters.get("pixel_size", 100), 2) * 1e-10
6565
),
6666
"image_size_x": data_collection_parameters.get("image_size_x", 0),
6767
"image_size_y": data_collection_parameters.get("image_size_y", 0),
@@ -244,7 +244,7 @@ def post_transfer(
244244
data={
245245
"tag": transferred_file.stem,
246246
"source": destination_search_dir,
247-
"pixel_size": metadata.get("pixel_size", 100),
247+
"pixel_size": round(metadata.get("pixel_size", 100), 2),
248248
"tilt_offset": midpoint(angles),
249249
"tilt_series_length": metadata.get(
250250
"tilt_series_length", len(angles)

tests/client/contexts/test_sxt.py

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from unittest.mock import patch
22
from urllib.parse import urlparse
33

4+
import numpy as np
5+
46
from murfey.client.contexts.sxt import SXTContext
57
from murfey.client.instance_environment import MurfeyInstanceEnvironment
68

@@ -36,91 +38,110 @@ def test_sxt_context_xrm(mock_post, tmp_path):
3638

3739

3840
@patch("requests.post")
39-
@patch("murfey.client.contexts.sxt.Inspector")
40-
@patch("murfey.client.contexts.sxt.open_txrm")
41-
@patch("murfey.client.contexts.sxt.read_stream")
42-
def test_sxt_context_txrm(
43-
mock_read_stream, mock_open_txrm, mock_inspector, mock_post, tmp_path
44-
):
41+
@patch("murfey.client.contexts.sxt.OleFileIO")
42+
def test_sxt_context_txrm(mock_ole_file, mock_post, tmp_path):
4543
mock_post().status_code = 200
46-
mock_read_stream.side_effect = [
47-
[-55, -25, 5, 35, 65], # Angles
48-
[0.01001], # Pixel size
49-
[1024], # Image Width
50-
[2048], # Image Height
51-
[1.5], # Exposure time
52-
[1000], # Mag
53-
[5], # Image count
44+
mock_ole_file().__enter__().exists.return_value = True
45+
# Motor position names
46+
mock_ole_file().__enter__().openstream().read.return_value = (
47+
"\x00Val1\x00\x00Energy\x00".encode()
48+
)
49+
# Metadata encoded arrays
50+
mock_ole_file().__enter__().openstream().getvalue.side_effect = [
51+
np.array([-55, -25, 5, 35, 65], dtype=np.float32).tobytes(), # Angles
52+
np.array([0.01001], dtype=np.float32).tobytes(), # Pixel size
53+
np.array([1024], dtype=np.int32).tobytes(), # Image Width
54+
np.array([2048], dtype=np.int32).tobytes(), # Image Height
55+
np.array([1.5], dtype=np.float32).tobytes(), # Exposure time
56+
np.array([1000], dtype=np.float32).tobytes(), # Mag
57+
np.array([5], dtype=np.int32).tobytes(), # Image count
58+
np.array([0, 519, 2, 3], dtype=np.float32).tobytes(), # Motor Pos (energy)
5459
]
5560

5661
env = MurfeyInstanceEnvironment(
5762
url=urlparse("http://localhost:8000"),
5863
client_id=0,
59-
sources=[tmp_path],
60-
default_destinations={tmp_path: str(tmp_path / "destination")},
64+
sources=[tmp_path / "cm12345-6/grid1"],
65+
default_destinations={
66+
f"{tmp_path}/cm12345-6/grid1": f"{tmp_path}/destination/cm12345-6/grid1"
67+
},
6168
instrument_name="",
62-
visit="test",
69+
visit="cm12345-6",
6370
murfey_session=1,
6471
)
65-
context = SXTContext("zeiss", tmp_path, {}, "")
72+
context = SXTContext("zeiss", tmp_path / "cm12345-6/grid1", {}, "")
6673
context.post_transfer(
67-
tmp_path / "example.txrm",
74+
tmp_path / "cm12345-6/grid1/example.txrm",
6875
required_position_files=[],
6976
required_strings=["fractions"],
7077
environment=env,
7178
)
7279

73-
mock_open_txrm.assert_called_once_with(
74-
tmp_path / "example.txrm", load_images=False, load_reference=False, strict=False
75-
)
76-
mock_inspector.assert_called_once()
80+
mock_ole_file.assert_any_call(str(tmp_path / "cm12345-6/grid1/example.txrm"))
81+
assert mock_ole_file().__enter__().exists.call_count == 10
82+
assert mock_ole_file().__enter__().openstream.call_count == 11 # 9 + 2 above
83+
mock_ole_file().__enter__().exists.assert_any_call("ReferenceData/Image")
84+
for field_name in [
85+
"ImageInfo/Angles",
86+
"ImageInfo/PixelSize",
87+
"ImageInfo/ImageWidth",
88+
"ImageInfo/ImageHeight",
89+
"ImageInfo/ExpTimes",
90+
"ImageInfo/XrayMagnification",
91+
"ImageInfo/ImagesTaken",
92+
"PositionInfo/AxisNames",
93+
"PositionInfo/MotorPositions",
94+
]:
95+
mock_ole_file().__enter__().exists.assert_any_call(field_name)
96+
mock_ole_file().__enter__().openstream.assert_any_call(field_name)
7797

7898
assert mock_post.call_count == 5
7999
mock_post.assert_any_call(
80-
"http://localhost:8000/workflow/visits/test/sessions/1/register_data_collection_group",
100+
"http://localhost:8000/workflow/visits/cm12345-6/sessions/1/register_data_collection_group",
81101
json={
82102
"experiment_type_id": 47,
83-
"tag": str(tmp_path),
103+
"tag": f"{tmp_path}/cm12345-6/grid1",
84104
},
85105
headers={"Authorization": "Bearer "},
86106
)
87107
mock_post.assert_any_call(
88-
"http://localhost:8000/workflow/visits/test/sessions/1/start_data_collection",
108+
"http://localhost:8000/workflow/visits/cm12345-6/sessions/1/start_data_collection",
89109
json={
90110
"experiment_type": "sxt",
91111
"file_extension": ".txrm",
92112
"acquisition_software": "zeiss",
93-
"image_directory": f"{tmp_path}/destination",
113+
"image_directory": f"{tmp_path}/destination/cm12345-6/grid1",
94114
"data_collection_tag": "example",
95-
"source": str(tmp_path),
115+
"source": f"{tmp_path}/cm12345-6/grid1",
96116
"tag": "example",
97-
"pixel_size_on_image": "100.1",
117+
"pixel_size_on_image": str(100.1 * 1e-10),
98118
"image_size_x": 1024,
99119
"image_size_y": 2048,
100120
"magnification": 1000,
121+
"energy": 519,
101122
"voltage": 0,
102123
},
103124
headers={"Authorization": "Bearer "},
104125
)
105126
mock_post.assert_any_call(
106-
"http://localhost:8000/workflow/visits/test/sessions/1/register_processing_job",
127+
"http://localhost:8000/workflow/visits/cm12345-6/sessions/1/register_processing_job",
107128
json={
108129
"tag": "example",
109-
"source": str(tmp_path),
130+
"source": f"{tmp_path}/cm12345-6/grid1",
110131
"recipe": "sxt-aretomo",
111132
"experiment_type": "sxt",
112133
},
113134
headers={"Authorization": "Bearer "},
114135
)
115136
mock_post.assert_any_call(
116-
"http://localhost:8000/workflow/sxt/visits/test/sessions/1/sxt_tilt_series",
137+
"http://localhost:8000/workflow/sxt/visits/cm12345-6/sessions/1/sxt_tilt_series",
117138
json={
118-
"session_id": 1,
119139
"tag": "example",
120-
"source": str(tmp_path),
140+
"source": f"{tmp_path}/cm12345-6/grid1",
121141
"pixel_size": 100.1,
122142
"tilt_offset": 5,
123-
"txrm": str(tmp_path / "destination/example.txrm"),
143+
"tilt_series_length": 5,
144+
"txrm": str(tmp_path / "destination/cm12345-6/grid1/example.txrm"),
124145
},
125146
headers={"Authorization": "Bearer "},
126147
)

tests/workflows/test_register_data_collection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def test_run(
7676
"experiment_type": "SPA",
7777
"image_suffix": ".jpg",
7878
"voltage": 200,
79+
"energy": 520,
7980
"pixel_size": 1e-9,
8081
"image_size_x": 2048,
8182
"image_size_y": 2048,

0 commit comments

Comments
 (0)