Skip to content

Commit

Permalink
Renamed variables called rcg (for RecordingChannelGroup) to chx (…
Browse files Browse the repository at this point in the history
…for ChannelIndex).
  • Loading branch information
apdavison committed Feb 21, 2016
1 parent 185ac01 commit 57fc637
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 172 deletions.
16 changes: 8 additions & 8 deletions doc/source/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ In some cases, a one-to-many relationship is sufficient. Here is a simple exampl
# the four tetrodes
for i in range(4):
rcg = ChannelIndex(name = 'Tetrode %d' % i,
chx = ChannelIndex(name = 'Tetrode %d' % i,
channel_indexes=[0, 1, 2, 3])
bl.channelindexes.append(rcg)
bl.channelindexes.append(chx)

# now we load the data and associate it with the created channels
# ...
Expand All @@ -136,16 +136,16 @@ Now consider a more complex example: a 1x4 silicon probe, with a neuron on chann
bl = Block(name='probe data')

# one group for each neuron
rcg0 = ChannelIndex(name='Group 0',
chx0 = ChannelIndex(name='Group 0',
channel_indexes=[0, 1, 2])
bl.channelindexes.append(rcg0)
bl.channelindexes.append(chx0)

rcg1 = ChannelIndex(name='Group 1',
chx1 = ChannelIndex(name='Group 1',
channel_indexes=[1, 2, 3])
bl.channelindexes.append(rcg1)
bl.channelindexes.append(chx1)

# now we add the spiketrain from Unit 0 to rcg0
# and add the spiketrain from Unit 1 to rcg1
# now we add the spiketrain from Unit 0 to chx0
# and add the spiketrain from Unit 1 to chx1
# ...

Note that because neurons are sorted from groups of channels in this situation, it is natural that the :py:class:`ChannelIndex` contains a reference to the :py:class:`Unit` object.
Expand Down
24 changes: 12 additions & 12 deletions doc/source/usecases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ Perhaps you want to see which physical location produces the strongest response,
.. doctest::

# We assume that our block has only 1 ChannelIndex
rcg = block.channelindexes[0]:
chx = block.channelindexes[0]:

index = rcg.channel_indexes
siglist = [sig[:, index] for sig in rcg.analogsignals]
index = chx.channel_indexes
siglist = [sig[:, index] for sig in chx.analogsignals]
avg = np.mean(siglist, axis=0)

plt.figure()
for index, name in zip(rcg.channel_indexes, rcg.channel_names):
for index, name in zip(chx.channel_indexes, chx.channel_names):
plt.plot(avg[:, index])
plt.title("Average response on channels %s: %s' % (index, name)

Expand All @@ -75,7 +75,7 @@ during the experiment and you want to follow up. What was the average response?

.. doctest::

index = rcg.channel_indexes[5]
index = chx.channel_indexes[5]
avg = np.mean([seg.analogsignals[0][:, index] for seg in block.segments[::2]], axis=1)
plt.plot(avg)

Expand Down Expand Up @@ -142,14 +142,14 @@ blending all units:

.. doctest::

for rcg in block.channelindexes:
for chx in block.channelindexes:
stlist = []
for unit in rcg.units:
for unit in chx.units:
stlist.extend([st - st.t_start for st in unit.spiketrains])
plt.figure()
count, bins = np.histogram(stlist)
plt.bar(bins[:-1], count, width=bins[1] - bins[0])
plt.title("PSTH blend of tetrode %s" % rcg.name)
plt.title("PSTH blend of tetrode %s" % chx.name)


Spike sorting
Expand Down Expand Up @@ -177,13 +177,13 @@ how you could iterate over the contained signals and extract spike times.
[0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1]],
sampling_rate=1000*Hz, units='V'))
rcg = ChannelIndex(channel_indexes=[0, 1, 2, 3])
rcg.analogsignals.append(seg.analogsignals[0])
chx = ChannelIndex(channel_indexes=[0, 1, 2, 3])
chx.analogsignals.append(seg.analogsignals[0])


# extract spike trains from each channel
st_list = []
for signal in rcg.analogsignals:
for signal in chx.analogsignals:
# use a simple threshhold detector
spike_mask = np.where(np.min(signal.magnitude, axis=1) < -1.0)[0] # note, np.min(Quantity) is borked

Expand All @@ -207,7 +207,7 @@ Unit to the group on which we detected it.

u = Unit()
u.spiketrains = st_list
rcg.units.append(u)
chx.units.append(u)

Now the recording channel group (tetrode) contains a list of analogsignals,
and a single Unit object containing all of the detected spiketrains from those
Expand Down
22 changes: 11 additions & 11 deletions examples/generated_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ def generate_block(n_segments=3, n_channels=8, n_units=3,
# Create container and grouping objects
segments = [neo.Segment(index=i) for i in range(n_segments)]

rcg = neo.ChannelIndex(name='T0')
chx = neo.ChannelIndex(name='T0')
for i in range(n_channels):
rc = neo.RecordingChannel(name='C%d' % i, index=i)
rc.channelindexes = [rcg]
rcg.recordingchannels.append(rc)
rc.channelindexes = [chx]
chx.recordingchannels.append(rc)

units = [neo.Unit('U%d' % i) for i in range(n_units)]
rcg.units = units
chx.units = units

block = neo.Block()
block.segments = segments
block.channel_indexes = [rcg]
block.channel_indexes = [chx]

# Create synthetic data
for seg in segments:
feature_pos = np.random.randint(0, data_samples - feature_samples)

# Analog signals: Noise with a single sinewave feature
wave = 3 * np.sin(np.linspace(0, 2 * np.pi, feature_samples))
for rc in rcg.recordingchannels:
for rc in chx.recordingchannels:
sig = np.random.randn(data_samples)
sig[feature_pos:feature_pos + feature_samples] += wave

Expand Down Expand Up @@ -87,8 +87,8 @@ def generate_block(n_segments=3, n_channels=8, n_units=3,

# We assume that our block has only 1 ChannelIndex and each
# RecordingChannel only has 1 AnalogSignal.
rcg = block.channel_indexes[0]
for rc in rcg.recordingchannels:
chx = block.channel_indexes[0]
for rc in chx.recordingchannels:
print("Analysing channel %d: %s" % (rc.index, rc.name))

siglist = rc.analogsignals
Expand Down Expand Up @@ -123,13 +123,13 @@ def generate_block(n_segments=3, n_channels=8, n_units=3,

# By ChannelIndex. Here we calculate a PSTH averaged over trials by
# channel location, blending all Units:
for rcg in block.channel_indexes:
for chx in block.channel_indexes:
stlist = []
for unit in rcg.units:
for unit in chx.units:
stlist.extend([st - st.t_start for st in unit.spiketrains])
count, bins = np.histogram(np.hstack(stlist))
plt.figure()
plt.bar(bins[:-1], count, width=bins[1] - bins[0])
plt.title("PSTH blend of recording channel group %s" % rcg.name)
plt.title("PSTH blend of recording channel group %s" % chx.name)

plt.show()
8 changes: 4 additions & 4 deletions neo/core/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ class Block(Container):
... blk.segments.append(seg)
...
>>> for ind in range(2):
... rcg = ChannelIndex(name='Array probe %d' % ind,
... chx = ChannelIndex(name='Array probe %d' % ind,
... channel_indexes=np.arange(64))
... blk.channel_indexes.append(rcg)
... blk.channel_indexes.append(chx)
...
>>> # Populate the Block with AnalogSignal objects
... for seg in blk.segments:
... for rcg in blk.channel_indexes:
... for chx in blk.channel_indexes:
... a = AnalogSignal(np.random.randn(10000, 64)*nA,
... sampling_rate=10*kHz)
... rcg.analogsignals.append(a)
... chx.analogsignals.append(a)
... seg.analogsignals.append(a)
*Required attributes/properties*:
Expand Down
20 changes: 10 additions & 10 deletions neo/core/recordingchannelgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ class ChannelIndex(Container):
... blk.segments.append(seg)
...
>>> for ind in range(2):
... rcg = ChannelIndex(name='Array probe %d' % ind,
... chx = ChannelIndex(name='Array probe %d' % ind,
... channel_indexes=np.arange(64))
... blk.channel_indexes.append(rcg)
... blk.channel_indexes.append(chx)
...
>>> # Populate the Block with AnalogSignal objects
... for seg in blk.segments:
... for rcg in blk.channel_indexes:
... for chx in blk.channel_indexes:
... a = AnalogSignal(np.random.randn(10000, 64)*nA,
... sampling_rate=10*kHz)
... rcg.analogsignals.append(a)
... chx.analogsignals.append(a)
... seg.analogsignals.append(a)
*Usage 2* grouping channels::
Expand All @@ -68,10 +68,10 @@ class ChannelIndex(Container):
... blk.segments[0].append(sig)
...
>>> # Create a new ChannelIndex which groups three channels from the signal
... rcg = ChannelIndex(channel_names=np.array(['ch1', 'ch4', 'ch6']),
... chx = ChannelIndex(channel_names=np.array(['ch1', 'ch4', 'ch6']),
... channel_indexes = np.array([0, 3, 5])
>>> rcg.analogsignals.append(sig)
>>> blk.channel_indexes.append(rcg)
>>> chx.analogsignals.append(sig)
>>> blk.channel_indexes.append(chx)
*Usage 3* dealing with :class:`Unit` objects::
Expand All @@ -81,15 +81,15 @@ class ChannelIndex(Container):
>>> blk = Block()
>>>
>>> # Create a new ChannelIndex and add it to the Block
>>> rcg = ChannelIndex(name='octotrode A')
>>> blk.channel_indexes.append(rcg)
>>> chx = ChannelIndex(name='octotrode A')
>>> blk.channel_indexes.append(chx)
>>>
>>> # create several Unit objects and add them to the
>>> # ChannelIndex
... for ind in range(5):
... unit = Unit(name = 'unit %d' % ind,
... description='after a long and hard spike sorting')
... rcg.units.append(unit)
... chx.units.append(unit)
*Required attributes/properties*:
:channel_indexes: (numpy.array 1D dtype='i')
Expand Down
10 changes: 5 additions & 5 deletions neo/core/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,18 @@ def construct_subsegment_by_unit(self, unit_list=None):
... ChannelIndex)
>>>
>>> blk = Block()
>>> rcg = ChannelIndex(name='group0')
>>> blk.channel_indexes = [rcg]
>>> chx = ChannelIndex(name='group0')
>>> blk.channel_indexes = [chx]
>>>
>>> for ind in range(5):
... unit = Unit(name='Unit #%s' % ind, channel_index=ind)
... rcg.units.append(unit)
... chx.units.append(unit)
...
>>>
>>> for ind in range(3):
... seg = Segment(name='Simulation #%s' % ind)
... blk.segments.append(seg)
... for unit in rcg.units:
... for unit in chx.units:
... train = SpikeTrain([1, 2, 3], units='ms', t_start=0.,
... t_stop=10)
... train.unit = unit
Expand All @@ -204,7 +204,7 @@ def construct_subsegment_by_unit(self, unit_list=None):
...
>>>
>>> seg0 = blk.segments[-1]
>>> seg1 = seg0.construct_subsegment_by_unit(rcg.units[:2])
>>> seg1 = seg0.construct_subsegment_by_unit(chx.units[:2])
>>> len(seg0.spiketrains)
5
>>> len(seg1.spiketrains)
Expand Down
2 changes: 1 addition & 1 deletion neo/io/baseio.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def write_analogsignal(self, anasig, **kargs):
def write_irregularlysampledsignal(self, irsig, **kargs):
assert(IrregularlySampledSignal in self.writeable_objects), write_error

def write_channelindex(self, rcg, **kargs):
def write_channelindex(self, chx, **kargs):
assert(ChannelIndex in self.writeable_objects), write_error

def write_event(self, ev, **kargs):
Expand Down
12 changes: 6 additions & 6 deletions neo/io/blackrockio.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ def read_block(self, lazy=False, cascade=True, load_waveforms = False):
index = sig.get_channel_index()[i]
break
if index is not None:
rcg = ChannelIndex(name = 'Group {0}'.format(channel_id),
chx = ChannelIndex(name = 'Group {0}'.format(channel_id),
channel_indexes=np.array([index]),
channel_ids=np.array([channel_id]))
unit = Unit(name=st.name)
unit.spiketrains.append(st)
rcg.units.append(unit)
bl.channel_indexes.append(rcg)
chx.units.append(unit)
bl.channel_indexes.append(chx)

bl.create_many_to_one_relationship()

Expand Down Expand Up @@ -420,13 +420,13 @@ def read_nsx(self, filename_nsx, seg, lazy, cascade):
channel_indexes = np.arange(anasig.shape[1])

# this assumes there is only ever a single segment
rcg = ChannelIndex(channel_indexes=channel_indexes,
chx = ChannelIndex(channel_indexes=channel_indexes,
channel_ids=np.array(ch['channel_id']),
channel_names=np.array(ch['label']),
name=name,
file_origin=filename_nsx)
rcg.analogsignals.append(anasig)
anasig.channel_index = rcg
chx.analogsignals.append(anasig)
anasig.channel_index = chx
seg.analogsignals.append(anasig)

def read_sif(self, filename_sif, seg, ):
Expand Down
10 changes: 5 additions & 5 deletions neo/io/blackrockio_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ def read_block(self, lazy=False, cascade=True,
n_stops = [self.loader.header.n_samples]

#~ # Add channel hierarchy
#~ rcg = ChannelIndex(name='allchannels',
#~ chx = ChannelIndex(name='allchannels',
#~ description='group of all channels', file_origin=self.filename)
#~ block.channel_indexes.append(rcg)
#~ block.channel_indexes.append(chx)
#~ self.channel_number_to_recording_channel = {}

#~ # Add each channel at a time to hierarchy
#~ for ch in channel_list:
#~ ch_object = RecordingChannel(name='channel%d' % ch,
#~ file_origin=self.filename, index=ch)
#~ rcg.channel_indexes.append(ch_object.index)
#~ rcg.channel_names.append(ch_object.name)
#~ rcg.recordingchannels.append(ch_object)
#~ chx.channel_indexes.append(ch_object.index)
#~ chx.channel_names.append(ch_object.name)
#~ chx.recordingchannels.append(ch_object)
#~ self.channel_number_to_recording_channel[ch] = ch_object

# Iterate through n_starts and n_stops and add one Segment
Expand Down
6 changes: 3 additions & 3 deletions neo/io/brainwaredamio.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ def read_block(self, lazy=False, cascade=True, **kargs):
return block

# create the objects to store other objects
rcg = ChannelIndex(file_origin=self._filename,
chx = ChannelIndex(file_origin=self._filename,
channel_ids=np.array([1]),
channel_indexes=np.array([0]),
channel_names=np.array(['Chan1'], dtype='S'))

# load objects into their containers
block.channel_indexes.append(rcg)
block.channel_indexes.append(chx)

# open the file
with open(self._path, 'rb') as fobject:
Expand All @@ -159,7 +159,7 @@ def read_block(self, lazy=False, cascade=True, **kargs):
break

# store the segment and signals
seg.analogsignals[0].channel_index = rcg
seg.analogsignals[0].channel_index = chx
block.segments.append(seg)

# remove the file object
Expand Down
6 changes: 3 additions & 3 deletions neo/io/brainwaref32io.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ def read_block(self, lazy=False, cascade=True, **kargs):
return block

# create the objects to store other objects
rcg = ChannelIndex(file_origin=self._filename,
chx = ChannelIndex(file_origin=self._filename,
channel_indexes=np.array([], dtype=np.int))
self.__unit = Unit(file_origin=self._filename)

# load objects into their containers
block.channel_indexes.append(rcg)
rcg.units.append(self.__unit)
block.channel_indexes.append(chx)
chx.units.append(self.__unit)

# initialize values
self.__t_stop = None
Expand Down
Loading

0 comments on commit 57fc637

Please sign in to comment.