Draft Forbes Group Website (Build by Nikola). The official site is hosted at:
License: GPL3
ubuntu2004
MayaVi for Data Analysis
Our goal here is to use MayaVi to effectively analyze 3D datasets. We shall show how to save the data to an HDF5 file, then load it for visualization in MayaVi. We assume that the data sets are large, and so try to use data sources that only load the required data into memory. Our data will be simple: rectagular meshes.
Jupyter Notebook
MayaVi can be run in a notebook. Instructions are provided in the documentation: Here is what I needed to do on the server (after updating various packages like notebook
.)
This might work locally, but trying to use the notebooks across the network gives rise to the following error:
This is discussed in Issue #439: Kernel dies on mlab import at jupyter notebook.
Example
Generating Data
Here we generate the generation of some simple data - in this case a mock simulation of a vortex moving through a cloud.
Here are some slices showing the vortex position.
In order to be able to load the data directly into VisIt and similar programs, we use an (undocumented?) convention of a "Pixie" format. This requires storing each array in a group called /Timestep_%i
where %i
is the frame number. Within each group, one can store different variables.
Here is the extremely sparse documentation I have found:
Now let's save 200 frames to a file. There are some tricks here:
We don't want to keep all the images in memory, so we must make an extensible dataset in the HDF5 file. We do this by explicitly creating a dataset with
maxshape = (None, Nx, Ny, Nz)
. This will allow us to add multiple arrays as we generate them (automatically increasing along the first dimension).Accessing an existing array in the HDF5 file is different than creating a new array. Thus, it is easist to delete the file first, but if you want to append, you will need some logic to check that the arrays are compatible if they already exist.
I am using a simple file here. If you want to use a file in a directory, you will need to make sure that the directory exists first - just passing a full name to
File
will not create the directory.It is very important to specify the
chunks
size if you want good performance. (The default here immediately created an 8GB array!)
Here are some timings to estimate file access speeds. Apparently the time to open the file is insignificant, so we can do this repeatedly if needed.
MayaVi
Note: On Mavericks (OS X 9), there are issues related to running MayaVi. In particular, the version of python running must be a "Framework" build. This seems to mean that the kernel is started with the version of python in python.app/Contents/MacOS/python
with the explicit path specified. I.e. Even if you have a symlink to this on your path, it is not sufficient to use that. You must invoke this explicitly. To find out where this is, look at the mayavi2
script:
#!/data/apps/anaconda/1.3.1/python.app/Contents/MacOS/python
In order to ensure that this is done properly here, all of our examples will be run as scripts, not from this notebook. We start by making a little application that will display the frames.