ufs-community / ufs-srweather-app

UFS Short-Range Weather Application
Other
58 stars 119 forks source link

change on degs_per_radian for grid generation #495

Open JiliDong-NOAA opened 1 year ago

JiliDong-NOAA commented 1 year ago

degs_per_radian is the conversion unit for degrees to radians. It is used in grid generation to convert delx/dely from m to radian. The recent commit has changed how degs_per_radian is calculated. Previously degs_per_radian is defined as:

degs_per_radian=360.0/(2.0*pi) 
pi=3.14159265358979323846264338327 

Now it is defined in ush/constants.yaml:

degs_per_radian=57.2957795131

This difference will result in different grids and topography even when the same delx and dely in m are chosen as it will lead to floating point difference of delx/dely in radians. The previous approach using pi seems more accurate. I am just curious if there is any reason to change how degs_per_radian is calculated.

danielabdi-noaa commented 1 year ago

@JiliDong-NOAA The change is mainly because of the transition to python, and yaml which does not support formulas.

# Pi.
pi_geom="3.14159265358979323846264338327"

# Degrees per radian.
degs_per_radian=$( bc -l <<< "360.0/(2.0*${pi_geom})" )

The old way uses bc and degs_per_radian=57.29577951308232087679 after the calculation. Python default float can store maximum 15 digit precision so even pi is truncated to 3.141592653589793. So the maximum we can have is 15 digit precision for both

./config_utils.py -c constants.yaml -o shell
# [constants]
PI_GEOM='3.141592653589793'
DEGS_PER_RADIAN='57.29577951308232'
RADIUS_EARTH='6371200.0'
NH0='0'
NH3='3'
NH4='4'

Will this be enough or is an arbitrary precision float required?