INM-6 / elephant

Elephant is the ElectroPhysiology Analysis Toolkit
BSD 3-Clause "New" or "Revised" License
9 stars 9 forks source link

[Bug] ValueError in generate_lfp for one-dimensional input #98

Open Moritz-Alexander-Kern opened 11 months ago

Moritz-Alexander-Kern commented 11 months ago

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

mdenker commented 11 months ago

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.