Skip to content

Commit 7ab6eb6

Browse files
committed
Fix hamdling missing/non-string CF axis units
(cherry picked from commit dfcd96c)
1 parent b8c4b74 commit 7ab6eb6

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

pyresample/test/test_utils/test_cf.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,26 @@ def test_load_cf_latlon(self, file_func, kwargs, exp_lat, exp_lon, future_geomet
244244
_validate_lonlat_cf_area(adef, cf_info, exp_lon, exp_lat)
245245
assert_future_geometry(adef, future_geometries)
246246

247+
def test_load_cf_axis_without_units(self):
248+
cf_file = _prepare_cf_nh10km()
249+
del cf_file['xc'].attrs['units']
250+
del cf_file['yc'].attrs['units']
251+
252+
_, cf_info = load_cf_area(cf_file, variable='ice_conc')
253+
254+
assert cf_info['x']['unit'] is None
255+
assert cf_info['y']['unit'] is None
256+
257+
def test_load_cf_axis_with_non_string_units(self):
258+
cf_file = _prepare_cf_nh10km()
259+
cf_file['xc'].attrs['units'] = 1
260+
cf_file['yc'].attrs['units'] = 1
261+
262+
_, cf_info = load_cf_area(cf_file, variable='ice_conc')
263+
264+
assert cf_info['x']['unit'] is None
265+
assert cf_info['y']['unit'] is None
266+
247267

248268
def _validate_lonlat_cf_area(adef, cf_info, exp_lon, exp_lat):
249269
assert adef.shape == (19, 37)

pyresample/utils/cf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ def _load_cf_axis_info(nc_handle, coord_varname):
167167
unit = None
168168

169169
# some units that are valid in CF are not valid to pass to proj
170-
if unit.startswith('rad') or \
171-
unit.startswith('deg'):
170+
if isinstance(unit, str) and unit.startswith(('rad', 'deg')):
172171
unit = None
173172

174173
# return in a dictionnary structure

0 commit comments

Comments
 (0)