CliMA / ClimaCore.jl

CliMA model dycore
https://clima.github.io/ClimaCore.jl/dev
Apache License 2.0
87 stars 8 forks source link

Spherical harmonics #549

Open simonbyrne opened 2 years ago

simonbyrne commented 2 years ago

We can compute spherical harmonics directly from the nodal points on the cubed sphere mesh. The easiest way is probably to compute the dot product with the different basis functions.

using AssociatedLegendrePolynomials
λlm(l, m, sind(lat)) * complex(cosd(m * long), sind(m * long))

Questions:

simonbyrne commented 2 years ago

@LenkaNovak @jiahe23 @szy21 any thoughts on this?

jiahe23 commented 2 years ago

ClimateMachine.jl has something written already. I think we could clean up and port over easily.

The way being done in ClimateMachine is: m (the zonal wavenumber) and l (the total wavenumber) are computed as in here

u and v are projected to the Fourier (or the spherical) space separately as scalars, and then the power spectra (Fourier or sperical) are computed in the frequency domain. The KE spectra vs wavenumber (frequency) are returned and plotted.

I don't know the answer to the second question here.

simonbyrne commented 2 years ago

The ClimateMachine.jl approach first interpolates to a lat-long grid, which I was hoping to avoid.

What are the maximum values of l and m that one would typically be interested in?

simonbyrne commented 2 years ago

Also, what normalization should be used? https://www2.atmos.umd.edu/~dkleist/docs/shtns/doc/html/spec.html

jiahe23 commented 2 years ago

Since l and m represent the wavenumber, they should reply on the minimal length scale of motion that could be resolved. The typical way is to compute from the number of meridians. I am not sure what would be an equivalent way if using the current grid.

@LenkaNovak Any thoughts here?

simonbyrne commented 2 years ago

E3SM: https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/1572504944/KE+Spectra+-+best+practices

jiahe23 commented 2 years ago

E3SM: https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/1572504944/KE+Spectra+-+best+practices looks like they do the lat/lon interpolation first

LenkaNovak commented 2 years ago

Hi Simon, is this for diagnosing the classical power spectrum? If so, interpolating to a lat-lon grid before transforming to the spherical harmonics should be sufficient.

The max number of spherical harmonics is determined by the grid resolution, e.g. here

If we need to transform the full velocity vector, it may be best to first convert it into the rotating+nonrotating components (i.e. vorticity+divergence), but for basic power spectra diagnostics, this should not be necessary. (also alluded to on Mark Taylor's page mentioned above)

As for normalization, Daniel and I followed appendix B of this book (gimme a shout if you need a copy of this or if it's easier to chat).

simonbyrne commented 2 years ago

Okay, that makes sense. I'll focus on the RLL interpolation, and we can build the spherical harmonics on top of that.

jiahe23 commented 2 years ago

Okay, that makes sense. I'll focus on the RLL interpolation, and we can build the spherical harmonics on top of that.

Do you need to compute it on the fly? If not, I suggest we run the simulation, save the data at some frequency, and output it into netcdf using the Tempest remapping functionality. By doing this, we could save the time of re-do the remapping and focus on computing the KE spectra?

What do you think? @simonbyrne @LenkaNovak

jakebolewski commented 2 years ago

That makes sense @jiahe23 and probably? you can re-use almost exactly the steps in https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/1572504944/KE+Spectra+-+best+practices#Software-needed with a few tweaks. It would be good to try at least once to see if it works end to end as that would be the fastest thing to get some output.

You can see the normalization used in the linked ncl script: https://github.com/mt5555/nclscript/blob/master/spectra/ke.ncl#L13-L15