Project

General

Profile

Wrong grid on NetCDF to GRIB conversion

Added by Milan Curcic almost 3 years ago

Hi CDO team,

I've been using CDO successfully to convert Lambert Conformal Conic NetCDF files to GRIB2 like this:

cdo -f grb2 copy in.nc out.grb

However, I now encountered strange behavior where for a 200-m resolution NetCDF file, the resulting GRIB2 grid seems incorrect. Here's the grid description for the source NetCDF file:

$ cdo griddes in.nc
#
# gridID 1
#
gridtype  = projection
gridsize  = 50000
xsize     = 250
ysize     = 200
xname     = x
xunits    = "m" 
yname     = y
yunits    = "m" 
xvals     = -3.72529029846191e-09 199.587681240402 399.945036566816 599.024267312139 
            799.385158726946 998.979852784425 1198.83229321986 1397.66247153655 1598.03042823169 
            ... many rows omitted for brevity
yvals     = 1.62981450557709e-09 199.014222515048 398.70365596097 598.730049135862 
            797.740483938949 1000.11186205386 1199.45798648917 1399.1410636201 1600.15574228903 
            ... many rows omitted for brevity
scanningMode = 64
grid_mapping = Lambert_Conformal
grid_mapping_name = lambert_conformal_conic
standard_parallel = 35.31035f
longitude_of_central_meridian = 75.f
latitude_of_projection_origin = 35.31035f
earth_radius = 6367470.
longitudeOfFirstGridPointInDegrees = 139.215f
latitudeOfFirstGridPointInDegrees = 35.30643f
cdo    griddes: Processed 5 variables [0.00s 51MB].

And here's the grid description for the target GRIB file:

t$ cdo griddes out.grb
#
# gridID 1
#
gridtype  = projection
gridsize  = 50000
xsize     = 250
ysize     = 200
xname     = x
xunits    = "m" 
yname     = y
yunits    = "m" 
xfirst    = 0
xinc      = 1.44
yfirst    = -89.55
yinc      = 0.9
scanningMode = 64
grid_mapping = Lambert_Conformal
grid_mapping_name = lambert_conformal_conic
standard_parallel = 35.310352
longitude_of_central_meridian = 75.
latitude_of_projection_origin = 35.310352
earth_radius = 6367470.
false_easting = -5424972.821748
false_northing = -1820872.47506838
longitudeOfFirstGridPointInDegrees = 139.215027
latitudeOfFirstGridPointInDegrees = 35.306431
cdo    griddes: Processed 5 variables [0.29s 81MB].

Based on xfirst, xinc, yfirst, and yinc, it seems to me that the target grid has x axis linearly spaced from approx. 0 to 360, and y axis from approx. -90 to 90. Instead, I expected xfirst and yfirst to be approx. 0 and xinc and yinc to be approx. 200.

I attach my in.nc and out.grb files. Any help or suggestions would be much appreciated.

Thank you!
Milan


Replies (3)

RE: Wrong grid on NetCDF to GRIB conversion - Added by Milan Curcic almost 3 years ago

This is my CDO build:

$ cdo -V
Climate Data Operators version 1.9.9rc1 (https://mpimet.mpg.de/cdo)
System: x86_64-pc-linux-gnu
CXX Compiler: g++ -g -O2 -fdebug-prefix-map=/build/cdo-51aH2m/cdo-1.9.9~rc1=. -fstack-protector-strong -Wformat -Werror=format-security -fopenmp 
CXX version : g++ (Ubuntu 9.2.1-28ubuntu1) 9.2.1 20200203
C Compiler: gcc -g -O2 -fdebug-prefix-map=/build/cdo-51aH2m/cdo-1.9.9~rc1=. -fstack-protector-strong -Wformat -Werror=format-security -Wall -pedantic -fPIC  -fopenmp  
C version : gcc (Ubuntu 9.2.1-28ubuntu1) 9.2.1 20200203
F77 Compiler: f77 -g -O2 -fdebug-prefix-map=/build/cdo-51aH2m/cdo-1.9.9~rc1=. -fstack-protector-strong
F77 version : unknown
Features: 7GB 4threads C++14 Fortran DATA PTHREADS OpenMP HDF5 NC4/HDF5/threadsafe OPeNDAP SZ UDUNITS2 PROJ MAGICS CURL FFTW3 SSE2
Libraries: HDF5/1.10.4 proj/6.3.0 curl/7.68.0(h7.66.0)
Filetypes: srv ext ieg grb1 grb2 nc1 nc2 nc4 nc4c nc5 
     CDI library version : 1.9.9rc1
 ecCodes library version : 2.16.0
  NetCDF library version : 4.7.3 of Jan 23 2020 04:18:16 $
    hdf5 library version : library undefined
    exse library version : 1.4.1
    FILE library version : 1.8.3

Thank you,
Milan

RE: Wrong grid on NetCDF to GRIB conversion - Added by Uwe Schulzweida almost 3 years ago

Hi Milan,

It looks like there are problems with the inaccurate x and y values. I will take a closer look. You can work around the problem by using the following grid description:

cat > mygrid << EOR
gridtype  = projection
xsize     = 250
ysize     = 200
xname     = x
xunits    = "m" 
yname     = y
yunits    = "m" 
xfirst    = 0
xinc      = 200
yfirst    = 0
yinc      = 200
grid_mapping = Lambert_Conformal
grid_mapping_name = lambert_conformal_conic
standard_parallel = 35.31035f
longitude_of_central_meridian = 75.f
latitude_of_projection_origin = 35.31035f
earth_radius = 6367470.
longitudeOfFirstGridPointInDegrees = 139.215f
latitudeOfFirstGridPointInDegrees = 35.30643f
EOR

cdo -f grb2 setgrid,mygrid in.nc out.grb
Cheers,
Uwe

RE: Wrong grid on NetCDF to GRIB conversion - Added by Milan Curcic almost 3 years ago

Uwe,

You rock--it works. Thanks a lot!

Milan

    (1-3/3)