@@ -822,6 +822,51 @@ def test_point_current():
822822 assert 'I1/area' in neuron .equations ['Im' ].expr .code
823823 assert 'I2/area' in neuron .equations ['Im' ].expr .code # see issue #1160
824824
825+ @pytest .mark .standalone_compatible
826+ @pytest .mark .multiple_runs
827+ def test_spatialneuron_threshold_location ():
828+ morpho = Soma (10 * um )
829+ morpho .axon = Cylinder (1 * um , n = 2 , length = 20 * um )
830+ model = '''
831+ Im = 0*nA/cm**2 : amp/meter**2
832+ should_spike : boolean (constant)
833+ '''
834+ neuron = SpatialNeuron (morpho , model , threshold_location = morpho .axon [15 * um ],
835+ threshold = 'should_spike' )
836+ # Different variants that should do the same thing
837+ neuron2 = SpatialNeuron (morpho , model , threshold_location = morpho .axon .indices [15 * um ],
838+ threshold = 'should_spike' )
839+ neuron3 = SpatialNeuron (morpho , model , threshold_location = 2 ,
840+ threshold = 'should_spike' )
841+ # Cannot use multiple compartments
842+ with pytest .raises (AttributeError ):
843+ SpatialNeuron (morpho , model , threshold_location = [2 , 3 ],
844+ threshold = 'should_spike' )
845+ with pytest .raises (AttributeError ):
846+ SpatialNeuron (morpho , model , threshold_location = morpho .axon [5 * um :15 * um ],
847+ threshold = 'should_spike' )
848+ neurons = [neuron , neuron2 , neuron3 ]
849+ monitors = [SpikeMonitor (n ) for n in neurons ]
850+
851+ net = Network (neurons , monitors )
852+ for n in neurons :
853+ n .should_spike = True # all compartments want to spike
854+ net .run (defaultclock .dt )
855+ for n in neurons :
856+ n .should_spike = False # no compartment wants to spike
857+ net .run (defaultclock .dt )
858+ for n in neurons :
859+ n .should_spike = [False , False , True ]
860+ net .run (defaultclock .dt )
861+ for n in neurons :
862+ n .should_spike = [True , True , False ]
863+ net .run (defaultclock .dt )
864+ device .build (direct_call = False , ** device .build_options )
865+ for mon in monitors :
866+ assert len (mon .i ) == 2
867+ assert all (mon .i == 2 )
868+ assert_allclose (mon .t , [0 * ms , 2 * defaultclock .dt ])
869+
825870
826871if __name__ == '__main__' :
827872 test_custom_events ()
0 commit comments