Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase coordinate precision for regridded SMC grids #51

Open
wants to merge 5 commits into
base: ukmo_ps46-1.hotfixes
Choose a base branch
from

Conversation

ukmo-kitstokes
Copy link

@ukmo-kitstokes ukmo-kitstokes commented Mar 24, 2025

Pull Request Summary

This pull request seeks to increase the precision assigned to grid coordinates for regridded SMC grids. This PR will act as a bugfix for UKMO PS46 ww3 code.

Description

When creating a re-gridded SMC grid output, ww3_ounf is unable to achieve the requested grid steps as the precision of the variables used to define and write the grid is limited to float precision. This results in an output grid that is truncated at 7 significant decimal digits, with associated rounding errors at the final digit. For grids that approach km-scale resolution more decimal places are required to represent the regular grid steps in the output grid.

To resolve this issue, the variables that define the re-gridded SMC grid XO0, YO0, DXO, DYO have been increased to double precision in w3gridmd.ftn, and double precision is maintained for these and other re-gridding variables within ww3_ounf.ftn. All other output grid types (including SMC type 1) are left with standard float grid coordinates. This is achieved by creation of new LONRGRD, LATRGRD variables that are used solely for storing the double precision coordinates for re-gridded SMC grids. The lat and lon coordinates for the regridded SMC grid are then written to Netcdf with double precision. For all other grid types, they remain written to netcdf using float precision.

A related issue is addressed regarding the precision of coordinate reference system (CRS) metadata values written to netcdf, which require a high degree of precision - specifically, double precision is required to represent the 'inverse flattening' crs value. To resolve this, a new metadata type "d" for double precision values is added in w3metamd.ftn and w3ounfmetamd.ftn. This allows "d" type metadata entries to be specified when supplying metadata information to ww3_ounf.

The changes to the source code are not expected to change any computed output values from WW3 except for:

  • the above described lat and lon variables written to netcdf when a re-gridded SMC grid type is requested
  • metadata entries specified as type "d"

It is suggested that Andy Saulter and Chris Bunney (just this one time!) review this PR.

Issue(s) addressed

The issue this PR addresses doesn't have a previous issue number (as far as I'm aware).

Commit Message

Increased precision of lat and lon output grid coordinates to double precision for re-gridded SMC grids only. Double precision metadata entries have also been enabled when writing output netcdf files.

Check list

Testing

The changes were tested by running WW3 on Met Office global and UK configurations for a 2-day simulation period and checking netcdf output variables (ncdump -h, ncdump -v longitude, ncdump -v latitude). Before the changes, lon and lat variables were output as floats in netcdf files, with at most 7 significant decimal digits (float precision) and rounding error occurs in the final digit meaning that the grid delta is not maintained throughout. In this example, the requested latitude delta should be 0.0135135 but instead the coordinates are written to netcdf with a rounded delta value that ranges between 0.01351-0.01352:
image
image

While after the changes, lon and lat variables are now output as double precision in netcdf files, and have more than 7 decimal places where needed, and no rounding errors are visible. In this example the grid delta of 0.0135135 is maintained throughout:
image
image

It has also been confirmed that these changes do not affect output grids other than re-gridded SMC grids (lat and lon variables remain as float precision).

The addition of metadata type "d" can be seen by the following example, where previously only float ("f") precision could be achieved in metadata entries, depicted here for the inverse_flattening crs metadata entry:
image

After the changes, double precision output is provided for the inverse_flattening crs metadata entry as confirmed by the log output from ww3_ounf:
image

NOTE - The precision of values written to netcdf files was found to be sensitive to the compiler settings and HPC used. These tests were done using GNU make on the Cray EX HPC at Met Office. Compiler optimisation for ww3_ounf was set to -O0 as our standard optimisation -O3 induced rounding errors in the coordinate precisions.

Regression tests

Regression tests have not been conducted for the proposed source code changes, as only output grid coordinates have been affected. However, the change in precision means that bit-for-bit differences are not expected to be achieved in SMC related regression tests as more memory is required to store the double precision output coordinates.

…sion variables to metadata in netcdf files. Specifically this is to resolve issues around printing long values for 'inverse flatting' in netcdf metadata.
…ww3_ounf by increasing the decimal places in the spaceholder used to calculate the structured grid coordinates to 8 and by specifying 'NF90_DOUBLE' when writing these variables to the netcdf file.
…fix coordinate precisions issues with regridded SMC output.
…idded SMC grids are defined with double precision output coordinates. All other grid types (including SMC type1) are still defined with float precision coordinates.
@ukmo-kitstokes ukmo-kitstokes self-assigned this Mar 24, 2025
@ukmo-kitstokes ukmo-kitstokes added the bug Something isn't working label Mar 24, 2025
@ukmo-kitstokes ukmo-kitstokes marked this pull request as ready for review March 24, 2025 16:31
Copy link
Member

@ukmo-ccbunney ukmo-ccbunney left a comment

Choose a reason for hiding this comment

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

These code changes all look very sensible.

The addition of the DOUBLE type in the meta data module is likely to be useful in the future too.

When we do this change in the main NOAA develop branch it will likely need an update to the manual to mention the new DOUBLE type in the metadata module. For this internal hotfix branch though I think it is fine.

It might be worth running at least the SMC regression tests, but I'll leave that up to you (again, you'll definitely need to do it when you raise this with NOAA).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants