def load(deck_cal_file=None): deck_cal_file = deck_cal_file or get_config_index().get( 'deckCalibrationFile') log.info("Loading deck calibration from {}".format(deck_cal_file)) deck_cal = _load_json(deck_cal_file).get('gantry_calibration', {}) settings_file = get_config_index().get('robotSettingsFile') log.info("Loading robot settings from {}".format(settings_file)) robot_settings = _load_json(settings_file) or {} return _build_config(deck_cal, robot_settings)
def save_deck_calibration(config: robot_config, dc_filename=None, tag=None): config_dict = config._asdict() dc_filename = dc_filename or get_config_index().get('deckCalibrationFile') if tag: root, ext = os.path.splitext(dc_filename) dc_filename = "{}-{}{}".format(root, tag, ext) deck_calibration = { 'gantry_calibration': config_dict.pop('gantry_calibration')} _save_json(deck_calibration, filename=dc_filename)
def save_robot_settings(config: robot_config, rs_filename=None, tag=None): config_dict = config._asdict() config_dict.pop('gantry_calibration') # Save everything else in a different file rs_filename = rs_filename or get_config_index().get('robotSettingsFile') if tag: root, ext = os.path.splitext(rs_filename) rs_filename = "{}-{}{}".format(root, tag, ext) _save_json(config_dict, filename=rs_filename) return config_dict
def get_all_adv_settings() -> dict: """ :return: a dict of settings keyed by setting ID, where each value is a dict with keys "id", "title", "description", and "value" """ settings_file = get_config_index().get('featureFlagFile') values = _read_settings_file(settings_file) for key, value in values.items(): s = copy(settings_by_id[key].__dict__) s.pop('old_id') values[key] = s values[key]['value'] = value return values
def test_update_instrument_config(fixture): from opentrons.trackers.pose_tracker import change_base from numpy import array import json robot = fixture.robot inst = fixture.instrument inst_offset = robot.config.instrument_offset[inst.mount][inst.type] cfg = update_instrument_config(instrument=inst, measured_center=(0.0, 0.0, 105.0)) new_tip_length = cfg.tip_length[inst.name] new_instrument_offset = cfg.instrument_offset[inst.mount][inst.type] assert new_tip_length == 55.0 assert new_instrument_offset == tuple(array(inst_offset) + (5.0, 5.0, 0.0)) assert tuple(change_base( robot.poses, src=inst, dst=inst.instrument_mover)) == (5.0, 5.0, 0), \ "Expected instrument position to update relative to mover in pose tree" filename = get_config_index().get('robotSettingsFile') expected = dict(robot_configs._build_config({}, {})._asdict()) expected.pop('gantry_calibration') expected['instrument_offset']['right']['single'] = [5.0, 5.0, 0.0] expected['tip_length']['Pipette'] = 55.0 with open(filename, 'r') as file: actual = json.load(file) # from pprint import pprint # print('=------> <------=') # print("Expected:") # pprint(expected) # print() # print("Actual:") # pprint(actual) # print() assert actual == expected
def test_save_and_clear_config(mock_config): # Clear should happen automatically after the following import, resetting # the robot config to the default value from robot_configs from opentrons.deck_calibration import dc_main from opentrons import robot import os old_config = robot.config base_filename = get_config_index().get('deckCalibrationFile') tag = "testing" root, ext = os.path.splitext(base_filename) filename = "{}-{}{}".format(root, tag, ext) dc_main.backup_configuration_and_reload(tag=tag) from opentrons import robot from opentrons.robot import robot_configs assert robot.config == robot_configs._build_config({}, {}) saved_config = robot_configs.load(filename) assert saved_config == old_config
def clear(): files = [ get_config_index().get('deckCalibrationFile'), get_config_index().get('robotSettingsFile')] for filename in files: _clear_file(filename)
import os import json import tempfile from opentrons.data_storage import labware_definitions as ldef from opentrons.data_storage import database from opentrons.config import get_config_index file_dir = os.path.abspath(os.path.dirname(__file__)) defn_dir = os.path.abspath( get_config_index().get('labware', {}).get('baseDefinitionDir', '')) user_defn_dir = os.path.abspath( get_config_index().get('labware', {}).get('userDefinitionDir', '')) offset_dir = os.path.abspath( get_config_index().get('labware', {}).get('offsetDir', '')) test_lw_name = '4-well-plate' expected_x = 40 expected_y = 40 expected_z = 30 expected_x_offset = 10 expected_y_offset = -10 expected_z_offset = 100 expected_final_x = expected_x + expected_x_offset expected_final_y = expected_y + expected_y_offset expected_final_z = expected_z + expected_z_offset def test_load_definition(): container_json = ldef._load_definition(user_defn_dir, test_lw_name)
def set_adv_setting(_id: str, value): _id = _clean_id(_id) settings_file = get_config_index().get('featureFlagFile') s = _read_settings_file(settings_file) s[_id] = value _write_settings_file(s, settings_file)
from opentrons.config import get_config_index from opentrons.data_storage import serializers as ser from opentrons.data_storage import labware_definitions as ldef from opentrons.data_storage import database as sqldb test_defn_root = get_config_index().get('labware').get('baseDefinitionDir') # =================== # Tests below are compatibility tests with sqlite database. These tests will no # longer be relevant once the sqlite database is removed, and should be revised # or deleted # =================== def test_one_deserializer(): plate = '6-well-plate' new_container = ser.json_to_container( ldef._load_definition(test_defn_root, plate)) old_container = sqldb.load_container(plate) old_wells = { wellname: [ round(well._coordinates[i] + old_container._coordinates[i], 3) for i in [0, 1, 2] ] for wellname, well in old_container.children_by_name.items() } new_wells = { wellname: [well._coordinates[i] for i in [0, 1, 2]] for wellname, well in new_container.children_by_name.items() }
def offset_dir(): return get_config_index().get('labware', {}).get('offsetDir')
def user_defn_dir(): return get_config_index().get('labware', {}).get('userDefinitionDir')
def default_definition_dir(): return get_config_index().get('labware', {}).get('baseDefinitionDir')