Esempio n. 1
0
 def init_scandb(self):
     dbconn = self.config
     if dbconn is not None:
         self.instname = dbconn.get('instrument', 'microscope_stages')
         self.scandb = ScanDB()
         self.instdb = InstrumentDB(self.scandb)
         print("Connect ScanDB ", self.scandb.engine, self.instname)
         if self.instdb.get_instrument(self.instname) is None:
             pvs = self.viewer.config['stages'].keys()
             self.instdb.add_instrument(self.instname, pvs=pvs)
Esempio n. 2
0
def make_uscope_rotation(scandb,
                         offline_inst='IDE_Microscope',
                         offline_xyz=('13IDE:m1.VAL', '13IDE:m2.VAL',
                                      '13IDE:m3.VAL'),
                         online_inst='IDE_SampleStage',
                         online_xyz=('13XRM:m4.VAL', '13XRM:m6.VAL',
                                     '13XRM:m5.VAL')):
    """
    Calculate and store the rotation maxtrix needed to convert
    positions from the GSECARS offline microscope (OSCAR)
    to the SampleStage in the microprobe station.

    This calculates the rotation matrix based on all position
    names that occur in the Position List for both instruments.

    Note:
        The result is saved as a json dictionary to the config table
    """
    instdb = InstrumentDB(scandb)

    pos_us = read_xyz(instdb, offline_inst, offline_xyz)
    pos_ss = read_xyz(instdb, online_inst, online_xyz)
    # calculate the rotation matrix
    mat_us2ss, v1, v2 = calc_rotmatrix(pos_us, pos_ss)
    if mat_us2ss is None:
        return
    #endif
    uscope = instdb.get_instrument(offline_inst)
    sample = instdb.get_instrument(online_inst)

    uname = uscope.name.replace(' ', '_')
    sname = sample.name.replace(' ', '_')
    conf_us2ss = "CoordTrans:%s:%s" % (uname, sname)

    us2ss = dict(source=offline_xyz,
                 dest=online_xyz,
                 rotmat=mat_us2ss.tolist())

    scandb.set_config(conf_us2ss, json.dumps(us2ss))

    # calculate the rotation matrix going the other way
    mat_ss2us, v1, v2 = calc_rotmatrix(pos_ss, pos_us)
    conf_ss2us = "CoordTrans:%s:%s" % (sname, uname)
    ss2us = dict(source=online_xyz,
                 dest=offline_xyz,
                 rotmat=mat_ss2us.tolist())
    print("Saving Calibration %s" % conf_ss2us)
    scandb.set_config(conf_ss2us, json.dumps(ss2us))
    scandb.commit()
Esempio n. 3
0
def connect_scandb(dbname=None, server='postgresql', _larch=None, **kwargs):
    if (_larch.symtable.has_symbol(SCANDB_NAME)
            and _larch.symtable.get_symbol(SCANDB_NAME) is not None):
        scandb = _larch.symtable.get_symbol(SCANDB_NAME)
    else:
        scandb = ScanDB(dbname=dbname, server=server, **kwargs)
        _larch.symtable.set_symbol(SCANDB_NAME, scandb)

    if (_larch.symtable.has_symbol(INSTDB_NAME)
            and _larch.symtable.get_symbol(INSTDB_NAME) is not None):
        instdb = _larch.symtable.get_symbol(INSTDB_NAME)
    else:
        instdb = InstrumentDB(scandb)
        _larch.symtable.set_symbol(INSTDB_NAME, instdb)
    return scandb
Esempio n. 4
0
 def init_scandb(self):
     dbconn = self.config
     if dbconn is not None:
         self.instname = dbconn.get('instrument', 'microscope_stages')
         dbconn_dir = dbconn.get('dbconn_dir', '')
         dbconn_file = dbconn.get('dbconn_file', '')
         if os.path.exists(dbconn_dir) and len(dbconn_file) > 0:
             sys.path.insert(0, dbconn_dir)
             mod = __import__(dbconn_file)
             conn = mod.conn
             scandb = ScanDB(**mod.conn)
             self.instdb = InstrumentDB(scandb)
             if self.instdb.get_instrument(self.instname) is None:
                 pvs = self.viewer.config['stages'].keys()
                 self.instdb.add_instrument(self.instname, pvs=pvs)
Esempio n. 5
0
def connect_scandb(scandb=None, dbname=None, _larch=None, **kwargs):
    global _scandb, _instdb
    if _scandb is not None:
        return _scandb
    if scandb is None:
        scandb = ScanDB(dbname=dbname, **kwargs)

    if scandb is not None:
        _scandb = scandb

    if _larch is not None:
        _larch.symtable.set_symbol(SCANDB_NAME, _scandb)

    if _instdb is None:
        _instdb = InstrumentDB(_scandb)

        if _larch is not None:
            _larch.symtable.set_symbol(INSTDB_NAME, _instdb)
    return _scandb