{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# MayaVi for Data Analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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.\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": { "toc": "true" }, "source": [ "# Table of Contents\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Jupyter Notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "MayaVi can be run in a notebook. Instructions are [provided in the documentation](http://docs.enthought.com/mayavi/mayavi/tips.html#using-mayavi-in-jupyter-notebooks): Here is what I needed to do on the server (after updating various packages like `notebook`.)\n", "\n", "```bash\n", "conda install mayavi\n", "jupyter nbextension install --py mayavi\n", "```\n", "\n", "This might work locally, but trying to use the notebooks across the network gives rise to the following error:\n", "\n", "```bash\n", "__main__.py: cannot connect to X server\n", "```\n", "\n", "This is discussed in [Issue #439: Kernel dies on mlab import at jupyter notebook](https://github.com/enthought/mayavi/issues/439).\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generating Data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we generate the generation of some simple data - in this case a mock simulation of a vortex moving through a cloud." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Each frame is 128 MB\n", "100 frames will be 12.5 GB\n" ] } ], "source": [ "import h5py\n", "import numpy as np\n", "\n", "Nt = 100\n", "Nx = Ny = 128\n", "Nz = 512\n", "lam = 8.0 # Aspect ratio\n", "x = np.linspace(-1, 1, Nx)[:, None, None]\n", "y = np.linspace(-1, 1, Ny)[None, :, None]\n", "z = np.linspace(-lam, lam, Nz)[None, None, :]\n", "\n", "xi = 0.1 # Size of vortex core\n", "V = x**2 + y**2 + (z/lam)**2\n", "mu = 0.8**2\n", "phi0 = np.where(V