0

I am generating a topography map in Python using the oceansdb module and Plotly. This map however shows a rough interpretation of the topography and I am wondering how I can smooth the map in between points?

This is the code I have tried:

import plotly.graph_objects as go
import oceansdb
import numpy as np 
from scipy.interpolate import griddata

Xa = np.linspace(29.005,29.405,200)
Ya = np.linspace(-93.6683,-93.2683,200)

db = oceansdb.ETOPO()
dcont = db['topography'].extract(lat=Xa, lon=Ya)
depth = dcont['height']

fig = go.Figure(data=[go.Surface(z=depth, x=Xa, y=Ya)])
fig.show()

I have tried scipy.interpolate.griddata to smooth the plot, but nothing changes in the plot.

1 Answer 1

2

I don't think interpolation is what you want, because if you interpolate within noisy points it will still be noisy. The scipy.ndimage library has some nice smoothing algorithms (the one I show is a simple gaussian smoothing).

import plotly.graph_objects as go
import oceansdb
import numpy as np 
import scipy.ndimage

Xa = np.linspace(29.005,29.405,200)
Ya = np.linspace(-93.6683,-93.2683,200)

db = oceansdb.ETOPO()
dcont = db['topography'].extract(lat=Xa, lon=Ya)
depth = dcont['height']

sigma = [4, 4]
print(sigma)
depthSmooth = scipy.ndimage.filters.gaussian_filter(depth, sigma)

fig = go.Figure(data=[go.Surface(z=depthSmooth, x=Xa, y=Ya)])
fig.show()

You can change the sigma value to change how much smoothing is done (greater sigma means more smoothing and the list is [sigmax, sigmay]).

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.