Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] ValueError: Number of signals and coords is not same #550

Open
rcpeene opened this issue Mar 21, 2023 · 1 comment
Open

[Bug] ValueError: Number of signals and coords is not same #550

rcpeene opened this issue Mar 21, 2023 · 1 comment
Labels
bug Indicates an unexpected problem or unintended behavior documentation Indicates a need for improvements or additions to documentation

Comments

@rcpeene
Copy link

rcpeene commented Mar 21, 2023

Describe the bug
I'm attempting to use elephant to perform CSD analysis. In a Jupyter notebook, I have implemented the temporary fix mentioned here in my usage. However, the output is not produced and I get an error (traceback below). Is this a failure of my usage? Or a bug in the code? I'm not fully sure what the error output means.

To Reproduce

  1. Run the following code after importing the relevant elephant namespaces:
xs = np.array(nwb.electrodes.x)
xs = xs.reshape(xs.shape[0],1)
ys = np.array(nwb.electrodes.x)
ys = ys.reshape(ys.shape[0],1)

lfp = generate_lfp(small_source_2D, xs, ys)
estimate_csd(lfp, method="KCSD2D")

where nwb.electrodes.x and nwb.electrodes.y are arrays of length 2304.

Expected behavior
A resulting CSD array is expected to be outputted.

Environment
Windows 10:
Installed elephant with pip install elephant:
Python version: 3.9.10
neo==0.12.0
numpy==1.21.5
elephant==0.12.0

Traceback

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [43], line 7
      4 ys = ys.reshape(ys.shape[0],1)
      6 lfp = generate_lfp(small_source_2D, xs, ys)
----> 7 estimate_csd(lfp, method="KCSD2D")

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\elephant\utils.py:80, in deprecated_alias.<locals>.deco.<locals>.wrapper(*args, **kwargs)
     77 @wraps(func)
     78 def wrapper(*args, **kwargs):
     79     _rename_kwargs(func.__name__, kwargs, aliases)
---> 80     return func(*args, **kwargs)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\elephant\current_source_density.py:137, in estimate_csd(lfp, coordinates, method, process_estimate, **kwargs)
    135     raise ValueError('Must specify a method of CSD implementation')
    136 if len(coordinates) != lfp.shape[1]:
--> 137     raise ValueError('Number of signals and coords is not same')
    138 for ii in coordinates:  # CHECK for Dimensionality of electrodes
    139     if len(ii) > 3:

ValueError: Number of signals and coords is not same
@Moritz-Alexander-Kern Moritz-Alexander-Kern added the bug Indicates an unexpected problem or unintended behavior label Mar 23, 2023
@Moritz-Alexander-Kern
Copy link
Member

Moritz-Alexander-Kern commented Mar 23, 2023

Hey @rcpeene,

thanks again for reaching out to us.

If I understand correctly, if no coordinates are supplied to estimate_csd function, the default value is the string 'coordinates'. In this case the coordinates are assumed to be available as annotations.

Try this to see if the coordinates are annotated to the lfp instance:

lfp.annotations['coordinates']

If not, I created the following minimal example that might help to use another approach:

import numpy as np
from elephant.current_source_density import generate_lfp, estimate_csd
from elephant.current_source_density_src.utility_functions import small_source_2D
import quantities as pq


xs=np.linspace(0, 10, 230).reshape(230,1)
ys=np.linspace(0, 10, 230).reshape(230,1)


lfp = generate_lfp(small_source_2D, xs, ys)
coordinates = np.stack((xs[:,0], ys[:,0]), axis=-1)*pq.mm
csd=estimate_csd(lfp, coordinates=coordinates, method="KCSD2D")
print(csd)

Here the coordinates are passed as quantities array.

print(coordinates)
[[ 0.          0.        ]
 [ 0.04366812  0.04366812]
 [ 0.08733624  0.08733624]
...
 [ 9.91266376  9.91266376]
 [ 9.95633188  9.95633188]
 [10.         10.        ]] mm

Which produces the following output:

No lambda given, using defaults
Cross validating R (all lambda) : 0.23
R, lambda : 0.23 2.8729848333536567e-13
[[[ 0.24422881  0.05464928  0.13539177 ... -0.01045737  0.00085341
    0.01609725]
  [ 0.05464928  0.01057368  0.01862725 ...  0.00056317  0.00126693
    0.00817861]
  [ 0.13539177  0.01862725 -0.0072203  ...  0.01467424  0.0080604
    0.04119698]
  ...
  [-0.01045737  0.00056317  0.01467424 ...  0.00287804 -0.00260698
   -0.02077326]
  [ 0.00085341  0.00126693  0.0080604  ... -0.00260698 -0.00399534
   -0.02497955]
  [ 0.01609725  0.00817861  0.04119698 ... -0.02077326 -0.02497955
   -0.15180521]]] uA/mm**3

Thanks again for reporting and let me know if this is helpful 👍

@Moritz-Alexander-Kern Moritz-Alexander-Kern added the documentation Indicates a need for improvements or additions to documentation label May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior documentation Indicates a need for improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants