def _setup_container(container_name): try: container = database.load_container(container_name) # Database.load_container throws ValueError when a container name is not # found. except ValueError: # First must populate "get persisted container" list old_container_loading.load_all_containers_from_disk() # Load container from old json file container = old_container_loading.get_persisted_container( container_name) # Rotate coordinates to fit the new deck map rotated_container = database_migration.rotate_container_for_alpha( container) # Save to the new database database.save_new_container(rotated_container, container_name) container.properties['type'] = container_name container_x, container_y, container_z = container._coordinates if not fflags.split_labware_definitions(): # infer z from height if container_z == 0 and 'height' in container[0].properties: container_z = container[0].properties['height'] from opentrons.util.vector import Vector container._coordinates = Vector(container_x, container_y, container_z) return container
def get_version(): '''Get the Opentrons-defined database version''' if fflags.split_labware_definitions(): # warnings.warn('database operations no longer have an effect') pass db_conn = sqlite3.connect(database_path) return _get_db_version(db_conn)
def calibrate_container_with_delta(pose_tree, container, delta_x, delta_y, delta_z, save, new_container_name=None): delta = Point(delta_x, delta_y, delta_z) new_coordinates = change_base( pose_tree, src=container, dst=container.parent) + delta pose_tree = update(pose_tree, container, new_coordinates) if ff.split_labware_definitions(): for well in container.wells(): well._coordinates = well._coordinates + delta else: container._coordinates = container._coordinates + delta if save and new_container_name: database.save_new_container(container, new_container_name) elif save: database.overwrite_container(container) return pose_tree
def get_grid(self): """ Calculates the grid inferring row/column structure from indexes. Currently only Letter+Number names are supported """ columns = OrderedDict() if ff.split_labware_definitions(): # implementing this for compatibility, but new refactors and # features should use `ordering` directly for i, col in enumerate(self.ordering): col_idx = str(i + 1) columns[col_idx] = OrderedDict() for well in col: row_idx = well[0] columns[col_idx][row_idx] = (row_idx, col_idx) else: index_pattern = r'^([A-Za-z]+)([0-9]+)$' for name in self.children_by_name: match = re.match(index_pattern, name) if match: row, col = match.groups(0) if col not in columns: columns[col] = OrderedDict() columns[col][row] = (row, col) return columns
def test_invalid_container_name(): if ff.split_labware_definitions(): error_type = FileNotFoundError else: error_type = ValueError with pytest.raises(error_type): database.load_container("fake_container")
def load_module(module_name: str) -> Container: if fflags.split_labware_definitions(): raise NotImplementedError else: db_conn = sqlite3.connect(database_path) res = _load_module_dict_from_db(db_conn, module_name) return res
def list_all_containers() -> List[str]: if fflags.split_labware_definitions(): # warnings.warn('list_all_containers is deprecated, please use list_all_labware') # noqa res = list_all_labware() else: db_conn = sqlite3.connect(database_path) res = _list_all_containers_by_name(db_conn) return res
def delete_container(container_name) -> bool: if fflags.split_labware_definitions(): raise NotImplementedError # What should delete do in the new system? else: db_conn = sqlite3.connect(database_path) _delete_container_object_in_db(db_conn, container_name) res = True # old delete fn does not return anything return res
def test_container_parse(): robot.reset() plate = containers_load(robot, '96-flat', '1') if ff.split_labware_definitions(): expected = {'x': 0, 'y': 0, 'z': 0} else: expected = {'x': 14.34, 'y': 11.24, 'z': 10.50} assert database._parse_container_obj(plate) == expected
def load_container(container_name: str) -> Container: if fflags.split_labware_definitions(): # warnings.warn('save_new_container is deprecated, please use save_labware') # noqa res = load_labware(container_name) else: db_conn = sqlite3.connect(database_path) res = _load_container_object_from_db(db_conn, container_name) return res
def save_new_container(container: Container, container_name: str) -> bool: if fflags.split_labware_definitions(): # warnings.warn('save_new_container is deprecated, please use save_labware') # noqa res = save_labware(container, container_name) else: db_conn = sqlite3.connect(database_path) _create_container_obj_in_db(db_conn, container, container_name) res = True # old create fn does not return anything return res
def overwrite_container(container: Container) -> bool: if fflags.split_labware_definitions(): # warnings.warn('overwrite_container is deprecated, please use save_labware_offset') # noqa res = save_labware_offset(container) else: log.debug("Overwriting container definition: {}".format( container.get_type())) db_conn = sqlite3.connect(database_path) _update_container_object_in_db(db_conn, container) res = True # old overwrite fn does not return anything return res
def test_container_from_container_load(): robot.reset() plate = containers_load(robot, '96-flat', '1') if ff.split_labware_definitions(): actual = plate[0]._coordinates + plate[0].top()[1] expected = Vector(14.34, 74.24, 10.50) else: actual = plate._coordinates expected = Vector(14.34, 11.24, 10.50) assert plate.get_type() == '96-flat' assert actual == expected
def add_container_to_pose_tracker(self, location, container: Container): """ Add container and child wells to pose tracker. Sets container.parent (slot) as pose tracker parent """ self.poses = pose_tracker.add( self.poses, container, container.parent, pose_tracker.Point(*container._coordinates)) for well in container: center_x, center_y, center_z = well.top()[1] offset_x, offset_y, offset_z = well._coordinates if not fflags.split_labware_definitions(): center_z = 0 self.poses = pose_tracker.add( self.poses, well, container, pose_tracker.Point(center_x + offset_x, center_y + offset_y, center_z + offset_z))
def test_well_from_center_new(split_labware_def): print("Split labware definitions? {}".format( ff.split_labware_definitions())) deck = Deck() slot = Slot() plate = generate_plate(wells=4, cols=2, spacing=(10, 10), offset=(0, 0), radius=5, height=20) deck.add(slot, 'A1', (0, 0, 0)) slot.add(plate) assert plate['B2'].center() == (5, 5, 10) assert plate['B2'].from_center(x=0.0, y=0.0, z=2.0) == (5, 5, 30) assert plate['B2'].from_center(r=1.0, theta=pi / 2, h=5.0) == (5, 10, 60) assert plate['B2'].top()[1] == (5, 5, 20) assert plate['B2'].bottom()[1] == (5, 5, 0)
from collections import OrderedDict import json import os import shutil import unittest from opentrons.data_storage import old_container_loading from opentrons.containers.placeable import Container, Well from opentrons.util import environment from opentrons.config import feature_flags as ff if not ff.split_labware_definitions(): class PersistedContainersTestCase(unittest.TestCase): @classmethod def setUpClass(cls): # here we are copying containers from data and # re-defining APP_DATA_DIR. This way we can # load a few more custom containers old_container_loading.persisted_containers_dict.clear() os.environ['APP_DATA_DIR'] = os.path.join( os.path.dirname(__file__), 'opentrons-data') environment.refresh() source = os.path.join(os.path.dirname(__file__), 'data') containers_dir = environment.get_path('CONTAINERS_DIR') shutil.rmtree(containers_dir) shutil.copytree(source, containers_dir) @classmethod
def get_children_list(self): if ff.split_labware_definitions(): return [self[i] for i in list(chain.from_iterable(self.ordering))] else: return super(Container, self).get_children_list()
def set_version(version): if fflags.split_labware_definitions(): # warnings.warn('database operations no longer have an effect') pass db_conn = sqlite3.connect(database_path) db_queries.set_user_version(db_conn, version)
def change_database(db_path: str): global database_path if fflags.split_labware_definitions(): # warnings.warn('database operations no longer have an effect') pass database_path = db_path