Error when converting grib file to netcdf

220 Views Asked by At

I'm trying to convert a grib file obtained from someone else to netcdf using cdo. The file is global data with a gaussian grid format:

File format : GRIB szip
    -1 : Institut Source   T Steptype Levels Num    Points Num Dtype : Parameter ID
     1 : MPIMET   unknown  v instant       1   1    294912   1  P24s : 182.128
   Grid coordinates :
     1 : gaussian                 : points=294912 (768x384)  F192
                              lon : 0 to 359.5312 by 0.46875 degrees_east  circular
                              lat : 89.64165 to -89.64165 degrees_north
   Vertical coordinates :
     1 : surface                  : levels=1
   Time coordinate :  unlimited steps

When running cdo, it gives me an error that I don't have the right decompression tool (szip), but I do have the newer package ECCODES:

[user]$ cdo -f nc copy input.grb output.nc
Warning (gribUnzip): Decompression disabled, szlib not available!

Error (grbUnzipRecord): Decompression problem!

I also tried using cfgrib and eccodes, but it also did not work, this time due to a different error. Code:

import xarray as xr
import cfgrib
import eccodes

ds = cfgrib.open_datasets('input.nc',backend_kwargs={'filter_by_keys': {'typeOfLevel':'surface','level':0,'shortName': 'e'}})

Error:

ValueError: conflicting sizes for dimension 'latitude': length 384 on 'e' and length 285 on {'time': 'time', 'step': 'step', 'surface': 'surface', 'latitude': 'latitude', 'longitude': 'longitude'}

I also tried gdal, but I also got another error. Code:

[user]$ gdalwarp -overwrite -to SRC_METHOD=NO_GEOTRANSFORM -t_srs EPSG:4326 input.grb -of netCDF output.nc

Error:

numPts * (numBits in a Group) + # of unused bits 7077888 != # of available bits 5244760
Creating output file that is 768P x 384L.
Processing /scistor/ivm/hmt250/raed_paper/swift.dkrz.de/clisap_echam_182/CLI_MPI-ESM-XR_t255l95_echam_265-276.cdo_processed.grb [1/1] : 0numPts * (numBits in a Group) + # of unused bits 7077896 != # of available bits 5225512
numPts * (numBits in a Group) + # of unused bits 7077888 != # of available bits 5265624
numPts * (numBits in a Group) + # of unused bits 7077888 != # of available bits 5258632
numPts * (numBits in a Group) + # of unused bits 7077896 != # of available bits 5275464
numPts * (numBits in a Group) + # of unused bits 7077888 != # of available bits 5352712

Finally I tried directly ECCODES and it also led to an error:

[user]$ grib_to_netcdf -o output2.nc input.grb
grib_to_netcdf: Version 2.21.0
grib_to_netcdf: Processing input file 'input.grb'.
grib_to_netcdf: Found 8760 GRIB fields in 1 file.
grib_to_netcdf: Ignoring key(s): method, type, stream, refdate, hdate
grib_to_netcdf: Creating netCDF file 'output2.nc'
grib_to_netcdf: NetCDF library version: 4.7.4 of Oct 29 2020 15:05:42 $
grib_to_netcdf: Creating large (64 bit) file format.
grib_to_netcdf: Defining variable 'e'.

grib_to_netcdf ERROR: line 2863, nc_put_vara_type: NetCDF: Start+count exceeds dimension bound

I would appreciate any help on converting this file to netcdf.

0

There are 0 best solutions below