Skip to content

Commit 6fc2329

Browse files
authored
Merge pull request #1122 from JuliaSprenger/enh/neuroshare
Make neuroshare robust for non-conform units
2 parents 13d3fe3 + 6600a3b commit 6fc2329

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

neo/io/neurosharectypesio.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ def read_segment(self, import_neuroshare_segment=True,
216216
ctypes.POINTER(ctypes.c_double)))
217217
total_read += pdwContCount.value
218218

219-
signal = pq.Quantity(pData, units=pAnalogInfo.szUnits.decode(), copy=False)
219+
try:
220+
signal = pq.Quantity(pData, units=pAnalogInfo.szUnits.decode(), copy=False)
221+
unit_annotation = None
222+
except LookupError:
223+
signal = pq.Quantity(pData, units='dimensionless', copy=False)
224+
unit_annotation = pAnalogInfo.szUnits.decode()
220225

221226
# t_start
222227
dwIndex = 0
@@ -229,6 +234,8 @@ def read_segment(self, import_neuroshare_segment=True,
229234
name=str(entityInfo.szEntityLabel),
230235
)
231236
anaSig.annotate(probe_info=str(pAnalogInfo.szProbeInfo))
237+
if unit_annotation is not None:
238+
anaSig.annotate(units=unit_annotation)
232239
seg.analogsignals.append(anaSig)
233240

234241
# segment

neo/test/iotest/test_neuroshareio.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ def setUp(self):
6565
raise unittest.SkipTest("Not currently supported on OS X")
6666

6767
def test_with_multichannel(self):
68-
filename0 = self.get_local_path(self.files_to_test[0])
69-
reader = NeuroshareIO(filename0, self.dllname)
70-
blocks = reader.read()
71-
n = len(blocks[0].segments[0].analogsignals)
72-
assert n == 2, \
73-
'For {} , nb AnalogSignal: {} (should be 2)'.format(self.files_to_download[0], n)
68+
for filename in self.files_to_test:
69+
filename = self.get_local_path(filename)
70+
reader = NeuroshareIO(filename, self.dllname)
71+
blocks = reader.read()
72+
n = len(blocks[0].segments[0].analogsignals)
73+
assert n > 0, f'Expect signals in file {filename}'
7474

7575

7676
if __name__ == "__main__":

0 commit comments

Comments
 (0)