Esempio n. 1
0
 def update_container_offset(self, container, instrument):
     inst = instrument._instrument
     log.info('Updating {} in {}'.format(container.name, container.slot))
     if instrument._context:
         if 'centerMultichannelOnWells' in container._container.quirks:
             cp = CriticalPoint.XY_CENTER
         else:
             cp = None
         here = self._hardware.gantry_position(Mount[inst.mount.upper()],
                                               critical_point=cp)
         # Reset calibration so we don’t actually calibrate the offset
         # relative to the old calibration
         container._container.set_calibration(Point(0, 0, 0))
         if ff.calibrate_to_bottom() and not (
                 container._container.is_tiprack):
             orig = _well0(container._container)._bottom().point
         else:
             orig = _well0(container._container)._top().point
         delta = here - orig
         labware.save_calibration(container._container, delta)
     else:
         inst.robot.calibrate_container_with_instrument(
             container=container._container,
             instrument=inst,
             save=True
         )
Esempio n. 2
0
def test_load_calibration(monkeypatch, clear_calibration):

    calibration_point = None

    def mock_set_calibration(self, delta):
        nonlocal calibration_point
        calibration_point = delta

    monkeypatch.setattr(labware.Labware, 'set_calibration',
                        mock_set_calibration)

    monkeypatch.setattr(labware, '_hash_labware_def', mock_hash_labware)

    test_labware = labware.Labware(minimalLabwareDef,
                                   Location(Point(0, 0, 0), 'deck'))

    test_offset = Point(1, 1, 1)
    test_tip_length = 31.7

    labware.save_calibration(test_labware, test_offset)
    labware.save_tip_length(test_labware, test_tip_length)

    # Set without saving to show that load will update with previously saved
    # data
    test_labware.set_calibration(Point(0, 0, 0))
    test_labware.tip_length = 46.8

    labware.load_calibration(test_labware)
    assert calibration_point == test_offset
    assert test_labware.tip_length == test_tip_length
Esempio n. 3
0
def test_add_index_file(labware_name, labware_offset_tempdir):
    deck = Deck()
    parent = deck.position_for(1)
    definition = labware.get_labware_definition(labware_name)
    lw = labware.Labware(definition, parent)
    labware_hash = helpers.hash_labware_def(definition)
    labware.save_calibration(lw, Point(0, 0, 0))

    lw_uri = helpers.uri_from_definition(definition)

    str_parent = labware._get_parent_identifier(lw)
    slot = '1'
    if str_parent:
        mod_dict = {str_parent: f'{slot}-{str_parent}'}
    else:
        mod_dict = {}
    full_id = f'{labware_hash}{str_parent}'
    blob = {
            "uri": f'{lw_uri}',
            "slot": full_id,
            "module": mod_dict
        }

    lw_path = labware_offset_tempdir / 'index.json'
    info = file_operators.read_cal_file(lw_path)
    assert info['data'][full_id] == blob
Esempio n. 4
0
def test_wells_rebuilt_with_offset():
    test_labware = labware.Labware(minimalLabwareDef,
                                   Location(Point(0, 0, 0), 'deck'))
    old_wells = test_labware._wells
    assert test_labware._offset == Point(10, 10, 5)
    assert test_labware._calibrated_offset == Point(10, 10, 5)
    labware.save_calibration(test_labware, Point(2, 2, 2))
    new_wells = test_labware._wells
    assert old_wells[0] != new_wells[0]
    assert test_labware._offset == Point(10, 10, 5)
    assert test_labware._calibrated_offset == Point(12, 12, 7)
Esempio n. 5
0
def set_up_index_file_temporary_directory(server_temp_directory):
    delete.clear_calibrations()
    deck = Deck()
    labware_list = [
        'nest_96_wellplate_2ml_deep', 'corning_384_wellplate_112ul_flat',
        'geb_96_tiprack_1000ul', 'nest_12_reservoir_15ml',
        'opentrons_96_tiprack_10ul'
    ]
    for idx, name in enumerate(labware_list):
        parent = deck.position_for(idx + 1)
        definition = labware.get_labware_definition(name)
        lw = labware.Labware(definition, parent)
        labware.save_calibration(lw, Point(0, 0, 0))
Esempio n. 6
0
def set_up_index_file(labware_offset_tempdir):
    deck = Deck()
    labware_list = [
        'nest_96_wellplate_2ml_deep',
        'corning_384_wellplate_112ul_flat',
        'geb_96_tiprack_1000ul',
        'nest_12_reservoir_15ml']
    for idx, name in enumerate(labware_list):
        parent = deck.position_for(idx+1)
        definition = labware.get_labware_definition(name)
        lw = labware.Labware(definition, parent)
        labware.save_calibration(lw, Point(0, 0, 0))

    return labware_list
Esempio n. 7
0
def test_schema_shape(monkeypatch, clear_calibration):
    def fake_time():
        return 1

    monkeypatch.setattr(time, 'time', fake_time)

    test_labware = labware.Labware(minimalLabwareDef,
                                   Location(Point(0, 0, 0), 'deck'))

    monkeypatch.setattr(labware, '_hash_labware_def', mock_hash_labware)

    labware.save_calibration(test_labware, Point(1, 1, 1))
    expected = {"default": {"offset": [1, 1, 1], "lastModified": 1}}
    with open(path(MOCK_HASH)) as f:
        result = json.load(f)
    assert result == expected
Esempio n. 8
0
def test_load_calibration(monkeypatch, clear_calibration):

    monkeypatch.setattr(helpers, 'hash_labware_def', mock_hash_labware)

    test_labware = labware.Labware(minimalLabwareDef,
                                   Location(Point(0, 0, 0), 'deck'))

    test_offset = Point(1, 1, 1)

    labware.save_calibration(test_labware, test_offset)

    # Set without saving to show that load will update with previously saved
    # data
    test_labware.set_calibration(Point(0, 0, 0))
    test_labware.tip_length = 46.8
    lookup_path = labware._get_labware_path(test_labware)
    calibration_point =\
        get.get_labware_calibration(lookup_path, test_labware._definition)
    assert calibration_point == test_offset
Esempio n. 9
0
def test_save_labware_calibration(monkeypatch, clear_calibration):
    # Test the save calibration file
    assert not os.path.exists(path(MOCK_HASH))
    calibration_point = None

    def mock_set_calibration(self, delta):
        nonlocal calibration_point
        calibration_point = delta

    monkeypatch.setattr(labware.Labware, 'set_calibration',
                        mock_set_calibration)

    monkeypatch.setattr(helpers, 'hash_labware_def', mock_hash_labware)

    test_labware = labware.Labware(minimalLabwareDef,
                                   Location(Point(0, 0, 0), 'deck'))

    labware.save_calibration(test_labware, Point(1, 1, 1))
    assert os.path.exists(path(MOCK_HASH))
    assert calibration_point == Point(1, 1, 1)
Esempio n. 10
0
def test_schema_shape(monkeypatch, clear_calibration):
    fake_time = utc_now()
    time_string = fake_time.isoformat()
    from_iso = datetime.datetime.fromisoformat(time_string)

    class fake_datetime:
        @classmethod
        def fromisoformat(cls, obj):
            return from_iso

        @classmethod
        def isoformat(cls):
            return time_string

    mock = Mock(spec=fake_datetime)
    mock.__class__ = datetime.datetime

    test_labware = labware.Labware(minimalLabwareDef,
                                   Location(Point(0, 0, 0), 'deck'))

    monkeypatch.setattr(
       helpers,
       'hash_labware_def', mock_hash_labware
    )

    expected = {"default": {"offset": [1, 1, 1], "lastModified": fake_time}}

    def fake_helper_data(path, delta):
        return expected

    monkeypatch.setattr(
        modify,
        '_helper_offset_data_format',
        fake_helper_data
    )

    labware.save_calibration(test_labware, Point(1, 1, 1))
    with open(path(MOCK_HASH)) as f:
        result = json.load(f, cls=ed.DateTimeDecoder)
    assert result == expected