feat: Add first tests for spectral helpers #824
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#678 introduced the initial infrastructure for computing spectral transforms. #788 and #709 will expand on this and implement several types of transform, including spherical harmonic transforms.
All of these transforms should have tests implemented. One crucial test for a transform and its inverse is idempotency, i.e. do I get the same thing when I perform the inverse followed by the direct transform, and vice versa? This PR implements idempotency tests for
EcTransOctahedralSHTModuleand its inverse. This will hopefully serve as a reference for implementing idempotency tests for other transforms.test_idempotency_inverse_directis hopefully self-explanatory.test_idempotency_direct_inversehas one nasty gotcha, which I've tried to work around in a somewhat suboptimal way. This test starts in grid point space and transforms to spectral space and back. The input is a random field on the octahedral grid. This field will contain high-frequency modes above the spectral band limit (set by the truncation) and which will therefore be stripped out when the direct transform is computed. When the inverse is then computed, these modes will not be restored and the before and after arrays will therefore never match.To work around this, for this test I actually randomise a spectral field and then inverse transform it to grid point space. This inverse transformed field is the input to the idempotency test, and will by definition not contain any modes above the band limit. It's not ideal, because we are using the inverse transform in order to initialise a test for the inverse transform. But I can't think of any other simple way to initialise the input to this test.
I'm not a pytest expert so please feel free to suggest improvements to the test suite.
Also note that this test requires an installation of ectrans4py in order to initialise
EcTransOctahedralSHTModule. This dependency will eventually be removed, once I can figure out how to cache the matrices which are computed by ectrans4py.As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/
By opening this pull request, I affirm that all authors agree to the Contributor License Agreement.