Stream: python-questions
Topic: gradsf
Katie Dagon (Apr 29 2021 at 17:49):
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.
Deepak Cherian (Apr 29 2021 at 17:58):
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: )
Katie Dagon (Apr 29 2021 at 18:13):
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).
Max Grover (Apr 29 2021 at 18:20):
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
Deepak Cherian (Apr 29 2021 at 19:04):
But metpy's gradient doesn't look like it uses spherical harmonics, which is what gradsf
uses?
Deepak Cherian (Apr 29 2021 at 19:31):
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.
Katie Dagon (Apr 29 2021 at 20:59):
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.
Katie Dagon (Apr 29 2021 at 21:06):
I created an issue on geocat-comp in case anyone else is interested in this: https://github.com/NCAR/geocat-comp/issues/147
Matt Long (Apr 29 2021 at 21:07):
cc @geocat
Orhan Eroglu (Apr 30 2021 at 20:16):
We are looking at it.
Last updated: Jan 30 2022 at 12:01 UTC