I'm downloading daily CMIP6 data for max air temperature. I've asked for a spatial subset covering Brazil. When I open the NetCDF file in Panoply, I get very strange image, with the values from the most eastern border interpolating into the western border and wrapping around the globe.
And if I use CDO to query the file information, I get an error:
cdo sinfo tasmax_day_GFDL-ESM4_ssp585_r1i1p1f1_gr1_20150101-21001231_v20180701.nc
Warning (cdf_set_var): Inconsistent variable definition for lat_bnds!
Warning (cdf_set_var): Inconsistent variable definition for lon_bnds!
Warning (cdf_set_var): Inconsistent variable definition for time_bnds!
Segmentation fault (core dumped)
I tried both MIROC and GFDL models, downloading from the site or using the Python API.
I just checked and if I don't do a spatial subset, the CDO comand works fine. So I believe that the spatial subsetting is generating a malformed NetCDF file.
Has this happened to anyone else?
5 Comments
Daniel Victoria
I just found out that ncinfo works on the file. But when I use ncdump to look at the lat_bnds variable, I get what appears to be an infinite dump of the latitude values. Meanwhile, the same ncdump for the lat_bnds variable in the NON-subsetted dataset works fine.
Here is the ncinfo output on the offending file
And here is the ncinfo output of the variable with inconsistent definition
Daniel Victoria
Found out that I can clean the file using nccopy command and extracting just the lat,lon,time,tasmax variables to a new file.
But I'm not sure what I'm missing when I trow away the lat_bnds, lon_bnds, time_bnds variable
Ed Maurer
Glad to find this thread. I thought someone else must have wondered why the time dimension is in lat_bnds and lon_bnds, and how to correct it. I took a similar approach to remove and replace the bounds so cdo functions work:
ncks -C -O -x -v lat_bnds,lon_bnds,time_bnds in.nc out1.nc
ncap2 -O -s 'defdim("bnds",2); lon_bnds=make_bounds(lon,$bnds); lat_bnds=make_bounds(lat,$bnds); time_bnds=make_bounds(time,$bnds)' out1.nc out2.nc
Daniel Victoria
My attempt to use nccopy did not work. Something was left behind. Wish I new how to use
ncks
andncap2
so I could fix the file in an easier way. I ended up writing an R scritpt that will rewrite the NetCDF without the bnds.If anyone is interested, here goes the script:
https://gist.github.com/dvictori/b439f19fa1c67707059847442a4e9c3a
Roshanak Tootoonchi
I deleted the dimension "bnds" using the following code:
$ ncwa -a bnds infile.nc outfile.nc
And CDO worked perfectly fine afterwards, since the outfile.nc has regular time,lev,lat,lon dimensions.
However, "nccopy" did not work for me.