From ec37de594203da4c9df17e1625c434352533fc12 Mon Sep 17 00:00:00 2001 From: caila-marashaj Date: Wed, 25 Sep 2024 16:52:24 -0400 Subject: [PATCH] rm frustum formula calculations --- .../protocol_engine/state/frustum_helpers.py | 25 ++-------- .../geometry/test_frustum_helpers.py | 49 +------------------ 2 files changed, 5 insertions(+), 69 deletions(-) diff --git a/api/src/opentrons/protocol_engine/state/frustum_helpers.py b/api/src/opentrons/protocol_engine/state/frustum_helpers.py index 60772cae7336..27e417aa8b41 100644 --- a/api/src/opentrons/protocol_engine/state/frustum_helpers.py +++ b/api/src/opentrons/protocol_engine/state/frustum_helpers.py @@ -1,7 +1,7 @@ """Helper functions for liquid-level related calculations inside a given frustum.""" from typing import List, Tuple, Iterator, Sequence, Any, Union, Optional from numpy import pi, iscomplex, roots, real -from math import sqrt, isclose +from math import isclose from ..errors.exceptions import InvalidLiquidHeightFound, InvalidWellDefinitionError from opentrons_shared_data.labware.types import ( @@ -60,18 +60,6 @@ def cross_section_area_rectangular(x_dimension: float, y_dimension: float) -> fl return x_dimension * y_dimension -def volume_from_frustum_formula(area_1: float, area_2: float, height: float) -> float: - """Get the area of a section with differently shaped boundary cross-sections.""" - area_term = area_1 + area_2 + sqrt(area_1 * area_2) - return (height / 3) * area_term - - -def height_from_frustum_formula(area_1: float, area_2: float, volume: float) -> float: - """Get the volume within a section with differently shaped boundary cross-sections.""" - area_term = area_1 + area_2 + sqrt(area_1 * area_2) - return 3 * volume / area_term - - def rectangular_frustum_polynomial_roots( bottom_length: float, bottom_width: float, @@ -283,14 +271,9 @@ def get_well_volumetric_capacity( well_volume.append((next_f["topHeight"], frustum_volume)) else: - for f, next_f in get_boundary_pairs(sorted_frusta): - bottom_cross_section_area = get_cross_section_area(f) - top_cross_section_area = get_cross_section_area(next_f) - section_height = next_f["topHeight"] - f["topHeight"] - bounded_volume = volume_from_frustum_formula( - bottom_cross_section_area, top_cross_section_area, section_height - ) - well_volume.append((next_f["topHeight"], bounded_volume)) + raise NotImplementedError( + "Well section with differing boundary shapes not yet implemented." + ) return well_volume diff --git a/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py b/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py index bfd6b703a9cd..0bf74aae5b2a 100644 --- a/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py +++ b/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py @@ -1,7 +1,6 @@ import pytest -from math import pi, sqrt, isclose +from math import pi, isclose from typing import Any, List -from hypothesis import given, strategies from opentrons_shared_data.labware.types import ( RectangularBoundedSection, @@ -13,8 +12,6 @@ cross_section_area_circular, reject_unacceptable_heights, get_boundary_pairs, - get_cross_section_area, - volume_from_frustum_formula, circular_frustum_polynomial_roots, rectangular_frustum_polynomial_roots, volume_from_height_rectangular, @@ -23,7 +20,6 @@ height_from_volume_circular, height_from_volume_rectangular, height_from_volume_spherical, - height_from_frustum_formula, ) from opentrons.protocol_engine.errors.exceptions import InvalidLiquidHeightFound @@ -146,49 +142,6 @@ def test_get_cross_section_boundaries(well: List[List[Any]]) -> None: i += 1 -@pytest.mark.parametrize("well", fake_frusta()) -def test_frustum_formula_volume(well: List[Any]) -> None: - """Test volume-of-a-frustum formula calculation.""" - for f, next_f in get_boundary_pairs(well): - if f["shape"] == "spherical" or next_f["shape"] == "spherical": - # not going to use formula on spherical segments - continue - f_area = get_cross_section_area(f) - next_f_area = get_cross_section_area(next_f) - frustum_height = next_f["topHeight"] - f["topHeight"] - expected_volume = (f_area + next_f_area + sqrt(f_area * next_f_area)) * ( - frustum_height / 3 - ) - found_volume = volume_from_frustum_formula( - area_1=f_area, area_2=next_f_area, height=frustum_height - ) - assert found_volume == expected_volume - - -@pytest.mark.parametrize("well", fake_frusta()) -@given(target_volume=strategies.floats(min_value=0, max_value=10)) -def test_frustum_formula_height(well: List[Any], target_volume: float) -> None: - """Test volume-of-a-frustum formula calculation for height.""" - for f, next_f in get_boundary_pairs(well): - if f["shape"] == "spherical" or next_f["shape"] == "spherical": - # not going to use formula on spherical segments - continue - f_area = get_cross_section_area(f) - next_f_area = get_cross_section_area(next_f) - area_term = f_area + next_f_area + sqrt(f_area * next_f_area) - expected_height = 3 * target_volume / area_term - found_height = height_from_frustum_formula( - area_1=f_area, - area_2=next_f_area, - volume=target_volume, - ) - assert found_height == expected_height - found_volume = volume_from_frustum_formula( - area_1=f_area, area_2=next_f_area, height=found_height - ) - assert isclose(round(found_volume, 4), round(target_volume, 4)) - - @pytest.mark.parametrize("well", fake_frusta()) def test_volume_and_height_circular(well: List[Any]) -> None: """Test both volume and height calculations for circular frusta."""