Skip to content

Commit

Permalink
Merge pull request NeuralEnsemble#169 from toddrjen/apibreak
Browse files Browse the repository at this point in the history
Fixes for brainware IO and enable working modules.
  • Loading branch information
toddrjen committed Jun 27, 2014
2 parents cc962c9 + d0a15b2 commit 40c1c85
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 95 deletions.
69 changes: 35 additions & 34 deletions neo/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,66 +69,67 @@
import os.path


#from neo.io.alphaomegaio import AlphaOmegaIO
#from neo.io.asciisignalio import AsciiSignalIO
#from neo.io.asciispiketrainio import AsciiSpikeTrainIO
from neo.io.alphaomegaio import AlphaOmegaIO
from neo.io.asciisignalio import AsciiSignalIO
from neo.io.asciispiketrainio import AsciiSpikeTrainIO
#from neo.io.axonio import AxonIO
#from neo.io.blackrockio import BlackrockIO
from neo.io.blackrockio import BlackrockIO
#from neo.io.brainvisionio import BrainVisionIO
#from neo.io.brainwaredamio import BrainwareDamIO
#from neo.io.brainwaref32io import BrainwareF32IO
#from neo.io.brainwaresrcio import BrainwareSrcIO
from neo.io.brainwaredamio import BrainwareDamIO
from neo.io.brainwaref32io import BrainwareF32IO
from neo.io.brainwaresrcio import BrainwareSrcIO
#from neo.io.elanio import ElanIO
#from neo.io.elphyio import ElphyIO
#from neo.io.exampleio import ExampleIO
#from neo.io.klustakwikio import KlustaKwikIO
from neo.io.exampleio import ExampleIO
from neo.io.klustakwikio import KlustaKwikIO
#from neo.io.micromedio import MicromedIO
#from neo.io.hdf5io import NeoHdf5IO
#from neo.io.neomatlabio import NeoMatlabIO
#from neo.io.neuroexplorerio import NeuroExplorerIO
#from neo.io.neuroscopeio import NeuroScopeIO
from neo.io.neuroscopeio import NeuroScopeIO
#from neo.io.neuroshareio import NeuroshareIO
#from neo.io.pickleio import PickleIO
from neo.io.pickleio import PickleIO
#from neo.io.plexonio import PlexonIO
#from neo.io.pynnio import PyNNNumpyIO
#from neo.io.pynnio import PyNNTextIO
#from neo.io.rawbinarysignalio import RawBinarySignalIO
from neo.io.pynnio import PyNNNumpyIO
from neo.io.pynnio import PyNNTextIO
from neo.io.rawbinarysignalio import RawBinarySignalIO
#from neo.io.spike2io import Spike2IO
#from neo.io.stimfitio import StimfitIO
from neo.io.stimfitio import StimfitIO
#from neo.io.tdtio import TdtIO
#from neo.io.winedrio import WinEdrIO
#from neo.io.winwcpio import WinWcpIO
from neo.io.winedrio import WinEdrIO
from neo.io.winwcpio import WinWcpIO


#iolist = [AlphaOmegaIO,
#AsciiSignalIO,
#AsciiSpikeTrainIO,
iolist = [AlphaOmegaIO,
AsciiSignalIO,
AsciiSpikeTrainIO,
#AxonIO,
#BlackrockIO,
BlackrockIO,
#BrainVisionIO,
#BrainwareDamIO,
#BrainwareF32IO,
#BrainwareSrcIO,
BrainwareDamIO,
BrainwareF32IO,
BrainwareSrcIO,
#ElanIO,
#ElphyIO,
#ExampleIO,
#KlustaKwikIO,
ExampleIO,
KlustaKwikIO,
#MicromedIO,
#NeoHdf5IO,
#NeoMatlabIO,
#NeuroExplorerIO,
#NeuroScopeIO,
NeuroScopeIO,
#NeuroshareIO,
#PickleIO,
PickleIO,
#PlexonIO,
#PyNNNumpyIO,
#PyNNTextIO,
#RawBinarySignalIO,
PyNNNumpyIO,
PyNNTextIO,
RawBinarySignalIO,
#Spike2IO,
#StimfitIO,
StimfitIO,
#TdtIO,
#WinEdrIO,
#WinWcpIO]
WinEdrIO,
WinWcpIO
]


def get_io(filename):
Expand Down
2 changes: 1 addition & 1 deletion neo/io/baseio.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from neo import logging_handler
from neo.core import (AnalogSignal, AnalogSignalArray, Block,
Epoch, Event, EventArray,
Epoch, Event,
IrregularlySampledSignal,
RecordingChannel, RecordingChannelGroup,
Segment, SpikeTrain, Unit)
Expand Down
84 changes: 41 additions & 43 deletions neo/io/brainwaresrcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import quantities as pq

# needed core neo modules
from neo.core import (Block, EventArray, RecordingChannel,
from neo.core import (Block, Event, RecordingChannel,
RecordingChannelGroup, Segment, SpikeTrain, Unit)

# need to subclass BaseIO
Expand Down Expand Up @@ -84,7 +84,7 @@ class BrainwareSrcIO(BaseIO):
Note 2:
The first Segment in each Block is always Comments, which stores all
comments as an EventArray object.
comments as an Event object.
Note 3:
The parameters from the BrainWare table for each condition are stored
Expand Down Expand Up @@ -117,7 +117,7 @@ class BrainwareSrcIO(BaseIO):
# This class is able to directly or indirectly handle the following objects
# You can notice that this greatly simplifies the full Neo object hierarchy
supported_objects = [Block, RecordingChannel, RecordingChannelGroup,
Segment, SpikeTrain, EventArray, Unit]
Segment, SpikeTrain, Event, Unit]

readable_objects = [Block]
writeable_objects = []
Expand Down Expand Up @@ -328,8 +328,8 @@ def read_next_block(self, cascade=True, lazy=False, **kargs):
self._rcg = None
self._unitdict = {}

# combine the comments into one big eventarray
self._combine_segment_eventarrays(self._seg0)
# combine the comments into one big event
self._combine_segment_events(self._seg0)

# result is None iff the end of the file is reached, so we can
# close the file
Expand Down Expand Up @@ -409,7 +409,6 @@ def _convert_timestamp(self, timestamp, start_date=datetime(1899, 12, 30)):
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------

#@profile
def _read_by_id(self):
"""
Reader for generic data
Expand Down Expand Up @@ -484,23 +483,23 @@ def _assign_sequence(self, data_obj):
self._unitdict[data_obj.name] = data_obj
elif isinstance(data_obj, Segment):
self.logger.warning('Unknown Segment found, '
'adding to Segments list')
'adding to Segments list')
self._blk.segments.append(data_obj)
elif isinstance(data_obj, EventArray):
self.logger.warning('Unknown EventArray found, '
'adding to comment Events list')
self._seg0.eventarrays.append(data_obj)
elif isinstance(data_obj, Event):
self.logger.warning('Unknown Event found, '
'adding to comment Events list')
self._seg0.events.append(data_obj)
elif isinstance(data_obj, SpikeTrain):
self.logger.warning('Unknown SpikeTrain found, '
'adding to the UnassignedSpikes Unit')
'adding to the UnassignedSpikes Unit')
self._unit0.spiketrains.append(data_obj)
elif hasattr(data_obj, '__iter__') and not isinstance(data_obj, str):
for sub_obj in data_obj:
self._assign_sequence(sub_obj)
else:
if self.logger.isEnabledFor(logging.WARNING):
self.logger.warning('Unrecognized sequence of type %s found, '
'skipping', type(data_obj))
'skipping', type(data_obj))

_default_datetime = datetime(1, 1, 1)
_default_t_start = pq.Quantity(0., units=pq.ms, dtype=np.float32)
Expand All @@ -522,24 +521,24 @@ def _assign_sequence(self, data_obj):
dtype=np.uint8),
side='')

def _combine_eventarrays(self, eventarrays):
def _combine_events(self, events):
"""
_combine_eventarrays(eventarrays) - combine a list of EventArrays
with single events into one long EventArray
_combine_events(events) - combine a list of Events
with single events into one long Event
"""
if not eventarrays or self._lazy:
eventarray = EventArray(times=pq.Quantity([], units=pq.s),
labels=np.array([], dtype='S'),
senders=np.array([], dtype='S'),
t_start=0)
if not events or self._lazy:
event = Event(times=pq.Quantity([], units=pq.s),
labels=np.array([], dtype='S'),
senders=np.array([], dtype='S'),
t_start=0)
if self._lazy:
eventarray.lazy_shape = len(eventarrays)
return eventarray
event.lazy_shape = len(events)
return event

times = []
labels = []
senders = []
for event in eventarrays:
for event in events:
times.append(event.times.magnitude)
labels.append(event.labels)
senders.append(event.annotations['sender'])
Expand All @@ -551,21 +550,21 @@ def _combine_eventarrays(self, eventarrays):
labels = np.array(labels)
senders = np.array(senders)

eventarray = EventArray(times=times, labels=labels,
t_start=t_start.tolist(), senders=senders)
event = Event(times=times, labels=labels,
t_start=t_start.tolist(), senders=senders)

return eventarray
return event

def _combine_segment_eventarrays(self, segment):
def _combine_segment_events(self, segment):
"""
_combine_segment_eventarrays(segment)
Combine all EventArrays in a segment.
_combine_segment_events(segment)
Combine all Events in a segment.
"""
eventarray = self._combine_eventarrays(segment.eventarrays)
eventarray_t_start = eventarray.annotations.pop('t_start')
segment.rec_datetime = self._convert_timestamp(eventarray_t_start)
segment.eventarrays = [eventarray]
eventarray.segment = segment
event = self._combine_events(segment.events)
event_t_start = event.annotations.pop('t_start')
segment.rec_datetime = self._convert_timestamp(event_t_start)
segment.events = [event]
event.segment = segment

def _combine_spiketrains(self, spiketrains):
"""
Expand Down Expand Up @@ -769,7 +768,7 @@ def __read_comment(self):
"""
Read a single comment.
The comment is stored as an EventArray in Segment 0, which is
The comment is stored as an Event in Segment 0, which is
specifically for comments.
----------------------
Expand Down Expand Up @@ -797,11 +796,10 @@ def __read_comment(self):
# char * numchars -- comment text
text = self.__read_str(numchars2, utf=False)

comment = EventArray(times=pq.Quantity(time, units=pq.d), labels=text,
sender=sender,
file_origin=self._file_origin)
comment = Event(times=pq.Quantity(time, units=pq.d), labels=text,
sender=sender, file_origin=self._file_origin)

self._seg0.eventarrays.append(comment)
self._seg0.events.append(comment)

return []

Expand Down Expand Up @@ -847,7 +845,7 @@ def __read_list(self):
if not self._damaged and numelements < 0:
self._damaged = True
self.logger.error('Negative sequence count %s, file damaged',
numelements)
numelements)

if not self._damaged:
# read the sequences into a list
Expand Down Expand Up @@ -923,7 +921,7 @@ def __read_segment(self):
# create an empty spike train
trains = [[self._default_spiketrain.copy()]]
elif hasattr(trains[0], 'dtype'):
#workaround for some broken files
# workaround for some broken files
trains = [unassigned_spikes +
[self._combine_spiketrains([trains])]]
else:
Expand Down Expand Up @@ -1211,7 +1209,7 @@ def __read_spiketrain_indexed(self):
ID: 29121
"""

#int32 -- index of the analogsignalarray in corresponding .dam file
# int32 -- index of the analogsignalarray in corresponding .dam file
dama_index = np.fromfile(self._fsrc, dtype=np.int32,
count=1)[0]

Expand Down
24 changes: 12 additions & 12 deletions neo/io/exampleio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
For the user, it generates a :class:`Segment` or a :class:`Block` with a
sinusoidal :class:`AnalogSignal`, a :class:`SpikeTrain` and an
:class:`EventArray`.
:class:`Event`.
For a developer, it is just an example showing guidelines for someone who wants
to develop a new IO module.
Expand Down Expand Up @@ -38,7 +38,7 @@
from neo.io.baseio import BaseIO

# to import from core
from neo.core import Segment, AnalogSignal, SpikeTrain, EventArray
from neo.core import Segment, AnalogSignal, SpikeTrain, Event


# I need to subclass BaseIO
Expand All @@ -48,7 +48,7 @@ class ExampleIO(BaseIO):
For the user, it generates a :class:`Segment` or a :class:`Block` with a
sinusoidal :class:`AnalogSignal`, a :class:`SpikeTrain` and an
:class:`EventArray`.
:class:`Event`.
For a developer, it is just an example showing guidelines for someone who wants
to develop a new IO module.
Expand All @@ -68,21 +68,21 @@ class ExampleIO(BaseIO):
[<SpikeTrain(array([ -0.83799524, 6.24017951, 7.76366686, 4.45573701,
12.60644415, 10.68328994, 8.07765735, 4.89967804,
...
>>> print(seg.eventarrays) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
[<EventArray: TriggerB@9.6976 s, TriggerA@10.2612 s, TriggerB@2.2777 s, TriggerA@6.8607 s, ...
>>> print(seg.events) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
[<Event: TriggerB@9.6976 s, TriggerA@10.2612 s, TriggerB@2.2777 s, TriggerA@6.8607 s, ...
>>> anasig = r.read_analogsignal(lazy=True, cascade=False)
>>> print(anasig._data_description)
{'shape': (150000,)}
>>> anasig = r.read_analogsignal(lazy=False, cascade=False)
"""

is_readable = True # This class can only read data
is_writable = False # write is not supported
is_readable = True # This class can only read data
is_writable = False # write is not supported

# This class is able to directly or indirectly handle the following objects
# You can notice that this greatly simplifies the full Neo object hierarchy
supported_objects = [ Segment , AnalogSignal, SpikeTrain, EventArray ]
supported_objects = [ Segment , AnalogSignal, SpikeTrain, Event ]

# This class can return either a Block or a Segment
# The first one is the default ( self.read )
Expand Down Expand Up @@ -198,10 +198,10 @@ def read_segment(self,
seg.spiketrains += [ sptr ]


# create an EventArray that mimic triggers.
# note that ExampleIO do not allow to acess directly to EventArray
# create an Event that mimic triggers.
# note that ExampleIO do not allow to acess directly to Event
# for that you need read_segment(cascade = True)
eva = EventArray()
eva = Event()
if lazy:
# in lazy case no data are readed
# eva is empty
Expand All @@ -221,7 +221,7 @@ def read_segment(self,
else : l.append( 'TriggerB' )
eva.labels = np.array( l )

seg.eventarrays += [ eva ]
seg.events += [ eva ]

seg.create_many_to_one_relationship()
return seg
Expand Down
Loading

0 comments on commit 40c1c85

Please sign in to comment.