find_Xtal - COM calculation bug fix

This commit is contained in:
2025-11-25 18:01:22 +01:00
parent bd84f2368f
commit 6f5701e700
+3 -3
View File
@@ -263,10 +263,10 @@ def com_nan_check(com):
else:
return True
def get_result_list_from_com(images, com):
def get_result_list_from_com(images, com: CenterOfMassModel):
if not com_nan_check(com):
return None
cy, cx = com[::-1]
cy, cx = com.n_x, com.n_y
start_x, end_x = round(cx - 1), round(cx + 1)
start_y, end_y = round(cy - 1), round(cy + 1)
logger.info(f"range x {start_x} {end_x}, y {start_y} {end_y}")
@@ -285,7 +285,7 @@ def get_com_image_number(com, images):
def raster_centre_of_mass(result_array, r:RasterGridRequest) -> CenterOfMassModel | None:
# grid_mm_x and grid_mm_y are relative to the top left corner of raster grid
com = ndimage.center_of_mass(result_array)
if com or not com_nan_check(com):
if com or not np.isnan(com[0]) or not np.isnan(com[1]):
logger.info(f"Center of mass: {com}")
return CenterOfMassModel(n_x=com[0], n_y=com[1])
else: