@@ -130,8 +130,8 @@ def _register_clem_imaging_site(
130130 thumbnail_height / result .pixels_y , thumbnail_width / result .pixels_x
131131 )
132132 clem_img_site .thumbnail_pixel_size = result .pixel_size / scaling_factor
133- clem_img_site .thumbnail_pixels_x = int (result .pixels_x * scaling_factor )
134- clem_img_site .thumbnail_pixels_y = int (result .pixels_y * scaling_factor )
133+ clem_img_site .thumbnail_pixels_x = int (round ( result .pixels_x * scaling_factor ) )
134+ clem_img_site .thumbnail_pixels_y = int (round ( result .pixels_y * scaling_factor ) )
135135 murfey_db .add (clem_img_site )
136136 murfey_db .commit ()
137137 murfey_db .close ()
@@ -354,30 +354,39 @@ def _register_grid_square(
354354 and clem_img_site .y0 is not None
355355 and clem_img_site .y1 is not None
356356 ):
357- # Find pixel corresponding to image midpoint on atlas
358- x_mid_real = (
359- 0.5 * (clem_img_site .x0 + clem_img_site .x1 ) - atlas_entry .x0
357+ # Find pixel coordinates corresponding to the centre of the image on the atlas
358+ cx = 0.5 * (clem_img_site .x0 + clem_img_site .x1 )
359+ cy = 0.5 * (clem_img_site .y0 + clem_img_site .y1 )
360+
361+ cx_scaled = int (
362+ round (
363+ (cx - atlas_entry .x0 )
364+ / atlas_width_real
365+ * atlas_entry .thumbnail_pixels_x
366+ )
360367 )
361- x_mid_px = int (
362- x_mid_real / atlas_width_real * atlas_entry .thumbnail_pixels_x
363- )
364- y_mid_real = (
365- 0.5 * (clem_img_site .y0 + clem_img_site .y1 ) - atlas_entry .y0
366- )
367- y_mid_px = int (
368- y_mid_real / atlas_height_real * atlas_entry .thumbnail_pixels_y
368+ cy_scaled = int (
369+ round (
370+ (cy - atlas_entry .y0 )
371+ / atlas_height_real
372+ * atlas_entry .thumbnail_pixels_y
373+ )
369374 )
370375
371376 # Find the size of the image, in pixels, when overlaid on the atlas
372377 width_scaled = int (
373- (clem_img_site .x1 - clem_img_site .x0 )
374- / atlas_width_real
375- * atlas_entry .thumbnail_pixels_x
378+ round (
379+ (clem_img_site .x1 - clem_img_site .x0 )
380+ / atlas_width_real
381+ * atlas_entry .thumbnail_pixels_x
382+ )
376383 )
377384 height_scaled = int (
378- (clem_img_site .y1 - clem_img_site .y0 )
379- / atlas_height_real
380- * atlas_entry .thumbnail_pixels_y
385+ round (
386+ (clem_img_site .y1 - clem_img_site .y0 )
387+ / atlas_height_real
388+ * atlas_entry .thumbnail_pixels_y
389+ )
381390 )
382391 else :
383392 logger .warning (
@@ -389,9 +398,9 @@ def _register_grid_square(
389398 grid_square_params = GridSquareParameters (
390399 tag = dcg_name ,
391400 x_location = clem_img_site .x0 ,
392- x_location_scaled = x_mid_px ,
401+ x_location_scaled = cx_scaled ,
393402 y_location = clem_img_site .y0 ,
394- y_location_scaled = y_mid_px ,
403+ y_location_scaled = cy_scaled ,
395404 readout_area_x = clem_img_site .image_pixels_x ,
396405 readout_area_y = clem_img_site .image_pixels_y ,
397406 thumbnail_size_x = clem_img_site .thumbnail_pixels_x ,
0 commit comments