What is the right way to calculate gradient in Metpy ? #2975
-
Hello, I have found two gradient functions in metpy, i.e. import metpy.calc as mpcalc
# function 1
grad1 = mpcalc.gradient(psl)
# function 2
dx, dy = mpcalc.lat_lon_grid_deltas(ds.lon, ds.lat)
grad2 = mpcalc.geospatial_gradient(psl, dx=dx, dy=dy) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
With that said, both calculations should produce very similar results up to 30-40 degrees latitude, with increasing differences towards the poles. If that's not the behavior you observe, we should dig in further to see what's going on and make sure there's not a bug lurking there. |
Beta Was this translation helpful? Give feedback.
metpy.calc.gradient
is just doing normal finite-difference-based approximation to the derivative, assuming the data are on a Cartesian grid. Effects of calculating on a spherical Earth are only handled by computing grid spacing using "great circle" distance between lat/lon points.metpy.calc.geospatial_gradient
explicit "corrects" plain Cartesian gradient for working in a spherical coordinate system with explicit factors like GEMPAK did. Note, you shouldn't need to pass dx/dy manually and should be able to do directlygrad2 = mpcalc.geospatial_gradient(psl)
.geospatial_gradient
is the most correct calculation, but requires the input data to have good information/metadata regarding the coo…