From 15b746ec258409876ef20358e31470b93663d7e6 Mon Sep 17 00:00:00 2001
From: Daniel Scheffler <danschef@gfz-potsdam.de>
Date: Fri, 22 Oct 2021 14:30:46 +0200
Subject: [PATCH 1/2] Fix a bug in GeoArray.get_mapPos() which leads to too
 small output in case mapBounds_prj is unequal to GeoArray.prj.

Signed-off-by: Daniel Scheffler <danschef@gfz-potsdam.de>
---
 HISTORY.rst            |  8 ++++++++
 geoarray/subsetting.py |  8 +++++---
 tests/test_geoarray.py | 24 ++++++++++++++++++++++--
 3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/HISTORY.rst b/HISTORY.rst
index d9ff398..f472ced 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -2,6 +2,14 @@
 History
 =======
 
+0.15.1 (22.10.2021)
+-------------------
+
+* Slight improvements for GeoArray.show_map().
+* Fixed a bug in GeoArray.get_mapPos() which leads to too small output
+  in case mapBounds_prj is unequal to GeoArray.prj (!29).
+
+
 0.15.0 (27.09.2021)
 -------------------
 
diff --git a/geoarray/subsetting.py b/geoarray/subsetting.py
index ffb56aa..842404e 100644
--- a/geoarray/subsetting.py
+++ b/geoarray/subsetting.py
@@ -228,9 +228,11 @@ def get_array_at_mapPos(arr, arr_gt, arr_prj, out_prj, mapBounds, mapBounds_prj=
         # mapBounds are expected to have the same projection like the input array
         if not prj_equal(arr_prj, mapBounds_prj):
             xmin, ymin, xmax, ymax = mapBounds
-            (xmin, ymin), (xmax, ymax) = \
-                [transform_any_prj(mapBounds_prj, arr_prj, X, Y) for X, Y in [(xmin, ymin), (xmax, ymax)]]
-            mapBounds = xmin, ymin, xmax, ymax
+            ULxy, URxy, LRxy, LLxy = \
+                [transform_any_prj(mapBounds_prj, arr_prj, X, Y)
+                 for X, Y in [(xmin, ymax), (xmax, ymax), (xmax, ymin), (xmin, ymin)]]
+            xvals, yvals = zip(ULxy, URxy, LRxy, LLxy)
+            mapBounds = min(xvals), min(yvals), max(xvals), max(yvals)
 
         out_prj = arr_prj
         out_arr, out_gt = _clip_array_at_mapPos(arr, mapBounds, arr_gt, band2clip=band2get, fillVal=fillVal)
diff --git a/tests/test_geoarray.py b/tests/test_geoarray.py
index 645641d..38eb5c2 100644
--- a/tests/test_geoarray.py
+++ b/tests/test_geoarray.py
@@ -615,11 +615,31 @@ class Test_GeoArray(TestCase):
         xmin, xmax, ymin, ymax = self.gA.box.boundsMap
         xgsd = self.gA.xgsd
         ygsd = self.gA.ygsd
-        arr_sub, gt, prj = self.gA.get_mapPos(mapBounds=(xmin + xgsd, ymin, xmax + xgsd, ymax - ygsd / 2),
-                                              mapBounds_prj=self.gA.prj)
+        mapBounds = (xmin + xgsd, ymin, xmax + xgsd, ymax - ygsd / 2)
+
+        arr_sub, gt, prj = self.gA.get_mapPos(mapBounds=mapBounds, mapBounds_prj=self.gA.prj)
+
+        self.assertIsInstance(arr_sub, np.ndarray)
+        self.assertIsInstance(gt, (tuple, list))
+        self.assertIsInstance(prj, str)
+
+        # -- validate that the result of get_mapPos is larger if mapBounds_prj is unequal to GeoArray.prj --
+
+        # get map bounds in UTM zone 32
+        xmin, ymin, xmax, ymax = mapBounds
+        ULxy, URxy, LRxy, LLxy = \
+            [transform_any_prj(self.gA.prj, 32632, X, Y)
+             for X, Y in [(xmin, ymax), (xmax, ymax), (xmax, ymin), (xmin, ymin)]]
+        xvals, yvals = zip(ULxy, URxy, LRxy, LLxy)
+        mapBounds_32 = min(xvals), min(yvals), max(xvals), max(yvals)
+
+        arr_sub_32, gt_32, prj_32 = self.gA.get_mapPos(mapBounds=mapBounds_32, mapBounds_prj=32632)
+
         self.assertIsInstance(arr_sub, np.ndarray)
         self.assertIsInstance(gt, (tuple, list))
         self.assertIsInstance(prj, str)
+        self.assertTrue(arr_sub_32.size > arr_sub.size)
+
 
     def test_read_pointData__singleCoord_oneband(self):
         vals_z = self.gA.read_pointData(mapXY_points=np.array([[366015, 5916585]]),
-- 
GitLab


From d7349d1a69ad9764139cfad03140db7926848049 Mon Sep 17 00:00:00 2001
From: Daniel Scheffler <danschef@gfz-potsdam.de>
Date: Fri, 22 Oct 2021 14:31:43 +0200
Subject: [PATCH 2/2] Fix linting.

Signed-off-by: Daniel Scheffler <danschef@gfz-potsdam.de>
---
 geoarray/baseclasses.py | 3 ++-
 tests/test_geoarray.py  | 1 -
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/geoarray/baseclasses.py b/geoarray/baseclasses.py
index 66778fc..bb76063 100644
--- a/geoarray/baseclasses.py
+++ b/geoarray/baseclasses.py
@@ -1382,7 +1382,8 @@ class GeoArray(object):
                     if epsg_code == 4326:
                         return PlateCarree()
                     else:
-                        raise NotImplementedError('The show_map() method currently does not support the given projection.')
+                        raise NotImplementedError('The show_map() method currently does not support the given '
+                                                  'projection.')
             else:
                 raise ValueError(f'Expected a valid EPSG code. Got {epsg_code}.')
 
diff --git a/tests/test_geoarray.py b/tests/test_geoarray.py
index 38eb5c2..fc21493 100644
--- a/tests/test_geoarray.py
+++ b/tests/test_geoarray.py
@@ -640,7 +640,6 @@ class Test_GeoArray(TestCase):
         self.assertIsInstance(prj, str)
         self.assertTrue(arr_sub_32.size > arr_sub.size)
 
-
     def test_read_pointData__singleCoord_oneband(self):
         vals_z = self.gA.read_pointData(mapXY_points=np.array([[366015, 5916585]]),
                                         band=1)
-- 
GitLab