From 5d302cd920cc619ddded9ad8be172342f8df2f24 Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Fri, 10 May 2019 00:11:11 +0200 Subject: [PATCH] Fixed issue #24 (TypeError: function takes exactly 1 argument (0 given)). Fixed issue #25 (RuntimeError: b'major axis or radius = 0 or not given'). Updated version info. Signed-off-by: Daniel Scheffler --- geoarray/baseclasses.py | 8 ++++++-- geoarray/version.py | 4 ++-- tests/test_geoarray.py | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/geoarray/baseclasses.py b/geoarray/baseclasses.py index 68afd35..1dce8c3 100644 --- a/geoarray/baseclasses.py +++ b/geoarray/baseclasses.py @@ -856,6 +856,10 @@ class GeoArray(object): NOTE: -> numpy also returns a 2D array in that case NOTE: if array is indexed with a slice -> keep it a 3D array """ + # a single value -> return as float/int + if arr.ndim == 2 and arr.size == 1: + arr = arr[0, 0] + # 2D -> 3D if arr.ndim == 2 and isinstance(getitem_params, (tuple, list)) and len(getitem_params) == 3 and \ isinstance(getitem_params[2], slice): @@ -1256,7 +1260,7 @@ class GeoArray(object): plt.subplots_adjust(left=0.05, right=0.95, top=0.90, bottom=0.05, wspace=0.15, hspace=0.05) ax = ax if ax is not None else plt.subplot(111) - m = Basemap(projection='tmerc', resolution=None, lon_0=center_lon, lat_0=center_lat, + m = Basemap(projection='tmerc', ellps='WGS84', resolution=None, lon_0=center_lon, lat_0=center_lat, urcrnrlon=UR_XY[0], urcrnrlat=UR_XY[1], llcrnrlon=LL_XY[0], llcrnrlat=LL_XY[1]) # set color palette @@ -1326,7 +1330,7 @@ class GeoArray(object): print(UL_XY, UR_XY, LR_XY, LL_XY) # m = Basemap(projection='tmerc', resolution=None, lon_0=center_lon, lat_0=center_lat, # urcrnrx=UR_XY[0], urcrnry=UR_XY[1], llcrnrx=LL_XY[0], llcrnry=LL_XY[1]) - m = Basemap(projection='tmerc', resolution=None, lon_0=center_lon, lat_0=center_lat, + m = Basemap(projection='tmerc', ellps='WGS84', resolution=None, lon_0=center_lon, lat_0=center_lat, urcrnrlon=UR_XY[0], urcrnrlat=UR_XY[1], llcrnrlon=LL_XY[0], llcrnrlat=LL_XY[1], k_0=0.9996, rsphere=(6378137.00, 6356752.314245179), suppress_ticks=False) # m.pcolormesh(Xarr, Yarr, self[:], cmap=plt.cm.jet) diff --git a/geoarray/version.py b/geoarray/version.py index c1d431e..40c0f8a 100644 --- a/geoarray/version.py +++ b/geoarray/version.py @@ -1,2 +1,2 @@ -__version__ = '0.8.16' -__versionalias__ = '20190429.02' +__version__ = '0.8.17' +__versionalias__ = '20190510.01' diff --git a/tests/test_geoarray.py b/tests/test_geoarray.py index caa67d6..cf369a7 100644 --- a/tests/test_geoarray.py +++ b/tests/test_geoarray.py @@ -346,6 +346,22 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase): self.assertEqual(inmem_res.ndim, notinmem_res.ndim) self.assertEqual(inmem_res.shape, notinmem_res.shape) + def test___getitem__consistency_2d_array(self): + testarr = np.zeros((2, 2)) + testarr[:, :] = [[11, 12], [13, 14]] + + gA_inmem = GeoArray(testarr) + inmem_res = gA_inmem[0, 0] + + with tempfile.TemporaryDirectory() as tf: + gA_inmem.save(os.path.join(tf, 'test.bsq')) + + gA_notinmem = GeoArray(os.path.join(tf, 'test.bsq')) + notinmem_res = gA_notinmem[0, 0] + + self.assertEqual(inmem_res.ndim, notinmem_res.ndim) + self.assertEqual(inmem_res.shape, notinmem_res.shape) + def test_numpy_array(self): arr = np.array(self.testtiff) self.assertIsInstance(arr, np.ndarray) -- GitLab