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

Can we remove wgrib2 from the dependencies? #591

Closed
edwardhartnett opened this issue Oct 21, 2021 · 26 comments · Fixed by #641
Closed

Can we remove wgrib2 from the dependencies? #591

edwardhartnett opened this issue Oct 21, 2021 · 26 comments · Fixed by #641
Assignees
Labels

Comments

@edwardhartnett
Copy link
Collaborator

Somehow wgrib2 crept into our dependencies.

We are trying to eliminate use of wgrib2 in NCEPLIBS. The wgrib2 library is not well-maintained, distributed, or tested, and there is no interest on the wgrib2 team in meeting our needs in these areas. So we need to not build more tools on top of wgrib2.

@kgerheiser
Copy link
Contributor

kgerheiser commented Oct 21, 2021

UFS_UTILS definitely depends on the wgrib2 library. That hasn't changed recently. The alternative is to port UFS_UTILS to use g2 as its grib2 library.

@GeorgeGayno-NOAA
Copy link
Collaborator

chgres_cube uses wgrib2. It could be modified to use the 'g2' library. I don't think that would be difficult. But it would take some work and testing. And it could be done is smaller chunks.

@edwardhartnett
Copy link
Collaborator Author

@GeorgeGayno-NOAA for future work, can you communicate to the other chgres_cube programmers that wgrib2 should be avoided?

@GeorgeGayno-NOAA
Copy link
Collaborator

@GeorgeGayno-NOAA for future work, can you communicate to the other chgres_cube programmers that wgrib2 should be avoided?

Absolutely.

Maybe I can add a warning to our wiki page? https://github.com/NOAA-EMC/UFS_UTILS/wiki
Or the PR template? https://github.com/NOAA-EMC/UFS_UTILS/blob/develop/.github/PULL_REQUEST_TEMPLATE

@edwardhartnett
Copy link
Collaborator Author

If we can remove the dependency on wgrib2, we should.

@GeorgeGayno-NOAA
Copy link
Collaborator

GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Oct 22, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Oct 25, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Oct 25, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Oct 26, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Oct 26, 2021
@XianwuXue-NOAA
Copy link

@GeorgeGayno-NOAA Based on the warning page "Pull requests that use WGRIB2 will be rejected.", do it also apply to the GEFS WCOSS2 Transition? Because GEFS uses chgres_cube.

GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Oct 27, 2021
Add diagnostic print to compare lat/lon computed by gdswzd
to those from wgrib2.

Use gdswzd computed lat/lon for use by rest of program.

Fixes ufs-community#591.
@GeorgeGayno-NOAA
Copy link
Collaborator

@GeorgeGayno-NOAA Based on the warning page "Pull requests that use WGRIB2 will be rejected.", do it also apply to the GEFS WCOSS2 Transition? Because GEFS uses chgres_cube.

Are you adding new code to chgres_cube that uses wgrib2?

@XianwuXue-NOAA
Copy link

No. I didn't change code except changing "grb2_UNDEFINED" to "9.999e20" to use wgrib2/2.0.7. My changes are XianwuXue-NOAA/UFS_UTILS@1b44601...a825b29

GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Oct 28, 2021
to determine the number of soil layers.

Fixes ufs-community#591.
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Oct 29, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Oct 29, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Nov 1, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Nov 2, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Nov 3, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Nov 3, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Nov 3, 2021
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Nov 3, 2021
@GeorgeGayno-NOAA
Copy link
Collaborator

Count number of soil layers using g2 instead of wgrib2 - d327b7a. All consistency tests passed on Dell.

@GeorgeGayno-NOAA
Copy link
Collaborator

Some further analysis of #591 (comment) and #591 (comment)

My branch at 474401f and 'develop' at 26cd024 were modified to output the grid cell center and corner lat/lons in netcdf format.

The files were placed on Hera in /scratch1/NCEPDEV/da/George.Gayno/ufs_utils.git/UFS_UTILS.upstream/latlon_check.

The latlon.gdswzd.nc files were produced by my branch and the latlon.wgrib2.nc files were produced by 'develop' using wgrib2. Note, lat/lons for the 13km RAP grid are not created from wgrib2; they are read in from file. That file is latlon_grid3.32769.nc. The ncdiff utility was used to create difference files (diff.nc). And the nccmp utility was used to print a summary of the differences (diff.log).

The files are in these sub-directories:

  • 13km_conus_rap_grib2 - the 13 km rotated lat/lon RAP grid
  • 13km_conus_nam_grib2 - the 13 km lambert conformal NAM grid
  • 3km_conus_hrrr_gfsdf_grib2 and 3km_conus_hrrr_newsfc_grib2 - the 3km lambert conformal HRRR grid.

More analysis will follow.

@GeorgeGayno-NOAA
Copy link
Collaborator

Here are the differences between my branch and 'develop' for the 13km RAP grid.

Variable        Group  Count         Sum      AbsSum          Min         Max      Range         Mean      StdDev
gridlat         /     790759    -120.266     162.903 -0.000530243 0.000289917 0.00082016 -0.000152089 0.000204953
gridlon         /     792752       49.76     771.789     -79.9549         360    439.955  6.27686e-05    0.414187
gridlat_corners /     792644    -120.655     164.868 -0.000541687  0.00219727 0.00273895 -0.000152219 0.000206831
gridlon_corners /     794497    -229.414     323.772    -0.181824    0.178787   0.360611 -0.000288754 0.000780303

The mean differences are very small - much smaller than the resolution of the grid. Viewing the files in ncview show the large longitude differences (-79.9 and 360 degrees) were located at the north pole (where the longitude lines converge) and the dateline respectively (where one point was -180 and the other was 180.).

Since we know the latlon_grid3.32769.nc file is correct, we can conclude the branch values are correct as well.

@GeorgeGayno-NOAA
Copy link
Collaborator

Here are the differences between the branch 474401f and 'develop' for the 13km NAM grid (lambert conformal)

Variable        Group  Count      Sum  AbsSum          Min         Max       Range        Mean      StdDev
gridlat         /     261655  22.6143 23.3464 -6.58035e-05 0.000183105 0.000248909 8.64278e-05 5.58303e-05
gridlon         /     254008  48.8392 50.8008 -0.000137329 0.000549316 0.000686646 0.000192274 0.000141188
gridlat_corners /     263804  513.784 2193.29   -0.0313454   0.0270767   0.0584221   0.0019476  0.00970519
gridlon_corners /     263835 -36764.1 36866.6    -0.212463    0.209259    0.421722   -0.139345   0.0287544

The grid cell centers are very close. The differences are much smaller than the resolution of the grid. The grid cell corners are off - especially the longitudes. The branch computes the centers using wgrib2 and the corners using routine get_cell_corners.

A similar result is seen with the 3km HRRR grid. The corner longitude difference is similar to the resolution of the grid:

Variable        Group   Count      Sum  AbsSum          Min          Max       Range         Mean      StdDev
gridlat         /     1885229   98.535 149.762 -0.000123978  0.000217438 0.000341415  5.22669e-05  7.8939e-05
gridlon         /     1905141 -871.205 871.205 -0.000732422 -0.000244141 0.000488281 -0.000457291 0.000110639
gridlat_corners /     1907294  830.204 4353.38  -0.00643921    0.0065918    0.013031  0.000435279   0.0026419
gridlon_corners /     1908000 -65904.6 65961.1   -0.0474243    0.0458069   0.0932312   -0.0345412  0.00527456

GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Feb 4, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Feb 4, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Feb 4, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Feb 11, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Feb 14, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Feb 18, 2022
GeorgeGayno-NOAA added a commit that referenced this issue Mar 22, 2022
…ines.

Update routines "read_input_atm_grib2_file", "read_input_sfc_grib2_file", "read_winds" and "read_grib_soil"
to read input GRIB2 files using G2LIB instead of WGRIB2.

Update routine "define_input_grid_gfs_grib2" to flip the pole of GFS GRIB2 data. WGRIB2 and 
G2LIB use different conventions for defining global gaussian grids.

Update to G2LIB v3.4.3 or higher, which eliminated occasional segmentation faults and slow wall 
clock times.

Add new units test for GRIB2 read routines "read_input_atm_grib2_file" and "read_input_sfc_grib2_file".

Part of #591.
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Mar 24, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Mar 24, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Mar 24, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Mar 28, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Mar 28, 2022
GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Mar 29, 2022
@GeorgeGayno-NOAA
Copy link
Collaborator

GeorgeGayno-NOAA commented Mar 30, 2022

The second - and hopefully - final PR was created for this issue - #641. This PR replaces the wgrib2 computation of input grid latitude/longitude with a computation from IPLIB routine gdswzd. So, our first check should compare the differences between the two computation methods. Both the branch and a local copy of develop were modified to dump the lat/lons to a netcdf file.

@GeorgeGayno-NOAA
Copy link
Collaborator

GeorgeGayno-NOAA commented Mar 30, 2022

Check lat/lon differences between develop at 31271f7 and the branch at 9f66174.

Test 1 - Check the lat/lon differences for 13km RAP data. This data is on a rotated lat/lon 'B' grid (grid definition template number - 32769).

   grid_template=32769:winds(grid):
        I am not an Arakawa E-grid.
        I am rotated but have no rotation angle.
        I am staggered. What am I?
        (953 x 834) units 1e-06 input WE:SN output WE:SN res 56
        lat0 -10.590603 lat-center 54.000000 dlat 121.813000
        lon0 220.914154 lon-center 254.000000 dlon 121.813000 #points=794802

The wgrib2 library can't compute the lat/lons for this grid, so they are read into chgres_cube from a file - latlon_grid3.32769.nc.

The differences between the file and gdswzd computations are:

Variable        Group  Count         Sum      AbsSum          Min         Max      Range         Mean      StdDev
gridlat         /     790759    -120.266     162.903 -0.000530243 0.000289917 0.00082016 -0.000152089 0.000204953
gridlon         /     792752       49.76     771.789     -79.9549         360    439.955  6.27686e-05    0.414187
gridlat_corners /     792644    -120.655     164.868 -0.000541687  0.00219727 0.00273895 -0.000152219 0.000206831
gridlon_corners /     794497    -229.414     323.772    -0.181824    0.178787   0.360611 -0.000288754 0.000780303

The mean are very small compared to the grid resolution of 13 km. Some large differences in longitude are near the dateline, where the sign of longitude switches.

@GeorgeGayno-NOAA
Copy link
Collaborator

Test 2 - Check the lat/lon differences for the 3km HRRR data. This data is on a lambert conformal grid:

  grid_template=30:winds(grid):
        Lambert Conformal: (1799 x 1059) input WE:SN output WE:SN res 8
        Lat1 21.138123 Lon1 237.280472 LoV 262.500000
        LatD 38.500000 Latin1 38.500000 Latin2 38.500000
        LatSP 0.000000 LonSP 0.000000
        North Pole (1799 x 1059) Dx 3000.000000 m Dy 3000.000000 m mode 8

The differences between the wgrib2 and gdswzd computations are:

Variable                  Group   Count      Sum  AbsSum          Min          Max       Range         Mean      StdDev
gridlat                   /     1885229   98.535 149.762 -0.000123978  0.000217438 0.000341415  5.22669e-05  7.8939e-05
gridlon                   /     1905141 -871.205 871.205 -0.000732422 -0.000244141 0.000488281 -0.000457291 0.000110639
gridlat_corners           /     1907294  830.204 4353.38  -0.00643921    0.0065918    0.013031  0.000435279   0.0026419
gridlon_corners           /     1908000 -65904.6 65961.1   -0.0474243    0.0458069   0.0932312   -0.0345412  0.00527456

The mean differences at the center of the grid cell are very small compared to the grid resolution of 3 km. And the corner point latitude differences are small. However, the mean corner point longitude differences are comparable to the grid resolution. Something is not correct.

@GeorgeGayno-NOAA
Copy link
Collaborator

Test 3 - Check the lat/lon differences for 12km NAM data. This data is on a lambert conformal grid:

    grid_template=30:winds(grid):
        Lambert Conformal: (614 x 428) input WE:SN output WE:SN res 56
        Lat1 12.190000 Lon1 226.541000 LoV 265.000000
        LatD 25.000000 Latin1 25.000000 Latin2 25.000000
        LatSP -90.000000 LonSP 0.000000
        North Pole (614 x 428) Dx 12191.000000 m Dy 12191.000000 m mode 56

The differences between the wgrib2 and gdswzd computations are:

Variable                  Group  Count      Sum  AbsSum          Min         Max       Range        Mean      StdDev
gridlat                   /     261655  22.6143 23.3464 -6.58035e-05 0.000183105 0.000248909 8.64278e-05 5.58303e-05
gridlon                   /     254008  48.8392 50.8008 -0.000137329 0.000549316 0.000686646 0.000192274 0.000141188
gridlat_corners           /     263804  513.784 2193.29   -0.0313454   0.0270767   0.0584221   0.0019476  0.00970519
gridlon_corners           /     263835 -36764.1 36866.6    -0.212463    0.209259    0.421722   -0.139345   0.0287544

The mean differences at the center of the grid cell are very small compared to the grid resolution of 12 km. And the corner point latitude differences are small. However, as with the 3 km HRRR data, the mean corner point longitude differences are comparable to the grid resolution. Something is not correct.

@GeorgeGayno-NOAA
Copy link
Collaborator

Test 2 - Check the lat/lon differences for the 3km HRRR data. This data is on a lambert conformal grid:

  grid_template=30:winds(grid):
        Lambert Conformal: (1799 x 1059) input WE:SN output WE:SN res 8
        Lat1 21.138123 Lon1 237.280472 LoV 262.500000
        LatD 38.500000 Latin1 38.500000 Latin2 38.500000
        LatSP 0.000000 LonSP 0.000000
        North Pole (1799 x 1059) Dx 3000.000000 m Dy 3000.000000 m mode 8

The differences between the wgrib2 and gdswzd computations are:

Variable                  Group   Count      Sum  AbsSum          Min          Max       Range         Mean      StdDev
gridlat                   /     1885229   98.535 149.762 -0.000123978  0.000217438 0.000341415  5.22669e-05  7.8939e-05
gridlon                   /     1905141 -871.205 871.205 -0.000732422 -0.000244141 0.000488281 -0.000457291 0.000110639
gridlat_corners           /     1907294  830.204 4353.38  -0.00643921    0.0065918    0.013031  0.000435279   0.0026419
gridlon_corners           /     1908000 -65904.6 65961.1   -0.0474243    0.0458069   0.0932312   -0.0345412  0.00527456

The mean differences at the center of the grid cell are very small compared to the grid resolution of 3 km. And the corner point latitude differences are small. However, the mean corner point longitude differences are comparable to the grid resolution. Something is not correct.

Attaching some plots of corner point longitude minus center point longitude. The wgrib2 plot shows this difference is of the wrong sign (It is positive everywhere. For this N Amer. grid, it should be negative). The gdswzd plots show the expected magnitude (about 0.015 deg or 1.5 km) and sign.

hrrr wgrib2

hrrr gdswzd

@GeorgeGayno-NOAA
Copy link
Collaborator

Test 3 - Check the lat/lon differences for 12km NAM data. This data is on a lambert conformal grid:

    grid_template=30:winds(grid):
        Lambert Conformal: (614 x 428) input WE:SN output WE:SN res 56
        Lat1 12.190000 Lon1 226.541000 LoV 265.000000
        LatD 25.000000 Latin1 25.000000 Latin2 25.000000
        LatSP -90.000000 LonSP 0.000000
        North Pole (614 x 428) Dx 12191.000000 m Dy 12191.000000 m mode 56

The differences between the wgrib2 and gdswzd computations are:

Variable                  Group  Count      Sum  AbsSum          Min         Max       Range        Mean      StdDev
gridlat                   /     261655  22.6143 23.3464 -6.58035e-05 0.000183105 0.000248909 8.64278e-05 5.58303e-05
gridlon                   /     254008  48.8392 50.8008 -0.000137329 0.000549316 0.000686646 0.000192274 0.000141188
gridlat_corners           /     263804  513.784 2193.29   -0.0313454   0.0270767   0.0584221   0.0019476  0.00970519
gridlon_corners           /     263835 -36764.1 36866.6    -0.212463    0.209259    0.421722   -0.139345   0.0287544

The mean differences at the center of the grid cell are very small compared to the grid resolution of 12 km. And the corner point latitude differences are small. However, as with the 3 km HRRR data, the mean corner point longitude differences are comparable to the grid resolution. Something is not correct.

Some plots. As in the previous comment (#591 (comment)), note how the gdswzd computation make more sense:

nam wgrib2

nam gdswzd

@GeorgeGayno-NOAA
Copy link
Collaborator

All files containing the input gridpoint latitude/longitudes and their differences (from the above tests) are on Hera here: /scratch1/NCEPDEV/da/George.Gayno/ufs_utils.git/chgres_cube_nowgrib2/PR641/latlon_check

Under each sub-directory, there are these netcdf files:

  • latlon.gdswzd.nc - the lat/lons computed by gdswzd (the branch)
  • latlon.wgrib.nc - the lat/lons computed by 'develop'.
  • diff.nc - the difference between the branch and develop.

@GeorgeGayno-NOAA
Copy link
Collaborator

Graphics from all failed consistency tests are on Hera here: /scratch1/NCEPDEV/da/George.Gayno/ufs_utils.git/chgres_cube_nowgrib2/PR641

Under each test sub-directory, the graphics are here:

  • ./graphics/atm - Some atmospheric plots from the branch, and the difference between the branch and the baseline. Three vertical levels are included - the model top, bottom and a mid-level.
  • ./graphics/sfc - Some surface plots from the branch, and the difference between the branch and the baseline.

For this latest PR (#641) all differences are due solely to the difference between how the branch and develop compute the input grid latitude/longitudes.

GeorgeGayno-NOAA added a commit to GeorgeGayno-NOAA/UFS_UTILS that referenced this issue Apr 19, 2022
JeffBeck-NOAA pushed a commit that referenced this issue Apr 20, 2022
* Begin update of model_grid.F90 to use g2 library.

Fixes #591

* Start new routine to set the esmf grid object for
grib2 data.

Fixes #591.

* Begin updates to add non-latlon grids.

Fixes #591

* Call gdswzd twice. Once for the grid point centers and once
for the corner points.

Fixes #591.

* Output lat/lons to a netcdf file.

* Adjust longitude convention of rotated lat/lon grids
in output netcdf file.

* Remove unused routines from model_grid.F90

Part of #591.

* Some cleanup to model_grid.F90

* Remove unused variable used to store the path and name
of the RAP grid coordinate file.

Part of #591.

* Remove all dependencies on wgrib2 from the build.

Fixes #591.

* Remove wgrib2 from workflow 'yml' files.

Fixes #591.

* Fix pole flip bug in gdt_to_gds for GFS GRIB2 data.

Fixes #591.

* Add diagnostic print of lat/lon corner/center differences.

Fixes #591.

* Remove some unused variables and the write of the diagnostic
file containing grid point lat/lons.

Fixes #591.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants