- Timestamp:
- 12/14/11 09:58:04 (5 months ago)
- Location:
- branches/neo_output
- Files:
-
- 1 added
- 8 modified
-
examples/reset_example.py (added)
-
src/common/control.py (modified) (2 diffs)
-
src/common/populations.py (modified) (3 diffs)
-
src/nest/recording.py (modified) (1 diff)
-
src/nest/simulator.py (modified) (1 diff)
-
src/neuron/electrodes.py (modified) (4 diffs)
-
src/neuron/recording.py (modified) (2 diffs)
-
src/neuron/simulator.py (modified) (1 diff)
-
src/recording/__init__.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/neo_output/src/common/control.py
r1000 r1032 41 41 42 42 def build_reset(simulator): 43 def reset( ):43 def reset(annotations={}): 44 44 """ 45 45 Reset the time to zero, neuron membrane potentials and synaptic weights to … … 47 47 is not changed, nor is the specification of which neurons to record from. 48 48 """ 49 for recorder in simulator.recorders: 50 recorder.store_to_cache(annotations) 49 51 simulator.reset() 50 52 return reset -
branches/neo_output/src/common/populations.py
r1030 r1032 622 622 self._positions = None 623 623 self._is_sorted = True 624 self.annotations = {} 624 625 # Build the arrays of cell ids 625 626 # Cells on the local node are represented as ID objects, other cells by integers … … 713 714 case of non-point models).""") 714 715 716 def annotate(self, **annotations): 717 self.annotations.update(annotations) 718 715 719 def describe(self, template='population_default.txt', engine='default'): 716 720 """ … … 732 736 "last_id": self.last_id, 733 737 } 738 context.update(self.annotations) 734 739 if len(self.local_cells) > 0: 735 740 first_id = self.local_cells[0] -
branches/neo_output/src/nest/recording.py
r1031 r1032 394 394 # self._create_device() 395 395 396 def _get(self, variables, gather=False, filter_ids=None):397 """Return the recorded data as a Neo `Block`."""398 always_local = (hasattr(self.population.celltype, 'always_local') and self.population.celltype.always_local)399 data = neo.Block()400 # TODO: add cached data from previous runs401 data.segments.append(self._get_current_segment(filter_ids=filter_ids, variables=variables))402 return data403 404 396 def _get_current_segment(self, filter_ids=None, variables='all'): 405 397 segment = neo.Segment(name=self.population.label, -
branches/neo_output/src/nest/simulator.py
r1026 r1032 36 36 write_on_end = [] # a list of (population, variable, filename) combinations that should be written to file on end() 37 37 recording_devices = [] 38 recorders = set([]) 38 39 39 40 global net -
branches/neo_output/src/neuron/electrodes.py
r957 r1032 13 13 14 14 from neuron import h 15 16 def _iclamp_property(local_name, hoc_name): 17 """ 18 Returns a new property for getting/setting iclamp attributes 19 """ 20 def get(self): 21 return getattr(self, local_name) 22 def set(self, value): 23 setattr(self, local_name, value) 24 for iclamp in self._devices: 25 setattr(iclamp, hoc_name, value) 26 return property(fget=get, fset=set) 15 27 16 28 … … 31 43 amplitude -- pulse amplitude in nA 32 44 """ 33 self. amplitude = amplitude34 self. start = start35 self. stop = stop or 1e1245 self._amplitude = amplitude 46 self._start = start 47 self._stop = stop or 1e12 36 48 self._devices = [] 37 49 … … 41 53 if id.local: 42 54 iclamp = h.IClamp(0.5, sec=id._cell.source_section) 43 iclamp.delay = self. start44 iclamp.dur = self. stop-self.start45 iclamp.amp = self. amplitude55 iclamp.delay = self._start 56 iclamp.dur = self._stop-self._start 57 iclamp.amp = self._amplitude 46 58 self._devices.append(iclamp) 59 60 amplitude = _iclamp_property("_amplitude", "amp") 61 62 def _set_start(self, value): 63 self._start = value 64 for iclamp in self._devices: 65 iclamp.delay = value 66 iclamp.dur = self._stop - value 67 start = property(fget=lambda self: self._start, 68 fset=_set_start) 69 70 def _set_stop(self, value): 71 self._stop = value 72 for iclamp in self._devices: 73 iclamp.dur = value - self._start 74 stop = property(fget=lambda self: self._start, 75 fset=_set_stop) 47 76 48 77 … … 79 108 self.amplitudes.play(iclamp._ref_amp, self.times) 80 109 110 # need to make times and amplitudes properties so they can be modified 111 -
branches/neo_output/src/neuron/recording.py
r1031 r1032 19 19 # --- For implementation of record_X()/get_X()/print_X() ----------------------- 20 20 21 def filter_variables(segment, variables):22 """23 Return a new `Segment` containing only recordings of the variables given in24 the list `variables`25 """26 if variables == 'all':27 return segment28 else:29 new_segment = copy(segment) # shallow copy30 if 'spikes' not in variables:31 new_segment.spiketrains = []32 new_segment.analogsignals = [sig for sig in segment.analogsignals if sig.name in variables]33 # also need to handle Units, RecordingChannels34 return new_segment35 36 37 class DataCache(object):38 # primitive implementation for now, storing in memory - later can consider caching to disk39 def __init__(self):40 self._data = []41 42 def __iter__(self):43 return iter(self._data)44 45 def store(self, obj):46 self._data.append(obj)47 48 49 21 50 22 class Recorder(recording.Recorder): 51 23 """Encapsulates data and functions related to recording model variables.""" 52 _simulator = simulator 53 54 def __init__(self, population, file=None): 55 __doc__ = super(Recorder, self).__init__.__doc__ 56 super(Recorder, self).__init__(population, file) 57 self.cache = DataCache() 24 _simulator = simulator 58 25 59 26 def _record(self, variable, new_ids): … … 107 74 else: 108 75 raise Exception("Recording of %s not implemented." % variable) 109 110 def _get(self, variables, gather=False, filter_ids=None):111 """Return the recorded data as a Neo `Block`."""112 data = neo.Block()113 data.segments = [filter_variables(segment, variables) for segment in self.cache]114 data.segments.append(self._get_current_segment(filter_ids=filter_ids, variables=variables))115 if gather and simulator.state.num_processes > 1:116 data = recording.gather(data)117 return data118 76 119 77 def _get_current_segment(self, filter_ids=None, variables='all'): -
branches/neo_output/src/neuron/simulator.py
r1025 r1032 39 39 write_on_end = [] 40 40 gid_sources = [] 41 recorders = set([]) 41 42 logger = logging.getLogger("PyNN") 42 43 -
branches/neo_output/src/recording/__init__.py
r1030 r1032 107 107 raise Exception("file extension %s not supported" % extension) 108 108 109 def filter_by_variables(segment, variables): 110 """ 111 Return a new `Segment` containing only recordings of the variables given in 112 the list `variables` 113 """ 114 if variables == 'all': 115 return segment 116 else: 117 new_segment = copy(segment) # shallow copy 118 if 'spikes' not in variables: 119 new_segment.spiketrains = [] 120 new_segment.analogsignals = [sig for sig in segment.analogsignals if sig.name in variables] 121 # also need to handle Units, RecordingChannels 122 return new_segment 123 124 125 class DataCache(object): 126 # primitive implementation for now, storing in memory - later can consider caching to disk 127 def __init__(self): 128 self._data = [] 129 130 def __iter__(self): 131 return iter(self._data) 132 133 def store(self, obj): 134 if obj not in self._data: 135 self._data.append(obj) 136 109 137 110 138 class Recorder(object): … … 125 153 self.population = population # needed for writing header information 126 154 self.recorded = defaultdict(set) 155 self.cache = DataCache() 156 self._simulator.recorders.add(self) 127 157 128 158 def record(self, variables, ids): … … 153 183 """Return the recorded data as a Neo `Block`.""" 154 184 variables = normalize_variables_arg(variables) 155 data = self._get(variables, gather, filter_ids) 185 data = neo.Block() 186 data.segments = [filter_by_variables(segment, variables) 187 for segment in self.cache] 188 if self._simulator.state.running: # reset() has not been called, so current segment is not in cache 189 data.segments.append(self._get_current_segment(filter_ids=filter_ids, variables=variables)) 156 190 data.name = self.population.label 157 191 data.description = self.population.describe() 158 192 data.rec_datetime = data.segments[0].rec_datetime 159 193 data.annotate(**self.metadata) 194 if gather and self._simulator.state.num_processes > 1: 195 data = recording.gather(data) 160 196 return data 161 197 … … 183 219 'label': self.population.label, 184 220 } 221 metadata.update(self.population.annotations) 185 222 metadata['dt'] = self._simulator.state.dt # note that this has to run on all nodes (at least for NEST) 186 223 return metadata … … 199 236 return N 200 237 238 def store_to_cache(self, annotations={}): 239 segment = self._get_current_segment() 240 segment.annotate(**annotations) 241 self.cache.store(segment)
