Python中球形投影图像的高程失真

时间:2017-09-01 15:29:51

标签: python matplotlib projection

我试图拍摄两个矩形图像,一个可见表面特征和一个表示高程,并将它们映射到3D球体上。我知道如何使用Cartopy将特征映射到球体上,并且我知道如何制作relief surface maps,但我找不到一种简单的方法来将它们组合起来以在球形投影上具有夸张的高度。例如,here's it done in MATLABExample picture

有人知道在Python中是否有一种简单的方法吗?

1 个答案:

答案 0 :(得分:2)

我的解决方案无法满足您的所有要求。但首先,它可能是一个好的开端。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from matplotlib.cbook import get_sample_data
from matplotlib._png import read_png

# Use world image with shape (360 rows, 720 columns) 
pngfile = 'temperature_15-115.png'

fn = get_sample_data(pngfile, asfileobj=False)
img = read_png(fn)   # get array of color

# Some needed functions / constant
r = 5
pi = np.pi
cos = np.cos
sin = np.sin
sqrt = np.sqrt

# Prep values to match the image shape (360 rows, 720 columns)
phi, theta = np.mgrid[0:pi:360j, 0:2*pi:720j]

# Parametric eq for a distorted globe (for demo purposes)
x = r * sin(phi) * cos(theta)
y = r * sin(phi) * sin(theta)
z = r * cos(phi) + 0.5* sin(sqrt(x**2 + y**2)) * cos(2*theta)

fig = plt.figure()
fig.set_size_inches(9, 9)
ax = fig.add_subplot(111, projection='3d', label='axes1')

# Drape the image (img) on the globe's surface
sp = ax.plot_surface(x, y, z, \
                rstride=2, cstride=2, \
                facecolors=img)

ax.set_aspect(1)

plt.show()

结果图片:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.derivative.html