Skip to content

Commit

Permalink
This removes support of RrcordingChannelGroup in CSD methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdenker committed Mar 10, 2022
1 parent 6d7790b commit 3a2f6e9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
51 changes: 28 additions & 23 deletions elephant/current_source_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@


@deprecated_alias(coords='coordinates')
def estimate_csd(lfp, coordinates=None, method=None,
def estimate_csd(lfp, coordinates='coordinates', method=None,
process_estimate=True, **kwargs):
"""
Function call to compute the current source density (CSD) from
Expand All @@ -72,12 +72,16 @@ def estimate_csd(lfp, coordinates=None, method=None,
Parameters
----------
lfp : neo.AnalogSignal
positions of electrodes can be added as neo.RecordingChannel
coordinate or sent externally as a func argument (See coords)
coordinates : [Optional] corresponding spatial coordinates of the
electrodes.
Defaults to None
Otherwise looks for ChannelIndex coordinate
Positions of electrodes can be added as an array annotation
coordinates : array-like Quantity or string
Specifies the corresponding spatial coordinates of the electrodes.
Coordinates can be directly supplied by a NxM array-like Quantity
with dimension of space, where M is the number of signals in 'lfp',
and N is equal to the dimensionality of the method.
Alternatively, if coordinates is a string, the function will fetch the
coordinates, supplied in the same format, as annotation of 'lfp' by that
name.
Default: 'coordinates'
method : string
Pick a method corresponding to the setup, in this implementation
For Laminar probe style (1D), use 'KCSD1D' or 'StandardCSD',
Expand Down Expand Up @@ -114,17 +118,19 @@ def estimate_csd(lfp, coordinates=None, method=None,
"""
if not isinstance(lfp, neo.AnalogSignal):
raise TypeError('Parameter `lfp` must be a neo.AnalogSignal object')
if coordinates is None:
coordinates = lfp.channel_index.coordinates
else:
scaled_coords = []
for coord in coordinates:
try:
scaled_coords.append(coord.rescale(pq.mm))
except AttributeError:
raise AttributeError('No units given for electrode spatial \
coordinates')
coordinates = scaled_coords
if isinstance(coordinates, str):
coordinates = lfp.annotations[coordinates]

# Scale all coordinates to mm as common basis
scaled_coords = []
for coord in coordinates:
try:
scaled_coords.append(coord.rescale(pq.mm))
except AttributeError:
raise AttributeError('No units given for electrode spatial \
coordinates')
coordinates = scaled_coords

if method is None:
raise ValueError('Must specify a method of CSD implementation')
if len(coordinates) != lfp.shape[1]:
Expand Down Expand Up @@ -249,7 +255,8 @@ def generate_lfp(csd_profile, x_positions, y_positions=None, z_positions=None,
-------
LFP : neo.AnalogSignal
The potentials created by the csd profile at the electrode positions.
The electrode positions are attached as RecordingChannel's coordinate.
The electrode positions are attached as an annotation named
'coordinates'.
"""

def integrate_1D(x0, csd_x, csd, h):
Expand Down Expand Up @@ -327,10 +334,8 @@ def integrate_3D(x, y, z, csd, xlin, ylin, zlin, X, Y, Z):
pots /= 4 * np.pi * sigma
ele_pos = np.vstack((x_positions, y_positions, z_positions)).T
ele_pos = ele_pos * pq.mm
ch = neo.ChannelIndex(index=range(len(pots)))

asig = neo.AnalogSignal(np.expand_dims(pots, axis=0),
sampling_rate=pq.kHz, units='mV')
ch.coordinates = ele_pos
ch.analogsignals.append(asig)
ch.create_relationship()
asig.annotate(coordinates=ele_pos)
return asig
18 changes: 3 additions & 15 deletions elephant/test/test_kcsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ def setUp(self):
temp_signals.append(self.pots[ii])
self.an_sigs = neo.AnalogSignal(np.array(temp_signals).T * pq.mV,
sampling_rate=1000 * pq.Hz)
chidx = neo.ChannelIndex(range(len(self.pots)))
chidx.analogsignals.append(self.an_sigs)
chidx.coordinates = self.ele_pos * pq.mm

chidx.create_relationship()
self.an_sigs.annotate(coordinates=self.ele_pos * pq.mm)

def test_kcsd1d_estimate(self, cv_params={}):
self.test_params.update(cv_params)
Expand Down Expand Up @@ -86,11 +82,7 @@ def setUp(self):
temp_signals.append(self.pots[ii])
self.an_sigs = neo.AnalogSignal(np.array(temp_signals).T * pq.mV,
sampling_rate=1000 * pq.Hz)
chidx = neo.ChannelIndex(range(len(self.pots)))
chidx.analogsignals.append(self.an_sigs)
chidx.coordinates = self.ele_pos * pq.mm

chidx.create_relationship()
self.an_sigs.annotate(coordinates=self.ele_pos * pq.mm)

def test_kcsd2d_estimate(self, cv_params={}):
self.test_params.update(cv_params)
Expand Down Expand Up @@ -149,11 +141,7 @@ def setUp(self):
temp_signals.append(self.pots[ii])
self.an_sigs = neo.AnalogSignal(np.array(temp_signals).T * pq.mV,
sampling_rate=1000 * pq.Hz)
chidx = neo.ChannelIndex(range(len(self.pots)))
chidx.analogsignals.append(self.an_sigs)
chidx.coordinates = self.ele_pos * pq.mm

chidx.create_relationship()
self.an_sigs.annotate(coordinates=self.ele_pos * pq.mm)

def test_kcsd3d_estimate(self, cv_params={}):
self.test_params.update(cv_params)
Expand Down

0 comments on commit 3a2f6e9

Please sign in to comment.