Skip to content

Commit

Permalink
Neuronexus datetime parsing (#1572)
Browse files Browse the repository at this point in the history
* neuronexus datetime parsing

* exclude some python verisons

* another try

* correct version check

* could be

* try another
  • Loading branch information
h-mayorquin authored Sep 27, 2024
1 parent 499db96 commit cb13a30
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions neo/rawio/neuronexusrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from pathlib import Path
import json
import datetime
import sys
import re

import numpy as np

Expand Down Expand Up @@ -219,21 +221,15 @@ def _parse_header(self):
# Add the minimum annotations
self._generate_minimal_annotations()

# date comes out as:
# year-month-daydayofweektime all as a string so we need to prep it for
# entering into datetime
# example: '2024-07-01T13:04:49.4972245-04:00'
stringified_date_list = self.metadata['status']['start_time'].split('-')
year = int(stringified_date_list[0])
month = int(stringified_date_list[1])
day = int(stringified_date_list[2][:2]) # day should be first two digits of the third item in list
time_info = stringified_date_list[2].split(':')
hour = int(time_info[0][-2:])
minute = int(time_info[1])
second = int(float(time_info[2]))
microsecond = int(1000 * 1000 * (float(time_info[2]) - second))# second -> micro is 1000 * 1000

rec_datetime = datetime.datetime(year, month, day, hour, minute, second, microsecond)
# date comes out as: '2024-07-01T13:04:49.4972245-04:00' so in ISO format
datetime_string = self.metadata["status"]["start_time"]

# Python 3.10 and older expect iso format to only have 3 or 6 decimal places
if sys.version_info.minor < 11:
datetime_string = re.sub(r"(\.\d{6})\d+", r"\1", datetime_string)

rec_datetime = datetime.datetime.fromisoformat(datetime_string)

bl_annotations = self.raw_annotations["blocks"][0]
seg_annotations = bl_annotations["segments"][0]
for d in (bl_annotations, seg_annotations):
Expand Down

0 comments on commit cb13a30

Please sign in to comment.