Skip to content

Commit

Permalink
thalamus: don't require bpo_threshold_current_dep's current (#41)
Browse files Browse the repository at this point in the history
* remove unused fitness_calculator argument

* consider depolarized threshold current being None when generating currents

* add test for get_thalamus_stim_currents' exception

* pycodestyle fix
  • Loading branch information
anilbey committed Feb 22, 2022
1 parent e061c41 commit ecb03f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 8 additions & 2 deletions emodelrunner/protocols/create_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,19 @@ def get_thalamus_stim_currents(self, responses, mtype, dt):
mtype (str): mtype to index the responses
dt (float): timestep of the generated currents (ms)
Raises:
KeyError: when "dep" holding or threshold current is missing
Returns:
dict: the generated currents in a dict.
"""
thres_i_hyp = responses[f"{mtype}.bpo_threshold_current_hyp"]
thres_i_dep = responses[f"{mtype}.bpo_threshold_current_dep"]
holding_i_hyp = responses[f"{mtype}.bpo_holding_current_hyp"]
holding_i_dep = responses[f"{mtype}.bpo_holding_current_dep"]
try:
thres_i_dep = responses[f"{mtype}.bpo_threshold_current_dep"]
holding_i_dep = responses[f"{mtype}.bpo_holding_current_dep"]
except KeyError:
thres_i_dep = holding_i_dep = None
currents = {}
for protocol in self.protocols.protocols:
currents.update(
Expand Down
3 changes: 0 additions & 3 deletions emodelrunner/protocols/thalamus_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def __init__(
thdetect_protocol_hyp=None,
other_protocols=None,
pre_protocols=None,
fitness_calculator=None,
):
"""Constructor."""
# pylint: disable=too-many-arguments
Expand All @@ -76,8 +75,6 @@ def __init__(

self.pre_protocols = pre_protocols

self.fitness_calculator = fitness_calculator

def subprotocols(self):
"""Return all the subprotocols contained in this protocol, is recursive."""
subprotocols = collections.OrderedDict({self.name: self})
Expand Down
18 changes: 18 additions & 0 deletions tests/unit_tests/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

from pathlib import Path
from types import SimpleNamespace

from emodelrunner.load import (
load_config,
Expand Down Expand Up @@ -108,6 +109,23 @@ def test_using_thalamus_protocols(self):
}
assert prot_obj_names - thalamus_recipe_protocol_keys == set()

def test_thalamus_stim_currents_exception(self):
"""Tests the exception case in get_thalamus_stim_currents."""
mtype = "test_mtype"
responses = {
f"{mtype}.bpo_threshold_current_hyp": 0.1,
f"{mtype}.bpo_holding_current_hyp": 0.3,
f"{mtype}.bpo_threshold_current_dep": 0.4,
}

mock_obj = SimpleNamespace(
protocols=[SimpleNamespace(generate_current=(lambda *args: {"args": args}))]
)

thal_protocols = ProtocolBuilder(protocols=mock_obj)
currents = thal_protocols.get_thalamus_stim_currents(responses, mtype, dt=0.025)
assert currents["args"] == (0.1, None, 0.3, None, 0.025)


class TestProtocolParser:
"""Tests for the ProtocolParser class."""
Expand Down

0 comments on commit ecb03f8

Please sign in to comment.