GithubHelp home page GithubHelp logo

Comments (3)

swharden avatar swharden commented on August 18, 2024

Awesome, this information dates back to ABF1 files so we have some documentation:
https://swharden.com/pyabf/abf1-file-format.md.html#the-abf-synch-section

The ABF Synch Section

The ABF Synch array is an important array that stores the start time and length
of each portion of the data if the data are not part of a continuous gap-free
acquisition. The data section might contain equal length or variable length
sweeps of data. The Synch Array contains a record to indicate the start time
and length of every sweep or Event in the data file. The ABF reading routines
automatically decode the Synch Array when providing information about the data.

A Synch array is created and used in the following acquisition modes:
ABF_VARLENEVENTS, ABF_FIXLENEVENTS & ABF_HIGHSPEEDOSC. The acquisition modes
ABF_GAPFREEFILE and ABF_WAVEFORMFILE do not always use a Synch array.

Offset Header Entry Name Type Description
0 lStart long Start time of sweep in fSynchTimeUnit units.
4 lLength long Length of the sweep in multiplexed samples.

from pyabf.

swharden avatar swharden commented on August 18, 2024

I got this working in concept...

# THIS EXAMPLE ASSUMES A SINGLE CHANNEL
filePath = DATA_FOLDER + "/2020_06_16_0000.abf"
abf = pyabf.ABF(filePath)

sweepYs = []
sweepXs = []
with open(filePath, 'rb') as fb:
    fb.seek(abf.dataByteStart)
    for sweepIndex in abf.sweepList:
        firstPoint = abf._syncArraySection.lStart[sweepIndex]
        pointCount = abf._syncArraySection.lLength[sweepIndex]
        sweepY = np.fromfile(fb, dtype=abf._dtype, count=pointCount)
        sweepY = np.multiply(sweepY, abf._dataGain)
        sweepY = np.add(sweepY, abf._dataOffset)
        sweepYs.append(sweepY)
        offsetSec = firstPoint / abf.dataRate
        sweepX = np.arange(len(sweepY)) / abf.dataRate + offsetSec
        sweepXs.append(sweepX)

plt.figure()
for i in abf.sweepList:
    plt.plot(sweepXs[i], sweepYs[i])
plt.show()

image

Implementing this in the core pyABF library will require extreme care to ensure the existing behavior for fixed-length sweeps remains unmodified. The ABF reading function is definitely one I do not want to break 😅 I'm happy I'm protected by thousands of automated tests, but still, to avoid headaches I'll only move on this when I'm ready to approach this very carefully.

from pyabf.

swharden avatar swharden commented on August 18, 2024

Got it all figured out, merged in, and it's now live on pypi (pyabf 2.2.6)

pip install --upgrade pyabf

The sweepY list may now be a variable size, and if absoluteTime is True then sweepX returns proper times in the recording. With variable length recordings this means gaps in the data may be present:

import pyabf
import matplotlib.pyplot as plt

abf = pyabf.ABF("2020_06_16_0000.abf")

for sweepIndex in abf.sweepList:
	abf.setSweep(sweepIndex, absoluteTime=True)
	plt.plot(abf.sweepX, abf.sweepY)
plt.show()

image

from pyabf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.