From 05d7e37623628c30ef3940fcc7a3cf067fd860a8 Mon Sep 17 00:00:00 2001 From: "Adam.Dybbroe" Date: Fri, 17 Nov 2023 16:24:15 +0100 Subject: [PATCH] Make use of the fact that longitudes are an xarray data array, and use 'y' dimension for rows/scanlines This makes the code resillient towards any other (awkward) data layout than the standard (where first dimension is usually the rows. Signed-off-by: Adam.Dybbroe --- pyresample/geometry.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyresample/geometry.py b/pyresample/geometry.py index 7586a06d8..5b8250d83 100644 --- a/pyresample/geometry.py +++ b/pyresample/geometry.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# Copyright (C) 2010-2020 Pyresample developers +# Copyright (C) 2010-2023 Pyresample developers # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by the Free @@ -693,7 +693,8 @@ def geocentric_resolution(self, ellps='WGS84', radius=None, nadir_factor=2): if self.ndim == 1: raise RuntimeError("Can't confidently determine geocentric " "resolution for 1D swath.") - rows = self.shape[0] + + rows = self.lons['y'].shape[0] start_row = rows // 2 # middle row src = CRS('+proj=latlong +datum=WGS84') if radius: @@ -701,8 +702,8 @@ def geocentric_resolution(self, ellps='WGS84', radius=None, nadir_factor=2): else: dst = CRS("+proj=cart +ellps={}".format(ellps)) # simply take the first two columns of the middle of the swath - lons = self.lons[start_row: start_row + 1, :2] - lats = self.lats[start_row: start_row + 1, :2] + lons = self.lons.sel(y=start_row)[:2] + lats = self.lats.sel(y=start_row)[:2] if hasattr(lons.data, 'compute'): # dask arrays, compute them together import dask.array as da