Skip to content
Merged
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
1 change: 1 addition & 0 deletions doc/changes/devel/12730.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug when reading NIRX files saved in a non-western encoding, by `Daniel McCloy`_.
1 change: 1 addition & 0 deletions mne/io/nirx/_localized_abbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
print('}\n')
"""

# TODO: this should really be outsourced to a dedicated module like arrow or babel
_localized_abbr = {
"en_US.utf8": {
"month": {
Expand Down
18 changes: 10 additions & 8 deletions mne/io/nirx/nirx.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@fill_doc
def read_raw_nirx(
fname, saturated="annotate", preload=False, verbose=None
fname, saturated="annotate", *, preload=False, encoding="latin-1", verbose=None
) -> "RawNIRX":
"""Reader for a NIRX fNIRS recording.

Expand All @@ -45,6 +45,7 @@ def read_raw_nirx(
Path to the NIRX data folder or header file.
%(saturated)s
%(preload)s
%(encoding_nirx)s
%(verbose)s

Returns
Expand All @@ -61,7 +62,9 @@ def read_raw_nirx(
-----
%(nirx_notes)s
"""
return RawNIRX(fname, saturated, preload, verbose)
return RawNIRX(
fname, saturated, preload=preload, encoding=encoding, verbose=verbose
)


def _open(fname):
Expand All @@ -78,6 +81,7 @@ class RawNIRX(BaseRaw):
Path to the NIRX data folder or header file.
%(saturated)s
%(preload)s
%(encoding_nirx)s
%(verbose)s

See Also
Expand All @@ -90,7 +94,7 @@ class RawNIRX(BaseRaw):
"""

@verbose
def __init__(self, fname, saturated, preload=False, verbose=None):
def __init__(self, fname, saturated, *, preload=False, encoding=None, verbose=None):
logger.info(f"Loading {fname}")
_validate_type(fname, "path-like", "fname")
_validate_type(saturated, str, "saturated")
Expand All @@ -102,10 +106,7 @@ def __init__(self, fname, saturated, preload=False, verbose=None):
fname = str(_check_fname(fname, "read", True, "fname", need_dir=True))

json_config = glob.glob(f"{fname}/*{'config.json'}")
if len(json_config):
is_aurora = True
else:
is_aurora = False
is_aurora = len(json_config)

if is_aurora:
# NIRSport2 devices using Aurora software
Expand Down Expand Up @@ -178,7 +179,7 @@ def __init__(self, fname, saturated, preload=False, verbose=None):
# Read header file
# The header file isn't compliant with the configparser. So all the
# text between comments must be removed before passing to parser
with _open(files["hdr"]) as f:
with open(files["hdr"], encoding=encoding) as f:
hdr_str_all = f.read()
hdr_str = re.sub("#.*?#", "", hdr_str_all, flags=re.DOTALL)
if is_aurora:
Expand Down Expand Up @@ -242,6 +243,7 @@ def __init__(self, fname, saturated, preload=False, verbose=None):
'"%a %d %b %Y""%H:%M:%S.%f"',
'"%a, %d %b %Y""%H:%M:%S.%f"',
"%Y-%m-%d %H:%M:%S.%f",
'"%Y年%m月%d日""%H:%M:%S.%f"',
]:
try:
meas_date = dt.datetime.strptime(loc_datetime_str, dt_code)
Expand Down
5 changes: 5 additions & 0 deletions mne/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,11 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
encoding according to the EDF+ standard).
"""

docdict["encoding_nirx"] = """
encoding : str
Text encoding of the NIRX header file. See :ref:`standard-encodings`.
"""

docdict["epochs_preload"] = """
Load all epochs from disk when creating the object
or wait before accessing each epoch (more memory
Expand Down