Increase coordinate precision for regridded SMC grids #51
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.
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 newLONRGRD, 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:
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: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:


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:After the changes, double precision output is provided for the

inverse_flattening
crs metadata entry as confirmed by the log output from ww3_ounf: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.