Saving Multiple Images in MayaVi

I want to make about 500 images and save them in different png files, so I wrote a small class that contains my dataset and render function

from mayavi import mlab mlab.options.offscreen=True class Dataset(object): def __init__(self): some init stuff etc . . . . def save_current_frame_to_png(self, filename): mlab.contour3d(self.frame_data, contours =30, opacity=0.2) mlab.savefig(filename) mlab.clf() mlab.close() gc.collect() def create_movie_files(self): folder_name = "animation" try: os.makedirs(folder_name) except OSError: raise OSError("Directory already exists.") self.__go_to_first_frame() for i in range(self.frames): filename = "".join([folder_name, "/%.5i" % i, ".png"]) print filename self.save_current_frame_to_png(filename) self.read_single_frame() self.__go_to_first_frame() 

So, everything seemed to work fine, but I was looking at using memory that rises until the system crashes. So I tried using mlab.clf() and gc.collect() so that my memory was low, which didn't work. I found a solution with mlab.close() that seems to work for memory usage, but this creates a new problem. Each time a new image is displayed, a new window created by Mayavi appears, so after about 200 windows the program crashes. Maybe there is an opportunity to completely disable the windows? It seems to me that mlab.options.offscreen=True disables only drawing inside the current window.

EDIT: self.frame_data is a multi-level array of the form (100,100,100), and self.read_single_frame() just reads the next frame from the text file and saves it in self.frame_data . These features do not increase the drum if I turn off memory rendering by 1.2%.

+7
python mayavi
source share

No one has answered this question yet.

See related questions:

2035
Capturing multiple exceptions on one line (except block)
1015
Save the image to an image file instead of displaying it using Matplotlib
994
How to return multiple values ​​from a function?
889
Select multiple columns in pandas data frame
798
How does Python super () work with multiple inheritance?
3
Save Mayavi Animations
2
Python Enthought Mayavi crashes when updating data with mlab_source.reset
one
Mayavi Saves Photos
one
Mayavi does not save images as eps
0
Joblib does not write to shared memory

All Articles