raster: now do auto_centre_line_scan based off of target_y instead of just above and below beam cente, if target avaialble, now submit iamges to databse, reduced number of significant figures inr aster message to db, grid_to_image and iamge_to_grid fucntions

This commit is contained in:
appleb_m committed 2026-04-24 14:19:36 +02:00
1 parent d856b77b7d
commit 3b39bb2144
2 files changed
+244 -15

No files matched your search

+49
View File
@@ -88,3 +88,52 @@ class RasterPayloadModel(BaseModel):
beam_mark_pxl: tuple[float, float]
beam_size_mm: Annotated[Coordinate, AfterValidator(positive_coords)]
def grid_to_image_id(grid_x: int, grid_y: int, number_of_cols: int) -> int:
"""
Get the associated image id for a given grid position (grid_x, grid_y)
using serpentine row ordering.
grid_x: 1-based column index
grid_y: 1-based row index
number_of_cols: total number of columns in the grid
"""
if number_of_cols < 1:
raise ValueError("number_of_cols must be >= 1")
if grid_x < 1:
raise ValueError("grid_x must be >= 1")
if grid_y < 1:
raise ValueError("grid_y must be >= 1")
if grid_x > number_of_cols:
raise ValueError("grid_x cannot be greater than number_of_cols")
col = grid_x - 1
row = grid_y - 1
if row % 2 == 0: # left -> right
return row * number_of_cols + col
else: # right -> left
return row * number_of_cols + (number_of_cols - 1 - col)
def image_id_to_grid(image_id: int, number_of_cols: int) -> tuple[int, int]:
"""
Get the associated grid position (grid_x, grid_y) for a given image id
using serpentine row ordering.
"""
if number_of_cols < 1:
raise ValueError("number_of_cols must be >= 1")
if image_id < 0:
raise ValueError("image_id must be >= 0")
row = image_id // number_of_cols
pos_in_row = image_id % number_of_cols
if row % 2 == 0: # left -> right
col = pos_in_row
else: # right -> left
col = number_of_cols - 1 - pos_in_row
grid_x = col + 1
grid_y = row + 1
return grid_x, grid_y