Skip to content

Regional power spectra using Discrete Cosine Transform (DCT)#1765

Merged
cehalliwell merged 21 commits intomainfrom
215_regional_power_spectra_DCT
Nov 12, 2025
Merged

Regional power spectra using Discrete Cosine Transform (DCT)#1765
cehalliwell merged 21 commits intomainfrom
215_regional_power_spectra_DCT

Conversation

@cehalliwell
Copy link
Contributor

@cehalliwell cehalliwell commented Oct 15, 2025

Follows on from #215

Calculate power spectra of 2D field in regional model using Discrete Fourier Transform (DCT)

Contribution checklist

Aim to have all relevant checks ticked off before merging. See the developer's guide for more detail.

  • Documentation has been updated to reflect change.
  • New code has tests, and affected old tests have been updated.
  • All tests and CI checks pass.
  • Ensured the pull request title is descriptive.
  • Conda lock files have been updated if dependencies have changed.
  • Attributed any Generative AI, such as GitHub Copilot, used in this PR.
  • Marked the PR as ready to review.

@cehalliwell cehalliwell self-assigned this Oct 15, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 15, 2025

Coverage

@cehalliwell
Copy link
Contributor Author

Power spectra calculated over regional (limited area) domain using Discrete Cosine Transform (DCT). This code is based on Denis et al 2002.

The code calculates power spectrum on a single (surface, pressure or model) level for each specified time/level but does not yet allow aggregation or consider ensembles.

Mean spectra over a specified time period for each level and/or mean spectra over a range of levels at a specified time may be future options.

M365 Copilot was used to optimise the code and give code suggestions.

@cehalliwell
Copy link
Contributor Author

cehalliwell commented Oct 22, 2025

Power Spectrum code changed so that the power spectrum is now calculated in _plot_and_save_power_spectrum_series rather than a separate operator. This is so results from multiple models can be plotted on the same plot.

The unit tests for the power spectrum code have now been updated to reflect these changes.
Microsoft Copilot was used to help design the unit tests.

There are currently only 2 recipes:
level_fields/generic_level_power_spectrum_series.yaml
surface_fields/generic_surface_power_spectrum_series.yaml

which allow plotting of power spectrum on model, pressure and surface levels. There is no method of aggregation at the moment. This might involve taking mean of spectra over times or levels but needs further investigation.

@cehalliwell cehalliwell requested a review from daflack October 23, 2025 11:42
@cehalliwell
Copy link
Contributor Author

cehalliwell commented Oct 23, 2025

This is an example plot from CSET using this method. Currently, models must be on the same grid.

power_spectrum_vertical_wind_at_pressure_levels_pressure_250_459459 0

Copy link
Collaborator

@daflack daflack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is looking good. I've got a few comments here, and some more specific ones in the code.

It is worth considering tests for the following: 3D data, a cubelist, no coordinate named time present (if allowing it, see comments in code), a multi-model run, a test to cover the other options of L2649, L2692, and L2702of plot.py if those if statements are needed.

It would be nice to include somewhere (either in the function description, or the recipe description) a quick guide to interpretation of power spectra.

You also need to update the conda lock files too: Actions -> Update conda lock files -> Run workflow, select your branch, and then merge in the PR that the bot creates into your PR.

Finally, it might be worth getting someone else to do a technical review of this PR as well, or discuss with @jfrost-mo whether the power spectra code should be separate from the plotting code. My only thought behind this is that for aggregation purposes it might be easier to have the calculation of the power spectra separate.

It's really great to see progress on this, and the output looks fantastic.

@daflack daflack added this to the CSET next milestone Oct 28, 2025
@jfrost-mo jfrost-mo self-requested a review October 31, 2025 16:18
Copy link
Member

@jfrost-mo jfrost-mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple minor comments but overall I think it looks good. Feel free to merge after addressing.

@jfrost-mo
Copy link
Member

jfrost-mo commented Nov 11, 2025

The tests will also need fixing, looks like just a rename required.

cehalliwell and others added 6 commits November 12, 2025 09:30
Co-authored-by: James Frost <james.frost@metoffice.gov.uk>
Co-authored-by: James Frost <james.frost@metoffice.gov.uk>
Co-authored-by: James Frost <james.frost@metoffice.gov.uk>
Co-authored-by: James Frost <james.frost@metoffice.gov.uk>
Co-authored-by: James Frost <james.frost@metoffice.gov.uk>
@jfrost-mo jfrost-mo dismissed daflack’s stale review November 12, 2025 10:03

I've taken over this review for David.

@cehalliwell cehalliwell merged commit b8127b5 into main Nov 12, 2025
8 checks passed
@cehalliwell cehalliwell deleted the 215_regional_power_spectra_DCT branch November 12, 2025 10:14
@daflack daflack mentioned this pull request Dec 17, 2025
7 tasks
@daflack daflack mentioned this pull request Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants