Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions neo/io/neomatlabio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
SCIPY_ERR = None

from neo.io.baseio import BaseIO
from neo.core import (Block, Segment, AnalogSignal, Event, Epoch, SpikeTrain,
objectnames, class_by_name)
from neo.core import (Block, Segment, AnalogSignal, IrregularlySampledSignal,
Event, Epoch, SpikeTrain, objectnames, class_by_name)

classname_lower_to_upper = {}
for k in objectnames:
Expand Down Expand Up @@ -190,7 +190,8 @@ class NeoMatlabIO(BaseIO):
is_readable = True
is_writable = True

supported_objects = [Block, Segment, AnalogSignal, Epoch, Event, SpikeTrain]
supported_objects = [Block, Segment, AnalogSignal, IrregularlySampledSignal,
Epoch, Event, SpikeTrain]
readable_objects = [Block]
writeable_objects = [Block]

Expand Down Expand Up @@ -251,6 +252,10 @@ def write_block(self, bl, **kargs):
anasig_struct = self.create_struct_from_obj(anasig)
seg_struct['analogsignals'].append(anasig_struct)

for irrsig in seg.irregularlysampledsignals:
irrsig_struct = self.create_struct_from_obj(irrsig)
seg_struct['irregularlysampledsignals'].append(irrsig_struct)

for ea in seg.events:
ea_struct = self.create_struct_from_obj(ea)
seg_struct['events'].append(ea_struct)
Expand Down Expand Up @@ -348,7 +353,13 @@ def create_ob_from_struct(self, struct, classname):
else:
data_complement["t_start"] = 0.0

ob = cl(arr, **data_complement)
if "times" in (at[0] for at in cl._necessary_attrs) and quantity_attr != "times":
# handle IrregularlySampledSignal
times = getattr(struct, "times")
data_complement["time_units"] = getattr(struct, "times_units")
ob = cl(times, arr, **data_complement)
else:
ob = cl(arr, **data_complement)
else:
ob = cl()

Expand Down
17 changes: 16 additions & 1 deletion neo/test/iotest/test_neomatlabio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"""

import unittest

from numpy.testing import assert_array_equal
import quantities as pq

from neo.core.analogsignal import AnalogSignal
from neo.core.irregularlysampledsignal import IrregularlySampledSignal
from neo import Block, Segment, SpikeTrain
from neo.test.iotest.common_io_test import BaseTestIO
from neo.io.neomatlabio import NeoMatlabIO, HAVE_SCIPY
Expand All @@ -21,8 +24,12 @@ def test_write_read_single_spike(self):
seg = Segment('segment1')
spiketrain1 = SpikeTrain([1] * pq.s, t_stop=10 * pq.s, sampling_rate=1 * pq.Hz)
spiketrain1.annotate(yep='yop')
sig1 = AnalogSignal([4, 5, 6] * pq.A, sampling_period=1 * pq.ms)
irrsig1 = IrregularlySampledSignal([0, 1, 2] * pq.ms, [4, 5, 6] * pq.A)
block1.segments.append(seg)
seg.spiketrains.append(spiketrain1)
seg.analogsignals.append(sig1)
seg.irregularlysampledsignals.append(irrsig1)

# write block
filename = self.get_local_path('matlabiotestfile.mat')
Expand All @@ -36,6 +43,14 @@ def test_write_read_single_spike(self):
self.assertEqual(block1.segments[0].spiketrains[0],
block2.segments[0].spiketrains[0])

assert_array_equal(block1.segments[0].analogsignals[0],
block2.segments[0].analogsignals[0])

assert_array_equal(block1.segments[0].irregularlysampledsignals[0].magnitude,
block2.segments[0].irregularlysampledsignals[0].magnitude)
assert_array_equal(block1.segments[0].irregularlysampledsignals[0].times,
block2.segments[0].irregularlysampledsignals[0].times)

# test annotations
spiketrain2 = block2.segments[0].spiketrains[0]
assert 'yep' in spiketrain2.annotations
Expand Down