"Not a valid data type or _FillValue type mismatch", but fill values appear to match data
Added by James Goldie about 2 years ago
I'm working with some climate projections based on NARCliM1.5 (https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2020EF001833).
I have two sample files attached: one based on the CORDEX grid (50km), and another based on a smaller, 10km grid.
I'm not having any problems operating on the CORDEX files, but the NARCliM (10km grid) ones are giving me problems: any sort of operation that involves writing a new file gives me:
Error (cdf_put_var_int): NetCDF: Not a valid data type or _FillValue type mismatch
.
For example, just using selname
to select a variable:
# cordex grid works $ cdo -selname,tasmax-bc test-cordex.nc test-cordex-result.nc Warning (cdfScanVarAttr): NetCDF: Variable not found - Rotated_pole cdo selname: Processed 9297280 values from 2 variables over 365 timesteps [0.27s 63MB]. # narclim grid fails $ cdo -selname,tasmax-bc test-narclim.nc test-narclim-result.nc Warning (cdfScanVarAttr): NetCDF: Variable not found - Rotated_pole cdf_put_var_int : 131072 6 1 Error (cdf_put_var_int): NetCDF: Not a valid data type or _FillValue type mismatch
(It's worth noting that the warning appears because the grid_mapping
attribute says Rotated_pole
instead of rotated_pole
, but i don't believe it's the cause of this problem.)
I've reproduced this problem on cdo 2.1.0 and netCDF 4.9.0 on an Apple Silicon Mac, as well as cdo 2.0.5 and netCDF 4.8.0 on an Ubuntu x64 system.
I understand that cdo is stricter about fill value mismatches since 4.6.2, but the fill values appear to match to me (and I'm having trouble sourcing an earlier version of cdo to test on).
$ ncdump -h test-cordex.nc | grep -C 1 _FillValue float AWAP_qualitymask(rlat, rlon) ; AWAP_qualitymask:_FillValue = 1.e+20f ; AWAP_qualitymask:standard_name = "quality_mask" ; -- float tasmax-bc(time, rlat, rlon) ; tasmax-bc:_FillValue = 1.e+20f ; tasmax-bc:standard_name = "air_temperature" ; $ ncdump -h test-narclim.nc | grep -C 1 _FillValue float tasmax-bc(time, rlat, rlon) ; tasmax-bc:_FillValue = 1.e+20f ; tasmax-bc:standard_name = "air_temperature" ; -- float AWAP_qualitymask(rlat, rlon) ; AWAP_qualitymask:_FillValue = 1.e+20f ; AWAP_qualitymask:standard_name = "quality_mask" ;
I've also tried removing the fill value attributes using ncatted
, editing them to another float, or converting the two data variables to doubles with ncep2
, in case there's something I'm not seeing there, but I still get the error.
Does anyone have any idea what might be causing this?
Thanks!
test-cordex.nc (3.53 MB) test-cordex.nc | Working 50km file | ||
test-narclim.nc (21.5 MB) test-narclim.nc | Not working 10km grid file |
Replies (5)
RE: "Not a valid data type or _FillValue type mismatch", but fill values appear to match data - Added by Uwe Schulzweida about 2 years ago
Hello James,
The NC_STRING data type is not handled correctly in CDO for the rotated_pole variable. We will fix the problem in the next CDO bugfix release 2.1.1.
In the first file (test-cordex.nc) the problem does not occur, because the first data variable (AWAP_qualitymask) in this file does not use the rotated_pole coordinate. This leads to the fact that also for the variable tasmax-bc the rotated_pole is not used.
Cheers,
Uwe
RE: "Not a valid data type or _FillValue type mismatch", but fill values appear to match data - Added by Karin Meier-Fleischer about 2 years ago
Hi James,
the variable tasmax-bc has the attribute grid_mapping = "rotated_pole" (this is ok) but the variable AWAP_qualitymask has the attribute grid_mapping = "Rotated_pole", this has to be "rotated_pole" too. This leads to the the warning message
Warning (cdfScanVarAttr): NetCDF: Variable not found - Rotated_pole
ncdump -h test-narclim.nc
... float AWAP_qualitymask(rlat, rlon) ; AWAP_qualitymask:_FillValue = 1.e+20f ; AWAP_qualitymask:standard_name = "quality_mask" ; AWAP_qualitymask:long_name = "AWAP quality mask" ; AWAP_qualitymask:units = "" ; AWAP_qualitymask:description = "Mask to define areas where AWAP might be unreliable" ; AWAP_qualitymask:grid_mapping = "Rotated_pole" ; AWAP_qualitymask:coordinates = "lon lat" ; ... string rotated_pole ; rotated_pole:grid_mapping_name = "rotated_latitude_longitude" ; rotated_pole:dx_m = 9783.618 ; rotated_pole:dy_m = 9783.618 ; rotated_pole:grid_north_pole_latitude = 60.31 ; rotated_pole:grid_north_pole_longitude = 147.63 ; ...
RE: "Not a valid data type or _FillValue type mismatch", but fill values appear to match data - Added by Karin Meier-Fleischer about 2 years ago
You can run the following Python script to make some corrections and write it to a new file test-narclim.nc. Then you can use it with CDO.
#!/usr/bin/env python # coding: utf-8 import xarray as xr from cdo import Cdo cdo = Cdo() infile = 'test-narclim.nc' ds = xr.open_dataset(infile) ds2 = ds.copy(deep=True) rp_new = xr.DataArray(data=[0], coords=None, dims=None, attrs=ds2.rotated_pole.attrs) ds2['rotated_pole'] = rp_new ds2['AWAP_qualitymask'].attrs['grid_mapping'] = 'rotated_pole' outfile = 'test-narclim_corrected.nc' ds2.to_netcdf(outfile)
RE: "Not a valid data type or _FillValue type mismatch", but fill values appear to match data - Added by James Goldie about 2 years ago
Thanks very much, Uwe and Karin! It looks like I blew off the grid_mapping
variable prematurely 😅
Working with this data before cdo 2.1.1 comes out, I'm just doing temporal and ensemble statistics in cdo - and the final step where I'm doing field averages is in R, where I point it to the curvilinear grid variables rlat
and rlon
.
Is it likely that simply deleting the grid_mapping
variable altogether (and potentially restoring it after my temporal and ensemble stats are calculated) is going to have any effect on my analysis?
(I can see that the grid_mapping
var has important information on the projection, and it's required by CF-1.4 - see page 3 of https://is-enes-data.github.io/cordex_archive_specifications.pdf - but it's not clear to me that cdo is actually taking it into account when aggregating on time and across ensembles.) I've run my first analysis step and it doesn't seem like the grid is affected.
Karin Meier-Fleischer wrote in RE: "Not a valid data type or _FillValue type mismatch", ...:
Hi James,
the variable tasmax-bc has the attribute grid_mapping = "rotated_pole" (this is ok) but the variable AWAP_qualitymask has the attribute grid_mapping = "Rotated_pole", this has to be "rotated_pole" too. This leads to the the warning message...
Thanks Karin! I was able to fix this warning similarly by modifying the grid_mapping
attribute with ncatted
. It unfortunately didn't fix the error too, but I'm proposing a solution (for my use case) above in this post.
RE: "Not a valid data type or _FillValue type mismatch", but fill values appear to match data - Added by James Goldie about 2 years ago
My mistake: I'm having success removing the grid_mapping
attributes, not variable.
ncks -xv grid_mapping test-narclim.nc test-narclim-nogridmap.nc cdo -selname,tasmax-bc test-narclim-nogridmap.nc test-narclim-result.nc
The grid_mapping
attributes still seem to be in test-narclim-nogridmap.nc
, so I'm not 100% sure why this seems to work.