def start_simulation(self):
"""Starts the simulation with visualization."""
self.show_setup(halt=False)
main_plot, = self.axes.plot([])
sim_process = mp.Process(target=self._sim_function, args=(self._plot_queue,))
sim_process.start()
# wait for simulation initialization
while self._plot_queue.empty():
pl.pause(0.1)
finished = False
while not finished:
# wait for new simulation result
while self._plot_queue.empty():
pl.pause(0.01)
message = self._plot_queue.get()
# simulation function returns field object when simulation is complete to get output
if isinstance(message, fld.Field):
# update main process field components with simulation result
self._update_components(message)
finished = True
else:
time, data = message
self.axes.title.set_text('{title} $t$ = {time:.{prec}f} {prefix}s'
.format(title=self.plot_title, time=time/self._t_factor,
prec=self.time_precision, prefix=self._t_prefix))
main_plot.set_data(self.field.x.vector / self._x_axis_factor, data)
pl.pause(self.frame_delay)
sim_process.join()
pp.show()
python类pause()的实例源码
def start_simulation(self):
"""Starts the simulation with visualization."""
self.show_setup(halt=False)
main_plot = self.axes.imshow(self.field_as_matrix(),
extent=(0, max(self.field.x.vector) / self._x_axis_factor,
max(self.field.y.vector) / self._y_axis_factor, 0),
cmap='viridis')
main_plot.set_clim(-self.scale, self.scale)
color_bar = pp.colorbar(main_plot)
color_bar.set_label(self.observed_component, rotation=270)
sim_process = mp.Process(target=self._sim_function, args=(self._plot_queue,))
sim_process.start()
# wait for simulation initialization
while self._plot_queue.empty():
pl.pause(0.1)
finished = False
while not finished:
# wait for new simulation result
while self._plot_queue.empty():
pl.pause(0.01)
message = self._plot_queue.get()
# simulation function returns field object when simulation is complete to get output
if isinstance(message, fld.Field):
# update main process field components with simulation result
self._update_components(message)
finished = True
else:
time, data = message
self.axes.title.set_text('{title} $t$ = {time:.{prec}f} {prefix}s'
.format(title=self.plot_title, time=time/self._t_factor,
prec=self.time_precision, prefix=self._t_prefix))
main_plot.set_data(self.field_as_matrix(data))
pl.pause(self.frame_delay)
sim_process.join()
pp.show()
def onclick(event):
#print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(event.button, event.x, event.y, event.xdata, event.ydata)
start_point = int(event.xdata)
sum_data = get_noise(start_point)
#plot_sum_data(sum_data)
process_data(start_point,sum_data)
display_wav('junk_out.wav')
cmd5 = 'play junk_out.mp3'
os.system(cmd5)
pylab.pause(2**31-1)
def db_plot(*args, **kwargs):
# plot utility for debugging
plt.plot(*args, **kwargs)
plt.show()
pause(1)
def image_loop(self, decay, display_mode):
import pylab
fig = pylab.figure()
pylab.ion()
img = pylab.imshow(self.image, vmax=1, vmin=-1,
interpolation='none', cmap='binary')
pylab.xlim(0, 127)
pylab.ylim(127, 0)
regions = {}
if self.count_spike_regions is not None:
for k, v in self.count_spike_regions.items():
minx, miny, maxx, maxy = v
rect = pylab.Rectangle((minx - 0.5, miny - 0.5),
maxx - minx,
maxy - miny,
facecolor='yellow', alpha=0.2)
pylab.gca().add_patch(rect)
regions[k] = rect
if self.track_periods is not None:
colors = ([(0,0,1), (0,1,0), (1,0,0), (1,1,0), (1,0,1)] * 10)[:len(self.p_y)]
scatter = pylab.scatter(self.p_x, self.p_y, s=50, c=colors)
else:
scatter = None
while True:
img.set_data(self.image)
for k, rect in regions.items():
alpha = self.get_spike_rate(k) * 0.5
alpha = min(alpha, 0.5)
rect.set_alpha(0.05 + alpha)
if scatter is not None:
scatter.set_offsets(np.array([self.p_x, self.p_y]).T)
c = [(r,g,b,min(self.track_certainty[i],1)) for i,(r,g,b) in enumerate(colors)]
scatter.set_color(c)
if display_mode == 'quick':
# this is much faster, but doesn't work on all systems
fig.canvas.draw()
fig.canvas.flush_events()
else:
# this works on all systems, but is kinda slow
pylab.pause(0.001)
self.image *= decay
def images_loop(self, decays, display_mode):
import pylab
fig = pylab.figure()
num_images = len(decays)
pylab.ion()
imgs = []
for i in range(len(decays)):
fig.add_subplot(1, num_images, i+1)
imgs.append( pylab.imshow(self.images[i], vmax=1, vmin=-1,
interpolation='none', cmap='binary') )
pylab.xlim(0, 127)
pylab.ylim(127, 0)
regions = {}
if self.count_spike_regions is not None:
for k, v in self.count_spike_regions.items():
minx, miny, maxx, maxy = v
rect = pylab.Rectangle((minx - 0.5, miny - 0.5),
maxx - minx,
maxy - miny,
facecolor='yellow', alpha=0.2)
pylab.gca().add_patch(rect)
regions[k] = rect
if self.track_periods is not None:
colors = ([(0,0,1), (0,1,0), (1,0,0), (1,1,0), (1,0,1)] * 10)[:len(self.p_y)]
scatter = pylab.scatter(self.p_x, self.p_y, s=50, c=colors)
else:
scatter = None
while True:
for i,d in enumerate(decays):
imgs[i].set_data(self.images[i])
for k, rect in regions.items():
alpha = self.get_spike_rate(k) * 0.5
alpha = min(alpha, 0.5)
rect.set_alpha(0.05 + alpha)
if scatter is not None:
scatter.set_offsets(np.array([self.p_x, self.p_y]).T)
c = [(r,g,b,min(self.track_certainty[i],1)) for i,(r,g,b) in enumerate(colors)]
scatter.set_color(c)
if display_mode == 'quick':
# this is much faster, but doesn't work on all systems
fig.canvas.draw()
fig.canvas.flush_events()
else:
# this works on all systems, but is kinda slow
pylab.pause(0.001)
for i,d in enumerate(decays):
self.images[i] *= d
def image_loop(self, decay, display_mode):
import pylab
fig = pylab.figure()
pylab.ion()
img = pylab.imshow(self.image, vmax=1, vmin=-1,
interpolation='none', cmap='binary')
pylab.xlim(0, 127)
pylab.ylim(127, 0)
regions = {}
if self.count_spike_regions is not None:
for k, v in self.count_spike_regions.items():
minx, miny, maxx, maxy = v
rect = pylab.Rectangle((minx - 0.5, miny - 0.5),
maxx - minx,
maxy - miny,
facecolor='yellow', alpha=0.2)
pylab.gca().add_patch(rect)
regions[k] = rect
if self.track_periods is not None:
colors = ([(0,0,1), (0,1,0), (1,0,0), (1,1,0), (1,0,1)] * 10)[:len(self.p_y)]
scatter = pylab.scatter(self.p_x, self.p_y, s=50, c=colors)
else:
scatter = None
while True:
img.set_data(self.image)
for k, rect in regions.items():
alpha = self.get_spike_rate(k) * 0.5
alpha = min(alpha, 0.5)
rect.set_alpha(0.05 + alpha)
if scatter is not None:
scatter.set_offsets(np.array([self.p_x, self.p_y]).T)
c = [(r,g,b,min(self.track_certainty[i],1)) for i,(r,g,b) in enumerate(colors)]
scatter.set_color(c)
if display_mode == 'quick':
# this is much faster, but doesn't work on all systems
fig.canvas.draw()
fig.canvas.flush_events()
else:
# this works on all systems, but is kinda slow
pylab.pause(0.001)
self.image *= decay