Neuroinflab / kCSD-python

Kernel Current Source Density
https://kcsd-python.readthedocs.io/en/latest/
Other
15 stars 23 forks source link

input potential vector with a size of (9,1) produces an estimated CSD vector of size (100,1) #137

Closed ahmeddeladly closed 2 years ago

ahmeddeladly commented 2 years ago

Hello I am trying to use the KCSD package on some toy data. I used the code below and for a LFP vector size of (9,1), an estimated CSD size of (100,1) was given as an output. Why is that? Should nt they be of the same size?

from kcsd import KCSD1D import numpy as np from matplotlib import pyplot as plt

elec_pos = np.array([[-0.5], [0], [1], [1.5], [3.5], [4.1], [5.0], [7.0], [8.0]])

pots = np.array([[-0.1], [0.3], [-0.4], [0.2], [0.8], [0.5], [0.2], [0.5], [0.6]])

def do_kcsd(elec_pos, pots): h = 1.
sigma = 1.0 pots = pots.reshape((len(elec_pos), 1)) # first time point k = KCSD1D(elec_pos, pots,h=h, sigma=sigma,
xmin=0.0, xmax=1.0, src_type='gauss', R_init=1.) return k

k = do_kcsd(elec_pos, pots) est_csd = k.values('CSD') est_pot = k.values('POT')

ccluri commented 2 years ago

Hello,

k = KCSD1D(elec_pos, pots,h=h, sigma=sigma, xmin=0.0, xmax=1.0, src_type='gauss', R_init=1.)

Firstly, in this line you, by setting xmin and xmax you are forcing to evaluate the CSD between 0 and 1. However your electrodes positions are in the range of -0.5 and 8. Please refer to the documentation for the KCSD1D class for clarification.

The parameter gdx - which you are not passing, controls for the 100 that you are asking about. Since you are not passing any arguments, it defaults to 0.01(xmax-xmin). This results in gdx of 0.01, hence 100. The subsampling is kernel interpolated value of the CSD at this grid resolution. As you know CSD is a 'density' - which is a continuous spatial property, and kCSD can give you this. Hope this clarifies it a bit.

ahmeddeladly commented 2 years ago

Hello Chaitanya,

Yes that clarifies it all. Thank you so much for your help and this cool package :)

Best, Ahmed

ahmeddeladly commented 2 years ago

Hello Chaitanya,

I have another question, how can I use the KCSD1D module to compute CSD for multiple time points? Does the KCSD1D accept an LFP matrix as an input?

Thanks,

abukaj commented 2 years ago

Hi @aeladly91, have you tried to pass a potential array with time points in columns? I mean e.g. 9x100 array if you have 9 electrodes and 100 time points.

Here is an example with the same potentials given in the first, second and last time points:

>>> POTS = np.random.uniform(-1, 1, (9, 100))
>>> POTS[:, 0] = [-.1, .3, -.4, .2, .8, .5, .2, .5, .6]
>>> POTS[:, 1] = POTS[:, 0]
>>> POTS[:, -1] = POTS[:, 0]
>>> k = KCSD1D(elec_pos, POTS,h=h, sigma=sigma, xmin=0.0, xmax=1.0, src_type='gauss', R_init=1.)
>>> CSD = k.values('CSD')                                                                                                                                                                                                                                                 
>>> assert abs(CSD[:, 0] - CSD[:, 1]).max() == 0                                                                                                                                                                                                                          
>>> assert abs(CSD[:, 0] - CSD[:, -1]).max() == 0                                                                                                                                                                                                                         
>>> print(abs(CSD[:, 0] - CSD[:, 2]).max())                                                                                                                                                                                                                               
74056.375

As expected, the same potentials lead to the same reconstruction.

ahmeddeladly commented 2 years ago

Thank you abukaj :)