Skip to content

Commit

Permalink
feat(api): Python API classes for liquid class properties (#16644)
Browse files Browse the repository at this point in the history
Adds python user-facing classes for liquid class properties
  • Loading branch information
jbleon95 authored Nov 4, 2024
1 parent d7a6221 commit 9ae68a8
Show file tree
Hide file tree
Showing 7 changed files with 714 additions and 27 deletions.
53 changes: 31 additions & 22 deletions api/src/opentrons/protocol_api/_liquid.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Optional, Sequence
from typing import Optional, Dict

from opentrons_shared_data.liquid_classes.liquid_class_definition import (
LiquidClassSchemaV1,
)

from ._liquid_properties import (
AspirateProperties,
SingleDispenseProperties,
MultiDispenseProperties,
ByPipetteSetting,
ByTipTypeSetting,
build_aspirate_properties,
build_single_dispense_properties,
build_multi_dispense_properties,
)


Expand Down Expand Up @@ -59,16 +65,29 @@ class LiquidClass:

_name: str
_display_name: str
_by_pipette_setting: Sequence[ByPipetteSetting]
_by_pipette_setting: Dict[str, Dict[str, TransferProperties]]

@classmethod
def create(cls, liquid_class_definition: LiquidClassSchemaV1) -> "LiquidClass":
"""Liquid class factory method."""

by_pipette_settings: Dict[str, Dict[str, TransferProperties]] = {}
for by_pipette in liquid_class_definition.byPipette:
tip_settings: Dict[str, TransferProperties] = {}
for tip_type in by_pipette.byTipType:
tip_settings[tip_type.tiprack] = TransferProperties(
_aspirate=build_aspirate_properties(tip_type.aspirate),
_dispense=build_single_dispense_properties(tip_type.singleDispense),
_multi_dispense=build_multi_dispense_properties(
tip_type.multiDispense
),
)
by_pipette_settings[by_pipette.pipetteModel] = tip_settings

return cls(
_name=liquid_class_definition.liquidClassName,
_display_name=liquid_class_definition.displayName,
_by_pipette_setting=liquid_class_definition.byPipette,
_by_pipette_setting=by_pipette_settings,
)

@property
Expand All @@ -81,26 +100,16 @@ def display_name(self) -> str:

def get_for(self, pipette: str, tiprack: str) -> TransferProperties:
"""Get liquid class transfer properties for the specified pipette and tip."""
settings_for_pipette: Sequence[ByPipetteSetting] = [
pip_setting
for pip_setting in self._by_pipette_setting
if pip_setting.pipetteModel == pipette
]
if len(settings_for_pipette) == 0:
try:
settings_for_pipette = self._by_pipette_setting[pipette]
except KeyError:
raise ValueError(
f"No properties found for {pipette} in {self._name} liquid class"
)
settings_for_tip: Sequence[ByTipTypeSetting] = [
tip_setting
for tip_setting in settings_for_pipette[0].byTipType
if tip_setting.tiprack == tiprack
]
if len(settings_for_tip) == 0:
try:
transfer_properties = settings_for_pipette[tiprack]
except KeyError:
raise ValueError(
f"No properties found for {tiprack} in {self._name} liquid class"
)
return TransferProperties(
_aspirate=settings_for_tip[0].aspirate,
_dispense=settings_for_tip[0].singleDispense,
_multi_dispense=settings_for_tip[0].multiDispense,
)
return transfer_properties
Loading

0 comments on commit 9ae68a8

Please sign in to comment.