From f03bcb4c227b85dd311e61198402ba0351e542e0 Mon Sep 17 00:00:00 2001 From: pmoegenburg Date: Thu, 10 Oct 2024 14:20:51 -0400 Subject: [PATCH] fixed up frustum_helpers and tests --- .../protocol_engine/commands/aspirate.py | 2 +- .../protocol_engine/state/frustum_helpers.py | 14 ++++++++----- .../state/test_geometry_view.py | 20 +++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/api/src/opentrons/protocol_engine/commands/aspirate.py b/api/src/opentrons/protocol_engine/commands/aspirate.py index f4edd7fcf1f..4a584298b10 100644 --- a/api/src/opentrons/protocol_engine/commands/aspirate.py +++ b/api/src/opentrons/protocol_engine/commands/aspirate.py @@ -118,7 +118,7 @@ async def execute(self, params: AspirateParams) -> _ExecuteReturn: well_location.volumeOffset = "operationVolume" if well_location.offset.z > 0.0: raise InvalidAspirateLocationError( - f"Cannot specify a meniscus-relative Aspirate with a z-offset of {well_location.offset.z}" + f"Cannot specify a meniscus-relative Aspirate with a positive z-offset (specified {well_location.offset.z})" ) position = await self._movement.move_to_well( diff --git a/api/src/opentrons/protocol_engine/state/frustum_helpers.py b/api/src/opentrons/protocol_engine/state/frustum_helpers.py index 4f132ac3b40..09f726de767 100644 --- a/api/src/opentrons/protocol_engine/state/frustum_helpers.py +++ b/api/src/opentrons/protocol_engine/state/frustum_helpers.py @@ -375,18 +375,22 @@ def _find_height_in_partial_frustum( bottom_section_volume = 0.0 for section, capacity in zip(sorted_well, volumetric_capacity): section_top_height, section_volume = capacity - if bottom_section_volume < target_volume < section_volume: + if ( + bottom_section_volume + < target_volume + < (bottom_section_volume + section_volume) + ): relative_target_volume = target_volume - bottom_section_volume - relative_section_height = section.topHeight - section.bottomHeight + section_height = section.topHeight - section.bottomHeight partial_height = height_at_volume_within_section( section=section, target_volume_relative=relative_target_volume, - section_height=relative_section_height, + section_height=section_height, ) return partial_height + section.bottomHeight # bottom section volume should always be the volume enclosed in the previously # viewed section - bottom_section_volume = section_volume + bottom_section_volume += section_volume # if we've looked through all sections and can't find the target volume, raise an error raise InvalidLiquidHeightFound( @@ -399,7 +403,7 @@ def find_height_at_well_volume( ) -> float: """Find the height within a well, at a known volume.""" volumetric_capacity = get_well_volumetric_capacity(well_geometry) - max_volume = volumetric_capacity[-1][1] + max_volume = sum(row[1] for row in volumetric_capacity) if target_volume < 0 or target_volume > max_volume: raise InvalidLiquidHeightFound("Invalid target volume.") diff --git a/api/tests/opentrons/protocol_engine/state/test_geometry_view.py b/api/tests/opentrons/protocol_engine/state/test_geometry_view.py index 5538228ca1f..9c05ff06852 100644 --- a/api/tests/opentrons/protocol_engine/state/test_geometry_view.py +++ b/api/tests/opentrons/protocol_engine/state/test_geometry_view.py @@ -1609,13 +1609,13 @@ def test_get_well_position_with_meniscus_and_literal_volume_offset( offset=WellOffset(x=2, y=3, z=4), volumeOffset="operationVolume", ), - operation_volume=-323.0, + operation_volume=-1245.833, ) assert result == Point( x=slot_pos[0] + 1 + well_def.x + 2, y=slot_pos[1] - 2 + well_def.y + 3, - z=slot_pos[2] + 3 + well_def.z + 4 + 40.0, + z=slot_pos[2] + 3 + well_def.z + 4 + 20.0, ) @@ -1654,7 +1654,7 @@ def test_get_well_position_with_meniscus_and_float_volume_offset( ) decoy.when( mock_well_view.get_last_measured_liquid_height("labware-id", "B2") - ).then_return(40.0) + ).then_return(45.0) labware_def = _load_labware_definition_data() assert labware_def.innerLabwareGeometry is not None inner_well_def = labware_def.innerLabwareGeometry["welldefinition1111"] @@ -1668,14 +1668,14 @@ def test_get_well_position_with_meniscus_and_float_volume_offset( well_location=LiquidHandlingWellLocation( origin=WellOrigin.MENISCUS, offset=WellOffset(x=2, y=3, z=4), - volumeOffset=-323.0, + volumeOffset=-1245.833, ), ) assert result == Point( x=slot_pos[0] + 1 + well_def.x + 2, y=slot_pos[1] - 2 + well_def.y + 3, - z=slot_pos[2] + 3 + well_def.z + 4 + 35.0, + z=slot_pos[2] + 3 + well_def.z + 4 + 20.0, ) @@ -1714,7 +1714,7 @@ def test_get_well_position_raises_validation_error( ) decoy.when( mock_well_view.get_last_measured_liquid_height("labware-id", "B2") - ).then_return(45.0) + ).then_return(40.0) labware_def = _load_labware_definition_data() assert labware_def.innerLabwareGeometry is not None inner_well_def = labware_def.innerLabwareGeometry["welldefinition1111"] @@ -1728,10 +1728,10 @@ def test_get_well_position_raises_validation_error( well_name="B2", well_location=LiquidHandlingWellLocation( origin=WellOrigin.MENISCUS, - offset=WellOffset(x=2, y=3, z=4), + offset=WellOffset(x=2, y=3, z=-40), volumeOffset="operationVolume", ), - operation_volume=-3000.0, + operation_volume=-100.0, ) @@ -3059,7 +3059,7 @@ def test_validate_dispense_volume_into_well_meniscus( ) decoy.when( mock_well_view.get_last_measured_liquid_height("labware-id", "A1") - ).then_return(45.0) + ).then_return(40.0) with pytest.raises(errors.InvalidDispenseVolumeError): subject.validate_dispense_volume_into_well( @@ -3069,5 +3069,5 @@ def test_validate_dispense_volume_into_well_meniscus( origin=WellOrigin.MENISCUS, offset=WellOffset(x=2, y=3, z=4), ), - volume=2000000.0, + volume=1100000.0, )