apps120911_iotorus.app02_iotorus_viz3dΒΆ

''' Visualize the io torus in 3D using mayavi.

As mayavi does not work properly for MacPorts, I use Linux,
or use Enthought.

For enthought user, you may want to install mkvirtualevn to
separate the environment.

.. code-block:: sh

    % mkvirtualenv -p /Library/Frameworks/Python.framework/Versions/7.3/bin/python --system-site-package 130314-pep-whatihave

Now, new environemnt with site-packages enabled as a name of ``130314-pep-whatihave``.
You may return to this environment by

.. code-block:: sh

    % workon 130314-pep-whatihave

Then, you have to install some of pyana packages.

.. code-block:: sh

    % cd ../../../pyana-deps/pyana.util/
    % python setup.py install
    % cd ../..
    % python setup.py develop

Some warning on dependency may be displayed,
but to run just this script you may disregard them.

Now it is time to run the script.
It is recommended to use ``ipython``.

.. code-block:: sh

    % /Library/Frameworks/Python.framework/Versions/7.3/bin/ipython

.. code-block:: py

    %run app02_iotorus_viz3d

Then, a result is displayed.




'''

import numpy as np
import matplotlib.pyplot as plt

import logging

from pyana.pep.iotorus import SimpleNeutralCloudModel, TwoPeakModel

def main():
    '''Main script'''

    torus = TwoPeakModel()

    x, y, z = np.mgrid[-7:7:30j, -7:7:30j, -7:7:30j]

    scalar = np.zeros_like(x)

    for ix, x0 in enumerate(x[:, 0, 0]):
        for iy, y0 in enumerate(y[0, :, 0]):
            for iz, z0 in enumerate(z[0, 0, :]):
                scalar[ix, iy, iz] = torus.get_density(x0, y0, z0)

    obj = contour3d(x, y, z, np.log10(scalar), contours=4, transparent=True)


if __name__ == "__main__":
    from mayavi.mlab import *
    main()