Package topo :: Package ep :: Module basic
[hide private]
[frames] | no frames]

Source Code for Module topo.ep.basic

 1  """ 
 2  Basic scalar EventProcessors 
 3   
 4  This file contains some EventProcessors that emit and accept scalar 
 5  events, e.g. pulses.  These are not currently used in the sample 
 6  simulations, but can be useful for testing purposes and for controlling 
 7  other types of simulations. 
 8   
 9  $Id: basic.py 10672 2009-10-28 01:00:50Z ceball $ 
10  """ 
11  __version__='$Revision: 10672 $' 
12   
13  import param 
14   
15  from topo.base.simulation import EventProcessor,EPConnectionEvent 
16   
17   
18 -class PulseGenerator(EventProcessor):
19 """ 20 A simple pulse generator node. 21 22 Produces pulses (scalars) of a fixed amplitude at a fixed 23 frequency and phase. Period and phase are in units of simulation 24 time. 25 """ 26 27 dest_ports=None # Allows connections to come in on any port 28 29 amplitude = param.Number(1.0,doc="The size of the pulse to generate.") 30 31 period = param.Number(1.0,bounds=(0.0,None),doc= 32 "The period with which to repeat the pulse. Must be greater than zero.") 33 34 phase = param.Number(0.0,doc= 35 "The time after starting the simulation to wait before sending the first pulse.") 36
37 - def input_event(self,conn,data):
38 """On input from self, generate output. Ignore all other inputs.""" 39 self.verbose("Received event from ",conn.src,'on port',conn.dest_port,'with data',data) 40 self.send_output(data=self.amplitude)
41
42 - def start(self):
43 conn=self.simulation.connect(self.name,self.name,delay=self.period) 44 e=EPConnectionEvent(self.simulation.time()+self.phase, conn) 45 self.simulation.enqueue_event(e) 46 EventProcessor.start(self)
47 48
49 -class ThresholdUnit(EventProcessor):
50 """ 51 A simple pulse-accumulator threshold node. Accumulates incoming 52 pulses. When the accumulated value rises above threshold, it 53 generates a pulse of a given amplitude and resets the accumulator 54 to zero. 55 """ 56 57 dest_ports=None # Allows connections to come in on any port 58 59 threshold = param.Number(default=1.0,doc="The threshold at which to fire.") 60 initial_accum = param.Number(default=0.0,doc="The initial accumulator value.") 61 amplitude = param.Number(default=1.0,doc="The size of the pulse to generate.") 62
63 - def __init__(self,**params):
64 EventProcessor.__init__(self,**params) 65 self.accum = self.initial_accum
66
67 - def input_event(self,conn,data):
68 if conn.dest_port == 'input': 69 self.accum += data 70 self.verbose("Received ",data,"; accumulator now",self.accum) 71 if self.accum > self.threshold: 72 self.send_output(data=self.amplitude) 73 self.accum = 0 74 self.verbose(`self` + ' firing, amplitude = ' + `self.amplitude`)
75 76
77 -class SumUnit(EventProcessor):
78 """A simple unit that outputs the running sum of input received thus far.""" 79 80 dest_ports=None # Allows connections to come in on any port 81
82 - def __init__(self,**params):
83 super(SumUnit,self).__init__(**params) 84 self.value = 0.0
85
86 - def input_event(self,conn,data):
87 self.value += data 88 self.debug("received",data,"from",conn.src,"value =",self.value)
89
90 - def process_current_time(self):
91 self.debug("process_current_time called, time =",self.simulation.time(),"value =",self.value) 92 if self.value: 93 self.debug("Sending output:",self.value) 94 self.send_output(data=self.value) 95 self.value = 0.0
96