jswhit / pygrib

Python interface for reading and writing GRIB data
https://jswhit.github.io/pygrib
MIT License
319 stars 93 forks source link

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

Open Telemaharry opened 11 months ago

Telemaharry commented 11 months ago

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)

jswhit commented 10 months ago

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