Skip to content

Commit

Permalink
Merge pull request #38 from nathanecross/master
Browse files Browse the repository at this point in the history
More updates to fix eeglab import function
  • Loading branch information
jnobyrne authored Oct 11, 2024
2 parents a4f9775 + 25960c6 commit 05ff777
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified wonambi/.DS_Store
Binary file not shown.
Binary file added wonambi/ioeeg/.DS_Store
Binary file not shown.
12 changes: 9 additions & 3 deletions wonambi/ioeeg/eeglab.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ def return_hdr(self):
EEG_starttime = [int(x[0]) for x in EEG['etc']['T0']]
start_time = datetime(*EEG_starttime)
elif 'rec_startdate' in list(EEG['etc']):
EEG_starttime = EEG['etc']['rec_startdate']
start_time_char = ''.join([chr(x) for x in EEG_starttime])
start_time = datetime.fromisoformat(start_time_char)
EEG_starttime = EEG['etc']['rec_startdate'][()]
start_time_char = EEG_starttime.tobytes().decode('utf-16-le')
start_time = datetime.fromisoformat(start_time_char)


#EEG_starttime = EEG['etc']['rec_startdate']

#start_time_char = ''.join([chr(x) for x in EEG_starttime])
#start_time = datetime.fromisoformat(start_time_char)
else:
start_time = DEFAULT_DATETIME
except ValueError:
Expand Down
27 changes: 23 additions & 4 deletions wonambi/ioeeg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from numpy import (append,
cumsum,
where,
ndarray,
)


Expand Down Expand Up @@ -63,23 +64,41 @@ def read_hdf5_chan_name(f, hdf5_labels):
# some hdf5 magic
# https://groups.google.com/forum/#!msg/h5py/FT7nbKnU24s/NZaaoLal9ngJ
chan_name = []

try:
labels = hdf5_labels.value.flat
except:
labels = hdf5_labels[()].flat

for l in labels:
chan_name.append(read_hdf5_str(f[l]))

return chan_name


def read_hdf5_str(value):
try:
datfile = ''.join([chr(str(x)) for x in value.value])
data = value[()]
if isinstance(data, bytes):
datfile = data.decode('utf-8')
elif isinstance(data, str):
datfile = data
elif isinstance(data, ndarray):
if data.dtype.kind in ('S', 'O'):

datfile = ''.join([x.decode('utf-8') if isinstance(x, bytes) else str(x) for x in data])
elif data.dtype.kind in ('i', 'u'): # Integer types

datfile = ''.join([chr(int(x)) for x in data])
else:
datfile = str(data)
else:
datfile = str(data)
except:
datfile = ''.join([chr(x[0]) for x in value])
try:
datfile = ''.join([chr(str(x)) for x in value.value])
except:
datfile = ''.join([chr(x[0]) for x in value])
if datfile == '\x00\x00':
return ''
else:
return datfile

0 comments on commit 05ff777

Please sign in to comment.