Changeset 372

Show
Ignore:
Timestamp:
06/18/08 14:47:45 (5 months ago)
Author:
apdavison
Message:

recording.write_compatible_output() now takes an input_format argument, specifying the order of time, id, voltage, etc columns.

Note, in nest2, reintroduced the use of recording_device.interval, since that seems to have reappeared (I'm using NEST version 1.9-7295 Jun 11 2008).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/nest2/__init__.py

    r364 r372  
    9999    """Encapsulates data and functions related to recording model variables.""" 
    100100     
     101    formats = {'spikes': 'id t', 
     102               'v': 'id t v'} 
     103     
    101104    def __init__(self, variable, population=None, file=None): 
    102105        """ 
     
    115118        self._device = nest.Create(device_name) 
    116119        device_parameters = {"withgid": True, "withtime": True, 
    117                              "to_file": True, "to_memory": False} 
     120                             "to_file": True, "to_memory": False, 
     121                             "interval": get_time_step()} 
    118122        if file is False: 
    119123            device_parameters.update(to_file=False, to_memory=True) 
     
    158162                user_filename += '.%d' % rank() 
    159163            if gather == False or rank() == 0: # if we gather, only do this on the master node 
    160                 recording.write_compatible_output(nest_filename, user_filename, 
     164                recording.write_compatible_output(nest_filename, user_filename, Recorder.formats[self.variable], 
    161165                                                  self.population, get_time_step()) 
    162166        else: 
  • trunk/src/neuron/__init__.py

    r370 r372  
    400400                write_data() 
    401401        else: 
    402             self.filename += ".%d" % myid     
     402            if num_processes() > 1: 
     403                self.filename += ".%d" % myid     
    403404            write_data() 
    404405                 
  • trunk/src/neuron2/utility.py

    r371 r372  
    11from pyNN import __path__ as pyNN_path 
    2 from pyNN import common 
     2from pyNN import common, recording 
    33import platform 
    44import logging 
     
    2727    """Encapsulates data and functions related to recording model variables.""" 
    2828     
    29     formats = {'spikes': "%g\t%d", 
     29    numpy_formats = {'spikes': "%g\t%d", 
    3030               'v': "%g\t%g\t%d"} 
     31    formats = {'spikes': 't id', 
     32               'v': 't v id'} 
    3133     
    3234    def __init__(self, variable, population=None, file=None): 
     
    4042        self.filename = file or None 
    4143        self.population = population # needed for writing header information 
    42         self.recorded = set([])         
     44        self.recorded = set([]) 
     45         
    4346 
    4447    def record(self, ids): 
     
    8083    def write(self, file=None, gather=False, compatible_output=True): 
    8184        data = self.get(gather) 
    82         numpy.savetxt(file or self.filename, data, Recorder.formats[self.variable]) 
     85        filename = file or self.filename 
     86        numpy.savetxt(filename, data, Recorder.numpy_formats[self.variable]) 
     87        if compatible_output: 
     88            recording.write_compatible_output(filename, filename, Recorder.formats[self.variable], 
     89                                              self.population, common.get_time_step()) 
    8390         
    8491class Initializer(object): 
  • trunk/src/recording.py

    r360 r372  
    5757             
    5858     
    59 def write_compatible_output(sim_filename, user_filename, population, dt): 
     59def write_compatible_output(sim_filename, user_filename, input_format, population, dt): 
    6060    """ 
    6161    Rewrite simulation data in a standard format: 
     
    6363    """ 
    6464    logging.info("Writing %s in compatible format (was %s)" % (user_filename, sim_filename)) 
    65     result = open(user_filename,'w',DEFAULT_BUFFER_SIZE) 
    66          
    67     # Write header info (e.g., dimensions of the population) 
    68     if population is not None: 
    69         result.write("# dimensions =" + "\t".join([str(d) for d in population.dim]) + "\n") 
    70         result.write("# first_id = %d\n" % population.id_start) 
    71         result.write("# last_id = %d\n" % (population.id_start+len(population)-1,)) 
    72         padding = population.id_start 
    73     else: 
    74         padding = 0 
    75     result.write("# dt = %g\n" % dt) 
    7665                     
    7766    # Writing spiketimes, cell_id-min(cell_id)                     
     
    7968    if os.path.getsize(sim_filename) > 0: 
    8069        data = readArray(sim_filename, sepchar=None) 
     70         
     71        result = open(user_filename,'w',DEFAULT_BUFFER_SIZE)     
     72        # Write header info (e.g., dimensions of the population) 
     73        if population is not None: 
     74            result.write("# dimensions =" + "\t".join([str(d) for d in population.dim]) + "\n") 
     75            result.write("# first_id = %d\n" % population.id_start) 
     76            result.write("# last_id = %d\n" % (population.id_start+len(population)-1,)) 
     77            padding = population.id_start 
     78        else: 
     79            padding = 0 
     80        result.write("# dt = %g\n" % dt) 
     81         
    8182        data[:,0] = data[:,0] - padding 
     83         
    8284        # sort 
    8385        #indx = data.argsort(axis=0, kind='mergesort')[:,0] # will quicksort (not stable) work? 
    8486        #data = data[indx] 
     87        input_format = input_format.split() 
     88        time_column = input_format.index('t') 
     89        id_column = input_format.index('id') 
     90         
    8591        if data.shape[1] == 4: # conductance files 
     92            ge_column = input_format.index('ge') 
     93            gi_column = input_format.index('gi') 
    8694            raise Exception("Not yet implemented") 
    8795        elif data.shape[1] == 3: # voltage files 
     96            v_column = input_format.index('v') 
    8897            #result.write("# n = %d\n" % int(nest.GetStatus([0], "time")[0]/dt)) 
    8998            result.write("# n = %d\n" % len(data)) 
    9099            for idx in xrange(len(data)): 
    91                 result.write("%g\t%d\n" % (data[idx][2], data[idx][0])) # v id 
     100                result.write("%g\t%d\n" % (data[idx][v_column], data[idx][id_column])) # v id 
    92101        elif data.shape[1] == 2: # spike files 
    93102            for idx in xrange(len(data)): 
    94                 result.write("%g\t%d\n" % (data[idx][1], data[idx][0])) # time id 
     103                result.write("%g\t%d\n" % (data[idx][t_column], data[idx][id_column])) # time id 
    95104        else: 
    96105            raise Exception("Data file should have 2,3 or 4 columns, actually has %d" % data.shape[1]) 
     106        result.close() 
    97107    else: 
    98108        logging.info("%s is empty" % sim_filename) 
    99     result.close() 
    100  
    101  
     109     
    102110def readArray(filename, sepchar=None, skipchar='#'): 
    103111    """