From 13bde88dc2dbbf866b653df277197dd68064f4c0 Mon Sep 17 00:00:00 2001 From: Eric Engle Date: Wed, 3 Jan 2024 14:41:34 -0500 Subject: [PATCH] Commit for _grib2io.py 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 --- grib2io/_grib2io.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/grib2io/_grib2io.py b/grib2io/_grib2io.py index c01af56..d48ff84 100644 --- a/grib2io/_grib2io.py +++ b/grib2io/_grib2io.py @@ -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 @@ -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