Stream: ESDS

Topic: Divergence Collaboration


view this post on Zulip Julia Kent (Mar 23 2023 at 20:47):

Hi ESDS community. I've been working on a script for vertically integration moisture flux (NCL application -- here). At one point in this script we have to calculate divergence. The NCL fx used is uv2dvf that uses spherical harmonics in the divergence calculation. Has anyone here used that function before? I would love to learn more about how using spherical harmonics improves the calculation and if it is worth writing a Python method that does this. Thanks!

view this post on Zulip Katie Dagon (Mar 23 2023 at 21:56):

@Julia Kent I haven't used that function before, but we've had some previous discussion on zulip related to spherical harmonics, for example the gradsf function with @Alea Kootz
Here's the thread -- apologies if you've already seen this and it's not helpful.

view this post on Zulip Julia Kent (Mar 23 2023 at 22:04):

Thanks Katie! It looks like you were ultimately after a gradient function that used spherical harmonics? It doesn't look like our gradient fx specifies that it uses those -- so what did you end up using? The gradient seems only one step away from making the divergence function.

view this post on Zulip Katie Dagon (Mar 23 2023 at 22:40):

I played around with a couple different options, the windspharm package, and some non-spherical harmonics options like numpy.gradient and metpy.calc.gradient. @Alea Kootz also provided some code to calculate spherical harmonics in python, as I recall.

view this post on Zulip Julia Kent (Mar 23 2023 at 23:01):

How different do you expect your results when using spherical harmonics and not?

view this post on Zulip Katie Dagon (Mar 23 2023 at 23:33):

I don't think they were that different for my specific case, but it's been a while since I thought about this. Happy to forward emails or share notebooks if that would be helpful.

view this post on Zulip Julia Kent (Mar 24 2023 at 14:33):

Thanks Katie. That's actually a big help. I'd appreciate any notebooks or materials you could send.

view this post on Zulip Max Grover (Mar 24 2023 at 16:44):

MetPy completed a big refactor last fall to take the earth's curvature into account for these functions, with their example here https://unidata.github.io/MetPy/latest/examples/calculations/Divergence.html#sphx-glr-examples-calculations-divergence-py you could also check out the issue thread here https://github.com/Unidata/MetPy/issues/893 which details the associated PRs that pushed it back the finish line and differences between taking the curvature into account vs. ignoring it.

view this post on Zulip Julia Kent (Mar 24 2023 at 16:56):

I'm getting some errors using Metpy's divergence that I don't fully understand yet. Numpy's gradient is working for me though.

view this post on Zulip Ryan May (Mar 24 2023 at 18:56):

@Julia Kent Feel free to open an issue/discussion. If we can get to the data, it's easy for us to take a look.

view this post on Zulip Ho-Hsuan Wei (Mar 28 2023 at 18:23):

Hi Julia, I did compare using spherical harmonics and using gradient function to calculate the divergence on spherical coordinate for ERA-Interim 6-hourly data. I am happy to share my code and some plots if you are interested. In short, the main difference for vertically integrated moisture flux is near the fronts.

view this post on Zulip Julia Kent (Mar 29 2023 at 14:53):

I am definitely interested in that. Thanks Ho-Hsuan! Could you point me to a workflow? And potentially a sample file you've calculated vertically integrated moisture flux with? That would be a huge help thanks!


Last updated: May 16 2025 at 17:14 UTC