Changeset 961
- Timestamp:
- 05/04/11 17:44:10 (13 months ago)
- Location:
- trunk/src
- Files:
-
- 2 modified
-
common.py (modified) (3 diffs)
-
nest/recording.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common.py
r957 r961 656 656 return (variable in self.celltype.recordable) 657 657 658 def _add_recorder(self, variable ):658 def _add_recorder(self, variable, to_file): 659 659 """Create a new Recorder for the supplied variable.""" 660 660 assert variable not in self.recorders … … 665 665 logger.debug("Adding recorder for %s to %s" % (variable, self.label)) 666 666 population.recorders[variable] = population.recorder_class(variable, 667 population=population )667 population=population, file=to_file) 668 668 669 669 def _record(self, variable, to_file=True): … … 682 682 logger.debug("%s.record('%s')", self.label, variable) 683 683 if variable not in self.recorders: 684 self._add_recorder(variable )684 self._add_recorder(variable, to_file) 685 685 if self.record_filter is not None: 686 686 self.recorders[variable].record(self.record_filter) 687 687 else: 688 688 self.recorders[variable].record(self.all_cells) 689 if isinstance(to_file, basestring):690 self.recorders[variable].file = to_file689 #if isinstance(to_file, basestring): 690 # self.recorders[variable].file = to_file 691 691 692 692 def record(self, to_file=True): -
trunk/src/nest/recording.py
r957 r961 1 """2 3 :copyright: Copyright 2006-2011 by the PyNN team, see AUTHORS.4 :license: CeCILL, see LICENSE for details.5 """6 7 1 import tempfile 8 2 import os … … 32 26 def __init__(self, device_type, to_memory=False): 33 27 assert device_type in ("multimeter", "spike_detector") 34 self.type = device_type35 self.device = nest.Create(device_type)36 28 self.type = device_type 29 self.device = nest.Create(device_type) 30 self.to_memory = to_memory 37 31 device_parameters = {"withgid": True, "withtime": True} 38 32 if self.type is 'multimeter': … … 170 164 non_empty_nest_files = [filename for filename in nest_files if os.stat(filename).st_size > 0] 171 165 if len(non_empty_nest_files) > 0: 172 data_list = [numpy.loadtxt(nest_file) for nest_file in non_empty_nest_files] 173 data = numpy.concatenate(data_list) 166 data = numpy.concatenate([numpy.loadtxt(nest_file) for nest_file in non_empty_nest_files]) 174 167 if len(non_empty_nest_files) == 0 or data.size == 0: 175 168 if self.type is "spike_detector": … … 199 192 # what if the method is called with different values of 200 193 # `compatible_output`? Need to cache these separately. 201 if gather and simulator.state.num_processes > 1: 202 if self._gathered: 203 logger.debug("Loading previously gathered data from cache") 204 self._gathered_file.seek(0) 205 data = numpy.load(self._gathered_file) 194 if not self.to_memory: 195 if gather and simulator.state.num_processes > 1: 196 if self._gathered: 197 logger.debug("Loading previously gathered data from cache") 198 self._gathered_file.seek(0) 199 data = numpy.load(self._gathered_file) 200 else: 201 local_data = self.read_local_data(compatible_output) 202 if always_local: 203 data = local_data # for always_local cells, no need to gather 204 else: 205 logger.debug("Gathering data") 206 data = recording.gather(local_data) 207 logger.debug("Caching gathered data") 208 self._gathered_file = tempfile.TemporaryFile() 209 numpy.save(self._gathered_file, data) 210 self._gathered = True 206 211 else: 207 local_data = self.read_local_data(compatible_output) 208 if always_local: 209 data = local_data # for always_local cells, no need to gather 210 else: 211 logger.debug("Gathering data") 212 data = recording.gather(local_data) 213 logger.debug("Caching gathered data") 214 self._gathered_file = tempfile.TemporaryFile() 215 numpy.save(self._gathered_file, data) 216 self._gathered = True 217 else: 218 data = self.read_local_data(compatible_output) 219 if len(data.shape) == 1: 220 data = data.reshape((1, data.size)) 221 return data 212 data = self.read_local_data(compatible_output) 213 if len(data.shape) == 1: 214 data = data.reshape((1, data.size)) 215 return data 216 else: 217 return self.read_data_from_memory(gather, compatible_output) 222 218 223 219 def read_subset(self, variables, gather, compatible_output, always_local=False): … … 296 292 if self._device.in_memory(): 297 293 events = nest.GetStatus(self._device.device, 'events')[0] 298 for id in filtered_ids:294 for id in self.filter_recorded(filter): 299 295 mask = events['senders'] == int(id) 300 N[i d] = len(events['times'][mask])296 N[int(id)] = len(events['times'][mask]) 301 297 else: 302 298 spikes = self._get(gather=False, compatible_output=False, 303 299 filter=filter) 304 300 for id in self.filter_recorded(filter): 305 N[i d] = 0301 N[int(id)] = 0 306 302 ids = numpy.sort(spikes[:,0].astype(int)) 307 303 idx = numpy.unique(ids)
