Commit 2b87c28d authored by Daniel Scheffler's avatar Daniel Scheffler

Lists are now allowed in zslice parameter for GeoArray.get_subset().

Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent a33ec5ac
Pipeline #4235 passed with stages
in 1 minute and 26 seconds
......@@ -1530,12 +1530,13 @@ class GeoArray(object):
def get_subset(self, xslice=None, yslice=None, zslice=None, return_GeoArray=True,
reset_bandnames=False):
# type: (slice, slice, slice, bool, bool) -> GeoArray
# type: (slice, slice, Union[slice, list], bool, bool) -> GeoArray
"""Return a new GeoArray instance representing a subset of the initial one wit respect to given array position.
:param xslice: a slice providing the X-position for the subset in the form slice(xstart, xend, xstep)
:param yslice: a slice providing the Y-position for the subset in the form slice(ystart, yend, ystep)
:param zslice: a slice providing the Z-position for the subset in the form slice(zstart, zend, zstep)
or a list containing the indices of the bands to extract
:param return_GeoArray: whether to return an instance of GeoArray (default) or a tuple(np.ndarray, gt, prj)
:param reset_bandnames: whether band names of subset should be copied from source GeoArray or reset to
'B1', 'B2', 'B3', ...
......@@ -1544,7 +1545,8 @@ class GeoArray(object):
xslice, yslice, zslice = xslice or slice(None), yslice or slice(None), zslice or slice(None)
xslicing = xslice.start is not None or xslice.stop is not None or xslice.step is not None # type: bool
yslicing = yslice.start is not None or yslice.stop is not None or yslice.step is not None # type: bool
zslicing = zslice.start is not None or zslice.stop is not None or zslice.step is not None # type: bool
zslicing = isinstance(zslice, list) or \
zslice.start is not None or zslice.stop is not None or zslice.step is not None # type: bool
# get array subset #
####################
......
__version__ = '0.8.19'
__versionalias__ = '20190522.01'
__version__ = '0.8.20'
__versionalias__ = '20190709.01'
......@@ -514,6 +514,10 @@ class Test_GeoarrayFunctions(unittest.TestCase):
sub_gA = self.testtiff.get_subset(yslice=slice(None, 3))
self.assertIsInstance(sub_gA, GeoArray)
# test with zslice provided as list
sub_gA = self.testtiff.get_subset(xslice=slice(2, 5), yslice=slice(None, 3), zslice=[0, 1])
self.assertIsInstance(sub_gA, GeoArray)
# test without providing zslice
sub_gA = self.testtiff.get_subset(xslice=slice(2, 5), yslice=slice(None, 3))
self.assertIsInstance(sub_gA, GeoArray)
......@@ -607,6 +611,8 @@ class Test_GeoarrayFunctions(unittest.TestCase):
# test with provided zslice
with self.assertRaises(ValueError):
gA_2D.get_subset(xslice=slice(2, 5), yslice=slice(None, 3), zslice=slice(1, 2))
with self.assertRaises(ValueError):
gA_2D.get_subset(xslice=slice(2, 5), yslice=slice(None, 3), zslice=[1, 2])
self.assertIsInstance(out, tuple)
self.assertTrue(len(out), 3)
......
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