@@ -54,7 +54,7 @@ def test_sxt_context_txrm(mock_ole_file, mock_post, tmp_path):
5454 np .array ([2048 ], dtype = np .int32 ).tobytes (), # Image Height
5555 np .array ([1.5 ], dtype = np .float32 ).tobytes (), # Exposure time
5656 np .array ([1000 ], dtype = np .float32 ).tobytes (), # Mag
57- np .array ([5 ], dtype = np .int32 ).tobytes (), # Image count
57+ np .array ([200 ], dtype = np .int32 ).tobytes (), # Image count
5858 np .array ([0 , 519 , 2 , 3 ], dtype = np .float32 ).tobytes (), # Motor Pos (energy)
5959 ]
6060
@@ -122,7 +122,7 @@ def test_sxt_context_txrm(mock_ole_file, mock_post, tmp_path):
122122 "voltage" : 0 ,
123123 "axis_start" : - 55 ,
124124 "axis_end" : 65 ,
125- "tilt_series_length" : 5 ,
125+ "tilt_series_length" : 200 ,
126126 },
127127 headers = {"Authorization" : "Bearer " },
128128 )
@@ -143,8 +143,120 @@ def test_sxt_context_txrm(mock_ole_file, mock_post, tmp_path):
143143 "source" : f"{ tmp_path } /cm12345-6/grid1" ,
144144 "pixel_size" : 100.1 ,
145145 "tilt_offset" : 5 ,
146- "tilt_series_length" : 5 ,
146+ "tilt_series_length" : 200 ,
147147 "txrm" : str (tmp_path / "destination/cm12345-6/grid1/example.txrm" ),
148+ "xrm_reference" : None ,
149+ },
150+ headers = {"Authorization" : "Bearer " },
151+ )
152+
153+
154+ @patch ("requests.post" )
155+ @patch ("murfey.client.contexts.sxt.OleFileIO" )
156+ def test_sxt_context_txrm_external_ref (mock_ole_file , mock_post , tmp_path ):
157+ mock_post ().status_code = 200
158+ exists_return = [False ] # False for reference, then True
159+ exists_return .extend ([True for i in range (20 )])
160+ mock_ole_file ().__enter__ ().exists .side_effect = exists_return
161+ # Motor position names
162+ mock_ole_file ().__enter__ ().openstream ().read .return_value = (
163+ "\x00 Val1\x00 \x00 Energy\x00 " .encode ()
164+ )
165+ # Metadata encoded arrays
166+ mock_ole_file ().__enter__ ().openstream ().getvalue .side_effect = [
167+ np .array ([- 55 , - 25 , 5 , 35 , 65 ], dtype = np .float32 ).tobytes (), # Angles
168+ np .array ([0.01001 ], dtype = np .float32 ).tobytes (), # Pixel size
169+ np .array ([1024 ], dtype = np .int32 ).tobytes (), # Image Width
170+ np .array ([2048 ], dtype = np .int32 ).tobytes (), # Image Height
171+ np .array ([1.5 ], dtype = np .float32 ).tobytes (), # Exposure time
172+ np .array ([1000 ], dtype = np .float32 ).tobytes (), # Mag
173+ np .array ([200 ], dtype = np .int32 ).tobytes (), # Image count
174+ np .array ([0 , 519 , 2 , 3 ], dtype = np .float32 ).tobytes (), # Motor Pos (energy)
175+ np .array ([0 ], dtype = np .int32 ).tobytes (), # Mosaic size
176+ np .array ([0 ], dtype = np .int32 ).tobytes (), # Mosaic size
177+ ]
178+
179+ # xrm file as reference
180+ (tmp_path / "cm12345-6/grid1" ).mkdir (parents = True )
181+ (tmp_path / "cm12345-6/grid1/ref.xrm" ).touch ()
182+
183+ env = MurfeyInstanceEnvironment (
184+ url = urlparse ("http://localhost:8000" ),
185+ client_id = 0 ,
186+ sources = [tmp_path / "cm12345-6/grid1" ],
187+ default_destinations = {
188+ f"{ tmp_path } /cm12345-6/grid1" : f"{ tmp_path } /destination/cm12345-6/grid1"
189+ },
190+ instrument_name = "" ,
191+ visit = "cm12345-6" ,
192+ murfey_session = 1 ,
193+ )
194+ context = SXTContext ("zeiss" , tmp_path / "cm12345-6/grid1" , {}, "" )
195+ context .post_transfer (
196+ tmp_path / "cm12345-6/grid1/example_-60to60@0.5.txrm" ,
197+ required_position_files = [],
198+ required_strings = ["fractions" ],
199+ environment = env ,
200+ )
201+
202+ mock_ole_file .assert_any_call (
203+ str (tmp_path / "cm12345-6/grid1/example_-60to60@0.5.txrm" )
204+ )
205+ mock_ole_file .assert_any_call (str (tmp_path / "cm12345-6/grid1/ref.xrm" ))
206+
207+ assert mock_post .call_count == 5
208+ mock_post .assert_any_call (
209+ "http://localhost:8000/workflow/visits/cm12345-6/sessions/1/register_data_collection_group" ,
210+ json = {
211+ "experiment_type_id" : 47 ,
212+ "tag" : f"{ tmp_path } /cm12345-6/grid1" ,
213+ },
214+ headers = {"Authorization" : "Bearer " },
215+ )
216+ mock_post .assert_any_call (
217+ "http://localhost:8000/workflow/visits/cm12345-6/sessions/1/start_data_collection" ,
218+ json = {
219+ "experiment_type" : "sxt" ,
220+ "file_extension" : ".txrm" ,
221+ "acquisition_software" : "zeiss" ,
222+ "image_directory" : f"{ tmp_path } /destination/cm12345-6/grid1" ,
223+ "data_collection_tag" : "example" ,
224+ "source" : f"{ tmp_path } /cm12345-6/grid1" ,
225+ "tag" : "example" ,
226+ "pixel_size_on_image" : str (100.1 * 1e-10 ),
227+ "image_size_x" : 1024 ,
228+ "image_size_y" : 2048 ,
229+ "magnification" : 1000 ,
230+ "energy" : 519 ,
231+ "voltage" : 0 ,
232+ "axis_start" : - 55 ,
233+ "axis_end" : 65 ,
234+ "tilt_series_length" : 200 ,
235+ },
236+ headers = {"Authorization" : "Bearer " },
237+ )
238+ mock_post .assert_any_call (
239+ "http://localhost:8000/workflow/visits/cm12345-6/sessions/1/register_processing_job" ,
240+ json = {
241+ "tag" : "example" ,
242+ "source" : f"{ tmp_path } /cm12345-6/grid1" ,
243+ "recipe" : "sxt-aretomo" ,
244+ "experiment_type" : "sxt" ,
245+ },
246+ headers = {"Authorization" : "Bearer " },
247+ )
248+ mock_post .assert_any_call (
249+ "http://localhost:8000/workflow/sxt/visits/cm12345-6/sessions/1/sxt_tilt_series" ,
250+ json = {
251+ "tag" : "example" ,
252+ "source" : f"{ tmp_path } /cm12345-6/grid1" ,
253+ "pixel_size" : 100.1 ,
254+ "tilt_offset" : 5 ,
255+ "tilt_series_length" : 200 ,
256+ "txrm" : str (
257+ tmp_path / "destination/cm12345-6/grid1/example_-60to60@0.5.txrm"
258+ ),
259+ "xrm_reference" : str (tmp_path / "destination/cm12345-6/grid1/ref.xrm" ),
148260 },
149261 headers = {"Authorization" : "Bearer " },
150262 )
0 commit comments