improve sample rate detection in ABF1 files
swharden opened this issue · comments
Adrián emailed an ABF file (190619B_0003.abf) which has been added to the data folder. This ABF1-formatted file is loaded with an incorrect sample rate. It should look like this:
Other multichannel ABF1 files to look at closer are:
pyABF/data/abfs/05210017_vc_abf1.abf
pyABF/data/abfs/18425108_abf1.abf
pyABF/data/abfs/190619B_0003.abf
pyABF/data/abfs/f1.abf
pyABF/data/abfs/File_axon_3.abf
pyABF/data/abfs/pclamp11_4ch_abf1.abf
Adrián suggested the problem may be that the sample rate is not being divided by the number of channels. Comparison between ABF1 and ABF2 sample rate determination sections shows that it's calculated from fADCSequenceInterval
but there isn't currently a difference between ABF1 and ABF2 files... so perhaps this rule only applies to ABF1 files? Or perhaps for ABF1 files a different header property should be used to calculate sample rate.
ABF1 data rate determination
Line 176 in e9d309e
ABF2 data rate determination
Lines 243 to 244 in e9d309e
I replicated the problem
abf = pyabf.ABF(PATH_DATA+"/190619B_0003.abf")
print(abf)
# OUTPUT:
# ABF (version 1.8.3.0) with 2 channels (mV, pA),
# sampled at 20.0 kHz, containing 10 sweeps,
# having no tags, with a total length of 0.28 minutes,
# recorded with protocol "IV_FI_IN0_saray".
plt.figure(figsize=(10, 4))
plt.grid(alpha=.2, ls='--')
for sweepNumber in abf.sweepList:
abf.setSweep(sweepNumber)
plt.plot(abf.sweepX, abf.sweepY, label=f"sweep {sweepNumber+1}")
plt.margins(0, .1)
plt.legend(fontsize=8)
plt.title(abf.abfID+".abf")
plt.ylabel(abf.sweepLabelY)
plt.xlabel(abf.sweepLabelX)
plt.tight_layout()
plt.show()
Fixed! Adrian you were spot on: e515cf6
This bug only affected multi-channel ABF1 files. The fix fixes the sample rate error and also corrects tag times for these ABFs. I'll publish this release on pypi tonight and update this ticket when I do
pip install --upgrade pyabf