swharden / pyABF

pyABF is a Python package for reading electrophysiology data from Axon Binary Format (ABF) files
https://swharden.com/pyabf
MIT License
103 stars 33 forks source link

Incorrect recording length for 2.0.0.0 gap-free files #139

Open VonEconomo opened 2 months ago

VonEconomo commented 2 months ago

I work with files from various ABF versions, for version 2.0.0.0 files, self._protocolSection.fEpisodeStartToStart appears to be set to a value that's significantly smaller than the actual sweep length, leading to an underestimation of the sweep Interval (sweepIntervalSec), and subsequently the total recording length (dataLengthSec).

Problematic Code in abf.py: https://github.com/swharden/pyABF/blob/2a0c1b0221428e21c961664b796d953eaae7746c/src/pyabf/abf.py#L419-L431

In my case,

if self.sweepIntervalSec == 0:
                self.sweepIntervalSec = self.sweepLengthSec

does not seem to catch the issue. In the 2.0 recordings that are available to me, fEpisodeStartToStart is consistently reported as 5. I did not further investigate this issue and solved it for me by setting

self.sweepIntervalSec = self.sweepLengthSec

regardless of the version.

My question now:

Why use fEpisodeStartToStart at all?

swharden commented 2 months ago

Hi @VonEconomo, thanks for reporting this!

In the 2.0 recordings that are available to me

Do you have a sample ABF you could include as an attachment here that we can look at and develop against?

Thanks! Scott

swharden commented 2 months ago

Solution

I want to highlight your solution for others who may land here after searching for this issue:

this issue and solved it for me by setting

self.sweepIntervalSec = self.sweepLengthSec

My question now: Why use fEpisodeStartToStart at all?

ABFs can be configured with an inter-sweep interval that is different from the sweep length. E.g., "record a 5 second sweep once every 30 seconds". I assume this is why the header has separate lActualAcqLength and fEpisodeStartToStart values. It's possible that is is supported in newer "version 2" abf files, but not 2.0.0.0 files 🤔

VonEconomo commented 2 months ago

V2_dataLengthSec_Example.txt Changed .abf to .txt in order to upload.

swharden commented 2 months ago

Thanks! Here's a ZIP of the sample ABF file in question: V2_dataLengthSec_Example.zip

It looks this this is a gap free file, so the inter-sweep interval value may not be relevant to this recording. However, the bug you initially described that causes this gap-free file to be read incorrectly is important to resolve! I'll look into fixing this and making a new release shortly.

Thanks so much for reporting this!

VonEconomo commented 2 months ago

Thanks for the explanation and the swift response!