示例#1
0
def save_labware_calibration(labware_path: local_types.StrPath,
                             definition: 'LabwareDefinition',
                             delta: 'Point',
                             slot: str = '',
                             parent: str = ''):
    """
    Function to be used whenever an updated delta is found for the first well
    of a given labware. If an offset file does not exist, create the file
    using labware id as the filename. If the file does exist, load it and
    modify the delta and the lastModified fields under the "default" key.

    :param labware_path: name of labware offset path
    :param definition: full definition of the labware
    :param delta: point you are saving
    :param slot: slot the labware calibration is associated with
    [not yet implemented so it will currently only be an empty string]
    :param parent: parent of the labware, either a slot or a module.
    """
    offset_path =\
        config.get_opentrons_path('labware_calibration_offsets_dir_v2')
    labware_offset_path = offset_path / labware_path
    labware_hash = helpers.hash_labware_def(definition)
    uri = helpers.uri_from_definition(definition)
    _add_to_index_offset_file(parent, slot, uri, labware_hash)
    calibration_data = _helper_offset_data_format(str(labware_offset_path),
                                                  delta)
    io.save_to_file(labware_offset_path, calibration_data)
示例#2
0
def _add_to_index_offset_file(parent: str, slot: str, uri: str, lw_hash: str):
    """
    A helper method to create or add to an index file so that calibration
    files can be looked up by their hash to reveal the labware uri and
    parent information of a given file.

    :param parent: A labware object
    :param slot
    :param lw_hash: The labware hash of the calibration
    """
    offset =\
        config.get_opentrons_path('labware_calibration_offsets_dir_v2')
    index_file = offset / 'index.json'
    if index_file.exists():
        migration.check_index_version(index_file)
        blob = io.read_cal_file(str(index_file))
    else:
        blob = {}

    full_id = f'{lw_hash}{parent}'
    try:
        blob['data'][full_id]
    except KeyError:
        if parent:
            mod_dict = {'parent': parent, 'fullParent': f'{slot}-{parent}'}
        else:
            mod_dict = {}
        new_index_data = {"uri": f'{uri}', "slot": full_id, "module": mod_dict}
        if blob.get('data'):
            blob['data'][full_id] = new_index_data
        else:
            blob['data'] = {full_id: new_index_data}
        blob['version'] = migration.MAX_VERSION
        io.save_to_file(index_file, blob)
示例#3
0
文件: get.py 项目: jen-fong/opentrons
def get_all_pipette_offset_calibrations() \
            -> typing.List[local_types.PipetteOffsetCalibration]:
    """
    A helper function that will list all of the pipette offset
    calibrations.

    :return: A list of dictionary objects representing all of the
    pipette offset calibration files found on the robot.
    """
    all_calibrations: typing.List[local_types.PipetteOffsetCalibration] = []
    pip_dir = config.get_opentrons_path('pipette_calibration_dir')
    index_path = pip_dir / 'index.json'
    if not index_path.exists():
        return all_calibrations

    index_file = io.read_cal_file(str(index_path))
    for mount_key, pips in index_file.items():
        for pip in pips:
            cal_path = pip_dir / mount_key / f'{pip}.json'
            if cal_path.exists():
                data = io.read_cal_file(str(cal_path))
                all_calibrations.append(
                    local_types.PipetteOffsetCalibration(
                        pipette=pip,
                        mount=mount_key,
                        offset=data['offset'],
                        tiprack=data['tiprack'],
                        uri=data['uri'],
                        last_modified=data['last_modified']))
    return all_calibrations
示例#4
0
文件: get.py 项目: jen-fong/opentrons
def get_all_calibrations() -> typing.List[local_types.CalibrationInformation]:
    """
    A helper function that will list all of the given calibrations
    in a succinct way.

    :return: A list of dictionary objects representing all of the
    labware calibration files found on the robot.
    """
    all_calibrations: typing.List[local_types.CalibrationInformation] = []
    offset_path =\
        config.get_opentrons_path('labware_calibration_offsets_dir_v2')
    index_path = offset_path / 'index.json'
    if not index_path.exists():
        return all_calibrations

    migration.check_index_version(index_path)
    index_file = io.read_cal_file(str(index_path))
    calibration_index = index_file.get('data', {})
    for key, data in calibration_index.items():
        cal_path = offset_path / f'{key}.json'
        if cal_path.exists():
            cal_blob = io.read_cal_file(str(cal_path))
            calibration = _format_calibration_type(cal_blob)  # type: ignore
            all_calibrations.append(
                local_types.CalibrationInformation(calibration=calibration,
                                                   parent=_format_parent(data),
                                                   labware_id=key,
                                                   uri=data['uri']))
    return all_calibrations
示例#5
0
def load_attitude_matrix() -> DeckCalibration:
    calibration_data = get.get_robot_deck_attitude()
    if not calibration_data and ff.enable_calibration_overhaul():
        gantry_cal = robot_configs.load().gantry_calibration
        if validate_gantry_calibration(gantry_cal) == DeckTransformState.OK:
            log.debug(
                "Attitude deck calibration matrix not found. Migrating "
                "existing affine deck calibration matrix to {}".format(
                    config.get_opentrons_path('robot_calibration_dir')))
            attitude = migrate_affine_xy_to_attitude(gantry_cal)
            modify.save_robot_deck_attitude(transform=attitude,
                                            pip_id=None,
                                            lw_hash=None)
            calibration_data = get.get_robot_deck_attitude()

    deck_cal_obj = None
    if calibration_data:
        try:
            deck_cal_obj = DeckCalibration(**calibration_data)
        except Exception as e:
            log.warning(f"Bad deck calibration, falling back to identity: {e}")

    if not deck_cal_obj:
        deck_cal_obj = DeckCalibration(
            attitude=robot_configs.DEFAULT_DECK_CALIBRATION_V2)
    return deck_cal_obj
示例#6
0
def labware_offset_tempdir(tmpdir):
    os.environ['OT_API_CONFIG_DIR'] = str(tmpdir)
    config.reload()

    yield config.get_opentrons_path('labware_calibration_offsets_dir_v2')

    del os.environ['OT_API_CONFIG_DIR']
    config.reload()
示例#7
0
def get_robot_deck_attitude() -> typing.Optional['DeckCalibrationData']:
    robot_dir = config.get_opentrons_path('robot_calibration_dir')
    gantry_path = robot_dir / 'deck_calibration.json'
    if gantry_path.exists():
        data = io.read_cal_file(gantry_path)
        return data  # type: ignore
    else:
        return None
示例#8
0
文件: get.py 项目: jen-fong/opentrons
def get_pipette_offset(
        pip_id: str,
        mount: Mount) -> typing.Optional['PipetteCalibrationData']:
    pip_dir = config.get_opentrons_path('pipette_calibration_dir')
    offset_path = pip_dir / mount.name.lower() / f'{pip_id}.json'
    if offset_path.exists():
        data = io.read_cal_file(offset_path)
        assert 'offset' in data.keys(), 'Not valid pipette calibration data'
        return data  # type: ignore
    else:
        return None
示例#9
0
def delete_pipette_offset_file(pipette: str, mount: Mount):
    """
    Delete pipette offset file based on mount and pipette serial number

    :param pipette: pipette serial number
    :param mount: pipette mount
    """
    offset_dir = config.get_opentrons_path('pipette_calibration_dir')
    offset_path = offset_dir / mount.name.lower() / f'{pipette}.json'

    _remove_pipette_offset_from_index(pipette, mount)
    offset_path.unlink()
示例#10
0
def grab_id(set_up_index_file_temporary_directory):
    labware_to_access = 'opentrons_96_tiprack_10ul'
    uri_to_check = f'opentrons/{labware_to_access}/1'
    offset_path =\
        config.get_opentrons_path('labware_calibration_offsets_dir_v2')
    index_path = offset_path / 'index.json'
    index_file = file_operators.read_cal_file(str(index_path))
    calibration_id = ''
    for key, data in index_file['data'].items():
        if data['uri'] == uri_to_check:
            calibration_id = key
    return calibration_id
def test_load_malformed_calibration(ot_config_tempdir):
    pathway = config.get_opentrons_path(
        'robot_calibration_dir') / 'deck_calibration.json'
    data = {
        'atsadasitude': [[1, 0, 1], [0, 1, -.5], [0, 0, 1]],
        'last_modified': utc_now(),
        'tiprack': 'hash',
        'statu': [1, 2, 3],
    }
    io.save_to_file(pathway, data)
    obj = robot_calibration.load_attitude_matrix()
    assert np.allclose(obj.attitude, [[1, 0, 0], [0, 1, 0], [0, 0, 1]])
def test_load_calibration(ot_config_tempdir):
    pathway = config.get_opentrons_path(
        'robot_calibration_dir') / 'deck_calibration.json'
    data = {
        'attitude': [[1, 0, 1], [0, 1, -.5], [0, 0, 1]],
        'pipette_calibrated_with': 'fake',
        'last_modified': utc_now(),
        'tiprack': 'hash'
    }
    io.save_to_file(pathway, data)
    obj = robot_calibration.load_attitude_matrix()
    transform = [[1, 0, 1], [0, 1, -.5], [0, 0, 1]]
    assert np.allclose(obj.attitude, transform)
示例#13
0
def save_robot_deck_attitude(transform: local_types.AttitudeMatrix,
                             pip_id: typing.Optional[str],
                             lw_hash: typing.Optional[str]):
    robot_dir = config.get_opentrons_path('robot_calibration_dir')
    robot_dir.mkdir(parents=True, exist_ok=True)
    gantry_path = robot_dir / 'deck_calibration.json'
    gantry_dict: 'DeckCalibrationData' = {
        'attitude': transform,
        'pipette_calibrated_with': pip_id,
        'last_modified': utc_now(),
        'tiprack': lw_hash
    }
    io.save_to_file(gantry_path, gantry_dict)
示例#14
0
def save_pipette_calibration(offset: 'Point', pip_id: str, mount: Mount,
                             tiprack_hash: str, tiprack_uri: str):
    pip_dir = config.get_opentrons_path(
        'pipette_calibration_dir') / mount.name.lower()
    pip_dir.mkdir(parents=True, exist_ok=True)
    offset_path = pip_dir / f'{pip_id}.json'
    offset_dict: 'PipetteCalibrationData' = {
        'offset': [offset.x, offset.y, offset.z],
        'tiprack': tiprack_hash,
        'uri': tiprack_uri,
        'last_modified': utc_now(),
    }
    io.save_to_file(offset_path, offset_dict)
    _add_to_pipette_offset_index_file(pip_id, mount)
示例#15
0
def delete_offset_file(calibration_id: local_types.CalibrationID):
    """
    Given a labware's hash, delete the file and remove it from the index file.

    :param calibration_id: labware hash
    """
    offset_path =\
        config.get_opentrons_path('labware_calibration_offsets_dir_v2')
    offset = offset_path / f'{calibration_id}.json'
    try:
        _remove_offset_from_index(calibration_id)
        offset.unlink()
    except FileNotFoundError:
        pass
示例#16
0
def clear_calibrations():
    """
    Delete all calibration files for labware. This includes deleting tip-length
    data for tipracks.
    """
    calibration_path =\
        config.get_opentrons_path('labware_calibration_offsets_dir_v2')
    try:
        targets = [
            f for f in calibration_path.iterdir() if f.suffix == '.json'
        ]
        for target in targets:
            target.unlink()
    except FileNotFoundError:
        pass
示例#17
0
def test_clear_calibrations():
    calpath = config.get_opentrons_path('labware_calibration_offsets_dir_v2')
    with open(calpath / '1.json', 'w') as offset_file:
        test_offset = {
            "default": {
                "offset": [1, 2, 3],
                "lastModified": 1
            },
            "tipLength": 1.2
        }
        json.dump(test_offset, offset_file)

    assert len(os.listdir(calpath)) > 0
    delete.clear_calibrations()
    assert len(os.listdir(calpath)) == 0
示例#18
0
def _remove_offset_from_index(calibration_id: local_types.CalibrationID):
    """
    Helper function to remove an individual offset file.

    :param calibration_id: labware hash
    :raises FileNotFoundError: If index file does not exist or
    the specified id is not in the index file.
    """
    offset_path =\
        config.get_opentrons_path('labware_calibration_offsets_dir_v2')
    index_path = offset_path / 'index.json'
    blob = io.read_cal_file(str(index_path))

    del blob['data'][calibration_id]
    io.save_to_file(index_path, blob)
示例#19
0
def _add_to_pipette_offset_index_file(pip_id: str, mount: Mount):
    index_file = config.get_opentrons_path(
        'pipette_calibration_dir') / 'index.json'
    try:
        index_data = index_data = io.read_cal_file(str(index_file))
    except FileNotFoundError:
        index_data = {}

    mount_key = mount.name.lower()
    if mount_key not in index_data:
        index_data[mount_key] = [pip_id]
    elif pip_id not in index_data[mount_key]:
        index_data[mount_key].append(pip_id)

    io.save_to_file(index_file, index_data)
示例#20
0
def clear_pipette_offset_calibrations():
    """
    Delete all pipette offset calibration files.
    """
    def _remove_json_files_in_directories(p: Path):
        for item in p.iterdir():
            if item.is_dir():
                _remove_json_files_in_directories(item)
            elif item.suffix == '.json':
                item.unlink()

    offset_dir = config.get_opentrons_path('pipette_calibration_dir')
    try:
        _remove_json_files_in_directories(offset_dir)
    except FileNotFoundError:
        pass
示例#21
0
def _remove_pipette_offset_from_index(pipette: str, mount: Mount):
    """
    Helper function to remove an individual pipette offset file.

    :param pipette: pipette serial number
    :param mount: pipette mount
    :raises FileNotFoundError: If index file does not exist or
    the specified id is not in the index file.
    """
    offset_dir = config.get_opentrons_path('pipette_calibration_dir')
    index_path = offset_dir / 'index.json'
    blob = io.read_cal_file(str(index_path))

    if pipette in blob[mount.name.lower()]:
        blob[mount.name.lower()].remove(pipette)
        io.save_to_file(index_path, blob)
def test_load_pipette_offset(ot_config_tempdir):
    pip_id = 'fakePip'
    mount = Mount.LEFT
    pip_dir = config.get_opentrons_path('pipette_calibration_dir') / 'left'
    pip_dir.mkdir(parents=True, exist_ok=True)
    pathway = pip_dir / 'fakePip.json'
    data = {
        'offset': [1, 2, 3],
        'tiprack': 'hash',
        'uri': 'opentrons/opentrons_96_tiprack_10ul/1',
        'last_modified': utc_now()
    }
    io.save_to_file(pathway, data)
    obj = robot_calibration.load_pipette_offset(pip_id, mount)
    offset = [1, 2, 3]
    assert np.allclose(obj.offset, offset)
def test_save_calibration(ot_config_tempdir):
    pathway = config.get_opentrons_path(
        'robot_calibration_dir') / 'deck_calibration.json'
    pip_id = 'fakePip'
    lw_hash = 'fakeHash'
    e = ((1, 1, 3), (2, 2, 2), (1, 2, 1))
    a = ((1.1, 3.1, 1.1), (2.1, 2.1, 2.2), (1.1, 2.1, 1.1))
    transform = [[0.975, 0.05, 0.0], [-1.025, 1.05, 0.0], [0.0, 0.0, 1.0]]
    expected = {
        'attitude': transform,
        'pipette_calibrated_with': pip_id,
        'last_modified': None,
        'tiprack': lw_hash
    }
    robot_calibration.save_attitude_matrix(e, a, pip_id, lw_hash)
    data = io.read_cal_file(pathway)
    data['last_modified'] = None
    assert data == expected
示例#24
0
文件: get.py 项目: jen-fong/opentrons
def get_labware_calibration(lookup_path: local_types.StrPath,
                            definition: 'LabwareDefinition',
                            parent: str = '',
                            slot: str = '') -> Point:
    """
    Find the delta of a given labware, if it exists.

    :param lookup_path: short path to the labware calibration
    :return: A point which represents the delta from well A1 origin of
    a labware
    """
    offset_path =\
        config.get_opentrons_path('labware_calibration_offsets_dir_v2')
    offset = Point(0, 0, 0)
    labware_path = offset_path / lookup_path
    if labware_path.exists():
        modify.add_existing_labware_to_index_file(definition, parent, slot)
        migration.check_index_version(offset_path / 'index.json')
        calibration_data = io.read_cal_file(str(labware_path))
        offset_array = calibration_data['default']['offset']
        offset = Point(x=offset_array[0], y=offset_array[1], z=offset_array[2])
    return offset
示例#25
0
def labware_offset_tempdir(ot_config_tempdir):
    yield config.get_opentrons_path('labware_calibration_offsets_dir_v2')
示例#26
0
def path(calibration_name):
    return config.get_opentrons_path(
        'labware_calibration_offsets_dir_v2') \
        / '{}.json'.format(calibration_name)
示例#27
0
from pathlib import Path

from opentrons.config import get_opentrons_path

OPENTRONS_NAMESPACE = 'opentrons'
CUSTOM_NAMESPACE = 'custom_beta'
STANDARD_DEFS_PATH = Path("labware/definitions/2")
USER_DEFS_PATH = get_opentrons_path('labware_user_definitions_dir_v2')

SHORT_TRASH_DECK = 'ot2_short_trash'
STANDARD_DECK = 'ot2_standard'