Skip to content

Commit

Permalink
fixed up frustum_helpers and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Oct 10, 2024
1 parent b688aac commit f03bcb4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/src/opentrons/protocol_engine/commands/aspirate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 9 additions & 5 deletions api/src/opentrons/protocol_engine/state/frustum_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.")

Expand Down
20 changes: 10 additions & 10 deletions api/tests/opentrons/protocol_engine/state/test_geometry_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


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


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


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

0 comments on commit f03bcb4

Please sign in to comment.