Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/opentrons/protocol_engine/state/frustum_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 22 additions & 2 deletions api/tests/opentrons/protocols/geometry/test_frustum_helpers.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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

Expand All @@ -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",
Expand Down Expand Up @@ -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)