@@ -130,8 +130,12 @@ 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 = (
134+ int (round (result .pixels_x * scaling_factor )) or 1
135+ )
136+ clem_img_site .thumbnail_pixels_y = (
137+ int (round (result .pixels_y * scaling_factor )) or 1
138+ )
135139 murfey_db .add (clem_img_site )
136140 murfey_db .commit ()
137141 murfey_db .close ()
@@ -354,30 +358,42 @@ def _register_grid_square(
354358 and clem_img_site .y0 is not None
355359 and clem_img_site .y1 is not None
356360 ):
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
360- )
361+ # Find the real coordinates of the image midpoint
362+ x_mid_real = 0.5 * (clem_img_site .x0 + clem_img_site .x1 )
363+ y_mid_real = 0.5 * (clem_img_site .y0 + clem_img_site .y1 )
364+
365+ # Find pixel coordinates corresponding to image midpoint on atlas
361366 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
367+ round (
368+ (x_mid_real - atlas_entry .x0 )
369+ / atlas_width_real
370+ * atlas_entry .thumbnail_pixels_x
371+ )
366372 )
367373 y_mid_px = int (
368- y_mid_real / atlas_height_real * atlas_entry .thumbnail_pixels_y
374+ round (
375+ (y_mid_real - atlas_entry .y0 )
376+ / atlas_height_real
377+ * atlas_entry .thumbnail_pixels_y
378+ )
369379 )
370380
371381 # Find the size of the image, in pixels, when overlaid on the atlas
372382 width_scaled = int (
373- (clem_img_site .x1 - clem_img_site .x0 )
374- / atlas_width_real
375- * atlas_entry .thumbnail_pixels_x
383+ round (
384+ (clem_img_site .x1 - clem_img_site .x0 )
385+ / atlas_width_real
386+ * atlas_entry .thumbnail_pixels_x
387+ )
388+ or 1
376389 )
377390 height_scaled = int (
378- (clem_img_site .y1 - clem_img_site .y0 )
379- / atlas_height_real
380- * atlas_entry .thumbnail_pixels_y
391+ round (
392+ (clem_img_site .y1 - clem_img_site .y0 )
393+ / atlas_height_real
394+ * atlas_entry .thumbnail_pixels_y
395+ )
396+ or 1
381397 )
382398 else :
383399 logger .warning (
0 commit comments