ufs-community / UFS_UTILS

Utilities for the NCEP models.
Other
21 stars 108 forks source link

Possible bug in chgres_cube's sst_guess routine. #441

Closed GeorgeGayno-NOAA closed 3 years ago

GeorgeGayno-NOAA commented 3 years ago

The sst_guess routine sets the SST values for small lakes that are far from other water bodies. The SST is based on latitude as follows:

if (latitude >= 60.0) then
   sst = 273.16
 elseif (abs(latitude) <= 30.0) then
   sst = 300.0
 else
   sst = (-0.8947) * abs(latitude) + 326.84
 endif

I suspect the first 'if' block should be if (abs(latitude) >= 60). Otherwise, SST values south of minus 60 would be below freezing.

I don't think this is causing problems because there are likely very few isolated open water lakes south of minus 60. But it should be fixed anyway.

edwardhartnett commented 3 years ago

Of course it must be fixed. But as part of the fix we need a test that demonstrates the bug.

GeorgeGayno-NOAA commented 3 years ago

Four tests were added under #279 to test all 'if' branches of sst_guess at c05b1e4

GeorgeGayno-NOAA commented 3 years ago

Here is the result of the SST default test. The SST returned for a point located at 65 degrees south latitude is below freezing (268.6845 Kelvin). That is clearly wrong:

 Run tests to check default logic for SST.
 CHECK DEFAULT LOGIC FOR FIELD NUMBER           11
 AT LATITUDE    75.0000000000000
 - TOTAL POINTS FOR VAR           11  REPLACED BY NEARBY VALUES:            0
 - TOTAL POINTS FOR VAR           11  REPLACED BY DEFAULT VALUE:            1
 OK
 CHECK DEFAULT LOGIC FOR FIELD NUMBER           11
 AT LATITUDE    45.0000000000000
 - TOTAL POINTS FOR VAR           11  REPLACED BY NEARBY VALUES:            0
 - TOTAL POINTS FOR VAR           11  REPLACED BY DEFAULT VALUE:            1
 OK
 CHECK DEFAULT LOGIC FOR FIELD NUMBER           11
 AT LATITUDE   0.000000000000000E+000
 - TOTAL POINTS FOR VAR           11  REPLACED BY NEARBY VALUES:            0
 - TOTAL POINTS FOR VAR           11  REPLACED BY DEFAULT VALUE:            1
 OK
 CHECK DEFAULT LOGIC FOR FIELD NUMBER           11
 AT LATITUDE   -65.0000000000000
 - TOTAL POINTS FOR VAR           11  REPLACED BY NEARBY VALUES:            0
 - TOTAL POINTS FOR VAR           11  REPLACED BY DEFAULT VALUE:            1
 TEST FAILED
 SST SHOULD BE:   273.160000000000
 SST FROM TEST:   268.684500000000
5
edwardhartnett commented 3 years ago

Good catch!

GeorgeGayno-NOAA commented 3 years ago

Bug was fixed with d69114e. The test is now working.

edwardhartnett commented 3 years ago

Excellent example of Test-Driven Development!

edwardhartnett commented 3 years ago

BTW does this change any of the output of our consistency checks?

If not, is it because they are all in the Northern hemisphere?

GeorgeGayno-NOAA commented 3 years ago

BTW does this change any of the output of our consistency checks?

If not, is it because they are all in the Northern hemisphere?

All the consistency tests (most are global) still pass. The default SST is only used when the search fails to find a neighboring valid SST value. Here "neighboring" is about 100 km. So for the default to be used, the lake must be isolated (away from larger water bodies). It must also be open water (i.e., not ice covered). And I doubt there are any isolated, open water lakes in Antarctica. (Our land masks are under ./fix/fix_fv3_gmted2010. The south pole is tile 6. I don't see any lakes.). So without the unit test, this bug would probably not have been found.