File: examples-misc_spikes_io.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (66 lines) | stat: -rw-r--r-- 1,661 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
.. currentmodule:: brian

.. index::
   pair: example usage; run
   pair: example usage; SpikeGeneratorGroup
   pair: example usage; show
   pair: example usage; raster_plot
   pair: example usage; clear
   pair: example usage; SpikeMonitor
   pair: example usage; PoissonGroup
   pair: example usage; reinit_default_clock
   pair: example usage; AERSpikeMonitor
   pair: example usage; close
   pair: example usage; load_aer

.. _example-misc_spikes_io:

Example: spikes_io (misc)
=========================

This script demonstrates how to save/load spikes in AER format from inside Brian.

::

    from brian import *
    
    ####################### SAVING #########################
    
    # First we need to generate some spikes
    N = 1000
    g = PoissonGroup(N, 200*Hz)
    
    # And set up a monitor to record those spikes to the disk
    Maer = AERSpikeMonitor(g, './dummy.aedat')
    
    # Now we can run
    run(100*ms)
    
    # This line executed automatically when the script ends, but here we
    # need to close the file because we re-use it from within the same script
    Maer.close()
    
    
    clear(all = True)
    reinit_default_clock()
    ####################### LOADING ########################
    
    # Now we can re-load the spikes
    addr, timestamps = load_aer('./dummy.aedat')
    
    # Feed them to a SpikeGeneratorGroup
    group = SpikeGeneratorGroup(N, (addr, timestamps))
    
    # The group can now be used as any other, here we choose to monitor
    # the spikes
    newM = SpikeMonitor(group, record = True)
    
    run(100*ms)
    
    # And plot the result
    raster_plot(newM)
    show()