File: examples-interface_interface.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 (62 lines) | stat: -rw-r--r-- 2,037 bytes parent folder | download | duplicates (2)
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
.. currentmodule:: brian

.. _example-interface_interface:

Example: interface (interface)
==============================

Interface example
Install cherrypy for this example
Then run the script and go to http://localhost:8080 on your web browser
You can use cherrypy to write html interfaces to your code.

::

    
    from brian import *
    import cherrypy
    import os.path
    
    # The server is defined here
    class MyInterface(object):
        @cherrypy.expose
        def index(self): # redirect to the html page we wrote
            return '<meta HTTP-EQUIV="Refresh" content="0;URL=index.html">'
    
        @cherrypy.expose
        def runscript(self, we="1.62", wi="-9", **kwd): # 'runscript' is the script name
            # we and wi are the names of form fields
            we = float(we)
            wi = float(wi)
            # From minimalexample
            reinit_default_clock()
            eqs = '''
            dv/dt = (ge+gi-(v+49*mV))/(20*ms) : volt
            dge/dt = -ge/(5*ms) : volt
            dgi/dt = -gi/(10*ms) : volt
            '''
            P = NeuronGroup(4000, model=eqs, threshold= -50 * mV, reset= -60 * mV)
            P.v = -60 * mV + 10 * mV * rand(len(P))
            Pe = P.subgroup(3200)
            Pi = P.subgroup(800)
            Ce = Connection(Pe, P, 'ge')
            Ci = Connection(Pi, P, 'gi')
            Ce.connect_random(Pe, P, 0.02, weight=we * mV)
            Ci.connect_random(Pi, P, 0.02, weight=wi * mV)
            M = SpikeMonitor(P)
            run(.5 * second)
            clf()
            raster_plot(M)
            savefig('image.png')
            # Redirect to the html page we wrote
            return '<meta HTTP-EQUIV="Refresh" content="0;URL=results.html">'
    
    # Set the directory for static files
    current_dir = os.path.dirname(os.path.abspath(__file__))
    conf = {'/': {'tools.staticdir.on':True,
                  'tools.staticdir.dir':current_dir}}
    
    # Start the server
    cherrypy.quickstart(MyInterface(), config=conf)