Skip to content

Commit

Permalink
Remove ChannelIndex, Unit; simplify object generation for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Mar 22, 2021
1 parent 7a1cd85 commit dae4a6b
Show file tree
Hide file tree
Showing 45 changed files with 851 additions and 5,007 deletions.
90 changes: 0 additions & 90 deletions neo/converter.py

This file was deleted.

12 changes: 2 additions & 10 deletions neo/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,10 @@
.. autoclass:: CircularRegionOfInterest
.. autoclass:: PolygonRegionOfInterest
Deprecated classes:
.. autoclass:: ChannelIndex
.. autoclass:: Unit
"""

from neo.core.block import Block
from neo.core.segment import Segment
from neo.core.channelindex import ChannelIndex
from neo.core.unit import Unit

from neo.core.analogsignal import AnalogSignal
from neo.core.irregularlysampledsignal import IrregularlySampledSignal

Expand All @@ -55,9 +47,9 @@
from neo.core.group import Group

# Block should always be first in this list
objectlist = [Block, Segment, ChannelIndex,
objectlist = [Block, Segment,
AnalogSignal, IrregularlySampledSignal,
Event, Epoch, Unit, SpikeTrain, ImageSequence,
Event, Epoch, SpikeTrain, ImageSequence,
RectangularRegionOfInterest, CircularRegionOfInterest,
PolygonRegionOfInterest, ChannelView, Group]

Expand Down
24 changes: 4 additions & 20 deletions neo/core/analogsignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _get_sampling_rate(sampling_rate, sampling_period):
def _new_AnalogSignalArray(cls, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s,
sampling_rate=None, sampling_period=None, name=None, file_origin=None,
description=None, array_annotations=None, annotations=None,
channel_index=None, segment=None):
segment=None):
'''
A function to map AnalogSignal.__new__ to function that
does not do the unit checking. This is needed for pickle to work.
Expand All @@ -68,7 +68,6 @@ def _new_AnalogSignalArray(cls, signal, units=None, dtype=None, copy=True, t_sta
sampling_period=sampling_period, name=name,
file_origin=file_origin, description=description,
array_annotations=array_annotations, **annotations)
obj.channel_index = channel_index
obj.segment = segment
return obj

Expand Down Expand Up @@ -140,9 +139,6 @@ class AnalogSignal(BaseSignal):
:times: (quantity 1D) The time points of each sample of the signal,
read-only.
(:attr:`t_start` + arange(:attr:`shape`[0])/:attr:`sampling_rate`)
:channel_index:
(deprecated) access to the channel_index attribute of the principal ChannelIndex
associated with this signal.
*Slicing*:
:class:`AnalogSignal` objects can be sliced. When taking a single
Expand All @@ -160,8 +156,8 @@ class AnalogSignal(BaseSignal):
'''

_parent_objects = ('Segment', 'ChannelIndex')
_parent_attrs = ('segment', 'channel_index')
_parent_objects = ('Segment',)
_parent_attrs = ('segment',)
_quantity_attr = 'signal'
_necessary_attrs = (('signal', pq.Quantity, 2),
('sampling_rate', pq.Quantity, 0),
Expand Down Expand Up @@ -192,7 +188,6 @@ def __new__(cls, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s,
obj._sampling_rate = _get_sampling_rate(sampling_rate, sampling_period)

obj.segment = None
obj.channel_index = None
return obj

def __init__(self, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s,
Expand Down Expand Up @@ -220,7 +215,7 @@ def __reduce__(self):
True, self.t_start, self.sampling_rate,
self.sampling_period, self.name, self.file_origin,
self.description, self.array_annotations,
self.annotations, self.channel_index, self.segment)
self.annotations, self.segment)

def _array_finalize_spec(self, obj):
'''
Expand All @@ -244,14 +239,6 @@ def __repr__(self):
self.t_start, self.t_stop,
self.sampling_rate))

def get_channel_index(self):
"""
"""
if self.channel_index:
return self.channel_index.index
else:
return None

def __getitem__(self, i):
'''
Get the item or slice :attr:`i`.
Expand All @@ -278,8 +265,6 @@ def __getitem__(self, i):
raise TypeError("%s not supported" % type(j))
if isinstance(k, (int, np.integer)):
obj = obj.reshape(-1, 1)
if self.channel_index:
obj.channel_index = self.channel_index.__getitem__(k)
obj.array_annotate(**deepcopy(self.array_annotations_at_index(k)))
elif isinstance(i, slice):
obj = super().__getitem__(i)
Expand Down Expand Up @@ -534,7 +519,6 @@ def splice(self, signal, copy=False):
if copy:
new_signal = deepcopy(self)
new_signal.segment = None
new_signal.channel_index = None
new_signal[i:j, :] = signal
return new_signal
else:
Expand Down
10 changes: 2 additions & 8 deletions neo/core/baseneo.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ def _reference_name(class_name):
`segment.block`. The attribute name `block` is obtained by calling
`_container_name("Block")`.
"""
name_map = {
"ChannelIndex": "channel_index"
}
return name_map.get(class_name, class_name.lower())
return class_name.lower()


def _container_name(class_name):
Expand All @@ -159,10 +156,7 @@ def _container_name(class_name):
referenced by `block.segments`. The attribute name `segments` is
obtained by calling `_container_name_plural("Segment")`.
"""
name_map = {
"ChannelIndex": "channel_indexes"
}
return name_map.get(class_name, _reference_name(class_name) + 's')
return _reference_name(class_name) + 's'


class BaseNeo:
Expand Down
19 changes: 0 additions & 19 deletions neo/core/basesignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from neo.core.baseneo import MergeError, merge_annotations
from neo.core.dataobject import DataObject, ArrayDict
from neo.core.channelindex import ChannelIndex

logger = logging.getLogger("Neo")

Expand Down Expand Up @@ -80,7 +79,6 @@ def __array_finalize__(self, obj):

# Parent objects
self.segment = getattr(obj, 'segment', None)
self.channel_index = getattr(obj, 'channel_index', None)

@classmethod
def _rescale(self, signal, units=None):
Expand All @@ -100,11 +98,6 @@ def _rescale(self, signal, units=None):
signal = signal.rescale(units)
return signal

def rescale(self, units):
obj = super().rescale(units)
obj.channel_index = self.channel_index
return obj

def __getslice__(self, i, j):
'''
Get a slice from :attr:`i` to :attr:`j`.attr[0]
Expand Down Expand Up @@ -279,18 +272,6 @@ def merge(self, other):
if hasattr(self, "lazy_shape"):
signal.lazy_shape = merged_lazy_shape

# merge channel_index (move to ChannelIndex.merge()?)
if self.channel_index and other.channel_index:
signal.channel_index = ChannelIndex(index=np.arange(signal.shape[1]),
channel_ids=np.hstack(
[self.channel_index.channel_ids,
other.channel_index.channel_ids]),
channel_names=np.hstack(
[self.channel_index.channel_names,
other.channel_index.channel_names]))
else:
signal.channel_index = ChannelIndex(index=np.arange(signal.shape[1]))

return signal

def time_slice(self, t_start, t_stop):
Expand Down
22 changes: 4 additions & 18 deletions neo/core/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,17 @@ class Block(Container):
data file.
:rec_datetime: (datetime) The date and time of the original recording.
*Properties available on this object*:
:list_units: (deprecated) descends through hierarchy and returns a list of
:class:`Unit` objects existing in the block. This shortcut exists
because a common analysis case is analyzing all neurons that
you recorded in a session.
Note: Any other additional arguments are assumed to be user-specific
metadata and stored in :attr:`annotations`.
*Container of*:
:class:`Segment`
:class:`Group`
:class:`ChannelIndex` (deprecated)
'''

_container_child_objects = ('Segment', 'ChannelIndex', 'Group')
_child_properties = ('Unit',)
_container_child_objects = ('Segment', 'Group')
_child_properties = ()
_recommended_attrs = ((('file_datetime', datetime),
('rec_datetime', datetime),
('index', int)) +
Expand Down Expand Up @@ -104,7 +97,7 @@ def data_children_recur(self):
obtained recursively.
'''
# subclassing this to remove duplicate objects such as SpikeTrain
# objects in both Segment and Unit
# objects in both Segment and Group
# Only Block can have duplicate items right now, so implement
# this here for performance reasons.
return tuple(unique_objs(super().data_children_recur))
Expand All @@ -117,14 +110,7 @@ def list_children_by_class(self, cls):
or the name of the container storing the class.
'''
# subclassing this to remove duplicate objects such as SpikeTrain
# objects in both Segment and Unit
# objects in both Segment and Group
# Only Block can have duplicate items right now, so implement
# this here for performance reasons.
return unique_objs(super().list_children_by_class(cls))

@property
def list_units(self):
'''
Return a list of all :class:`Unit` objects in the :class:`Block`.
'''
return self.list_children_by_class('unit')
Loading

0 comments on commit dae4a6b

Please sign in to comment.