Skip to content

Commit

Permalink
fix all the things using typing caught
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthecoder committed Oct 1, 2024
1 parent 167ceb9 commit ccf895b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
30 changes: 15 additions & 15 deletions api/src/opentrons/protocol_engine/state/frustum_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,39 +230,39 @@ def get_well_volumetric_capacity(

for segment in sorted_well:
section_volume: Optional[float] = None
if segment.shape == "spherical":
if segment["shape"] == "spherical":
if sorted_well[0] != segment:
raise InvalidWellDefinitionError(
"spherical segment must only be at the bottom of a well."
)
target_height=segment.topHeight,
radius_of_curvature=segment.radiusOfCurvature,
section_volume = _volume_from_height_spherical(
target_height=segment["topHeight"],
radius_of_curvature=segment["radiusOfCurvature"],
)
elif segment.shape == "rectangular":
section_height = segment.topHeight - segment.bottomHeight
elif segment["shape"] == "rectangular":
section_height = segment["topHeight"] - segment["bottomHeight"]
section_volume = _volume_from_height_rectangular(
target_height=section_height,
bottom_length=segment.bottomYDimension,
bottom_width=segment.bottomXDimension,
top_length=segment.topYDimension,
top_width=segment.topXDimension,
bottom_length=segment["bottomYDimension"],
bottom_width=segment["bottomXDimension"],
top_length=segment["topYDimension"],
top_width=segment["topXDimension"],
total_frustum_height=section_height,
)
elif segment.shape == "circular":
section_height = segment.topHeight - segment.bottomHeight
elif segment["shape"] == "circular":
section_height = segment["topHeight"] - segment["bottomHeight"]
section_volume = _volume_from_height_circular(
target_height=section_height,
total_frustum_height=section_height,
bottom_radius=(segment.bottomDiameter / 2),
top_radius=(segment.topDiameter / 2),
bottom_radius=(segment["bottomDiameter"] / 2),
top_radius=(segment["topDiameter"] / 2),
)
# TODO: implement volume calculations for truncated circular and rounded rectangular segments
if not section_volume:
raise NotImplementedError(
f"volume calculation for shape: {segment.shape} not yet implemented."
f"volume calculation for shape: {segment['shape']} not yet implemented."
)
well_volume.append((segment.topHeight, section_volume))
well_volume.append((segment["topHeight"], section_volume))
return well_volume


Expand Down
30 changes: 26 additions & 4 deletions api/tests/opentrons/protocols/geometry/test_frustum_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ def fake_frusta() -> List[List[Any]]:
topHeight=1.0,
bottomHeight=1.0,
),
SphericalSegment(shape="spherical", radiusOfCurvature=4.0, topHeight=1.0),
SphericalSegment(
shape="spherical",
radiusOfCurvature=4.0,
topHeight=1.0,
bottomHeight=0.0,
),
]
)
frusta.append(
Expand Down Expand Up @@ -112,11 +117,23 @@ def fake_frusta() -> List[List[Any]]:
topHeight=3.0,
bottomHeight=2.0,
),
SphericalSegment(shape="spherical", radiusOfCurvature=3.5, topHeight=2.0),
SphericalSegment(
shape="spherical",
radiusOfCurvature=3.5,
topHeight=2.0,
bottomHeight=0.0,
),
]
)
frusta.append(
[SphericalSegment(shape="spherical", radiusOfCurvature=4.0, topHeight=3.0)]
[
SphericalSegment(
shape="spherical",
radiusOfCurvature=4.0,
topHeight=3.0,
bottomHeight=0.0,
)
]
)
frusta.append(
[
Expand All @@ -129,7 +146,12 @@ def fake_frusta() -> List[List[Any]]:
topHeight=3.5,
bottomHeight=1.5,
),
SphericalSegment(shape="spherical", radiusOfCurvature=4.0, topHeight=1.5),
SphericalSegment(
shape="spherical",
radiusOfCurvature=4.0,
topHeight=1.5,
bottomHeight=0.0,
),
]
)
return frusta
Expand Down
1 change: 1 addition & 0 deletions shared-data/python/opentrons_shared_data/labware/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class SphericalSegment(TypedDict):
shape: Spherical
radiusOfCurvature: float
topHeight: float
bottomHeight: Literal[0.0] = 0.0


class CircularFrustum(TypedDict):
Expand Down

0 comments on commit ccf895b

Please sign in to comment.