Skip to content

Commit

Permalink
test_correlospinmatrix_detector to py
Browse files Browse the repository at this point in the history
  • Loading branch information
janeirik committed Apr 25, 2023
1 parent de1cc76 commit fb1b360
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions testsuite/pytests/test_correlospinmatrix_detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
#
# test_correlospinmatrix_detector.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.


import nest
import pytest
import numpy as np


def test_correlospinmatrix_detector():
"""Expected output
The output send to std::cout is a superposition of the output of
the voltmeter and the spike recorder. Both, voltmeter and spike
detector are connected to the same neuron.
"""

# 3-tensor of correlation functions
expected_corr = np.array(
[
[[0, 0, 0, 0, 0, 10, 20, 30, 40, 50, 60, 50, 40, 30, 20, 10, 0, 0, 0, 0, 0],
[0, 10, 20, 30, 40, 50, 50, 40, 30, 20, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
\
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 20, 30, 40, 50, 50, 40, 30, 20, 10, 0],
[0, 0, 0, 0, 0, 0, 10, 20, 30, 40, 50, 40, 30, 20, 10, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
\
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
])

sg1 = nest.Create("spike_generator")
sg2 = nest.Create("spike_generator")
sg3 = nest.Create("spike_generator")

csd = nest.Create("correlospinmatrix_detector")

csd.set(N_channels=3, tau_max=10., delta_tau=1.)

sg1.set(spike_times=[10., 10., 16.])
sg2.set(spike_times=[15., 15., 20.])

# one final event needed so that last down transition will be detected
sg3.set(spike_times=[25.])

nest.Connect(sg1, csd, syn_spec={"receptor_type": 0})
nest.Connect(sg2, csd, syn_spec={"receptor_type": 1})
nest.Connect(sg3, csd, syn_spec={"receptor_type": 2})

nest.Simulate(100.)

np.testing.assert_equal(np.array(csd.count_covariance), expected_corr)

0 comments on commit fb1b360

Please sign in to comment.