Skip to content

Commit

Permalink
fix array conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohnsen committed Mar 15, 2024
1 parent 569db62 commit b8e0832
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wslfp"
version = "0.2.0"
version = "0.2.1"
description = "Weighted Sum Local Field Potentials - Implementation of the proxy method for point neurons from Mazzoni, Lindén et al., 2015"
authors = [
"Kyle Johnsen <[email protected]>",
Expand Down
13 changes: 7 additions & 6 deletions tests/test_wslfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,27 @@
# length of time and current array must equal
([1, 2, 4], [1, 2, 10], [9], True),
# missing I_gaba at t=9
([1, 2, 10], [1, 2, 4], [9], False),
([1, 2, 10], [1, 2, 4], 9, False),
([3, 2, 1], [3, 2, 1], [2], False), # Non-increasing order, should fail
([], [], [], False), # Empty arrays, should fail
([1, 5, 9, 12, 17], [1, 3, 5, 9, 12], [8, 11], True),
([1, 5, 9, 12, 17], [1, 3, 5, 9, 12], [], False),
([2, 4, 6, 23, 25], [7, 10, 15, 21, 25], [12, 20, 24], True),
([2, 3, 4, 5, 6], [50, 60, 70, 80, 90], [70, 100], False),
([0], [6], [6], True),
([6], [6], [6], False),
([6], [0], [6], False),
(0, 6, 6, True),
([6], 6, [6], False),
(6, [0], [6], False),
],
)
def test_calculate(t_ampa, t_gaba, t_eval, success, n_elec, seed):
rng = np.random.default_rng(seed)
# Dummy data for currents and coordinates
n_src = 3
n_elec = 2
I_ampa = np.arange(len(t_ampa))
I_ampa = np.arange(np.size(t_ampa))
I_ampa = I_ampa[:, np.newaxis] + np.arange(n_src)
I_gaba = -np.arange(len(t_gaba)) - 2
I_gaba = -np.arange(np.size(t_gaba)) - 2
I_gaba = I_gaba[:, np.newaxis] - np.arange(n_src)

source_coords = rng.uniform(-10, 10, (n_src, 3))
Expand All @@ -47,7 +48,7 @@ def test_calculate(t_ampa, t_gaba, t_eval, success, n_elec, seed):
calc = wslfp.from_xyz_coords(elec_coords, source_coords, strict_boundaries=True)
if success:
lfp_values = calc.calculate(t_eval, t_ampa, I_ampa, t_gaba, I_gaba)
assert lfp_values.shape == (len(t_eval), n_elec)
assert lfp_values.shape == (np.size(t_eval), n_elec)
# increasing could be negative or positive
# can't use np.abs since normalization can put values on either side of 0
assert np.all(
Expand Down
12 changes: 6 additions & 6 deletions wslfp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ def calculate(
each electrode
"""
# convert t to arrays if needed
if isinstance(t_eval_ms, (list, tuple, int, float)):
t_eval_ms = np.array(t_eval_ms)
if isinstance(t_ampa_ms, (list, tuple, int, float)):
t_ampa_ms = np.array(t_ampa_ms)
if isinstance(t_gaba_ms, (list, tuple, int, float)):
t_gaba_ms = np.array(t_gaba_ms)
if isinstance(t_eval_ms, (int, float)):
t_eval_ms = np.array([t_eval_ms])
if isinstance(t_ampa_ms, (int, float)):
t_ampa_ms = np.array([t_ampa_ms])
if isinstance(t_gaba_ms, (int, float)):
t_gaba_ms = np.array([t_gaba_ms])

I_ampa = np.reshape(I_ampa, (-1, self.n_sources))
assert I_ampa.shape == (
Expand Down

0 comments on commit b8e0832

Please sign in to comment.