Issue with transforms grdtospec and spectogrd

Issue #17 invalid
Former user created an issue

Hi, I'm using shtns-2.6.3-r520 (with openmp enabled) and fftw-3.3.4. The issue is with the python code shallow_water.py. I was checking for the accuracy of transformations. So I took the variable ug and did some transformations as shown below,

us = x.spectogrd(ug) u1 = x.spectogrd(x.grdtospec(ug)) u2 = x.grdtospec(x.spectogrd(us))

Now the maximum error between u2 and us is of order 1e-14 which is as expected. But the maximum error between u1 and ug is of order 1. Am also attaching the plot of difference field (ug-u1) and similar field for vg. The error is especially large at y=0.

Comments (2)

  1. Nathanaël Schaeffer repo owner

    This is not an issue, it is the correct, expected behaviour.

    If ug is a spherical component of a vector (ug,vg), then it cannot be represented with spherical harmonics. Spherical harmonics can represent only smooth (scalar) functions on the sphere. To represent (u,v) use vector spherical harmonics instead, or vorticity/divergence as in the shallow_water.py example.

    More explicitely, if

    u1 = x.spectogrd(x.grdtospec(ug))
    u2 = x.grdtospec(x.spectogrd(us))
    

    then ||u2-us||/||us|| << 1 is almost always true (unless you have put non-zero imaginary parts in us for m=0); but ||u1-ug||/||ug|| << 1 is only true if ug samples a smooth scalar function, with proper bandlimit (ie there exists U such as ug = x.spectogrd(U) )

  2. Log in to comment