Source

python-axonbinaryfile / axonbinaryfile / __init__.py

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

    
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
    num_channels
    channel_names

    data access is via self.arr which is a numpy array of the form
    arr[
    
    """
    abf_modes = {
        1: 'VARLENEVENTS',
        2: 'FIXLENEVENTS',        #(ABF_FIXLENEVENTS == ABF_LOSSFREEOSC)
        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_adcs = self.header['ADCNumChannels'] # number inputs
            self.adc_names = self.header['ADCChannelName'] #input names
            self.sample_interval_us = self.header['ADCSequenceInterval']
            self._clean_header_strings()
        else:
            
            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
        representation"""
        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_cmd_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.file_name, 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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.