diff --git a/common/src/aaredaqlib/find_xtal.py b/common/src/aaredaqlib/find_xtal.py index 80ad4771..fec9a5bb 100644 --- a/common/src/aaredaqlib/find_xtal.py +++ b/common/src/aaredaqlib/find_xtal.py @@ -11,43 +11,42 @@ logger = setup_logger('aareDAQ') def identify_crystal_raster(result, r: RasterGridRequest): images = result.images - if images and any(getattr(img, "spots", 0) for img in images): + # if images and any(getattr(img, "spots", 0) for img in images): + # + # indexed_images = [img for img in images if img.index and img.spots_low_res > 4 and img.bkg > 4.5] + # + # 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 > 4 and ( + # img.spots_ice / img.spots_low_res) < 5.0 + # and (img.spots_ice / img.spots_low_res) != 1] + # + # if indexed_images: + # logger.debug(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] + # + # logger.debug(f"Image with maximum spots_low_res: {max_image}") + # logger.debug(f"Maximum spots_indexed value: {max_image.spots_indexed}") + # logger.debug(f"Maximum spots_low_res value: {max_image.spots_low_res}") + # else: + logger.debug(f"Find image by maximum number of low resolution spots") + max_image = max(images, key=lambda img: img.spots_low_res) + logger.debug(f"Image with maximum spots_low_res: {max_image}") + logger.debug(f"Maximum spots_low_res value: {max_image.spots_low_res}") + logger.debug(f"Maximum image found at grid coordiantes {max_image.nx}, {max_image.ny}") + logger.debug(f"Maximum image found at umL {max_image.nx * r.grid_size_mm.x}, {max_image.ny * r.grid_size_mm.y}") - indexed_images = [img for img in images if img.index and img.spots_low_res > 4 and img.bkg > 4.5] + grid_mm_x = (max_image.nx+0.5) * r.grid_size_mm.x + grid_mm_y = (max_image.ny+0.5) * r.grid_size_mm.y - 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 > 4 and ( - img.spots_ice / img.spots_low_res) < 5.0 - and (img.spots_ice / img.spots_low_res) != 1] - - if indexed_images: - logger.debug(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] - - logger.debug(f"Image with maximum spots_low_res: {max_image}") - logger.debug(f"Maximum spots_indexed value: {max_image.spots_indexed}") - logger.debug(f"Maximum spots_low_res value: {max_image.spots_low_res}") - else: - logger.debug(f"Find image by maximum number of low resolution spots") - max_image = max(images, key=lambda img: img.spots_low_res) - logger.debug(f"Image with maximum spots_low_res: {max_image}") - logger.debug(f"Maximum spots_low_res value: {max_image.spots_low_res}") - - grid_mm_x = max_image.nx * r.grid_size_mm.x - grid_mm_y = max_image.ny * r.grid_size_mm.y - - logger.debug(f"Grid coordinates in mm: ({grid_mm_x}, {grid_mm_y})") - return grid_mm_x, grid_mm_y - - else: - return None, None + logger.debug(f"Grid coordinates in mm: ({grid_mm_x}, {grid_mm_y})") + return grid_mm_x, grid_mm_y def rebuild_array_from_scan_results(scan_results: List, value_field: str,