Spherical Image Distortion in Python

I am trying to take two rectangular images, one of the visible surface functions and one representing the height, and plot them on a three-dimensional sphere. I know how to display objects on a sphere using Cartopy , and I know how to make a relief surface of a map , but I cannot find an easy way to combine them to have an exaggerated elevation on a spherical projection. For example, here it is done in MATLAB : Image example

Does anyone know if there is an easy way to do this in Python?

+4
source share
1 answer

. .

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 surface
sp = ax.plot_surface(x, y, z, \
                rstride=2, cstride=2, \
                facecolors=img)

ax.set_aspect(1)

plt.show()

:

enter image description here

+1

Source: https://habr.com/ru/post/1684906/


All Articles