Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shared-data): Add the ability to handle sub wells in labware geometry #16658

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 57 additions & 32 deletions api/src/opentrons/protocol_engine/state/frustum_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,28 +220,40 @@ def _get_segment_capacity(segment: WellSegment) -> float:
section_height = segment.topHeight - segment.bottomHeight
match segment:
case SphericalSegment():
return _volume_from_height_spherical(
target_height=segment.topHeight,
radius_of_curvature=segment.radiusOfCurvature,
return (
_volume_from_height_spherical(
target_height=segment.topHeight,
radius_of_curvature=segment.radiusOfCurvature,
)
* segment.count
)
case CuboidalFrustum():
return _volume_from_height_rectangular(
target_height=section_height,
bottom_length=segment.bottomYDimension,
bottom_width=segment.bottomXDimension,
top_length=segment.topYDimension,
top_width=segment.topXDimension,
total_frustum_height=section_height,
return (
_volume_from_height_rectangular(
target_height=section_height,
bottom_length=segment.bottomYDimension,
bottom_width=segment.bottomXDimension,
top_length=segment.topYDimension,
top_width=segment.topXDimension,
total_frustum_height=section_height,
)
* segment.count
)
case ConicalFrustum():
return _volume_from_height_circular(
target_height=section_height,
total_frustum_height=section_height,
bottom_radius=(segment.bottomDiameter / 2),
top_radius=(segment.topDiameter / 2),
return (
_volume_from_height_circular(
target_height=section_height,
total_frustum_height=section_height,
bottom_radius=(segment.bottomDiameter / 2),
top_radius=(segment.topDiameter / 2),
)
* segment.count
)
case SquaredConeSegment():
return _volume_from_height_squared_cone(section_height, segment)
return (
_volume_from_height_squared_cone(section_height, segment)
* segment.count
)
case _:
# TODO: implement volume calculations for truncated circular and rounded rectangular segments
raise NotImplementedError(
Expand Down Expand Up @@ -272,6 +284,7 @@ def height_at_volume_within_section(
section_height: float,
) -> float:
"""Calculate a height within a bounded section according to geometry."""
target_volume_relative = target_volume_relative / section.count
Copy link
Contributor

@caila-marashaj caila-marashaj Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may not have to do this for height to volume ? In the two cases where height is given, either:

  • The height is not in the subwell: the calculation doesnt change
  • the height is within the subwells: the volume we're trying to find is contained only within the one subwell we're getting the liquid height from

Copy link
Contributor Author

@ryanthecoder ryanthecoder Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still correct, if we want to be say 24ul above the bottom and there are 8 subwells, we need to find the height in 1 subwell that equals (24/8)=3ul if we didn't do the division, then we would be trying to find where it would be 24ul in 1 subwell

match section:
case SphericalSegment():
return _height_from_volume_spherical(
Expand Down Expand Up @@ -311,28 +324,40 @@ def volume_at_height_within_section(
"""Calculate a volume within a bounded section according to geometry."""
match section:
case SphericalSegment():
return _volume_from_height_spherical(
target_height=target_height_relative,
radius_of_curvature=section.radiusOfCurvature,
return (
_volume_from_height_spherical(
target_height=target_height_relative,
radius_of_curvature=section.radiusOfCurvature,
)
* section.count
)
case ConicalFrustum():
return _volume_from_height_circular(
target_height=target_height_relative,
total_frustum_height=section_height,
bottom_radius=(section.bottomDiameter / 2),
top_radius=(section.topDiameter / 2),
return (
_volume_from_height_circular(
target_height=target_height_relative,
total_frustum_height=section_height,
bottom_radius=(section.bottomDiameter / 2),
top_radius=(section.topDiameter / 2),
)
* section.count
)
case CuboidalFrustum():
return _volume_from_height_rectangular(
target_height=target_height_relative,
total_frustum_height=section_height,
bottom_width=section.bottomXDimension,
bottom_length=section.bottomYDimension,
top_width=section.topXDimension,
top_length=section.topYDimension,
return (
_volume_from_height_rectangular(
target_height=target_height_relative,
total_frustum_height=section_height,
bottom_width=section.bottomXDimension,
bottom_length=section.bottomYDimension,
top_width=section.topXDimension,
top_length=section.topYDimension,
)
* section.count
)
case SquaredConeSegment():
return _volume_from_height_squared_cone(target_height_relative, section)
return (
_volume_from_height_squared_cone(target_height_relative, section)
* section.count
)
case _:
# TODO(cm): this would be the NEST-96 2uL wells referenced in EXEC-712
# we need to input the math attached to that issue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,27 @@
},
"innerLabwareGeometry": {
"cuboidalWell": {
"sections": []
"sections": [
{
"shape": "cuboidal",
"topXDimension": 107.25,
"topYDimension": 8,
"bottomXDimension": 101.25,
"bottomYDimension": 1.66,
"topHeight": 2,
"bottomHeight": 8,
"yCount": 8
},
{
"shape": "cuboidal",
"topXDimension": 107.5,
"topYDimension": 71.25,
"bottomXDimension": 107.25,
"bottomYDimension": 71.0,
"topHeight": 39.22,
"bottomHeight": 2
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,28 @@
},
"innerLabwareGeometry": {
"cuboidalWell": {
"sections": []
"sections": [
{
"shape": "cuboidal",
"topXDimension": 9,
"topYDimension": 9,
"bottomXDimension": 1.93,
"bottomYDimension": 1.93,
"topHeight": 2,
"bottomHeight": 0,
"xCount": 12,
"yCount": 8
},
{
"shape": "cuboidal",
"topXDimension": 71.3,
"topYDimension": 70.6,
"bottomXDimension": 107.3,
"bottomYDimension": 106.8,
"topHeight": 26.85,
"bottomHeight": 2
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,27 @@
},
"innerLabwareGeometry": {
"cuboidalWell": {
"sections": []
"sections": [
{
"shape": "squaredcone",
"bottomCrossSection": "circular",
"circleDiameter": 2.5,
"rectangleXDimension": 7.98,
"rectangleYDimension": 70.98,
"topHeight": 4.05,
"bottomHeight": 0.0,
"yCount": 8
},
{
"shape": "cuboidal",
"topXDimension": 8.34,
"topYDimension": 71.85,
"bottomXDimension": 7.98,
"bottomYDimension": 70.98,
"topHeight": 41.75,
"bottomHeight": 4.05
}
]
}
}
}
30 changes: 30 additions & 0 deletions shared-data/labware/schemas/3.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
},
"bottomHeight": {
"type": "number"
},
"xCount": {
"type": "integer"
},
"yCount": {
"type": "integer"
}
}
},
Expand Down Expand Up @@ -112,6 +118,12 @@
},
"bottomHeight": {
"type": "number"
},
"xCount": {
"type": "integer"
},
"yCount": {
"type": "integer"
}
}
},
Expand Down Expand Up @@ -149,6 +161,12 @@
},
"bottomHeight": {
"type": "number"
},
"xCount": {
"type": "integer"
},
"yCount": {
"type": "integer"
}
}
},
Expand Down Expand Up @@ -187,6 +205,12 @@
},
"bottomHeight": {
"type": "number"
},
"xCount": {
"type": "integer"
},
"yCount": {
"type": "integer"
}
}
},
Expand Down Expand Up @@ -225,6 +249,12 @@
},
"bottomHeight": {
"type": "number"
},
"xCount": {
"type": "integer"
},
"yCount": {
"type": "integer"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ class SphericalSegment(BaseModel):
...,
description="Height of the bottom of the segment, must be 0.0",
)
xCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)
yCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)

@cached_property
def count(self) -> int:
return self.xCount * self.yCount

class Config:
keep_untouched = (cached_property,)


class ConicalFrustum(BaseModel):
Expand All @@ -276,6 +291,21 @@ class ConicalFrustum(BaseModel):
...,
description="The height at the bottom of a bounded subsection of a well, relative to the bottom of the well",
)
xCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)
yCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)

@cached_property
def count(self) -> int:
return self.xCount * self.yCount

class Config:
keep_untouched = (cached_property,)


class CuboidalFrustum(BaseModel):
Expand Down Expand Up @@ -305,6 +335,21 @@ class CuboidalFrustum(BaseModel):
...,
description="The height at the bottom of a bounded subsection of a well, relative to the bottom of the well",
)
xCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)
yCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)

@cached_property
def count(self) -> int:
return self.xCount * self.yCount

class Config:
keep_untouched = (cached_property,)


# A squared cone is the intersection of a cube and a cone that both
Expand Down Expand Up @@ -354,6 +399,14 @@ class SquaredConeSegment(BaseModel):
...,
description="The height at the bottom of a bounded subsection of a well, relative to the bottom of the well",
)
xCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)
yCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)

@staticmethod
def _area_trap_points(
Expand Down Expand Up @@ -433,6 +486,10 @@ def height_to_volume_table(self) -> Dict[float, float]:
def volume_to_height_table(self) -> Dict[float, float]:
return dict((v, k) for k, v in self.height_to_volume_table.items())

@cached_property
def count(self) -> int:
return self.xCount * self.yCount

class Config:
keep_untouched = (cached_property,)

Expand Down Expand Up @@ -546,6 +603,21 @@ class RoundedCuboidSegment(BaseModel):
...,
description="The height at the bottom of a bounded subsection of a well, relative to the bottom of the well",
)
xCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)
yCount: _StrictNonNegativeInt = Field(
default=1,
description="Number of instances of this shape in the stackup, used for wells that have multiple sub-wells",
)

@cached_property
def count(self) -> int:
return self.xCount * self.yCount

class Config:
keep_untouched = (cached_property,)


class Metadata1(BaseModel):
Expand Down
Loading