python-axonbinaryfile / axonbinaryfile /

import _abf
import exceptions
class AbfNotSupported(exceptions.Exception):

class Abf(object):
    reads an axon abf file
    supports versions upto and including 2.0 (pClamp9 and pClamp10)

    all the meta data is stored in self.header dictionary
    some is copied to show the

    data access is via self.arr which is a numpy array of the form
    abf_modes = {
        1: 'VARLENEVENTS',
        3: 'LOSSFREEOSC',
        3: 'GAPFREEFILE',
        4: 'HIGHSPEEDOSC',
        5: 'WAVEFORMFILE',

    def __init__(self, file_name):
        self.file_name = file_name
        self.header = _abf.get_header_info(file_name)

        if self.header['OperationMode'] == 5:
            self.description = "axon abf file recorded in episodic mode (WAVEFORMFILE mode)"
            self.header, self.arr = _abf.read_episodic_file(file_name)
            self.num_channels = self.header['ADCNumChannels']
            self.channel_names = self.header['ADCChannelName']
            self.sample_interval_us = self.header['ADCSequenceInterval']
            raise AbfNotSupported("Only support episodic abf files.  This type, %s, is not yet supported" % self.abf_modes[self.header['OperationMode']])
    def __getitem__(self,key):
        # this is prbably a silly interface-quite inefficient
        return self.arr[key]

    def __repr__(self):
        return "Abf('%s')" % self.file_name

    def __unicode__(self):
        return "Abf('%s') %s" % (self.file_name, self.modename)

    def _clean_header_strings(self):
        """only called after reading in header, do cleanup of the
        strArrays = ['ADCChannelName', 'ADCUnits','DACChannelName',
                       'DACChannelUnits', 'DACFilePath','ULParamValueList',]
        h = self.header
        for sa in strArrays:
            slist = h[sa]
            for ii in range(len(slist)):
                slist[ii] = slist[ii].strip()

    def get_waveform(self, episode, dac_channel):
        easy way to get the stimulus waveform for a run
        note per python way, episode count starts at 0

        don't yet check if parameters are in range
        returns at float32 1dim numpy array
        return _abf.get_cmdwaveform(self.filename, episode+1, dac_channel)

def readabf(file_name):
    """reads an axon abf file
    supports versions upto and including 2.0 (pClamp9 and pClamp10)
    returns the data in the form of an Abf() class instance
    return Abf(file_name)