Closed abakleriche closed 2 years ago
Regarding the total number of points: Let's sum the "pl" array to see how many total points there are (on all latitudes)
% echo 'print "[pl\!1]";' | grib_filter - T_2016120100_an-00-h_h-00100-m.grb | awk '{ s+= $1 } END {print s}'
542080
So that matches the numbers ecCodes gives.
% grib_ls -jp numberOfDataPoints,numberOfCodedValues,numberOfMissing T_2016120100_an-00-h_h-00100-m.grb
..
"numberOfDataPoints": 542080,
"numberOfCodedValues": 542080,
"numberOfMissing": 0
..
Thank you for your answer. I am not an expert on the GRIB format, but I understand we have a reduced gaussian grid in this file, and cfgrib does not expand it to a regular grid. The question is : is there a means to expand it simply ? Or does cfgrib has an option to do it, or will a future version of cfgrib do it ? Or should I try to do it myself, by postprocessing cfgrib result ?
Hello @abakleriche , cfgrib does not perform this type of operation. We do supply the Metview package, which can regrid GRIB data onto a regular grid. You will need to install the Metview binaries too, details here: https://metview.readthedocs.io/en/latest/install.html
See an example here: https://metview.readthedocs.io/en/latest/examples/grib_interpolation.html
An example call might look something like
regular_grib = mv.read(source='my_file.grib', grid=[0.5,0.5])
to put it onto a 0.5-degree regular grid. You can then call
ds = regular_grib.to_dataset()
which calls cfgrib in the background, to get the xarray from it, or call the write('reg_path.grib')
method to write it to disk before calling cfgrib yourself.
For more advanced control over the regridding exercise, see, for example, https://metview.readthedocs.io/en/latest/examples/advanced_regrid.html
Cheers, Iain
Hello Iain,
Thank you for your answer. Finally I have postprocessed the cfgrib result to expand data to a regular grid.
Regards,
Roger
Great to hear it Roger! Cheers, Iain
I try to read the ERA5 following GRIB file T_2016120100_an-00-h_h-00100-m.zip If I view it with a tool like IDV or Panoply, the grid is 1280 longitudes x 640 latitudes, that is 819200 values. There is a value at each grid point When I load it with cfgrib, the variable has only one dimension with only 542080 values I looked at issue #134 where a similar problem is exposed. An answer propose a solution (reshaping xarray) at this link https://stackoverflow.com/questions/59845442/how-to-reshape-xarray-data-with-new-dimensions. But when I try it, the number of longitudes is 11942 instead of 1280 . Furthermore, even if the number of longitudes was good, I think this solution can't work because the initial number of values is 542080 and the reshaped array should contain 819200 values. The reshaping opération would add Nans. How to obtain the right grid ?