units of variables with CF standard_name in netCDF files created with cfgrib to_netcdf not CF-compliant
Hello,
I noted that converting ERA5 grib files to netCDF (with cfgrib version 0.9.8.5 installed with mambaforge-4.11.0-0 on Linux-x86_64)
cfgrib to_netcdf ifile.grb sometimes yields CF units errors.
Here an example of the grib-to-netcdf conversion of the ERA5 GRIB file E5sf12_1D_202101-11_146 which I downloaded from ECMWF Mars. E5sf12_1D_202101-11_146.gz The GRIB file contains param 146 Table 128 which is the "Surface sensible heat flux" in J m-2 (https://apps.ecmwf.int/codes/grib/param-db?id=146).
(1) look at the GRIB file header
grib_dump E5sf12_1D_202101-11_146|head
***** FILE: E5sf12_1D_202101-11_146
#============== MESSAGE 1 ( length=1085524 ) ==============
GRIB {
editionNumber = 1;
table2Version = 128;
# European Centre for Medium-Range Weather Forecasts (common/c-1.table)
centre = 98;
generatingProcessIdentifier = 145;
# Surface sensible heat flux (J m**-2) (grib1/2.98.128.table)
indicatorOfParameter = 146;
(2) Conversion to netCDF
cfgrib to_netcdf E5sf12_1D_202101-11_146
(3) Look at the created netCDF
ncdump -h E5sf12_1D_202101-11_146.nc|grep sshf|tail -4
sshf:long_name = "Surface sensible heat flux" ;
sshf:units = "J m**-2" ;
sshf:standard_name = "surface_upward_sensible_heat_flux" ;
sshf:coordinates = "time step surface latitude longitude valid_time" ;
You see that variable sshf (parameter 146) now has a CF standard_name attribute with the value "surface_upward_sensible_heat_flux".
The canonical units of the CF standard_name surface_upward_sensible_heat_flux, however, is "W m**-2" (https://cfconventions.org/Data/cf-standard-names/current/build/cf-standard-name-table.html) and not "J m**-2" .
When checking the netCDF file with the CEDA CF checker (https://github.com/cedadev/cf-checker, version 4.1.0), I obtain a units error.
cfchecks E5sf12_1D_202101-11_146.nc
CHECKING NetCDF FILE: E5sf12_1D_202101-11_146.nc
=====================
Using CF Checker Version 4.1.0
Checking against CF Version CF-1.8
....
------------------
Checking variable: sshf
------------------
ERROR: (3.1): Units are not consistent with those given in the standard_name table.
ERRORS detected: 1
WARNINGS given: 1
INFORMATION messages: 0
When, test-wise, I edit the units metadata to adjust them to the CF canonical units of "W m**-2", then the cfchecks routine does not complain:
ncatted -O -a units,sshf,o,c,"W m**-2" E5sf12_1D_202101-11_146.nc|cfchecks E5sf12_1D_202101-11_146.nc|grep ERROR
ERRORS detected: 0
or, since W mm**-2 is consistent with the canonical units "W m**-2":
ncatted -O -a units,sshf,o,c,"W mm**-2" E5sf12_1D_202101-11_146.nc|cfchecks E5sf12_1D_202101-11_146.nc|grep ERROR
ERRORS detected: 0
So, the cfchecks routine does not consider "J m**-2" to be consistent with the canonical units "W m**-2".
As explained in https://apps.ecmwf.int/codes/grib/param-db?id=146, the parameter ID 146 (table 128) with the short name sshf is an accumulated quantity. So it is accumulated over a particular time period which depends on the data extracted. The units are joules per square metre (J m-2). To convert to watts per square metre (W m-2), the accumulated values should be divided by the accumulation period expressed in seconds.
https://cfconventions.org/Data/cf-standard-names/current/build/cf-standard-name-table.html further states that "a variable with a standard_name attribute must have units which are physically equivalent (not necessarily identical) to the canonical units, possibly modified by an operation specified by either the standard name modifier ... or by the cell_methods attribute."
The netCDF file created by cfgrib does not contain any standard name modifier or cell_methods attribute that would indicate how to convert the units. It also does not contain any information that the sshf parameter is an accumulated quantity and that it has to be converted by dividing by the accumulation period [in sec] to obtain the quantity that is consistent with the standard_name surface_upward_sensible_heat_flux.
I would very appreciate if a solution could be found for this. There are GRIB several parameters (e.g. params 176 to 181 Table 128) where a cfgrib conversion results in netCDF files which the cfchecks routine considers as not CF compliant due to inconsistent units.
Thanks a lot and best regards Angelika
Dear @atmodatcode This is similar to https://github.com/ecmwf/eccodes/pull/69#issuecomment-1142370579
It is best if you submit an email to ECMWF software support [email protected] outlining the issue and your suggested fix.
Many thanks