Skip to content

Commit d36a43b

Browse files
committed
make it pass
1 parent f15ac0f commit d36a43b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

mne_bids/write.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _should_use_bti_pdf_suffix() -> bool:
136136
return use_pdf_suffix
137137

138138

139-
def _channels_tsv(raw, fname, overwrite=False):
139+
def _channels_tsv(raw, fname, *, convert, overwrite=False):
140140
"""Create a channels.tsv file and save it.
141141
142142
Parameters
@@ -193,10 +193,21 @@ def _channels_tsv(raw, fname, 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._orig_units:
196+
# if raw data is merely copied, check `raw._orig_units`.
197+
if not convert and raw._orig_units:
197198
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)
198204
else:
199-
units = [_unit2human.get(ch_i["unit"], "n/a") for ch_i in raw.info["chs"]]
205+
units = [
206+
"µV"
207+
if ch_i["unit"] == FIFF.FIFF_UNIT_V
208+
else _unit2human.get(ch_i["unit"], "n/a")
209+
for ch_i in raw.info["chs"]
210+
]
200211
units = [u if u not in ["NA"] else "n/a" for u in units]
201212

202213
# Translate from MNE to BIDS unit naming
@@ -2229,7 +2240,6 @@ def write_raw_bids(
22292240
emptyroom_fname=associated_er_path,
22302241
overwrite=overwrite,
22312242
)
2232-
_channels_tsv(raw, channels_path.fpath, overwrite)
22332243

22342244
# create parent directories if needed
22352245
_mkdir_p(os.path.dirname(data_path))
@@ -2288,6 +2298,9 @@ def write_raw_bids(
22882298
f"for {datatype} datatype."
22892299
)
22902300

2301+
# this can't happen until after value of `convert` has been determined
2302+
_channels_tsv(raw, channels_path.fpath, convert=convert, overwrite=overwrite)
2303+
22912304
# raise error when trying to copy files (copyfile_*) into same location
22922305
# (src == dest, see https://github.com/mne-tools/mne-bids/issues/867)
22932306
if (

0 commit comments

Comments
 (0)