diff --git a/src/aare/daq/aaredb.py b/src/aare/daq/aaredb.py index a3204a6f..6b567077 100644 --- a/src/aare/daq/aaredb.py +++ b/src/aare/daq/aaredb.py @@ -348,7 +348,7 @@ class AareWrapper: raster_result: ScanResult, raster_request: RasterGridRequest, geom: SampleGeometryModel, - com: CenterOfMassModel, + com: CenterOfMassModel | None, analysis_image_scores: list[float | None] | None, beam_mark_pxl: tuple[float, float], decision: GridScanDecision | None, @@ -364,10 +364,11 @@ class AareWrapper: beam_loc = raster_request.smargon_top_left.sh_mm start_pxl = geom.smargon_to_picture(beam_loc) - - com_grid_pxl = com.get_com_pxl(raster_request, geom) - center_pxl = Coordinate(x=start_pxl.x + com_grid_pxl.x, y=start_pxl.y + com_grid_pxl.y) - + if com: + com_grid_pxl = com.get_com_pxl(raster_request, geom) + center_pxl = Coordinate(x=start_pxl.x + com_grid_pxl.x, y=start_pxl.y + com_grid_pxl.y) + else: + com_grid_pxl, center_pxl = None, None return RasterPayloadModel( request=raster_request, result=raster_result, diff --git a/tests/unit/daq/operations/test_ml_raster_plan.py b/tests/unit/daq/operations/test_ml_raster_plan.py index fc3f22d2..225ee0a9 100644 --- a/tests/unit/daq/operations/test_ml_raster_plan.py +++ b/tests/unit/daq/operations/test_ml_raster_plan.py @@ -167,38 +167,3 @@ def test_crystal_union_extends_grid_only_when_enabled(monkeypatch): assert on.n_x > off.n_x # grid widened to reach the crystal assert on.n_y == off.n_y # crystal is within the loop's y-range (same padding both) - -def test_zoom_box_uses_loop_all_unless_clipped(): - from aare.daq.operations.raster.service import RasterService - - svc = RasterService.__new__(RasterService) - - # loop_all fully inside the frame -> used for zoom - ok = mlb.MLRasterPlan( - grid_request=None, - loop_all_box=(100, 100, 400, 400), - loop_face_box=(150, 150, 300, 300), - image_width=1000, - image_height=1000, - ) - assert svc._zoom_to_fit_box(ok) == (100, 100, 400, 400) - - # loop_all touches the left edge (clipped) -> fall back to loop_face - clipped = mlb.MLRasterPlan( - grid_request=None, - loop_all_box=(0, 100, 400, 400), - loop_face_box=(150, 150, 300, 300), - image_width=1000, - image_height=1000, - ) - assert svc._zoom_to_fit_box(clipped) == (150, 150, 300, 300) - - # no loop_all -> loop_face - only_face = mlb.MLRasterPlan( - grid_request=None, - loop_all_box=None, - loop_face_box=(150, 150, 300, 300), - image_width=1000, - image_height=1000, - ) - assert svc._zoom_to_fit_box(only_face) == (150, 150, 300, 300) diff --git a/tests/unit/daq/test_aaredb.py b/tests/unit/daq/test_aaredb.py index e3ab9dc2..d97c3bf2 100644 --- a/tests/unit/daq/test_aaredb.py +++ b/tests/unit/daq/test_aaredb.py @@ -4,6 +4,7 @@ import numpy as np import pytest from aarecommon.math.coordinate import Coordinate, SmargonCoordinate from aarecommon.math.sample_geometry import SampleGeometryModel +from aarecommon.models.gridscan_decision import GridScanDecision, GridScanResult from aarecommon.models.models import DewarAddress, PuckLoadedInfo, SampleShortInfo from aarecommon.models.raster_grid import CenterOfMassModel, RasterGridRequest from aarecommon.models.rotation_scan import RotationScanRequest @@ -277,13 +278,29 @@ def test_ingest_gridscan(mock_post, mock_api, mock_bl, sample_info, geom_model): com = CenterOfMassModel(n_x=5.0, n_y=5.0) wrapper.ingest_gridscan( - sample_info, raster_result, raster_request, geom_model, com, (500.0, 500.0) + sample_info, + raster_result, + raster_request, + [], + geom_model, + com, + (500.0, 500.0), + GridScanDecision(algorithm="none", result=GridScanResult(found=False)), ) mock_post.assert_called_once() # None sample mock_post.reset_mock() - wrapper.ingest_gridscan(None, raster_result, raster_request, geom_model, com, (500.0, 500.0)) + wrapper.ingest_gridscan( + None, + raster_result, + raster_request, + [], + geom_model, + com, + (500.0, 500.0), + GridScanDecision(algorithm="none", result=GridScanResult(found=False)), + ) mock_post.assert_not_called() @@ -316,7 +333,14 @@ def test_format_gridscan_payload_no_com(mock_api, mock_bl, sample_info, geom_mod ) payload = wrapper.format_gridscan_payload( - sample_info, raster_result, raster_request, geom_model, None, (500.0, 500.0) + sample_info, + raster_result, + raster_request, + geom_model, + None, + [], + (500.0, 500.0), + GridScanDecision(algorithm="none", result=GridScanResult(found=False)), ) assert payload.center_pxl is None assert payload.sample_id == sample_info.db_id @@ -336,26 +360,18 @@ def test_format_gridscan_payload_with_top_left(mock_api, mock_bl, sample_info, g ) payload = wrapper.format_gridscan_payload( - sample_info, raster_result, raster_request, geom_model, None, (500.0, 500.0) + sample_info, + raster_result, + raster_request, + geom_model, + None, + [], + (500.0, 500.0), + GridScanDecision(algorithm="none", result=GridScanResult(found=False)), ) assert payload.sample_id == sample_info.db_id -@patch("aareDB.ApiClient") -def test_ingest_gridscan_payload_none(mock_api, mock_bl, sample_info, geom_model): - wrapper = AareWrapper(bl=mock_bl) - # We want format_gridscan_payload to return None - # Looking at aaredb.py, it returns None if an exception occurs and it's caught - # But wait, it raises 'e' after logging. Oh, I see. - # Lines 351-352 in aaredb.py: if payload is None: return - # This happens if format_gridscan_payload returns None. - with patch.object(AareWrapper, "format_gridscan_payload", return_value=None): - wrapper.ingest_gridscan(sample_info, None, None, geom_model, None, (0, 0)) # type: ignore # intended - - with patch.object(AareWrapper, "format_scan_payload", return_value=None): - wrapper.ingest_scan(sample_info, None, geom_model, (0, 0)) # type: ignore # intended - - @patch("aareDB.ApiClient") def test_format_gridscan_payload_error(mock_api, mock_bl, sample_info, caplog): wrapper = AareWrapper(bl=mock_bl)