I do not wish to cross post but not sure whether the question belongs here or not - https://codereview.stackexchange.com/questions/185368/numerical-differentiation-on-sphere-with-python. This is a direct example of the question I asked here - Atmospheric science fortran code review ? It appears it is unrelated to meteorology as written for that SE but it is in fact very much related to meteorology when you consider that it is taking the spatial derivative of the wind along a isobaric surface or potential temperature in the zonal direction. Obviously I would reword it for this site.
Responding to Jeopardy Tempest's request
The question could go something like this
Here is an algorithm for taking the spatial derivative for a global rectilinear grid for isobaric zonal and meridional winds
#GRIB Scan order goes eastward and then northward # Spatial derivatives for interior points # du(zonal)/dx = u(east) - u(west) #dv(meridional)/dy = v(north) - v(south) Loop South to North Loop West to East dudx = u(i+1) - u(i-1)/2* dlambda dvdy - v(j+1) - v(j-1) /2* dphi End loop End loop # Section for handling poles(north and south) Something similar here