示例#1
0
def plot_motion(delta=30000):
    """Rotate to a new position and plot the position, speed, and other parameters measured during motion.

    This is used to debug motion control when moving the motor to hit a specific encoder value.
    """
    global win
    win = pg.GraphicsWindow()
    p1 = win.addPlot(title='position')
    p2 = win.addPlot(title='speed', row=1, col=0)
    p3 = win.addPlot(title='target speed', row=2, col=0)
    p4 = win.addPlot(
        title=
        'distance, <span style="color: green">distance-until-decel</span>',
        row=3,
        col=0)
    p2.setXLink(p1)
    p3.setXLink(p1)
    p4.setXLink(p1)

    t = []
    x = []
    v = []
    vt = []
    dx = []
    dxt = []
    start = time.time()
    started = False
    while True:
        now = time.time()
        pos = mfc.position()
        if not started and now - start > 0.2:
            move = pos + delta
            print("move:", move)
            mfc.move(move)
            started = True
        if now - start > 2:
            break
        t.append(now - start)
        x.append(pos)
        v.append(mfc.mcm['actual_speed'])
        vt.append(mfc.mcm['target_speed'])
        dx.append(mfc.mcm.get_global('gp1'))
        dxt.append(mfc.mcm.get_global('gp2'))
    p1.plot(t, x, clear=True)
    p2.plot(t, v, clear=True)
    p3.plot(t, vt, clear=True)
    p4.plot(t, dx, clear=True)
    p4.plot(t, dxt, pen='g')

    print("Final:", mfc.position())
示例#2
0
def showAll():
    global xVals, data, psp, fits
    w = pg.GraphicsWindow()
    for i in range(psp.shape[0]):
        for j in range(psp.shape[1]):
            p = w.addPlot()
            fit = pspFunc(fits[i, j], xVals)
            err = (abs(data[i, j] - fit)**2).sum() / (data[i, j]**2).sum()

            green = np.clip((np.log(err) + 3) * 60, 0, 255)
            p.plot(xVals, data[i, j], pen=(80, 60, 60))
            p.plot(xVals, fit, pen=(50, green, 255 - green, 200))
            #p.plot(xVals, pspFunc(psp[i,j], xVals), pen='b')
            p.hideAxis('left')
            p.hideAxis('bottom')
            p.hideButtons()
        w.nextRow()
示例#3
0
def plot_motion():
    win = pg.GraphicsWindow()
    p1 = win.addPlot(title='position')
    p2 = win.addPlot(title='speed', row=1, col=0)
    p3 = win.addPlot(title='target speed', row=2, col=0)
    p4 = win.addPlot(title='distance', row=3, col=0)
    p2.setXLink(p1)
    p3.setXLink(p1)
    p4.setXLink(p1)

    t = []
    x = []
    v = []
    vt = []
    dx = []
    dxt = []
    start = time.time()
    started = False
    while True:
        now = time.time()
        pos = mfc.position()
        if not started and now - start > 0.2:
            move = pos + 20000
            print "move:", move
            mfc.move(move)
            started = True
        if now - start > 2:
            break
        t.append(now-start)
        x.append(pos)
        v.append(mfc.mcm['actual_speed'])
        vt.append(mfc.mcm['target_speed'])
        dx.append(mfc.mcm.get_global('gp1'))
        dxt.append(mfc.mcm.get_global('gp2'))
    p1.plot(t, x, clear=True)
    p2.plot(t, v, clear=True)
    p3.plot(t, vt, clear=True)
    p4.plot(t, dx, clear=True)
    p4.plot(t, dxt, pen='g')

    print "Final:", mfc.position()
示例#4
0
import acq4.Manager
import acq4.analysis.atlas.CochlearNucleus as cn

man = acq4.Manager.getManager()
initialized = False

def __reload__(old):  ## re-use existing objects if module is reloaded
    global initialized, w, v, atlas
    initialized = True
    w = old['w']
    v = old['v']
    atlas = old['atlas']

if not initialized:
    atlas = cn.CochlearNucleus()
    w = pg.GraphicsWindow()
    w.setRenderHints(Qt.QPainter.Antialiasing | Qt.QPainter.TextAntialiasing | Qt.QPainter.SmoothPixmapTransform)
    w.setBackground(pg.mkColor('w'))
    v = w.addViewBox()
    v.setAspectLocked()
    v.invertY()
    w.show()
    initialized = True

def show(dh=None):
    """
    Display a graphic of the currently selected slice / cell
    """
    
    global v, g, atlas
    if dh is None:
示例#5
0
    def showErrorAnalysis(self):
        if not hasattr(self, 'errorMap'):
            filename = self.dev.configFileName('error_map.np')
            self.errorMap = np.load(open(filename, 'rb'))[np.newaxis][0]

        err = self.errorMap
        imx = pg.image(err['err'][..., 0].transpose(1, 0, 2), title='X error')
        imy = pg.image(err['err'][..., 1], title='Y error')
        imz = pg.image(err['err'][..., 2], title='Z error')

        # get N,3 array of offset values used to randomize hysteresis
        off = np.vstack(err['offsets'])
        sh = err['err'].shape

        # Get N,3 array of measured position errors
        errf = err['err'].reshape(sh[0] * sh[1] * sh[2], 3)[err['order']]

        # Display histogram of errors
        win = pg.GraphicsWindow(title="%s error" % self.dev.name())
        # subtract out slow drift
        normErr = errf - scipy.ndimage.gaussian_filter(errf, (20, 0))
        # calculate magnitude of error
        absErr = (normErr**2).sum(axis=1)**0.5
        # errPlot.plot(absErr)
        title = "Error Histogram (mean=%s)" % pg.siFormat(absErr.mean(),
                                                          suffix='m')
        errPlot = win.addPlot(row=0,
                              col=0,
                              title=title,
                              labels={'bottom': ('Position error', 'm')})
        hist = np.histogram(absErr, bins=50)
        errPlot.plot(hist[1], hist[0], stepMode=True)

        # display drift and hysteresis plots
        driftPlot = win.addPlot(row=0,
                                col=1,
                                rowspan=1,
                                colspan=2,
                                title="Pipette Drift",
                                labels={
                                    'left': ('Position error', 'm'),
                                    'bottom': ('Time', 's')
                                })
        driftPlot.plot(np.linspace(0, err['time'], errf.shape[0]),
                       errf[:, 0],
                       pen='r')
        driftPlot.plot(np.linspace(0, err['time'], errf.shape[0]),
                       errf[:, 1],
                       pen='g')
        driftPlot.plot(np.linspace(0, err['time'], errf.shape[0]),
                       errf[:, 2],
                       pen='b')

        xhplot = win.addPlot(row=1,
                             col=0,
                             title='X Hysteresis',
                             labels={
                                 'left': ('Position error', 'm'),
                                 'bottom': ('Last pipette movement', 'm')
                             })
        xhplot.plot(-off[:, 0], errf[:, 0], pen=None, symbol='o')

        yhplot = win.addPlot(row=1,
                             col=1,
                             title='Y Hysteresis',
                             labels={
                                 'left': ('Position error', 'm'),
                                 'bottom': ('Last pipette movement', 'm')
                             })
        yhplot.plot(-off[:, 1], errf[:, 1], pen=None, symbol='o')

        zhplot = win.addPlot(row=1,
                             col=2,
                             title='Z Hysteresis',
                             labels={
                                 'left': ('Position error', 'm'),
                                 'bottom': ('Last pipette movement', 'm')
                             })
        zhplot.plot(-off[:, 2], errf[:, 2], pen=None, symbol='o')

        # Print best fit for manipulator axes
        expPos = err['inds'] * err['stepSize']
        measPos = expPos + off
        guess = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]],
                         dtype='float')

        def errFn(v):
            return ((measPos -
                     np.dot(expPos, v.reshape(3, 4))[:, :3])**2).sum()

        fit = scipy.optimize.minimize(errFn, guess)
        print("Pipette position transform:", fit)

        self.errorMapAnalysis = (imx, imy, imz, win)
示例#6
0
        if len(a) != len(b):
            print "  WARNING: optimize changed size of list"
            return
        for i in range(len(a)):
            if a[i] not in bLocs:
                print "  WARNING: optimize changed contents of list"
                print a[i], "not in solution"
                return
            elif bLocs[i] not in a:
                print "  WARNING: optimize changed contents of list"
                print bLocs[i], "not in original"
                return
        #print "List check OK"


    view = pg.GraphicsWindow(border=(50, 50, 50))
    greed = 1.0
    for d in [0.2e-3, 0.5e-3, 2e-3]:
        for n in [20]:
            for compMethod in ['max', 'rms', 'sum']:
                locs = []
                for i in np.linspace(-d, d, n):
                    for j in np.linspace(-d, d, n):
                        locs.append((i,j))
                key = "grid\td=%0.1gmm\tn=%d\tgreed=%0.2g" % (d*2000, n, greed)
                locSets[key] = locs
                
                start = time.time()
                for step, last in opt2(locs, minTime, minDist, deadTime, greed=greed, compMethod=compMethod):
                    if last is None:
                        l2 = step