I am trying to find a python-based solution for the NCL function gradfs (https://www.ncl.ucar.edu/Document/Functions/Built-in/gradsf.shtml) which I previously used to calculate latitude and longitude gradients on a fixed grid. Does anyone know of anything that might work? If not, I will open an issue in GeoCAT-comp.
How about windspharm's gradient. It's weird because they use VectorWind as the main interface instead of a Grid object(what if you don't have winds? :thinking: )
Thanks @Deepak Cherian I will take a look at this, though I am looking for something more general to match the functionality of gradsf (e.g., for temperature gradients).
I would suggest taking a look at MetPy for this - they have an example explicitly on temperature gradients and temperature advection (https://unidata.github.io/python-gallery/examples/850hPa_Temperature_Advection.html), with a general gradient function here https://unidata.github.io/MetPy/latest/examples/calculations/Gradient.html#sphx-glr-examples-calculations-gradient-py
I hope this helps @Katie Dagon
But metpy's gradient doesn't look like it uses spherical harmonics, which is what gradsf
uses?
and VectorWind.gradient
takes a scalar chi
as input, so you could fake it by initializing VectorWind
with arrays of ones of appropriate shapes and then pass actual temperature to the gradient.
Good point about spherical harmonics. I tried @Deepak Cherian's suggestion to initialize VectorWind
but apparently the software doesn't like the grid type (even number of latitude points that includes the poles). I found a related issue: https://github.com/ajdawson/windspharm/issues/77. I'd rather not have to regrid/interpolate. I will keep investigating.
I created an issue on geocat-comp in case anyone else is interested in this: https://github.com/NCAR/geocat-comp/issues/147
cc @geocat
We are looking at it.
Last updated: May 16 2025 at 17:14 UTC