def write_frames(self, nframes): if nframes >= 1e6: raise Exception( "Cannot handle movies with 1 million frames or more.") self.frame_directory = tempfile.mkdtemp( prefix='tmp_NeuroTools_visualization_') time_label = self.fig.text(0.01, 0.01, "t = 0 ms", horizontalalignment='left') for i in range(int(nframes)): for panel, obj in self.panels: assert self.frame_duration == obj.frame_duration, "%s != %s" % ( self.frame_duration, obj.frame_duration) panel.lines = [] panel.images = [] plot = getattr(panel, obj.plot_function) plot(*obj.next_frame(), **obj.kwargs) if obj.plot_function == "imshow" and i == 0: pos = panel.get_position() try: l, b, w, h = pos # older versions of Matplotlib except TypeError: l, b, w, h = pos.bounds # newer versions return a Bbox object cb_panel = self.fig.add_axes([l + w, b, 0.05 * w, h]) self.fig.colorbar(panel.images[0], cb_panel) time_label.set_text("t = %g ms" % (i * self.frame_duration, )) self.canvas.print_figure( os.path.join(self.frame_directory, "frame%06d.png" % i)) progress_bar(float(i) / nframes)
def runTest(self): import time print '\nINFO: Testing progress bar...' for i in range(100): plotting.progress_bar(i/100.) time.sleep(.01) print '\n'
def runTest(self): import time print '\nINFO: Testing progress bar...' for i in range(100): plotting.progress_bar(i / 100.) time.sleep(.01) print '\n'
def write_frames(self, nframes): if nframes >= 1e6: raise Exception("Cannot handle movies with 1 million frames or more.") self.frame_directory = tempfile.mkdtemp(prefix='tmp_NeuroTools_visualization_') time_label = self.fig.text(0.01, 0.01, "t = 0 ms", horizontalalignment='left') for i in range(int(nframes)): for panel,obj in self.panels: assert self.frame_duration == obj.frame_duration, "%s != %s" % (self.frame_duration, obj.frame_duration) panel.lines = []; panel.images = [] plot = getattr(panel, obj.plot_function) plot(*obj.next_frame(), **obj.kwargs) if obj.plot_function == "imshow" and i==0: pos = panel.get_position() try: l,b,w,h = pos # older versions of Matplotlib except TypeError: l,b,w,h = pos.bounds # newer versions return a Bbox object cb_panel = self.fig.add_axes([l+w, b, 0.05*w, h]) self.fig.colorbar(panel.images[0], cb_panel) time_label.set_text("t = %g ms" % (i*self.frame_duration,)) self.canvas.print_figure(os.path.join(self.frame_directory, "frame%06d.png" % i)) progress_bar(float(i)/nframes)
def _calculate_input_currents(self, visual_space, duration): """ Calculate the input currents for all cells. """ assert isinstance(visual_space, VisualSpace) if duration is None: duration = visual_space.get_maximum_duration() P_rf = self.parameters.receptive_field rf_function = eval(P_rf.func) rf_ON = SpatioTemporalReceptiveField(rf_function, P_rf.func_params, P_rf.width, P_rf.height, P_rf.duration) rf_OFF = SpatioTemporalReceptiveField(lambda x,y,t,p: -1.0*rf_function(x,y,t,p), P_rf.func_params, P_rf.width, P_rf.height, P_rf.duration) dx = dy = P_rf.spatial_resolution dt = P_rf.temporal_resolution for rf in rf_ON, rf_OFF: rf.quantize(dx, dy, dt) rf = {'X_ON': rf_ON, 'X_OFF': rf_OFF} # create population of CellWithReceptiveFields, setting the receptive # field centres based on the size/location of self logger.debug("Creating population of `CellWithReceptiveField`s") input_cells = {} effective_visual_field_width, effective_visual_field_height = self.parameters.size #x_values = numpy.linspace(-effective_visual_field_width/2.0, effective_visual_field_width/2.0, self.shape[0]) #y_values = numpy.linspace(-effective_visual_field_height/2.0, effective_visual_field_height/2.0, self.shape[1]) for rf_type in self.rf_types: input_cells[rf_type] = [] for i in xrange(0,len(self.sheets[rf_type].pop.positions[0])): cell = CellWithReceptiveField(self.sheets[rf_type].pop.positions[0][i], self.sheets[rf_type].pop.positions[1][i], rf[rf_type], self.parameters.gain) cell.initialize(visual_space.background_luminance, duration) input_cells[rf_type].append(cell) logger.debug("Processing frames") t = 0 retinal_input = [] while t < duration: for rf_type in self.rf_types: for cell in input_cells[rf_type]: cell.view(visual_space) t = visual_space.update() visual_region = VisualRegion(location_x=0,location_y=0, size_x=P_rf.width,size_y=P_rf.height) im = visual_space.view(visual_region, pixel_size=rf_ON.spatial_resolution) retinal_input.append(im) progress_bar(t/duration) input_currents = {} for rf_type in self.rf_types: input_currents[rf_type] = [cell.response_current() for cell in input_cells[rf_type]] cell0_currents = input_currents[rf_type][0] #logger.debug("Input current values for %s cell #0: %s" % (rf_type, cell0_currents['amplitudes'])) #visual_logging.debug(cell0_currents['amplitudes'], cell0_currents['times'], # "Time (ms)", "Current (nA)", "Input current values for %s cell #0" % rf_type) for i in xrange(0,1): a = [cell.response_current()['amplitudes'][i] for cell in input_cells[rf_type]] return (input_currents,retinal_input)