Skip to content

Commit a25c8cd

Browse files
committed
SXT context test
1 parent 6abf2b1 commit a25c8cd

3 files changed

Lines changed: 131 additions & 2 deletions

File tree

src/murfey/client/context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ def ensure_dcg_exists(
9999
)
100100
except Exception as e:
101101
logger.warning(f"Get EPU session hook failed: {e}")
102+
elif collection_type == "sxt":
103+
experiment_type_id = 47
104+
session_file = metadata_source / "Session.dm"
105+
source_visit_dir = metadata_source.parent
102106
else:
103107
logger.error(f"Unknown collection type {collection_type}")
104108
return None

src/murfey/client/contexts/sxt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def register_sxt_data_collection(
5858
"source": str(self._basepath),
5959
"tag": tilt_series,
6060
"pixel_size_on_image": str(
61-
data_collection_parameters.get("pixel_size_on_image", 100)
61+
data_collection_parameters.get("pixel_size", 100)
6262
),
6363
"image_size_x": data_collection_parameters.get("image_size_x", 0),
6464
"image_size_y": data_collection_parameters.get("image_size_y", 0),
@@ -142,7 +142,7 @@ def post_transfer(
142142
strict=True,
143143
)
144144
if pixel_size_txrm:
145-
metadata["pixel_size_microns"] = pixel_size_txrm[0]
145+
metadata["pixel_size"] = pixel_size_txrm[0] * 1e4
146146

147147
image_width_txrm = read_stream(
148148
inspector.txrm.ole,

tests/client/contexts/test_sxt.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
from unittest.mock import patch
2+
from urllib.parse import urlparse
3+
4+
from murfey.client.contexts.sxt import SXTContext
5+
from murfey.client.instance_environment import MurfeyInstanceEnvironment
6+
7+
8+
def test_sxt_context_initialisation(tmp_path):
9+
context = SXTContext("zeiss", tmp_path, "")
10+
assert context._acquisition_software == "zeiss"
11+
assert context._basepath == tmp_path
12+
13+
14+
@patch("requests.post")
15+
def test_sxt_context_xrm(mock_post, tmp_path):
16+
"""Currently nothing happens with an xrm file"""
17+
env = MurfeyInstanceEnvironment(
18+
url=urlparse("http://localhost:8000"),
19+
client_id=0,
20+
sources=[tmp_path],
21+
default_destinations={tmp_path: str(tmp_path)},
22+
instrument_name="",
23+
visit="test",
24+
murfey_session=1,
25+
)
26+
context = SXTContext("zeiss", tmp_path, "")
27+
return_value = context.post_transfer(
28+
tmp_path / "example.xrm",
29+
required_position_files=[],
30+
required_strings=["fractions"],
31+
environment=env,
32+
)
33+
assert return_value
34+
mock_post.assert_not_called()
35+
36+
37+
@patch("requests.post")
38+
@patch("murfey.client.contexts.sxt.Inspector")
39+
@patch("murfey.client.contexts.sxt.open_txrm")
40+
@patch("murfey.client.contexts.sxt.read_stream")
41+
def test_sxt_context_txrm(
42+
mock_read_stream, mock_open_txrm, mock_inspector, mock_post, tmp_path
43+
):
44+
mock_post().status_code = 200
45+
mock_read_stream.side_effect = [
46+
[-55, -25, 5, 35, 65], # Angles
47+
[0.01001], # Pixel size
48+
[1024], # Image Width
49+
[2048], # Image Height
50+
[1.5], # Exposure time
51+
[1000], # Mag
52+
[5], # Image count
53+
]
54+
55+
env = MurfeyInstanceEnvironment(
56+
url=urlparse("http://localhost:8000"),
57+
client_id=0,
58+
sources=[tmp_path],
59+
default_destinations={tmp_path: str(tmp_path / "destination")},
60+
instrument_name="",
61+
visit="test",
62+
murfey_session=1,
63+
)
64+
context = SXTContext("zeiss", tmp_path, "")
65+
context.post_transfer(
66+
tmp_path / "example.txrm",
67+
required_position_files=[],
68+
required_strings=["fractions"],
69+
environment=env,
70+
)
71+
72+
mock_open_txrm.assert_called_once_with(
73+
tmp_path / "example.txrm", load_images=False, load_reference=False, strict=False
74+
)
75+
mock_inspector.assert_called_once()
76+
77+
assert mock_post.call_count == 5
78+
mock_post.assert_any_call(
79+
"http://localhost:8000/workflow/visits/test/sessions/1/register_data_collection_group",
80+
json={
81+
"experiment_type_id": 47,
82+
"tag": str(tmp_path),
83+
},
84+
headers={"Authorization": "Bearer "},
85+
)
86+
mock_post.assert_any_call(
87+
"http://localhost:8000/workflow/visits/test/sessions/1/start_data_collection",
88+
json={
89+
"experiment_type": "sxt",
90+
"file_extension": ".txrm",
91+
"acquisition_software": "zeiss",
92+
"image_directory": f"{tmp_path}/destination",
93+
"data_collection_tag": "example",
94+
"source": str(tmp_path),
95+
"tag": "example",
96+
"pixel_size_on_image": "100.1",
97+
"image_size_x": 1024,
98+
"image_size_y": 2048,
99+
"magnification": 1000,
100+
"voltage": 0,
101+
},
102+
headers={"Authorization": "Bearer "},
103+
)
104+
mock_post.assert_any_call(
105+
"http://localhost:8000/workflow/visits/test/sessions/1/register_processing_job",
106+
json={
107+
"tag": "example",
108+
"source": str(tmp_path),
109+
"recipe": "sxt-tomo-align",
110+
"experiment_type": "sxt",
111+
},
112+
headers={"Authorization": "Bearer "},
113+
)
114+
mock_post.assert_any_call(
115+
"http://localhost:8000/workflow/sxt/visits/test/sessions/1/sxt_tilt_series",
116+
json={
117+
"session_id": 1,
118+
"tag": "example",
119+
"source": str(tmp_path),
120+
"pixel_size": 100.1,
121+
"tilt_offset": 5,
122+
"txrm": str(tmp_path / "destination/example.txrm"),
123+
},
124+
headers={"Authorization": "Bearer "},
125+
)

0 commit comments

Comments
 (0)