I have a data set such that for discrete values of theta and phi, I have some value. I want to represent this on a sphere such that at the point on the sphere given by the polar angle theta and the azimuthal angle phi, the color shows that particular value.

我有一个数据集,对于theta和phi的离散值,我有一些价值。我想在球体上表示这一点,使得在由极角θ和方位角φ给出的球体上的点处,颜色显示出该特定值。

How can I do it in python?

我怎么能在python中做到这一点?

1 个解决方案

#1


0

I think this spherical harmonics example is what you need.

我认为这个球谐函数的例子就是你所需要的。

  • Minimal example:

    最小的例子:

    from mayavi import mlab
    import numpy as np
    
    # Make sphere, choose colors
    phi, theta = np.mgrid[0:np.pi:101j, 0:2*np.pi:101j]
    x, y, z = np.sin(phi) * np.cos(theta), np.sin(phi) * np.sin(theta), np.cos(phi)
    s = x*y  # <-- colors
    
    # Display
    mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(600, 500))
    mlab.mesh(x, y, z, scalars=s, colormap='Spectral')
    mlab.view()
    mlab.show()
    
  • You will need python2, not python3. See this thread from 2015.
  • 你需要python2,而不是python3。从2015年看这个主题。
  • In Ubuntu 14.04 I said:

    在Ubuntu 14.04中我说:

    sudo apt-get install python-vtk python-scipy python-numpy
    sudo pip install mayavi
    python main.py  # After saving the code below as main.py
    
  • Here's the full code:

    这是完整的代码:

    # Author: Gael Varoquaux <gael.varoquaux@normalesup.org>
    # Copyright (c) 2008, Enthought, Inc.
    # License: BSD Style.
    
    from mayavi import mlab
    import numpy as np
    from scipy.special import sph_harm
    
    # Create a sphere
    r = 0.3
    pi = np.pi
    cos = np.cos
    sin = np.sin
    phi, theta = np.mgrid[0:pi:101j, 0:2 * pi:101j]
    
    x = r * sin(phi) * cos(theta)
    y = r * sin(phi) * sin(theta)
    z = r * cos(phi)
    
    mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(400, 300))
    mlab.clf()
    # Represent spherical harmonics on the surface of the sphere
    for n in range(1, 6):
        for m in range(n):
            s = sph_harm(m, n, theta, phi).real
    
            mlab.mesh(x - m, y - n, z, scalars=s, colormap='jet')
    
            s[s < 0] *= 0.97
    
            s /= s.max()
            mlab.mesh(s * x - m, s * y - n, s * z + 1.3,
                      scalars=s, colormap='Spectral')
    
    mlab.view(90, 70, 6.2, (-1.3, -2.9, 0.25))
    mlab.show()
    
  • You can expect about 20 seconds of loading time for this example if you have a slow computer.

    如果您的计算机速度较慢,则此示例的加载时间约为20秒。

  • You can use your mouse to rotate and zoom the image.
  • 您可以使用鼠标旋转和缩放图像。

更多相关文章

  1. 如何使用Thymleaf做到这一点?

随机推荐

  1. 一文看懂 Node.js 中的多线程和多进程[每
  2. QUAMAR T60 碎冰机
  3. 讲给前端的正则表达式(4):避免灾难性回溯[
  4. JS 和 Node.js 中的“事件驱动”是什么意
  5. 数组
  6. V8 引擎发布了 v8.0[每日前端夜话0x103]
  7. 离线安装veeam agent
  8. 栈的实现
  9. Java 中有哪些无锁技术来解决并发问题?如
  10. 如何解决Renault Can Clip代码不正确的问