Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions neo/rawio/axonrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,15 +665,24 @@ def _parse_abf_v1(f, header_description):
header["sProtocolPath"] = header["sProtocolPath"].replace(b"\\", b"/")

# date and time
YY = 1900
MM = 1
DD = 1
# lFileStartDate is a YYYYMMDD-packed integer, parsed the same way as uFileStartDate in ABF2.
# An unset/sentinel value (0 or 0xFFFFFFFF) yields an out-of-range date that the try/except
# below turns into rec_datetime=None.
YY = int(header["lFileStartDate"] / 10000)
MM = int((header["lFileStartDate"] - YY * 10000) / 100)
DD = int(header["lFileStartDate"] - YY * 10000 - MM * 100)
hh = int(header["lFileStartTime"] / 3600.0)
mm = int((header["lFileStartTime"] - hh * 3600) / 60)
ss = header["lFileStartTime"] - hh * 3600 - mm * 60
ms = int(np.mod(ss, 1) * 1e6)
ss = int(ss)
header["rec_datetime"] = datetime.datetime(YY, MM, DD, hh, mm, ss, ms)
try:
header["rec_datetime"] = datetime.datetime(YY, MM, DD, hh, mm, ss, ms)
except (ValueError, OverflowError):
# Date/time header fields hold an out-of-range or "no date" sentinel
# (e.g. 0xFFFFFFFF). The acquisition date is non-essential annotation,
# so fall back to None rather than blocking the read of the signal.
header["rec_datetime"] = None

return header

Expand Down Expand Up @@ -1060,6 +1069,7 @@ def safe_decode_units(s):
("lActualAcqLength", 10, "i"),
("nNumPointsIgnored", 14, "h"),
("lActualEpisodes", 16, "i"),
("lFileStartDate", 20, "i"),
("lFileStartTime", 24, "i"),
("lDataSectionPtr", 40, "i"),
("lTagSectionPtr", 44, "i"),
Expand Down
15 changes: 14 additions & 1 deletion neo/test/rawiotest/test_axonrawio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import unittest

from neo.rawio.axonrawio import AxonRawIO
from neo.rawio.axonrawio import AxonRawIO, parse_axon_soup

from neo.test.rawiotest.common_rawio_test import BaseTestRawIO

Expand Down Expand Up @@ -28,6 +29,18 @@ def test_read_raw_protocol(self):

reader.read_raw_protocol()

def test_v1_reads_real_acquisition_date(self):
# ABF1 stores the calendar date in lFileStartDate (a YYYYMMDD-packed integer). Older neo
# ignored that field and hardcoded 1900-01-01, so the recording date was always wrong for
# ABF1 files. It must now be read from the header.
expected_datetime = datetime.datetime(2005, 6, 11, 14, 15, 0)
header = parse_axon_soup(self.get_local_path("axon/File_axon_2.abf"))
rec_datetime = header["rec_datetime"]
# Drop sub-second precision: the millisecond field round-trips through a float, so the
# microsecond is a rounding artifact, not a meaningful value to assert.
self.assertEqual(rec_datetime.replace(microsecond=0), expected_datetime)


if __name__ == "__main__":
unittest.main()

Loading