Commit 8ddd2d40 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

GeoArray.__getitem__() now first reads a band subset instead of the whole...

GeoArray.__getitem__() now first reads a band subset instead of the whole array if only a single band is requested (fixes #31

).
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 9b5d12d0
......@@ -572,6 +572,14 @@ class GeoArray(object):
# handle requests like geoArr[[1,2],[3,4] -> not implemented in from_path if array is not in mem
types = [type(i) for i in given]
if list in types or tuple in types:
# avoid that the whole cube is read if only data from a single band is requested
if not self.is_inmem \
and len(given) == 3 \
and isinstance(given[2], (int, float, np.integer, np.floating)):
band_subset = GeoArray(self.filePath)[:, :, given[2]]
return band_subset[given[:2]]
self.to_mem()
if len(given) == 3:
......
......@@ -192,6 +192,11 @@ class Test_GeoArray(TestCase):
validate(gA[1], (R, C)) # only band is given # returns 2D
validate(gA['B1'], (R, C)) # only bandname is given
# test read point data in case only data of a single band is needed
validate(gA[[1, 5], [2, 4], 1], (2, ))
if not gA.is_inmem:
self.assertNotEqual(gA._arr_cache['arr_cached'].shape, gA.shape)
# test wrong inputs
self.assertRaises(ValueError, gA.__getitem__, 'B01')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment