Skip to content

Commit 9c7eb51

Browse files
authored
Merge pull request #1466 from PeterNSteinmetz/fixNeuroscopeSignalScale
Neuroscope: fix scale of signals.
2 parents 53f4dcd + d82d09b commit 9c7eb51

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

neo/rawio/neuroscoperawio.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ def _parse_header(self):
9292
for xml_rc in xml_chx:
9393
channel_group[int(xml_rc.text)] = grp_index
9494

95+
sig_dtype = "int16"
96+
# scale to convert sample values to voltage in mV = range of recording in volts *
97+
# 1000 mV/V /(number of bits * amplification)
9598
if nbits == 16:
96-
sig_dtype = "int16"
97-
gain = voltage_range / (2**16) / amplification / 1000.0
99+
gain = voltage_range * 1000 / (2**nbits) / amplification
98100
# ~ elif nbits==32:
99101
# Not sure if it is int or float
100102
# ~ dt = 'int32'

neo/test/rawiotest/test_neuroscoperawio.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import unittest
21
import logging
2+
import os
33
from pathlib import Path
4+
import unittest
45

56
from neo.rawio.neuroscoperawio import NeuroScopeRawIO
67
from neo.test.rawiotest.common_rawio_test import BaseTestRawIO
@@ -17,6 +18,17 @@ class TestNeuroScopeRawIO(BaseTestRawIO, unittest.TestCase):
1718
"neuroscope/dataset_1/YutaMouse42-151117.eeg",
1819
]
1920

21+
def test_signal_scale(self):
22+
local_test_dir = get_local_testing_data_folder()
23+
fname = os.path.join(local_test_dir, "neuroscope/test1/test1.xml")
24+
reader = NeuroScopeRawIO(filename=fname)
25+
reader.parse_header()
26+
27+
gain = reader.header['signal_channels'][0]['gain']
28+
29+
# scale is in mV = range of recording in volts * 1000 mV/V /(number of bits * ampification)
30+
self.assertAlmostEqual(20.0 * 1000 / (2**16 * 1000), gain)
31+
2032
def test_binary_argument_with_non_canonical_xml_file(self):
2133

2234
local_test_dir = get_local_testing_data_folder()

0 commit comments

Comments
 (0)