Skip to content

Commit

Permalink
Merge 506ec78 into 063b9ad
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Mar 16, 2022
2 parents 063b9ad + 506ec78 commit dad19fd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
12 changes: 6 additions & 6 deletions brian2/spatialneuron/spatialneuron.py
Expand Up @@ -246,12 +246,12 @@ def __init__(self, morphology=None, model=None, threshold=None,
if hasattr(threshold_location,
'_indices'): # assuming this is a method
threshold_location = threshold_location._indices()
# for now, only a single compartment allowed
if len(threshold_location) == 1:
threshold_location = threshold_location[0]
else:
raise AttributeError("Threshold can only be applied on a "
"single location")
# for now, only a single compartment allowed
try:
treshold_location = int(threshold_location)
except TypeError:
raise AttributeError("Threshold can only be applied on a "
"single location")
threshold = f"({threshold}) and (i == {str(threshold_location)})"

# Check flags (we have point currents)
Expand Down
45 changes: 45 additions & 0 deletions brian2/tests/test_spatialneuron.py
Expand Up @@ -822,6 +822,51 @@ def test_point_current():
assert 'I1/area' in neuron.equations['Im'].expr.code
assert 'I2/area' in neuron.equations['Im'].expr.code # see issue #1160

@pytest.mark.standalone_compatible
@pytest.mark.multiple_runs
def test_spatialneuron_threshold_location():
morpho = Soma(10*um)
morpho.axon = Cylinder(1*um, n=2, length=20*um)
model = '''
Im = 0*nA/cm**2 : amp/meter**2
should_spike : boolean (constant)
'''
neuron = SpatialNeuron(morpho, model, threshold_location=morpho.axon[15*um],
threshold='should_spike')
# Different variants that should do the same thing
neuron2 = SpatialNeuron(morpho, model, threshold_location=morpho.axon.indices[15*um],
threshold='should_spike')
neuron3 = SpatialNeuron(morpho, model, threshold_location=2,
threshold='should_spike')
# Cannot use multiple compartments
with pytest.raises(AttributeError):
SpatialNeuron(morpho, model, threshold_location=[2, 3],
threshold='should_spike')
with pytest.raises(AttributeError):
SpatialNeuron(morpho, model, threshold_location=morpho.axon[5*um:15*um],
threshold='should_spike')
neurons = [neuron, neuron2, neuron3]
monitors = [SpikeMonitor(n) for n in neurons]

net = Network(neurons, monitors)
for n in neurons:
n.should_spike = True # all compartments want to spike
net.run(defaultclock.dt)
for n in neurons:
n.should_spike = False # no compartment wants to spike
net.run(defaultclock.dt)
for n in neurons:
n.should_spike = [False, False, True]
net.run(defaultclock.dt)
for n in neurons:
n.should_spike = [True, True, False]
net.run(defaultclock.dt)
device.build(direct_call=False, **device.build_options)
for mon in monitors:
assert len(mon.i) == 2
assert all(mon.i == 2)
assert_allclose(mon.t, [0*ms, 2*defaultclock.dt])


if __name__ == '__main__':
test_custom_events()
Expand Down

0 comments on commit dad19fd

Please sign in to comment.