pygrib icon indicating copy to clipboard operation
pygrib copied to clipboard

Reading NCEP GFS atmospheric data using Pygrib gives different output with wgrib2

Open Telemaharry opened this issue 2 years ago • 1 comments

am trying to read NOAA's GFS weather data which is in .grb2 format with Pygrib in PYTHON. An example of the data can be found https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.20230610/06/atmos/gfs.t06z.pgrb2.0p25.f000 The issue is that Pygrib output a 721 X 1440 array for the wind data.

I converted the file to NetCDF using wgrib2 (https://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/netcdf.html) and the output of the .nc file is 1440 X 721.

I did a workaround with the following code and the output from pygrib and wgrib2 are now the same. Is this normal? I just wanted to make sure the output from Pygrib is consistent with that of wgrib2.

import pygrib import numpy as np

file_name = 'my_grib_file.grb2'

wind_data = pygrib.open(file_name) UGRD_950mb = wind_data[1].values UGRD_1000mb = UGRD_1000mb.T UGRD_1000mb = np.flip(UGRD_1000mb,1)

Telemaharry avatar Jun 19 '23 15:06 Telemaharry

wgrib2 is returning the data in fortran (column major) order, while pygrib is returning it in c order (row major). See https://en.wikipedia.org/wiki/Row-_and_column-major_order

jswhit avatar Jul 15 '23 17:07 jswhit