6

I have a code that creates a 3d topographic surface from lat, lon and elev data.

I'm using ax.plot_surface, which creates a topographic surface that looks like this:

plot1

I would like to smooth the data to create a picture that looks more like this: plot2

Is there a better way to smooth out the interpolation done by mesh grid?

my_data is sorted by [lat,lon,elev] size(912,3)

Code below

import os
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from scipy.interpolate import griddata


fig = plt.figure()
ax = Axes3D(fig)
my_data = np.genfromtxt('2014_0.01_v3_HDF5.txt', delimiter = ',',     skip_header = 1)
my_data[my_data==0] = np.nan 
my_data = my_data[~np.isnan(my_data).any(axis=1)]
X = my_data[:,0] 
Y = my_data[:,1]
Z = my_data[:,2]
xi = np.linspace(X.min(),X.max(),(len(Z)/3))
yi = np.linspace(Y.min(),Y.max(),(len(Z)/3))
zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='nearest')

xig, yig = np.meshgrid(xi, yi)

surf = ax.plot_surface(xig, yig, zi, cmap='gist_earth')
fig.colorbar(surf, shrink=0.5, aspect=5)
ax.set_title('2014 ATM Data 0.01 Degree Spacing')
ax.set_xlabel('Latitude')
ax.set_ylabel('Longitude')
ax.set_zlabel('Elevation (m)')
ax.set_zlim3d(0,8000)

1 Answer 1

2

You can replace the method of interpolation from nearest to cubic. It gives you a far better surface.

zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='cubic')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.