DAQ: Added further complexity to identify_crystal_raster. Looking at the number of spots indexed, and if multiple images with this value, selects the median image number

This commit is contained in:
2025-07-17 14:27:19 +02:00
parent 8146184fad
commit abab0aac10
+24 -20
View File
@@ -302,35 +302,39 @@ class AareDAQ:
images = result.images
if images:
indexed_images = [img for img in images if img.index and img.spots_low_res > 4]
if indexed_images:
#indexed_images = [img for img in indexed_images if img.spots_indexed > 10]
images = indexed_images
filtered_images = [img for img in images
if img.spots_ice is not None and img.spots_low_res > 0 and (img.spots_ice / img.spots_low_res) < 5.0
if img.spots_ice is not None and img.spots_low_res > 4 and (
img.spots_ice / img.spots_low_res) < 5.0
and (img.spots_ice / img.spots_low_res) != 1]
if filtered_images:
images=filtered_images
indexed_images = [img for img in images if img.index]
images = filtered_images
if indexed_images:
max_image = max(indexed_images, key=lambda img: img.spots_low_res)
print(max_image.spots_ice / max_image.spots_low_res)
print(f"Image with maximum spots_low_res: {max_image}")
print(f"Maximum spots_low_res value: {max_image.spots_low_res}")
print(f"Find image by maximum number of spots indexed")
max_image = max(images, key=lambda img: img.spots_indexed)
max_spots = max_image.spots_indexed
max_images = [img for img in images if img.spots_indexed == max_spots]
max_image = max_images[len(max_images) // 2]
print(f"Image with maximum spots_low_res: {max_image}")
print(f"Maximum spots_indexed value: {max_image.spots_indexed}")
print(f"Maximum spots_low_res value: {max_image.spots_low_res}")
else:
images = [img for img in images]
print("No indexed images found.")
print(f"Find image by maximum number of low resolution spots")
max_image = max(images, key=lambda img: img.spots_low_res)
print(f"Image with maximum spots_low_res: {max_image}")
print(f"Maximum spots_low_res value: {max_image.spots_low_res}")
grid_x = max_image.number % r.n_x #this should be max_image.number, however on the return raster, the calc is n_x-max_index%n_x
grid_y = max_image.number // r.n_x
if grid_y % 2 == 1:
grid_x = r.n_x - grid_x - 1
print(f"Grid coordinates: ({grid_x}, {grid_y})")
grid_mm_x = grid_x * r.grid_size_mm.x + r.grid_size_mm.x/2
grid_mm_y = grid_y * r.grid_size_mm.y + r.grid_size_mm.y/2
grid_mm_x = max_image.nx * r.grid_size_mm.x
grid_mm_y = max_image.ny * r.grid_size_mm.y
print(f"Grid coordinates in mm: ({grid_mm_x}, {grid_mm_y})")
delta_mm = self.sample_geometry.smargon_nudge(Coordinate(x=grid_mm_x, y=grid_mm_y))
return delta_mm
@@ -363,10 +367,10 @@ class AareDAQ:
grid.omega_deg += 90
self.__devs.aerotech.move(grid.omega_deg, wait=True)
grid.n_x = 20
grid.n_y = 40
grid.n_x = 1
grid.n_y = 100
grid.file_prefix = f"{old_prefix}_{grid.omega_deg}deg"
offset = Coordinate(x=-grid.n_x * grid.grid_size_mm.x / 2.0, y=-grid.n_y * grid.grid_size_mm.y / 2.0)
offset = Coordinate(x=0, y=-grid.n_y * grid.grid_size_mm.y / 2.0)
geom = self.sample_geometry
grid.smargon.sh_mm = geom.smargon.sh_mm + geom.smargon_nudge(offset)
res2 = self.__raster(grid)