Changeset 961

Show
Ignore:
Timestamp:
05/04/11 17:44:10 (13 months ago)
Author:
pierre
Message:

Fix for the to_file=False option in NEST. I had a fix also for this, since I saw this was not working. It has been tested in a paralell context, and it works. Spikes saved in memory can also after be saved to file via printSpikes() if needed.

Location:
trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common.py

    r957 r961  
    656656        return (variable in self.celltype.recordable) 
    657657 
    658     def _add_recorder(self, variable): 
     658    def _add_recorder(self, variable, to_file): 
    659659        """Create a new Recorder for the supplied variable.""" 
    660660        assert variable not in self.recorders 
     
    665665        logger.debug("Adding recorder for %s to %s" % (variable, self.label)) 
    666666        population.recorders[variable] = population.recorder_class(variable, 
    667                                                                    population=population) 
     667                                                                   population=population, file=to_file) 
    668668 
    669669    def _record(self, variable, to_file=True): 
     
    682682            logger.debug("%s.record('%s')", self.label, variable) 
    683683            if variable not in self.recorders: 
    684                 self._add_recorder(variable) 
     684                self._add_recorder(variable, to_file) 
    685685            if self.record_filter is not None: 
    686686                self.recorders[variable].record(self.record_filter) 
    687687            else: 
    688688                self.recorders[variable].record(self.all_cells) 
    689             if isinstance(to_file, basestring): 
    690                 self.recorders[variable].file = to_file 
     689            #if isinstance(to_file, basestring): 
     690            #    self.recorders[variable].file = to_file 
    691691 
    692692    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  
    71import tempfile 
    82import os 
     
    3226    def __init__(self, device_type, to_memory=False): 
    3327        assert device_type in ("multimeter", "spike_detector") 
    34         self.type = device_type 
    35         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 
    3731        device_parameters = {"withgid": True, "withtime": True} 
    3832        if self.type is 'multimeter': 
     
    170164            non_empty_nest_files = [filename for filename in nest_files if os.stat(filename).st_size > 0] 
    171165            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]) 
    174167            if len(non_empty_nest_files) == 0 or data.size == 0: 
    175168                if self.type is "spike_detector": 
     
    199192        # what if the method is called with different values of 
    200193        # `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 
    206211            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) 
    222218     
    223219    def read_subset(self, variables, gather, compatible_output, always_local=False): 
     
    296292        if self._device.in_memory(): 
    297293            events = nest.GetStatus(self._device.device, 'events')[0] 
    298             for id in filtered_ids: 
     294            for id in self.filter_recorded(filter): 
    299295                mask = events['senders'] == int(id) 
    300                 N[id] = len(events['times'][mask]) 
     296                N[int(id)] = len(events['times'][mask]) 
    301297        else: 
    302298            spikes = self._get(gather=False, compatible_output=False, 
    303299                               filter=filter) 
    304300            for id in self.filter_recorded(filter): 
    305                 N[id] = 0 
     301                N[int(id)] = 0 
    306302            ids   = numpy.sort(spikes[:,0].astype(int)) 
    307303            idx   = numpy.unique(ids)