From 83cfbc1f21999c7295f0b4866dddafb1dacee234 Mon Sep 17 00:00:00 2001 From: Ryan howard Date: Tue, 1 Oct 2024 17:26:53 -0400 Subject: [PATCH] Mark some methods as non-public --- .../protocol_engine/state/frustum_helpers.py | 54 +++++++++---------- .../state/test_geometry_view.py | 16 +++--- .../geometry/test_frustum_helpers.py | 48 +++++++++-------- 3 files changed, 60 insertions(+), 58 deletions(-) diff --git a/api/src/opentrons/protocol_engine/state/frustum_helpers.py b/api/src/opentrons/protocol_engine/state/frustum_helpers.py index 7718288bd1f3..bdd92dae224d 100644 --- a/api/src/opentrons/protocol_engine/state/frustum_helpers.py +++ b/api/src/opentrons/protocol_engine/state/frustum_helpers.py @@ -8,7 +8,7 @@ from opentrons_shared_data.labware.labware_definition import InnerWellGeometry -def reject_unacceptable_heights( +def _reject_unacceptable_heights( potential_heights: List[float], max_height: float ) -> float: """Reject any solutions to a polynomial equation that cannot be the height of a frustum.""" @@ -42,18 +42,18 @@ def get_cross_section_area(bounded_section: Any) -> float: return cross_section_area -def cross_section_area_circular(diameter: float) -> float: +def _cross_section_area_circular(diameter: float) -> float: """Get the area of a circular cross-section.""" radius = diameter / 2 return pi * (radius**2) -def cross_section_area_rectangular(x_dimension: float, y_dimension: float) -> float: +def _cross_section_area_rectangular(x_dimension: float, y_dimension: float) -> float: """Get the area of a rectangular cross-section.""" return x_dimension * y_dimension -def rectangular_frustum_polynomial_roots( +def _rectangular_frustum_polynomial_roots( bottom_length: float, bottom_width: float, top_length: float, @@ -75,7 +75,7 @@ def rectangular_frustum_polynomial_roots( return a, b, c -def circular_frustum_polynomial_roots( +def _circular_frustum_polynomial_roots( bottom_radius: float, top_radius: float, total_frustum_height: float, @@ -88,14 +88,14 @@ def circular_frustum_polynomial_roots( return a, b, c -def volume_from_height_circular( +def _volume_from_height_circular( target_height: float, total_frustum_height: float, bottom_radius: float, top_radius: float, ) -> float: """Find the volume given a height within a circular frustum.""" - a, b, c = circular_frustum_polynomial_roots( + a, b, c = _circular_frustum_polynomial_roots( bottom_radius=bottom_radius, top_radius=top_radius, total_frustum_height=total_frustum_height, @@ -104,7 +104,7 @@ def volume_from_height_circular( return volume -def volume_from_height_rectangular( +def _volume_from_height_rectangular( target_height: float, total_frustum_height: float, bottom_length: float, @@ -113,7 +113,7 @@ def volume_from_height_rectangular( top_width: float, ) -> float: """Find the volume given a height within a rectangular frustum.""" - a, b, c = rectangular_frustum_polynomial_roots( + a, b, c = _rectangular_frustum_polynomial_roots( bottom_length=bottom_length, bottom_width=bottom_width, top_length=top_length, @@ -124,7 +124,7 @@ def volume_from_height_rectangular( return volume -def volume_from_height_spherical( +def _volume_from_height_spherical( target_height: float, radius_of_curvature: float, ) -> float: @@ -135,14 +135,14 @@ def volume_from_height_spherical( return volume -def height_from_volume_circular( +def _height_from_volume_circular( volume: float, total_frustum_height: float, bottom_radius: float, top_radius: float, ) -> float: """Find the height given a volume within a circular frustum.""" - a, b, c = circular_frustum_polynomial_roots( + a, b, c = _circular_frustum_polynomial_roots( bottom_radius=bottom_radius, top_radius=top_radius, total_frustum_height=total_frustum_height, @@ -151,14 +151,14 @@ def height_from_volume_circular( x_intercept_roots = (a, b, c, d) height_from_volume_roots = roots(x_intercept_roots) - height = reject_unacceptable_heights( + height = _reject_unacceptable_heights( potential_heights=list(height_from_volume_roots), max_height=total_frustum_height, ) return height -def height_from_volume_rectangular( +def _height_from_volume_rectangular( volume: float, total_frustum_height: float, bottom_length: float, @@ -167,7 +167,7 @@ def height_from_volume_rectangular( top_width: float, ) -> float: """Find the height given a volume within a rectangular frustum.""" - a, b, c = rectangular_frustum_polynomial_roots( + a, b, c = _rectangular_frustum_polynomial_roots( bottom_length=bottom_length, bottom_width=bottom_width, top_length=top_length, @@ -178,14 +178,14 @@ def height_from_volume_rectangular( x_intercept_roots = (a, b, c, d) height_from_volume_roots = roots(x_intercept_roots) - height = reject_unacceptable_heights( + height = _reject_unacceptable_heights( potential_heights=list(height_from_volume_roots), max_height=total_frustum_height, ) return height -def height_from_volume_spherical( +def _height_from_volume_spherical( volume: float, radius_of_curvature: float, total_frustum_height: float, @@ -198,7 +198,7 @@ def height_from_volume_spherical( x_intercept_roots = (a, b, c, d) height_from_volume_roots = roots(x_intercept_roots) - height = reject_unacceptable_heights( + height = _reject_unacceptable_heights( potential_heights=list(height_from_volume_roots), max_height=total_frustum_height, ) @@ -223,13 +223,13 @@ def get_well_volumetric_capacity( raise InvalidWellDefinitionError( "spherical segment must only be at the bottom of a well." ) - section_volume = volume_from_height_spherical( target_height=segment.topHeight, radius_of_curvature=segment.radiusOfCurvature, + section_volume = _volume_from_height_spherical( ) elif segment.shape == "rectangular": section_height = segment.topHeight - segment.bottomHeight - section_volume = volume_from_height_rectangular( + section_volume = _volume_from_height_rectangular( target_height=section_height, bottom_length=segment.bottomYDimension, bottom_width=segment.bottomXDimension, @@ -239,7 +239,7 @@ def get_well_volumetric_capacity( ) elif segment.shape == "circular": section_height = segment.topHeight - segment.bottomHeight - section_volume = volume_from_height_circular( + section_volume = _volume_from_height_circular( target_height=section_height, total_frustum_height=section_height, bottom_radius=(segment.bottomDiameter / 2), @@ -261,20 +261,20 @@ def height_at_volume_within_section( ) -> float: """Calculate a height within a bounded section according to geometry.""" if section["shape"] == "spherical": - partial_height = height_from_volume_spherical( + partial_height = _height_from_volume_spherical( volume=target_volume_relative, total_frustum_height=section_height, radius_of_curvature=section.radiusOfCurvature, ) elif section["shape"] == "circular": - partial_height = height_from_volume_circular( + partial_height = _height_from_volume_circular( volume=target_volume_relative, top_radius=(section["bottomDiameter"] / 2), bottom_radius=(section["topDiameter"] / 2), total_frustum_height=section_height, ) elif section["shape"] == "rectangular": - partial_height = height_from_volume_rectangular( + partial_height = _height_from_volume_rectangular( volume=target_volume_relative, total_frustum_height=section_height, bottom_width=section["bottomXDimension"], @@ -296,19 +296,19 @@ def volume_at_height_within_section( ) -> float: """Calculate a volume within a bounded section according to geometry.""" if section["shape"] == "spherical": - partial_volume = volume_from_height_spherical( + partial_volume = _volume_from_height_spherical( target_height=target_height_relative, radius_of_curvature=section["radiusOfCurvature"], ) elif section["shape"] == "circular": - partial_volume = volume_from_height_circular( + partial_volume = _volume_from_height_circular( target_height=target_height_relative, total_frustum_height=section_height, bottom_radius=(section["bottomDiameter"] / 2), top_radius=(section["topDiameter"] / 2), ) elif section["shape"] == "rectangular": - partial_volume = volume_from_height_rectangular( + partial_volume = _volume_from_height_rectangular( target_height=target_height_relative, total_frustum_height=section_height, bottom_width=section["BottomXDimension"], 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 6bbd13c5e25c..427dececa7bb 100644 --- a/api/tests/opentrons/protocol_engine/state/test_geometry_view.py +++ b/api/tests/opentrons/protocol_engine/state/test_geometry_view.py @@ -83,10 +83,10 @@ ) from opentrons.protocol_engine.state.geometry import GeometryView, _GripperMoveType from opentrons.protocol_engine.state.frustum_helpers import ( - height_from_volume_circular, - height_from_volume_rectangular, - volume_from_height_circular, - volume_from_height_rectangular, + _height_from_volume_circular, + _height_from_volume_rectangular, + _volume_from_height_circular, + _volume_from_height_rectangular, ) from ..pipette_fixtures import get_default_nozzle_map from ..mock_circular_frusta import TEST_EXAMPLES as CIRCULAR_TEST_EXAMPLES @@ -2776,7 +2776,7 @@ def _find_volume_from_height_(index: int) -> None: top_width = frustum["width"][index] target_height = frustum["height"][index] - found_volume = volume_from_height_rectangular( + found_volume = _volume_from_height_rectangular( target_height=target_height, total_frustum_height=total_frustum_height, top_length=top_length, @@ -2785,7 +2785,7 @@ def _find_volume_from_height_(index: int) -> None: bottom_width=bottom_width, ) - found_height = height_from_volume_rectangular( + found_height = _height_from_volume_rectangular( volume=found_volume, total_frustum_height=total_frustum_height, top_length=top_length, @@ -2815,14 +2815,14 @@ def _find_volume_from_height_(index: int) -> None: top_radius = frustum["radius"][index] target_height = frustum["height"][index] - found_volume = volume_from_height_circular( + found_volume = _volume_from_height_circular( target_height=target_height, total_frustum_height=total_frustum_height, top_radius=top_radius, bottom_radius=bottom_radius, ) - found_height = height_from_volume_circular( + found_height = _height_from_volume_circular( volume=found_volume, total_frustum_height=total_frustum_height, top_radius=top_radius, diff --git a/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py b/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py index 79f9cbee8018..98a5f4e91008 100644 --- a/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py +++ b/api/tests/opentrons/protocols/geometry/test_frustum_helpers.py @@ -8,17 +8,17 @@ SphericalSegment, ) from opentrons.protocol_engine.state.frustum_helpers import ( - cross_section_area_rectangular, - cross_section_area_circular, - reject_unacceptable_heights, - circular_frustum_polynomial_roots, - rectangular_frustum_polynomial_roots, - volume_from_height_rectangular, - volume_from_height_circular, - volume_from_height_spherical, - height_from_volume_circular, - height_from_volume_rectangular, - height_from_volume_spherical, + _cross_section_area_rectangular, + _cross_section_area_circular, + _reject_unacceptable_heights, + _circular_frustum_polynomial_roots, + _rectangular_frustum_polynomial_roots, + _volume_from_height_rectangular, + _volume_from_height_circular, + _volume_from_height_spherical, + _height_from_volume_circular, + _height_from_volume_rectangular, + _height_from_volume_spherical, ) from opentrons.protocol_engine.errors.exceptions import InvalidLiquidHeightFound @@ -151,11 +151,11 @@ def test_reject_unacceptable_heights( """Make sure we reject all mathematical solutions that are physically not possible.""" if len(expected_heights) != 1: with pytest.raises(InvalidLiquidHeightFound): - reject_unacceptable_heights( + _reject_unacceptable_heights( max_height=max_height, potential_heights=potential_heights ) else: - found_heights = reject_unacceptable_heights( + found_heights = _reject_unacceptable_heights( max_height=max_height, potential_heights=potential_heights ) assert found_heights == expected_heights[0] @@ -165,7 +165,7 @@ def test_reject_unacceptable_heights( def test_cross_section_area_circular(diameter: float) -> None: """Test circular area calculation.""" expected_area = pi * (diameter / 2) ** 2 - assert cross_section_area_circular(diameter) == expected_area + assert _cross_section_area_circular(diameter) == expected_area @pytest.mark.parametrize( @@ -175,7 +175,9 @@ def test_cross_section_area_rectangular(x_dimension: float, y_dimension: float) """Test rectangular area calculation.""" expected_area = x_dimension * y_dimension assert ( - cross_section_area_rectangular(x_dimension=x_dimension, y_dimension=y_dimension) + _cross_section_area_rectangular( + x_dimension=x_dimension, y_dimension=y_dimension + ) == expected_area ) @@ -193,7 +195,7 @@ def test_volume_and_height_circular(well: List[Any]) -> None: a = pi * ((top_radius - bottom_radius) ** 2) / (3 * total_height**2) b = pi * bottom_radius * (top_radius - bottom_radius) / total_height c = pi * bottom_radius**2 - assert circular_frustum_polynomial_roots( + assert _circular_frustum_polynomial_roots( top_radius=top_radius, bottom_radius=bottom_radius, total_frustum_height=total_height, @@ -205,7 +207,7 @@ def test_volume_and_height_circular(well: List[Any]) -> None: + b * (target_height**2) + c * target_height ) - found_volume = volume_from_height_circular( + found_volume = _volume_from_height_circular( target_height=target_height, total_frustum_height=total_height, bottom_radius=bottom_radius, @@ -213,7 +215,7 @@ def test_volume_and_height_circular(well: List[Any]) -> None: ) assert found_volume == expected_volume # test going backwards to get height back - found_height = height_from_volume_circular( + found_height = _height_from_volume_circular( volume=found_volume, total_frustum_height=total_height, bottom_radius=bottom_radius, @@ -244,7 +246,7 @@ def test_volume_and_height_rectangular(well: List[Any]) -> None: + (bottom_width * (top_length - bottom_length)) ) / (2 * total_height) c = bottom_length * bottom_width - assert rectangular_frustum_polynomial_roots( + assert _rectangular_frustum_polynomial_roots( top_length=top_length, bottom_length=bottom_length, top_width=top_width, @@ -258,7 +260,7 @@ def test_volume_and_height_rectangular(well: List[Any]) -> None: + b * (target_height**2) + c * target_height ) - found_volume = volume_from_height_rectangular( + found_volume = _volume_from_height_rectangular( target_height=target_height, total_frustum_height=total_height, bottom_length=bottom_length, @@ -268,7 +270,7 @@ def test_volume_and_height_rectangular(well: List[Any]) -> None: ) assert found_volume == expected_volume # test going backwards to get height back - found_height = height_from_volume_rectangular( + found_height = _height_from_volume_rectangular( volume=found_volume, total_frustum_height=total_height, bottom_length=bottom_length, @@ -290,12 +292,12 @@ def test_volume_and_height_spherical(well: List[Any]) -> None: * (target_height**2) * (3 * well[0]["radiusOfCurvature"] - target_height) ) - found_volume = volume_from_height_spherical( + found_volume = _volume_from_height_spherical( target_height=target_height, radius_of_curvature=well[0]["radiusOfCurvature"], ) assert found_volume == expected_volume - found_height = height_from_volume_spherical( + found_height = _height_from_volume_spherical( volume=found_volume, radius_of_curvature=well[0]["radiusOfCurvature"], total_frustum_height=well[0]["topHeight"],