From d2dd11bd23e7570525fda0acf5992997830a83ed Mon Sep 17 00:00:00 2001 From: Andy Sigler Date: Thu, 27 Mar 2025 11:12:35 -0400 Subject: [PATCH] fix(api): Estimating volume when liquid height is zero should return zero not error (#17877) --- .../protocol_engine/state/frustum_helpers.py | 2 +- .../geometry/test_frustum_helpers.py | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/api/src/opentrons/protocol_engine/state/frustum_helpers.py b/api/src/opentrons/protocol_engine/state/frustum_helpers.py index c88fb6567ea3..f56cb77c65f5 100644 --- a/api/src/opentrons/protocol_engine/state/frustum_helpers.py +++ b/api/src/opentrons/protocol_engine/state/frustum_helpers.py @@ -344,7 +344,7 @@ def _find_volume_in_partial_frustum( ) -> float: """Look through a sorted list of frusta for a target height, and find the volume at that height.""" for segment in sorted_well: - if segment.bottomHeight < target_height < segment.topHeight: + if segment.bottomHeight <= target_height <= segment.topHeight: relative_target_height = target_height - segment.bottomHeight section_height = segment.topHeight - segment.bottomHeight return volume_at_height_within_section( diff --git a/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py b/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py index d9bd8173834b..3a7d15f58e9c 100644 --- a/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py +++ b/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py @@ -1,11 +1,12 @@ import pytest from math import pi, isclose -from typing import Any, List +from typing import Any, List, cast from opentrons_shared_data.labware.labware_definition import ( ConicalFrustum, CuboidalFrustum, SphericalSegment, + InnerWellGeometry, ) from opentrons.protocol_engine.state.frustum_helpers import ( _cross_section_area_rectangular, @@ -20,6 +21,7 @@ _height_from_volume_spherical, height_at_volume_within_section, _get_segment_capacity, + find_volume_at_well_height, ) from opentrons.protocol_engine.errors.exceptions import InvalidLiquidHeightFound @@ -45,7 +47,7 @@ def fake_frusta() -> List[List[Any]]: bottomXDimension=15.0, bottomYDimension=18.0, topHeight=5.0, - bottomHeight=1.0, + bottomHeight=2.0, ), ConicalFrustum( shape="conical", @@ -323,3 +325,21 @@ def test_height_at_volume_within_section(well: List[Any]) -> None: segment, _get_segment_capacity(segment), segment_height ) assert isclose(height, segment_height) + + +@pytest.mark.parametrize("well", fake_frusta()) +def test_volume_at_section_boundary_heights(well: List[Any]) -> None: + """Test that finds the volume at the segment boundaries (top/bottom).""" + inner_well_geometry = InnerWellGeometry(sections=well) + tot_ul = 0.0 + # reverse b/c list of top->bottom + for segment in reversed(well): + bottom_ul = find_volume_at_well_height( + target_height=segment.bottomHeight, well_geometry=inner_well_geometry + ) + assert isclose(cast(float, bottom_ul), tot_ul) + top_ul = find_volume_at_well_height( + target_height=segment.topHeight, well_geometry=inner_well_geometry + ) + tot_ul += _get_segment_capacity(segment) + assert isclose(cast(float, top_ul), tot_ul)