Source

python-axonbinaryfile / tests / test_abf.py

import numpy as np
import scipy.io
import axonbinaryfile as abf

# make sure difference is less than 10^-4
epsilon = 0.0001

def test_abf2():
    """test version 2 abf in episodic stimulus mode
    file handling with 2 acq signals
    vs abf2load.m from matlab
    """
    xd = abf.readabf('pclamp10v2abf-1.abf')
    x = xd.arr
    
    yd = scipy.io.loadmat('pclamp10v2abf-1.mat')
    y = yd['d1'].transpose()
    dw = y-x

    assert np.all(dw < epsilon)


def test_abf183():
    """
    test versio 1.83 abf file with episodic sitmulus
    17 episodes, 1 channel, each 51612 samples long
    vs abf2load.m
    """
    xd = abf.readabf('pclamp9v183-1.abf')
    x = xd.arr
    
    yd = scipy.io.loadmat('pclamp9v183-1.mat')

    y = yd['d3'].transpose()
    dw = y-x

    assert np.all(dw < epsilon)
    
def test_get_waveform():
    """
    test ability to get command waveform for epoch/episode based stimulus
    """
    a = abf.readabf('data-IV-80to70x2.abf')
    episodes,channels,numsamples = a.arr.shape
    print "a.arr.shape:", a.arr.shape
    ws = []
    for ii in range(episodes):
      w = a.get_cmd_waveform(ii,0) # for ii in range(episodes)]
      ws.append(w)
    
    # can compare with data-IV-80to70x2.abf.extracedcmd0.npy
    return ws