Repository: mne-tools/mne-python

Issue:
read_raw_brainvision should support mV
While working on https://github.com/bids-standard/pybv/pull/39 (an option to explicitly specify the unit for the exported file), I noticed that `read_raw_brainvision` only supports signals in V, µV or nV, but not mV (https://github.com/mne-tools/mne-python/blob/master/mne/io/brainvision/brainvision.py#L504). Would it be OK if I added the missing mV unit?


Discussion:
sure go for it. We should backport too

cool, thanks for finding the issue @cbrnr 

Resolving patch:
diff --git a/mne/io/brainvision/brainvision.py b/mne/io/brainvision/brainvision.py
--- a/mne/io/brainvision/brainvision.py
+++ b/mne/io/brainvision/brainvision.py
@@ -288,6 +288,7 @@ def _check_bv_version(header, kind):
 _unit_dict = {'V': 1.,  # V stands for Volt
               'µV': 1e-6,
               'uV': 1e-6,
+              'mV': 1e-3,
               'nV': 1e-9,
               'C': 1,  # C stands for celsius
               'µS': 1e-6,  # S stands for Siemens
@@ -501,7 +502,7 @@ def _get_vhdr_info(vhdr_fname, eog, misc, scale):
         orig_units[name] = unit  # Save the original units to expose later
         cals[n] = float(resolution)
         ranges[n] = _unit_dict.get(unit, 1) * scale
-        if unit not in ('V', 'nV', 'µV', 'uV'):
+        if unit not in ('V', 'mV', 'µV', 'uV', 'nV'):
             misc_chs[name] = (FIFF.FIFF_UNIT_CEL if unit == 'C'
                               else FIFF.FIFF_UNIT_NONE)
     misc = list(misc_chs.keys()) if misc == 'auto' else misc


Test patch:
diff --git a/mne/io/brainvision/tests/data/test_nV.vhdr b/mne/io/brainvision/tests/data/test_units.vhdr
similarity index 99%
rename from mne/io/brainvision/tests/data/test_nV.vhdr
rename to mne/io/brainvision/tests/data/test_units.vhdr
--- a/mne/io/brainvision/tests/data/test_nV.vhdr
+++ b/mne/io/brainvision/tests/data/test_units.vhdr
@@ -30,9 +30,9 @@ BinaryFormat=INT_16
 ; Fields are delimited by commas, some fields might be omitted (empty).
 ; Commas in channel names are coded as "\1".
 Ch1=FP1,,500,nV
-Ch2=FP2,,0.5,µV
-Ch3=F3,,0.5,µV
-Ch4=F4,,0.5,µV
+Ch2=FP2,,0.0005,mV
+Ch3=F3,,0.0000005,V
+Ch4=F4,,0.5,uV
 Ch5=C3,,0.5,µV
 Ch6=C4,,0.5,µV
 Ch7=P3,,0.5,µV
diff --git a/mne/io/brainvision/tests/test_brainvision.py b/mne/io/brainvision/tests/test_brainvision.py
--- a/mne/io/brainvision/tests/test_brainvision.py
+++ b/mne/io/brainvision/tests/test_brainvision.py
@@ -50,7 +50,7 @@
 neuroone_vhdr = op.join(data_path, 'Brainvision', 'test_NO.vhdr')
 
 # Test for nanovolts as unit
-vhdr_nV_path = op.join(data_dir, 'test_nV.vhdr')
+vhdr_units_path = op.join(data_dir, 'test_units.vhdr')
 
 # Test bad date
 vhdr_bad_date = op.join(data_dir, 'test_bad_date.vhdr')
@@ -457,15 +457,24 @@ def test_brainvision_data():
     # test loading v2
     read_raw_brainvision(vhdr_v2_path, eog=eog, preload=True,
                          verbose='error')
-    # For the nanovolt unit test we use the same data file with a different
-    # header file.
-    raw_nV = _test_raw_reader(
-        read_raw_brainvision, vhdr_fname=vhdr_nV_path, eog=eog, misc='auto'
+    # test different units with alternative header file
+    raw_units = _test_raw_reader(
+        read_raw_brainvision, vhdr_fname=vhdr_units_path, eog=eog, misc='auto'
     )
-    assert_equal(raw_nV.info['chs'][0]['ch_name'], 'FP1')
-    assert_equal(raw_nV.info['chs'][0]['kind'], FIFF.FIFFV_EEG_CH)
-    data_nanovolt, _ = raw_nV[0]
-    assert_array_almost_equal(data_py[0, :], data_nanovolt[0, :])
+    assert_equal(raw_units.info['chs'][0]['ch_name'], 'FP1')
+    assert_equal(raw_units.info['chs'][0]['kind'], FIFF.FIFFV_EEG_CH)
+    data_units, _ = raw_units[0]
+    assert_array_almost_equal(data_py[0, :], data_units.squeeze())
+
+    assert_equal(raw_units.info['chs'][1]['ch_name'], 'FP2')
+    assert_equal(raw_units.info['chs'][1]['kind'], FIFF.FIFFV_EEG_CH)
+    data_units, _ = raw_units[1]
+    assert_array_almost_equal(data_py[1, :], data_units.squeeze())
+
+    assert_equal(raw_units.info['chs'][2]['ch_name'], 'F3')
+    assert_equal(raw_units.info['chs'][2]['kind'], FIFF.FIFFV_EEG_CH)
+    data_units, _ = raw_units[2]
+    assert_array_almost_equal(data_py[2, :], data_units.squeeze())
 
 
 def test_brainvision_vectorized_data():