Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def tearDown(self):
mlab.close(all=True)
def plot_one_scene(lyftdata, scene_token):
scene = lyftdata.get('scene', scene_token)
token = scene['first_sample_token']
while token != '':
sample = lyftdata.get('sample', token)
plot_lidar_with_depth(lyftdata, sample)
token = sample['next']
input_str=input('Press any key to continue to next sample, enter "kill" to terminate \n')
mlab.close()
for proc in psutil.process_iter():
if proc.name() == "display":
proc.kill()
if input_str == "kill":
break
figure_list.append(current_fig)
if gallery_conf.get('find_mayavi_figures', False):
from mayavi import mlab
e = mlab.get_engine()
last_matplotlib_fig_num = fig_count + len(figure_list)
total_fig_num = last_matplotlib_fig_num + len(e.scenes)
mayavi_fig_nums = range(last_matplotlib_fig_num + 1, total_fig_num + 1)
for scene, mayavi_fig_num in zip(e.scenes, mayavi_fig_nums):
current_fig = image_path.format(mayavi_fig_num)
mlab.savefig(current_fig, figure=scene)
# make sure the image is not too large
scale_image(current_fig, current_fig, 850, 999)
figure_list.append(current_fig)
mlab.close(all=True)
# Depending on whether we have one or more figures, we're using a
# horizontal list or a single rst call to 'image'.
images_rst = ""
if len(figure_list) == 1:
figure_name = figure_list[0]
images_rst = SINGLE_IMAGE % figure_name.lstrip('/')
elif len(figure_list) > 1:
images_rst = HLIST_HEADER
for figure_name in figure_list:
images_rst += HLIST_IMAGE_TEMPLATE % figure_name.lstrip('/')
return figure_list, images_rst
figure_list.append(current_fig)
if gallery_conf.get('find_mayavi_figures', False):
from mayavi import mlab
e = mlab.get_engine()
last_matplotlib_fig_num = fig_count + len(figure_list)
total_fig_num = last_matplotlib_fig_num + len(e.scenes)
mayavi_fig_nums = range(last_matplotlib_fig_num + 1, total_fig_num + 1)
for scene, mayavi_fig_num in zip(e.scenes, mayavi_fig_nums):
current_fig = image_path.format(mayavi_fig_num)
mlab.savefig(current_fig, figure=scene)
# make sure the image is not too large
scale_image(current_fig, current_fig, 850, 999)
figure_list.append(current_fig)
mlab.close(all=True)
# Depending on whether we have one or more figures, we're using a
# horizontal list or a single rst call to 'image'.
images_rst = ""
if len(figure_list) == 1:
figure_name = figure_list[0]
images_rst = SINGLE_IMAGE % figure_name.lstrip('/')
elif len(figure_list) > 1:
images_rst = HLIST_HEADER
for figure_name in figure_list:
images_rst += HLIST_IMAGE_TEMPLATE % figure_name.lstrip('/')
return figure_list, images_rst
figure_list.append(current_fig)
if gallery_conf.get('find_mayavi_figures', False):
from mayavi import mlab
e = mlab.get_engine()
last_matplotlib_fig_num = fig_count + len(figure_list)
total_fig_num = last_matplotlib_fig_num + len(e.scenes)
mayavi_fig_nums = range(last_matplotlib_fig_num + 1, total_fig_num + 1)
for scene, mayavi_fig_num in zip(e.scenes, mayavi_fig_nums):
current_fig = image_path.format(mayavi_fig_num)
mlab.savefig(current_fig, figure=scene)
# make sure the image is not too large
scale_image(current_fig, current_fig, 850, 999)
figure_list.append(current_fig)
mlab.close(all=True)
return figure_rst(figure_list, gallery_conf['src_dir'])
figure_list.append(current_fig)
if gallery_conf.get('find_mayavi_figures', False):
from mayavi import mlab
e = mlab.get_engine()
last_matplotlib_fig_num = fig_count + len(figure_list)
total_fig_num = last_matplotlib_fig_num + len(e.scenes)
mayavi_fig_nums = range(last_matplotlib_fig_num + 1, total_fig_num + 1)
for scene, mayavi_fig_num in zip(e.scenes, mayavi_fig_nums):
current_fig = image_path.format(mayavi_fig_num)
mlab.savefig(current_fig, figure=scene)
# make sure the image is not too large
scale_image(current_fig, current_fig, 850, 999)
figure_list.append(current_fig)
mlab.close(all=True)
return figure_rst(figure_list, gallery_conf['src_dir'])
time_elapsed = float(open(time_path).read())
if (not os.path.exists(first_image_file) or
os.stat(first_image_file).st_mtime
<= os.stat(src_file).st_mtime):
# We need to execute the code
print 'plotting %s' % fname
t0 = time()
import matplotlib.pyplot as plt
plt.close('all')
try:
from mayavi import mlab
except Exception, e:
from enthought.mayavi import mlab
mlab.close(all=True)
cwd = os.getcwd()
try:
# First CD in the original example dir, so that any file
# created by the example get created in this directory
orig_stdout = sys.stdout
os.chdir(os.path.dirname(src_file))
my_buffer = StringIO()
my_stdout = Tee(sys.stdout, my_buffer)
sys.stdout = my_stdout
my_globals = {'pl': plt}
execfile(os.path.basename(src_file), my_globals)
time_elapsed = time() - t0
sys.stdout = orig_stdout
my_stdout = my_buffer.getvalue()
def close(self):
"""Close all figures and cleanup data structure."""
for ri, ff in enumerate(self._figures):
for ci, f in enumerate(ff):
if f is not None:
mlab.close(f)
self._figures[ri][ci] = None
# should we tear down other variables?
if self._v is not None:
self._v.dispose()
self._v = None