Skip to content

Commit f186271

Browse files
committed
improve logic and comment
1 parent d36a43b commit f186271

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

mne_bids/write.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,31 @@ def _channels_tsv(raw, fname, *, convert, overwrite=False):
193193
ch_type.append(map_chs[_channel_type])
194194
description.append(map_desc[_channel_type])
195195
low_cutoff, high_cutoff = (raw.info["highpass"], raw.info["lowpass"])
196-
# if raw data is merely copied, check `raw._orig_units`.
197-
if not convert and raw._orig_units:
198-
units = [raw._orig_units.get(ch, "n/a") for ch in raw.ch_names]
199-
# If `raw._orig_units` is missing (or if data are being *converted*),
200-
# unit is determined by destination format:
201-
# - `eeglabio.raw.export_set` always converts V to uV
202-
# - `mne.export._edf_bdf._export_raw_edf_bdf` always converts V to uV
203-
# - `pybv.write_brainvision` converts V to uV by default (and we don't alter that)
204-
else:
196+
# If data are being *converted*, unit is determined by destination format:
197+
# - `eeglabio.raw.export_set` always converts V to µV, cf:
198+
# https://github.com/jackz314/eeglabio/blob/3961bb29daf082767ea44e7c7d9da2df10971c37/eeglabio/raw.py#L57
199+
#
200+
# - `mne.export._edf_bdf._export_raw_edf_bdf` always converts V to µV, cf:
201+
# https://github.com/mne-tools/mne-python/blob/1b921f4af5154bad40202d87428a2583ef896a00/mne/export/_edf_bdf.py#L61-L63
202+
#
203+
# - `pybv.write_brainvision` converts V to µV by default (and we don't alter that)
204+
# https://github.com/bids-standard/pybv/blob/2832c80ee00d12990a8c79f12c843c0d4ddc825b/pybv/io.py#L40
205+
# https://github.com/mne-tools/mne-bids/blob/1e0a96e132fc904ba856d42beaa9ddddb985f1ed/mne_bids/write.py#L1279-L1280
206+
if convert:
205207
units = [
206208
"µV"
207209
if ch_i["unit"] == FIFF.FIFF_UNIT_V
208210
else _unit2human.get(ch_i["unit"], "n/a")
209211
for ch_i in raw.info["chs"]
210212
]
211-
units = [u if u not in ["NA"] else "n/a" for u in units]
213+
# if raw data is merely copied, check `raw._orig_units`
214+
elif raw._orig_units:
215+
units = [raw._orig_units.get(ch, "n/a") for ch in raw.ch_names]
216+
# If `raw._orig_units` is missing, assume SI units
217+
else:
218+
units = [_unit2human.get(ch_i["unit"], "n/a") for ch_i in raw.info["chs"]]
219+
# fixup "NA" (from `_unit2human`) → "n/a"
220+
units = [u if u not in ["NA"] else "n/a" for u in units]
212221

213222
# Translate from MNE to BIDS unit naming
214223
for idx, mne_unit in enumerate(units):

0 commit comments

Comments
 (0)