Commit 7c1fbfa1 authored by Daniel Scheffler's avatar Daniel Scheffler

Bugfix for GeoArray.get_subset().

parent 7cc9d3c0
Pipeline #1614 passed with stages
in 1 minute and 42 seconds
......@@ -12,8 +12,8 @@ from .masks import CloudMask # noqa: E402
__author__ = """Daniel Scheffler"""
__email__ = 'danschef@gfz-potsdam.de'
__version__ = '0.7.5'
__versionalias__ = 'v20171124.01'
__version__ = '0.7.6'
__versionalias__ = 'v20171127.01'
__all__ = ['GeoArray',
'BadDataMask',
'NoDataMask',
......
......@@ -1411,12 +1411,14 @@ class GeoArray(object):
def get_subset(self, xslice=None, yslice=None, zslice=None, return_GeoArray=True, reset_bandnames=False):
# type: (slice, slice, slice, bool) -> GeoArray
"""Returns a new instatnce of GeoArray representing a subset of the initial one wit respect to given array position.
"""Returns a new instance of GeoArray 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)
: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', ...
:return:
"""
......@@ -1431,8 +1433,12 @@ class GeoArray(object):
sub_gt = (sub_ulXY[0], self.gt[1], self.gt[2], sub_ulXY[1], self.gt[4], self.gt[5])
# apply zslice to bandnames and metadata
bNs_out = list(np.array(list(self.bandnames))[zslice])
meta_out = None if self._metadata is None else self.meta[list(np.array(range(self.bands))[zslice])]
if zslice:
bNs_out = list(np.array(list(self.bandnames))[zslice])
meta_out = None if self._metadata is None else self.meta[list(np.array(range(self.bands))[zslice])]
else:
bNs_out = list(self.bandnames)
meta_out = self.meta
# get output GeoArray and copy some properties from the input GeoArray
sub_gA = GeoArray(sub_arr, sub_gt, self.prj,
......
......@@ -24,7 +24,7 @@ test_requirements = requirements + ["coverage", "nose", "nose2", "nose-htmloutpu
setup(
name='geoarray',
version='0.7.5',
version='0.7.6',
description="Fast Python interface for geodata - either on disk or in memory.",
long_description=readme + '\n\n' + history,
author="Daniel Scheffler",
......
......@@ -451,12 +451,16 @@ class Test_GeoarrayFunctions(unittest.TestCase):
self.assertTrue(np.array_equal(tile, self.testtiff[rS: rE + 1, cS: cE + 1]))
def test_get_subset(self):
# test without reseting band names
# test without resetting band names
sub_gA = self.testtiff.get_subset(xslice=slice(2, 5), yslice=slice(None, 3), zslice=slice(1, 2))
self.assertIsInstance(sub_gA, GeoArray)
self.assertTrue(list(sub_gA.bandnames), list(self.testtiff.bandnames)[1])
# test with reseting band names
# test without providing zslice
sub_gA = self.testtiff.get_subset(xslice=slice(2, 5), yslice=slice(None, 3))
self.assertIsInstance(sub_gA, GeoArray)
# test with resetting band names
sub_gA = self.testtiff.get_subset(xslice=slice(2, 5), yslice=slice(None, 3), zslice=slice(1, 2),
reset_bandnames=True)
self.assertTrue(list(sub_gA.bandnames), ['B1'])
......
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