Skip to content

Conversation

@samhatfield
Copy link
Collaborator

@samhatfield samhatfield commented Jan 23, 2026

#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 EcTransOctahedralSHTModule and its inverse. This will hopefully serve as a reference for implementing idempotency tests for other transforms.

test_idempotency_inverse_direct is hopefully self-explanatory. test_idempotency_direct_inverse has 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.

@github-project-automation github-project-automation bot moved this to To be triaged in Anemoi-dev Jan 23, 2026
@samhatfield samhatfield changed the title Add first tests for spectral helpers feat: Add first tests for spectral helpers Jan 23, 2026
@anaprietonem anaprietonem added the ATS Approval Not Needed No approval needed by ATS label Jan 27, 2026
samhatfield and others added 2 commits January 27, 2026 09:09
Just two idempotency tests for EcTransOctahedralSHTModule first.
@samhatfield samhatfield force-pushed the feat/add_first_spectral_helper_tests branch from c134821 to 295a195 Compare January 27, 2026 09:10
@samhatfield
Copy link
Collaborator Author

Note: it's now necessary to precompute Legendre assets, store them to disk, and pass this location as the dir_path argument to EcTransOctahedralSHTModule. We have not yet found a solution for where to store these files, so this PR should not be merged yet.

@samhatfield
Copy link
Collaborator Author

Correction: we know where to store the files, I just haven't got round to figuring out how to get them there and fetch them :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ATS Approval Not Needed No approval needed by ATS models

Projects

Status: To be triaged

Development

Successfully merging this pull request may close these issues.

2 participants