1. Chris Lee-Messer
  2. python-axonbinaryfile

Source

python-axonbinaryfile / axonbinaryfile / utils / plottraces.py

import axonbinaryfile as abf
import pylab
import numpy as np

def plottraces(abff,time='ms'):
    m = abff.arr
    trnum, signum, numsamples = m.shape
    print "trnum, signum, numsamples:", trnum, signum, numsamples
    if time=='ms':
        t_ms = np.arange(numsamples,dtype='float64')*abff.dt_us/1000.0
    else:
        t_ms = np.arange(numsamples)
    pylab.figure()
    pylab.subplot(signum,1,1)
    for ss in range(signum):
        pylab.subplot(signum,1,ss+1)
        pylab.ylabel(abff.header['ADCUnits'][ss])
        for tt in range(trnum):
            pylab.plot(t_ms, m[tt,ss])

    pylab.xlabel('ms')


def plottraces_allback_noticks(abff,time='ms', fmts='-k'):
    m = abff.arr
    trnum, signum, numsamples = m.shape
    print "trnum, signum, numsamples:", trnum, signum, numsamples
    if time=='ms':
        t_ms = np.arange(numsamples,dtype='float64')*abff.dt_us/1000.0
    else:
        t_ms = np.arange(numsamples)
    pylab.figure()
    pylab.subplot(signum,1,1)
    for ss in range(signum):
        pylab.subplot(signum,1,ss+1, frameon=False)
        pylab.ylabel(abff.header['ADCUnits'][ss])
        for tt in range(trnum):
            pylab.plot(t_ms, m[tt,ss], fmts)
            pylab.xticks([])
            pylab.yticks([])
    pylab.xlabel('ms')

def plottraces_allback(abff,time='ms', fmts='-k'):
    m = abff.arr
    trnum, signum, numsamples = m.shape
    print "trnum, signum, numsamples:", trnum, signum, numsamples
    if time=='ms':
        t_ms = np.arange(numsamples,dtype='float64')*abff.dt_us/1000.0
    else:
        t_ms = np.arange(numsamples)
    pylab.figure()
    pylab.subplot(signum,1,1)
    for ss in range(signum):
        pylab.subplot(signum,1,ss+1)
        pylab.ylabel(abff.header['ADCUnits'][ss])
        for tt in range(trnum):
            pylab.plot(t_ms, m[tt,ss], fmts)

    pylab.xlabel('ms')


def ivcurve(at_ms,abf):
    mspersample = abf.dt_us / 1000.0
    smpl_at = int(at_ms / mspersample)

    # I=g*V
    m = abf.arr
    trnum, signum, numsamples = abf.arr.shape
    # 2 x trnum # (signum assume is 2)
    iv = np.zeros((trnum, 2), dtype='float')
    for tr in range(trnum):
        pa = m[tr, 0, smpl_at]
        mv = m[tr, 1, smpl_at]
        g = (mv,pa)
        iv[tr,0]=mv
        iv[tr,1]=pa
    return iv

def plottraces_ap(abff,time='ms', ticks=True, fmts='-k', t0=0,t1=None):
    ms2sample = 1000.0/abff.dt_us
    if t1:
        x0,x1 = int(t0*ms2sample), int(t1*ms2sample)
    m = abff.arr
    trnum, signum, numsamples = m.shape
    if t1:
        numsamples = x1-x0
    else:
        x0 = 0
        x1 = numsamples
        
    print "trnum, signum, numsamples:", trnum, signum, numsamples
    if time=='ms':
        t_ms = np.arange(x1-x0,dtype='float64')*abff.dt_us/1000.0
    else:
        t_ms = np.arange(numsamples)
    pylab.figure()
    pylab.subplot(signum,1,1)
    for ss in range(signum):
        pylab.subplot(signum,1,ss+1, frameon=False)
        pylab.ylabel(abff.header['ADCUnits'][ss])
        for tt in range(trnum):
            pylab.plot(t_ms, m[tt,ss,x0:x1], fmts)
            if not ticks:
                pylab.xticks([])
                pylab.yticks([])
    pylab.xlabel('ms')