Changeset 372
- Timestamp:
- 06/18/08 14:47:45 (5 months ago)
- Files:
-
- trunk/src/nest2/__init__.py (modified) (3 diffs)
- trunk/src/neuron/__init__.py (modified) (1 diff)
- trunk/src/neuron2/utility.py (modified) (4 diffs)
- trunk/src/recording.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/nest2/__init__.py
r364 r372 99 99 """Encapsulates data and functions related to recording model variables.""" 100 100 101 formats = {'spikes': 'id t', 102 'v': 'id t v'} 103 101 104 def __init__(self, variable, population=None, file=None): 102 105 """ … … 115 118 self._device = nest.Create(device_name) 116 119 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()} 118 122 if file is False: 119 123 device_parameters.update(to_file=False, to_memory=True) … … 158 162 user_filename += '.%d' % rank() 159 163 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], 161 165 self.population, get_time_step()) 162 166 else: trunk/src/neuron/__init__.py
r370 r372 400 400 write_data() 401 401 else: 402 self.filename += ".%d" % myid 402 if num_processes() > 1: 403 self.filename += ".%d" % myid 403 404 write_data() 404 405 trunk/src/neuron2/utility.py
r371 r372 1 1 from pyNN import __path__ as pyNN_path 2 from pyNN import common 2 from pyNN import common, recording 3 3 import platform 4 4 import logging … … 27 27 """Encapsulates data and functions related to recording model variables.""" 28 28 29 formats = {'spikes': "%g\t%d",29 numpy_formats = {'spikes': "%g\t%d", 30 30 'v': "%g\t%g\t%d"} 31 formats = {'spikes': 't id', 32 'v': 't v id'} 31 33 32 34 def __init__(self, variable, population=None, file=None): … … 40 42 self.filename = file or None 41 43 self.population = population # needed for writing header information 42 self.recorded = set([]) 44 self.recorded = set([]) 45 43 46 44 47 def record(self, ids): … … 80 83 def write(self, file=None, gather=False, compatible_output=True): 81 84 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()) 83 90 84 91 class Initializer(object): trunk/src/recording.py
r360 r372 57 57 58 58 59 def write_compatible_output(sim_filename, user_filename, population, dt):59 def write_compatible_output(sim_filename, user_filename, input_format, population, dt): 60 60 """ 61 61 Rewrite simulation data in a standard format: … … 63 63 """ 64 64 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_start73 else:74 padding = 075 result.write("# dt = %g\n" % dt)76 65 77 66 # Writing spiketimes, cell_id-min(cell_id) … … 79 68 if os.path.getsize(sim_filename) > 0: 80 69 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 81 82 data[:,0] = data[:,0] - padding 83 82 84 # sort 83 85 #indx = data.argsort(axis=0, kind='mergesort')[:,0] # will quicksort (not stable) work? 84 86 #data = data[indx] 87 input_format = input_format.split() 88 time_column = input_format.index('t') 89 id_column = input_format.index('id') 90 85 91 if data.shape[1] == 4: # conductance files 92 ge_column = input_format.index('ge') 93 gi_column = input_format.index('gi') 86 94 raise Exception("Not yet implemented") 87 95 elif data.shape[1] == 3: # voltage files 96 v_column = input_format.index('v') 88 97 #result.write("# n = %d\n" % int(nest.GetStatus([0], "time")[0]/dt)) 89 98 result.write("# n = %d\n" % len(data)) 90 99 for idx in xrange(len(data)): 91 result.write("%g\t%d\n" % (data[idx][ 2], data[idx][0])) # v id100 result.write("%g\t%d\n" % (data[idx][v_column], data[idx][id_column])) # v id 92 101 elif data.shape[1] == 2: # spike files 93 102 for idx in xrange(len(data)): 94 result.write("%g\t%d\n" % (data[idx][ 1], data[idx][0])) # time id103 result.write("%g\t%d\n" % (data[idx][t_column], data[idx][id_column])) # time id 95 104 else: 96 105 raise Exception("Data file should have 2,3 or 4 columns, actually has %d" % data.shape[1]) 106 result.close() 97 107 else: 98 108 logging.info("%s is empty" % sim_filename) 99 result.close() 100 101 109 102 110 def readArray(filename, sepchar=None, skipchar='#'): 103 111 """

