@@ -42,15 +42,53 @@ def register_search_map_in_database(
4242 search_map .pixel_size = search_map_params .pixel_size or search_map .pixel_size
4343 search_map .image = search_map_params .image or search_map .image
4444 search_map .binning = search_map_params .binning or search_map .binning
45- search_map .reference_matrix = (
46- search_map_params .reference_matrix or search_map .reference_matrix
45+ search_map .reference_matrix_m11 = (
46+ search_map_params .reference_matrix .get ("m11" )
47+ or search_map .reference_matrix_m11
4748 )
48- search_map .stage_correction = (
49- search_map_params .stage_correction or search_map .stage_correction
49+ search_map .reference_matrix_m12 = (
50+ search_map_params .reference_matrix .get ("m12" )
51+ or search_map .reference_matrix_m12
5052 )
51- search_map .image_shift_correction = (
52- search_map_params .image_shift_correction
53- or search_map .image_shift_correction
53+ search_map .reference_matrix_m21 = (
54+ search_map_params .reference_matrix .get ("m21" )
55+ or search_map .reference_matrix_m21
56+ )
57+ search_map .reference_matrix_m22 = (
58+ search_map_params .reference_matrix .get ("m22" )
59+ or search_map .reference_matrix_m22
60+ )
61+ search_map .stage_correction_m11 = (
62+ search_map_params .stage_correction .get ("m11" )
63+ or search_map .stage_correction_m11
64+ )
65+ search_map .stage_correction_m12 = (
66+ search_map_params .stage_correction .get ("m12" )
67+ or search_map .stage_correction_m12
68+ )
69+ search_map .stage_correction_m21 = (
70+ search_map_params .stage_correction .get ("m21" )
71+ or search_map .stage_correction_m21
72+ )
73+ search_map .stage_correction_m22 = (
74+ search_map_params .stage_correction .get ("m22" )
75+ or search_map .stage_correction_m22
76+ )
77+ search_map .image_shift_correction_m11 = (
78+ search_map_params .image_shift_correction .get ("m11" )
79+ or search_map .image_shift_correction_m11
80+ )
81+ search_map .image_shift_correction_m12 = (
82+ search_map_params .image_shift_correction .get ("m12" )
83+ or search_map .image_shift_correction_m12
84+ )
85+ search_map .image_shift_correction_m21 = (
86+ search_map_params .image_shift_correction .get ("m21" )
87+ or search_map .image_shift_correction_m21
88+ )
89+ search_map .image_shift_correction_m22 = (
90+ search_map_params .image_shift_correction .get ("m22" )
91+ or search_map .image_shift_correction_m22
5492 )
5593 search_map .height = search_map_params .height or search_map .height
5694 search_map .width = search_map_params .width or search_map .width
@@ -78,9 +116,26 @@ def register_search_map_in_database(
78116 pixel_size = search_map_params .pixel_size ,
79117 image = search_map_params .image ,
80118 binning = search_map_params .binning ,
81- reference_matrix = search_map_params .reference_matrix ,
82- stage_correction = search_map_params .stage_correction ,
83- image_shift_correction = search_map_params .image_shift_correction ,
119+ reference_matrix_m11 = search_map_params .reference_matrix .get ("m11" ),
120+ reference_matrix_m12 = search_map_params .reference_matrix .get ("m12" ),
121+ reference_matrix_m21 = search_map_params .reference_matrix .get ("m21" ),
122+ reference_matrix_m22 = search_map_params .reference_matrix .get ("m22" ),
123+ stage_correction_m11 = search_map_params .stage_correction .get ("m11" ),
124+ stage_correction_m12 = search_map_params .stage_correction .get ("m12" ),
125+ stage_correction_m21 = search_map_params .stage_correction .get ("m21" ),
126+ stage_correction_m22 = search_map_params .stage_correction .get ("m22" ),
127+ image_shift_correction_m11 = search_map_params .image_shift_correction .get (
128+ "m11"
129+ ),
130+ image_shift_correction_m12 = search_map_params .image_shift_correction .get (
131+ "m12"
132+ ),
133+ image_shift_correction_m21 = search_map_params .image_shift_correction .get (
134+ "m21"
135+ ),
136+ image_shift_correction_m22 = search_map_params .image_shift_correction .get (
137+ "m22"
138+ ),
84139 height = search_map_params .height ,
85140 width = search_map_params .width ,
86141 )
@@ -96,8 +151,8 @@ def register_search_map_in_database(
96151
97152 if all (
98153 [
99- search_map .reference_matrix ,
100- search_map .stage_correction ,
154+ search_map .reference_matrix_m11 ,
155+ search_map .stage_correction_m11 ,
101156 search_map .x_stage_position ,
102157 search_map .y_stage_position ,
103158 search_map .pixel_size ,
@@ -110,25 +165,25 @@ def register_search_map_in_database(
110165 M = np .array (
111166 [
112167 [
113- search_map .reference_matrix [ "m11" ] ,
114- search_map .reference_matrix [ "m12" ] ,
168+ search_map .reference_matrix_m11 ,
169+ search_map .reference_matrix_m12 ,
115170 ],
116171 [
117- search_map .reference_matrix [ "m21" ] ,
118- search_map .reference_matrix [ "m22" ] ,
172+ search_map .reference_matrix_m21 ,
173+ search_map .reference_matrix_m22 ,
119174 ],
120175 ]
121176 )
122177 B = np .array ([search_map .x_stage_position , search_map .y_stage_position ])
123178 R = np .array (
124179 [
125180 [
126- search_map .stage_correction [ "m11" ] ,
127- search_map .stage_correction [ "m12" ] ,
181+ search_map .stage_correction_m11 ,
182+ search_map .stage_correction_m12 ,
128183 ],
129184 [
130- search_map .stage_correction [ "m21" ] ,
131- search_map .stage_correction [ "m22" ] ,
185+ search_map .stage_correction_m21 ,
186+ search_map .stage_correction_m22 ,
132187 ],
133188 ]
134189 )
@@ -152,6 +207,8 @@ def register_search_map_in_database(
152207 search_map .y_location = search_map_params .y_location
153208 if _transport_object :
154209 _transport_object .do_update_search_map (search_map .id , search_map_params )
210+ else :
211+ logger .info (f"Unable to register search map { search_map_name } position yet" )
155212 murfey_db .add (search_map )
156213 murfey_db .commit ()
157214 murfey_db .close ()
@@ -188,61 +245,80 @@ def register_batch_position_in_database(
188245 )
189246
190247 # Get the pixel location on the searchmap
191- M = np . array (
248+ if all (
192249 [
193- [
194- search_map .reference_matrix ["m11" ],
195- search_map .reference_matrix ["m12" ],
196- ],
197- [
198- search_map .reference_matrix ["m21" ],
199- search_map .reference_matrix ["m22" ],
200- ],
250+ search_map .reference_matrix_m11 ,
251+ search_map .stage_correction_m11 ,
252+ search_map .x_stage_position ,
253+ search_map .y_stage_position ,
254+ search_map .pixel_size ,
255+ search_map .height ,
256+ search_map .width ,
201257 ]
202- )
203- R1 = np .array (
204- [
205- [
206- search_map .stage_correction ["m11" ],
207- search_map .stage_correction ["m12" ],
208- ],
258+ ):
259+ M = np .array (
209260 [
210- search_map .stage_correction ["m21" ],
211- search_map .stage_correction ["m22" ],
212- ],
213- ]
214- )
215- R2 = np .array (
216- [
261+ [
262+ search_map .reference_matrix_m11 ,
263+ search_map .reference_matrix_m12 ,
264+ ],
265+ [
266+ search_map .reference_matrix_m21 ,
267+ search_map .reference_matrix_m22 ,
268+ ],
269+ ]
270+ )
271+ R1 = np .array (
217272 [
218- search_map .image_shift_correction ["m11" ],
219- search_map .image_shift_correction ["m12" ],
220- ],
273+ [
274+ search_map .stage_correction_m11 ,
275+ search_map .stage_correction_m12 ,
276+ ],
277+ [
278+ search_map .stage_correction_m21 ,
279+ search_map .stage_correction_m22 ,
280+ ],
281+ ]
282+ )
283+ R2 = np .array (
221284 [
222- search_map .image_shift_correction ["m21" ],
223- search_map .image_shift_correction ["m22" ],
224- ],
225- ]
226- )
285+ [
286+ search_map .image_shift_correction_m11 ,
287+ search_map .image_shift_correction_m12 ,
288+ ],
289+ [
290+ search_map .image_shift_correction_m21 ,
291+ search_map .image_shift_correction_m22 ,
292+ ],
293+ ]
294+ )
227295
228- A = np .array ([search_map .x_stage_position , search_map .y_stage_position ])
229- B = np .array ([batch_parameters .x_stage_position , batch_parameters .y_stage_position ])
296+ A = np .array ([search_map .x_stage_position , search_map .y_stage_position ])
297+ B = np .array (
298+ [batch_parameters .x_stage_position , batch_parameters .y_stage_position ]
299+ )
230300
231- vector_pixel = np .matmul (
232- np .linalg .inv (M ),
233- np .matmul (np .linalg .inv (R1 ), np .matmul (np .linalg .inv (R2 ), np .matmul (M , B - A ))),
234- )
235- centre_batch_pixel = vector_pixel / search_map .pixel_size + [
236- search_map .width / 2 ,
237- search_map .height / 2 ,
238- ]
239- tilt_series .x_location = (
240- centre_batch_pixel [0 ]
241- - BatchPositionParameters .x_beamshift / search_map .pixel_size
242- )
243- tilt_series .y_location = (
244- centre_batch_pixel [1 ]
245- - BatchPositionParameters .y_beamshift / search_map .pixel_size
246- )
301+ vector_pixel = np .matmul (
302+ np .linalg .inv (M ),
303+ np .matmul (
304+ np .linalg .inv (R1 ), np .matmul (np .linalg .inv (R2 ), np .matmul (M , B - A ))
305+ ),
306+ )
307+ centre_batch_pixel = vector_pixel / search_map .pixel_size + [
308+ search_map .width / 2 ,
309+ search_map .height / 2 ,
310+ ]
311+ tilt_series .x_location = (
312+ centre_batch_pixel [0 ]
313+ - BatchPositionParameters .x_beamshift / search_map .pixel_size
314+ )
315+ tilt_series .y_location = (
316+ centre_batch_pixel [1 ]
317+ - BatchPositionParameters .y_beamshift / search_map .pixel_size
318+ )
319+ else :
320+ logger .warning (
321+ f"No search map information available to register position of { batch_name } "
322+ )
247323 murfey_db .add (tilt_series )
248324 murfey_db .commit ()
0 commit comments