Changeset 444
- Timestamp:
- 08/20/08 11:42:21 (3 months ago)
- Files:
-
- trunk/src/neuron/__init__.py (modified) (11 diffs)
- trunk/src/recording.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/neuron/__init__.py
r431 r444 23 23 import logging 24 24 import platform 25 import tempfile 25 26 Set = set 26 27 … … 330 331 331 332 def write(self, file=None, gather=False, compatible_output=True): 332 hoc_execute(['objref gathered_vec_list', 333 'gathered_vec_list = new List()']) 333 hoc_execute(['objref gathered_vec_list, gathered_id_vec', 334 'gathered_vec_list = new List()', 335 'gathered_id_vec = new Vector(0)']) 334 336 vector_operation = '' 335 337 if self.variable == 'spikes': … … 338 340 if self.population is None: 339 341 cell_template = "cell%d" 340 post_ label = "node%d: post cellX.%s" % (myid, self.variable)342 post_fmt = "node%%d: post cellX.%s" % self.variable 341 343 id_list = gidlist 342 344 padding = 0 343 345 else: 344 346 cell_template = "%s.object(%s)" % (self.population.hoc_label, "%d") 345 post_ label = 'node%d: post_%s.%s' % (myid,self.population.hoc_label, self.variable)347 post_fmt = 'node%%d: post_%s.%s' % (self.population.hoc_label, self.variable) 346 348 id_list = self.population.gidlist 347 349 padding = self.population.first_id … … 349 351 def post_data(): 350 352 pack_template = 'tmp = pc.pack(%s.%s%s)' % (cell_template, 351 RECORDING_VECTOR_NAME [self.variable],353 RECORDING_VECTOR_NAMES[self.variable], 352 354 vector_operation) 355 hoc_commands = ['tmp = pc.pack(%d)' % len(self.recorded)] 353 356 for cell in self.recorded: 354 hoc_commands += ['tmp = pc.pack(%d)' % id_list.index(cell),357 hoc_commands += ['tmp = pc.pack(%d)' % cell, #id_list.index(cell), 355 358 pack_template % id_list.index(cell)] 356 hoc_commands += ['tmp = pc.post("%s")' % post_label]357 hoc_execute(hoc_commands,"--- Population[%s].__print()__ --- [Post objects to master]" % self.label)359 hoc_commands += ['tmp = pc.post("%s")' % (post_fmt % myid,)] 360 hoc_execute(hoc_commands,"--- Population[%s].__print()__ --- [Post objects to master]" % self.population.label) 358 361 def take_data(): 359 hoc_commands = ['tmp = pc.take(post_label)']362 #hoc_commands = ['tmp = pc.take(post_label)'] 360 363 for node in range(1, num_processes()): 361 hoc_commands += ['gathered_vec_list.append(pc.upkscalar())', 362 'gathered_vec_list.append(pc.upkvec())'] 364 take_label = post_fmt % node 365 hoc_commands = ['tmp = pc.take("%s")' % take_label, 366 'n = pc.upkscalar()', 367 'for i = 1,n { gathered_id_vec.append(pc.upkscalar()) gathered_vec_list.append(pc.upkvec()) }'] 368 hoc_execute(hoc_commands,"--- Population[%s].__print()__ --- [Take objects from node %d]" % (self.population.label, node)) 363 369 def write_data(): 364 370 if self.population is None: … … 388 394 hoc_commands += ['fmt = "%s\\t%d\\n"' % (num_format, cell-padding), 389 395 write_template % id_list.index(cell)] 390 # writing gathered data is currently broken391 #hoc_commands += ['while i < gathered_vec_list.count()-2 { gathered_vec_list.o(i+1).printf(fileobj, "%s broken") ' % num_format]392 hoc_commands += ['tmp = fileobj.close()']393 396 hoc_execute(hoc_commands, "Recorder.write()") 397 # write gathered data 398 for id, vec in zip(h.gathered_id_vec, h.gathered_vec_list): 399 fmt = "%s\t%d\n" % (num_format, int(id)-padding) 400 vec.printf(h.fileobj, fmt) 401 h.fileobj.close() 402 394 403 395 404 if gather: … … 401 410 else: 402 411 if num_processes() > 1: 403 self.filename += ".%d" % myid 412 if file: 413 file += ".%d" % myid 414 else: 415 self.filename += ".%d" % myid 404 416 write_data() 405 417 … … 585 597 if tgt > gid or tgt < 0 or not isinstance(tgt, int): 586 598 raise common.ConnectionError, "Postsynaptic cell id %s does not exist." % str(tgt) 587 if "cond" in tgt.cellclass.__name__:599 if hasattr(tgt.cellclass, '__name__') and "cond" in tgt.cellclass.__name__: 588 600 weight = abs(weight) # weights must be positive for conductance-based synapses 589 601 if tgt in gidlist: # only create connections to cells that exist on this machine … … 598 610 else: 599 611 if p >= 1.0 or rarr[j] < p: # might be more efficient to vectorise the latter comparison 600 hoc_commands += [ #'nc = pc.gid_connect(%d, pc.gid2cell(%d).%s)' % (src, tgt, syn_objref),601 'nc = pc.gid_connect(%d, cell%d.%s)' % (src, tgt, syn_objref),612 hoc_commands += ['nc = pc.gid_connect(%d, pc.gid2cell(%d).%s)' % (src, tgt, syn_objref), 613 #'nc = pc.gid_connect(%d, cell%d.%s)' % (src, tgt, syn_objref), 602 614 'nc.delay = %g' % delay, 603 615 'nc.weight = %g' % weight, … … 608 620 if src > gid or src < 0 or not isinstance(src, int): 609 621 raise common.ConnectionError, "Presynaptic cell id %s does not exist." % str(src) 610 print hoc_commands611 622 hoc_execute(hoc_commands, "--- connect(%s,%s) ---" % (str(source), str(target))) 612 623 return range(nc_start, ncid) … … 1041 1052 """ 1042 1053 # This is a bit of a hack implemetation 1043 tmpfile = "neuron_tmpfile"# should really use tempfile module1054 tmpfile = os.path.join(tempfile.mkdtemp(prefix="pyNN_neuron"), "getSpikes_tmpfile") # should really use tempfile module 1044 1055 self.recorders['spikes'].write(tmpfile, gather, compatible_output=False) 1045 if not gather :1046 tmpfile += ' %d' % myid1056 if not gather and num_processes()>1: 1057 tmpfile += '.%d' % myid 1047 1058 if myid==0 or not gather: 1048 1059 f = open(tmpfile, 'r') … … 1051 1062 spikes = numpy.array([line2spike(line.split()) for line in lines]) 1052 1063 f.close() 1053 #os.remove(tmpfile) 1064 #os.remove(tmpfile) # should also remove tmp parent directory 1054 1065 return spikes 1055 1066 else: trunk/src/recording.py
r430 r444 79 79 N = 0 80 80 81 result = open(user_filename,'w',DEFAULT_BUFFER_SIZE) 82 # Write header info (e.g., dimensions of the population) 83 if population is not None: 84 result.write("# dimensions =" + "\t".join([str(d) for d in population.dim]) + "\n") 85 result.write("# first_id = %d\n" % population.first_id) 86 result.write("# last_id = %d\n" % (population.first_id+len(population)-1,)) 87 padding = population.first_id 88 else: 89 padding = 0 90 result.write("# dt = %g\n" % dt) 91 81 92 if N > 0: 82 93 data = readArray(sim_filename, sepchar=None) 83 84 result = open(user_filename,'w',DEFAULT_BUFFER_SIZE)85 # Write header info (e.g., dimensions of the population)86 if population is not None:87 result.write("# dimensions =" + "\t".join([str(d) for d in population.dim]) + "\n")88 result.write("# first_id = %d\n" % population.first_id)89 result.write("# last_id = %d\n" % (population.first_id+len(population)-1,))90 padding = population.first_id91 else:92 padding = 093 result.write("# dt = %g\n" % dt)94 95 94 data[:,0] = data[:,0] - padding 96 97 95 # sort 98 96 #indx = data.argsort(axis=0, kind='mergesort')[:,0] # will quicksort (not stable) work? … … 119 117 else: 120 118 raise Exception("Data file should have 2,3 or 4 columns, actually has %d" % data.shape[1]) 121 result.close()122 119 else: 123 120 logging.info("%s is empty" % sim_filename) 121 result.write("# n = 0\n") 122 result.close() 124 123 125 124 def write_compatible_output1(data_source, user_filename, variable, input_format, population, dt):

