Commit 4b0d5e73 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Merge branch 'enhancement/speedup_pointdata' into 'master'

Enhancement/speedup pointdata

Closes #31

See merge request !23
parents 9b5d12d0 dedb4850
Pipeline #21799 passed with stages
in 19 minutes and 23 seconds
......@@ -2,6 +2,14 @@
History
=======
0.10.12 (2021-04-13)
--------------------
* GeoArray.__getitem__() now first reads a band subset instead of the whole array if only a single band is requested
(fixes #31).
* Fixed remaining test outputs aufter running Test_Geoarray.test_save().
0.10.11 (2021-04-08)
--------------------
......
......@@ -571,7 +571,16 @@ class GeoArray(object):
elif isinstance(given, (tuple, list)):
# 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')
......@@ -421,16 +426,16 @@ class Test_GeoArray(TestCase):
@parameterized.expand(_get_gA_inMem_notInMem())
def test_save(self, _, gA):
"""Test GeoArray.save."""
with tempfile.NamedTemporaryFile(dir=os.path.join(tests_path, "tests", "data", "output"),
prefix="L8_BadDataMask10x11_copy_",
suffix=".tif") as tf:
with tempfile.TemporaryDirectory(dir=os.path.join(tests_path, "tests", "data", "output"),
prefix='test_save_') as td:
# save GeoArray and validate output
for fmt in ['ENVI', 'GTiff']:
gA.save(tf.name, fmt=fmt)
gA_copy = GeoArray(tf.name)
outpath = os.path.join(td, "TestGeoArray_10x11_copy.tif")
gA.save(outpath, fmt=fmt)
self.assertTrue(os.path.exists(outpath))
self.assertTrue(os.path.exists(tf.name))
gA_copy = GeoArray(outpath)
self.assertIsInstance(gA_copy, GeoArray)
self.assertTrue(np.array_equal(gA[:], gA_copy[:]))
self.assertEqual(gA._nodata, gA_copy._nodata)
......
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