NCAR / pynio

PyNIO is a multi-format data I/O package with a NetCDF-style interface
http://www.pyngl.ucar.edu/Nio.shtml
Apache License 2.0
112 stars 37 forks source link

Unexpected behavior when opening Canadian global GEM 25km grib files using pynio #40

Open ShaneMill1 opened 4 years ago

ShaneMill1 commented 4 years ago

Hi all,

I am experiencing interesting behavior when opening a GEM global 25km resolution grib files using pynio.

ds=xr.open_dataset('CMC_glb_TMP_ISBL_700_latlon.24x.24_2020050600_P198.grb',engine='pynio')
print(ds)
<xarray.Dataset>
Dimensions: (lat_0: 751, lon_0: 1500)
Coordinates:

lat_0 (lat_0) float32 -90.0 -89.76 -89.52 ... 89.52 89.76 90.0
lon_0 (lon_0) float32 180.0 180.24 180.48 ... 539.52 539.76
Data variables:
TMP_P0_L100_GLL0 (lat_0, lon_0) float32 ...
print(ds['lon_0'])
<xarray.DataArray 'lon_0' (lon_0: 1500)>
array([180. , 180.24, 180.48, ..., 539.28, 539.52, 539.76], dtype=float32)
Coordinates:
lon_0 (lon_0) float32 180.0 180.24 180.48 180.72 ... 539.28 539.52 539.76
Attributes:
long_name: longitude
grid_type: Latitude/Longitude
units: degrees_east
Dj: [0.24]
Di: [0.24000001]
Lo2: [179.76]
La2: [90.]
Lo1: [180.]
La1: [-90.]

Notice that the range for lon_0 is 180->539.76. When I open using cfgrib as the xarray engine:

ds=xr.open_dataset('CMC_glb_TMP_ISBL_700_latlon.24x.24_2020050600_P198.grb',engine='cfgrib')
print(ds['longitude'])
<xarray.DataArray 'longitude' (longitude: 1500)>
array([-180. , -179.76, -179.52, ..., 179.28, 179.52, 179.76])
Coordinates:
time datetime64[ns] ...
step timedelta64[ns] ...
isobaricInhPa int64 ...

longitude (longitude) float64 -180.0 -179.8 -179.5 ... 179.5 179.8
valid_time datetime64[ns] ...
Attributes:
units: degrees_east
standard_name: longitude
long_name: longitude

Therefore, it appears 'cgfrib' shows the longitude correctly while 'pynio' does not.

This was originally posted as an xarray issue: https://github.com/pydata/xarray/issues/4040

However, after investigating further, I found that this occurs when using pynio directly also: ds=Nio.open_file('CMC_glb_TMP_ISBL_700_latlon.24x.24_2020050600_P198.grb') ds.variables['lon_0'].get_value()

gives a result of: array([180. , 180.24, 180.48, ..., 539.28, 539.52, 539.76], dtype=float32)