NeuralEnsemble / python-neo

Neo is a package for representing electrophysiology data in Python, together with support for reading a wide range of neurophysiology file formats
http://neo.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
322 stars 247 forks source link

Alternative way to get offset before first "epoch" in axon protocol conversion #1305

Open MichaelClerx opened 1 year ago

MichaelClerx commented 1 year ago

At the moment Neo uses a slightly "magic" equation to work out the (undocumented) time spent at holding potential before the first "epoch" of a protocol starts:

https://github.com/NeuralEnsemble/python-neo/blob/6ce00dc9c13e85c2b2cbf6dacb6d66f93b0099c6/neo/rawio/axonrawio.py#L338-L340

Digging into the File Support Pack 1 for Windows for the old ABF 1.x format, there's a method inside AxonDev/Comp/AxAbfFio32/ABFHWAVE.CPP (which I guess deals with "waveforms", a.k.a. D/A protocol outputs) called _GetHoldingLength():

//===============================================================================================
// FUNCTION: GetHoldingLength
// PURPOSE:  Get the duration of the first/last holding period.
//
static int _GetHoldingLength(int nSweepLength, int nNumChannels)
{
   ASSERT((nSweepLength % nNumChannels)==0);

   // Calculate holding count.
   int nHoldingCount = nSweepLength / ABFH_HOLDINGFRACTION;

   // Round down to nearest sequence length.
   nHoldingCount -= nHoldingCount % nNumChannels;

   // If less than one sequence, round up to one sequence.
   if (nHoldingCount < nNumChannels)
      nHoldingCount = nNumChannels;

   return nHoldingCount;
}

where ABFH_HOLDINGFRACTION is a macro defined as 64 and where I'm guessing nNumChannels is the number of AD (not DA) channels.

I've tried for a few files and it seems to give the same result as the current code. Don't want to fix what isn't broken, but perhaps good to try out?

The next function down, ABFH_GetHoldingDuration, suggests a difference for "old" versions of the format (but given that these were "old" in 2000, maybe that's ok)

Note that the file starts with

// Copyright (c) 1993-2000 Axon Instruments. // All rights reserved. // Permission is granted to freely to use, modify and copy the code in this file.

JuliaSprenger commented 1 year ago

Hi @MichaelClerx. Thanks for digging into the Axon format and looking for potential bugs in Neo. If the current code is already loading the file correctly I don't think it's necessary to change it. If you find it important, feel free to open a PR and include a corresponding test in the our code base here.