File: ratemonitor.pyx

package info (click to toggle)
brian 2.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,872 kB
  • sloc: python: 51,820; cpp: 2,033; makefile: 108; sh: 72
file content (41 lines) | stat: -rw-r--r-- 1,260 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{# USES_VARIABLES { N, t, rate, _clock_t, _clock_dt, _spikespace,
                    _num_source_neurons, _source_start, _source_stop } #}
{% extends 'common_group.pyx' %}

{% block maincode %}

    cdef size_t _num_spikes = {{_spikespace}}[_num{{_spikespace}}-1]
    
    # For subgroups, we do not want to record all spikes
    # We assume that spikes are ordered
    cdef int _start_idx = -1
    cdef int _end_idx = -1
    cdef size_t _j
    for _j in range(_num_spikes):
        _idx = {{_spikespace}}[_j]
        if _idx >= _source_start:
            _start_idx = _j
            break
    if _start_idx == -1:
        _start_idx = _num_spikes
    for _j in range(_start_idx, _num_spikes):
        _idx = {{_spikespace}}[_j]
        if _idx >= _source_stop:
            _end_idx = _j
            break
    if _end_idx == -1:
        _end_idx =_num_spikes
    _num_spikes = _end_idx - _start_idx
    
    # Calculate the new length for the arrays
    cdef size_t _new_len = {{_dynamic_t}}.shape[0] + 1

    # Resize the arrays
    _owner.resize(_new_len)
    {{N}} = _new_len

    # Set the new values
    {{_dynamic_t}}.data[_new_len-1] = {{_clock_t}}
    {{_dynamic_rate}}.data[_new_len-1] = _num_spikes/{{_clock_dt}}/_num_source_neurons

{% endblock %}