From bf0c9fde559879e754b5201591bf8c2613596456 Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Wed, 11 Dec 2019 05:45:24 +0000 Subject: [PATCH] Address PR comment. --- datacube/utils/xarray_geoextensions.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/datacube/utils/xarray_geoextensions.py b/datacube/utils/xarray_geoextensions.py index 772c55705a..a3a8ec750a 100644 --- a/datacube/utils/xarray_geoextensions.py +++ b/datacube/utils/xarray_geoextensions.py @@ -41,11 +41,13 @@ def _get_crs(obj): # Assumption: spatial dimensions are always the last 2) spatial_dims = data_array.dims[-2:] crs_set = set(data_array[d].attrs.get('crs', None) for d in spatial_dims) + crs = None if len(crs_set) > 1: raise ValueError('Spatial dimensions have different crs.') - elif len(crs_set) == 1 and None not in crs_set: - crs = data_array[data_array.dims[-1]].crs - else: + elif len(crs_set) == 1: + crs = crs_set.pop() + + if crs is None: # fall back option crs = data_array.attrs.get('crs', None) or obj.attrs.get('crs', None) return crs