Skip to content

Commit

Permalink
Commit for _grib2io.py
Browse files Browse the repository at this point in the history
This commit fixes an issue where the _latlon_datastore, now holding a dictionary
instead of tuples would raise a KeyError when using the xarray backend.

This commit references issue #117
  • Loading branch information
EricEngle-NOAA committed Jan 3, 2024
1 parent 1000446 commit 13bde88
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions grib2io/_grib2io.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,6 @@ def grid(self, unrotate=True):
if self._sha1_section3 in _latlon_datastore.keys():
return (_latlon_datastore[self._sha1_section3]['latitude'],
_latlon_datastore[self._sha1_section3]['longitude'])
else:
_latlon_datastore[self._sha1_section3] = {}
gdtn = self.gridDefinitionTemplateNumber.value
gdtmpl = self.gridDefinitionTemplate
reggrid = self.gridDefinitionSection[2] == 0 # This means regular 2-d grid
Expand Down Expand Up @@ -1047,13 +1045,15 @@ def grid(self, unrotate=True):
lons = np.where(lons>180.0,lons-360.0,lons)
vector_rotation_angles_vectorized = np.vectorize(arakawa_rotated_grid.vector_rotation_angles)
rots = vector_rotation_angles_vectorized(lats, lons, clat, losp, xlats)
_latlon_datastore[self._sha1_section3]['vector_rotation_angles'] = rots
del xlat1d, xlon1d, xlats, xlons
else:
raise ValueError('Unsupported grid')

_latlon_datastore[self._sha1_section3]['latitude'] = lats
_latlon_datastore[self._sha1_section3]['longitude'] = lons
_latlon_datastore[self._sha1_section3] = dict(latitude=lats,longitude=lons)
try:
_latlon_datastore[self._sha1_section3]['vector_rotation_angles'] = rots
except(NameError):
pass

return lats, lons

Expand Down

0 comments on commit 13bde88

Please sign in to comment.