Skip to content

Commit 6af1291

Browse files
authored
ENH: Add encoding parameter to Nihon Kohden reader
1 parent 181fea1 commit 6af1291

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

mne/io/nihon/nihon.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _ensure_path(fname):
2323

2424

2525
@fill_doc
26-
def read_raw_nihon(fname, preload=False, verbose=None) -> "RawNihon":
26+
def read_raw_nihon(fname, preload=False, encoding='utf-8', verbose=None) -> "RawNihon":
2727
"""Reader for an Nihon Kohden EEG file.
2828
2929
Parameters
@@ -44,7 +44,7 @@ def read_raw_nihon(fname, preload=False, verbose=None) -> "RawNihon":
4444
--------
4545
mne.io.Raw : Documentation of attributes and methods of RawNihon.
4646
"""
47-
return RawNihon(fname, preload, verbose)
47+
return RawNihon(fname, preload, encoding, verbose)
4848

4949

5050
_valid_headers = [
@@ -315,7 +315,7 @@ def _parse_sub_event_log(sub_event_log):
315315
return t_sub_desc, t_sub_onset
316316

317317

318-
def _read_nihon_annotations(fname):
318+
def _read_nihon_annotations(fname, encoding):
319319
fname = _ensure_path(fname)
320320
log_fname = fname.with_suffix(".LOG")
321321
if not log_fname.exists():
@@ -346,15 +346,10 @@ def _read_nihon_annotations(fname):
346346
t_onset += t_sub_onset
347347

348348
t_desc = t_desc.rstrip(b"\x00")
349-
for enc in _encodings:
350-
try:
351-
t_desc = t_desc.decode(enc)
352-
except UnicodeDecodeError:
353-
pass
354-
else:
355-
break
356-
else:
357-
warn(f"Could not decode log as one of {_encodings}")
349+
try:
350+
t_desc = t_desc.decode(encoding)
351+
except UnicodeDecodeError:
352+
warn(f"Could not decode log as {encoding}")
358353
continue
359354

360355
all_onsets.append(t_onset)
@@ -422,7 +417,7 @@ class RawNihon(BaseRaw):
422417
"""
423418

424419
@verbose
425-
def __init__(self, fname, preload=False, verbose=None):
420+
def __init__(self, fname, preload=False, encoding='utf-8', verbose=None):
426421
fname = _check_fname(fname, "read", True, "fname")
427422
data_name = fname.name
428423
logger.info(f"Loading {data_name}")
@@ -468,7 +463,7 @@ def __init__(self, fname, preload=False, verbose=None):
468463
)
469464

470465
# Get annotations from LOG file
471-
annots = _read_nihon_annotations(fname)
466+
annots = _read_nihon_annotations(fname, encoding)
472467

473468
# Annotate acquisition skips
474469
controlblock = header["controlblocks"][0]

0 commit comments

Comments
 (0)