pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.62k stars 1.08k forks source link

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

Closed ShaneMill1 closed 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.

MCVE Code Sample

# Your code here

Expected Output

Problem Description

Versions

Output of xr.show_versions()
dcherian commented 4 years ago

Can you check if the file is read properly using only pynio? i.e. remove xarray from the equation here.

ShaneMill1 commented 4 years ago

Good question, actually it appears that this is occurring in pynio without the use of xarray:

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)

dcherian commented 4 years ago

Ah thanks for checking. I would raise an issue over at pynio then.

ShaneMill1 commented 4 years ago

Will do, thanks!