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 in generate_lfp for one-dimensional input #98

Open
Moritz-Alexander-Kern opened this issue Oct 17, 2023 · 1 comment
Open

Comments

@Moritz-Alexander-Kern
Copy link

Describe the bug

Running the function generate_lfp with one-dimensional input results in a ValueError.

To Reproduce

  1. Define an array xs to x coordinate values with a length of 2304
  2. Run generate_lfp(gauss_1d_dipole, xs)
  3. See the resulting error. (Traceback shown below)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [22], line 1
----> 1 lfp = generate_lfp(gauss_1d_dipole, xs)

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:302, in generate_lfp(csd_profile, x_positions, y_positions, z_positions, x_limits, y_limits, z_limits, resolution)
    300 chrg_x = x
    301 csd = csd_profile(chrg_x)
--> 302 pots = integrate_1D(x_positions, chrg_x, csd, h)
    303 pots /= 2. * sigma  # eq.: 26 from Potworowski et al
    304 ele_pos = x_positions

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\elephant\current_source_density.py:263, in generate_lfp.<locals>.integrate_1D(x0, csd_x, csd, h)
    262 def integrate_1D(x0, csd_x, csd, h):
--> 263     m = np.sqrt((csd_x - x0) ** 2 + h ** 2) - abs(csd_x - x0)
    264     y = csd * m
    265     I = simps(y, csd_x)

ValueError: operands could not be broadcast together with shapes (50,) (2304,) 

Expected behavior I expected the function to return an array of LFP values.

Environment

  • Windows 10:
  • Installed elephant with pip install elephant:
  • Python version: 3.9.10
  • neo==0.12.0
  • numpy==1.21.5
@mdenker
Copy link
Member

mdenker commented Oct 17, 2023

Thanks for reporting this issue!
I was able to reproduce it using your minimal example and to track down the error. As an immediate workaround, you can reshape the input xs to (2304, 1) using numpy.reshape.
I will start working on a fix to make this workaround unnecessary in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants