Commit 172b79f5 authored by Daniel Scheffler's avatar Daniel Scheffler

Bugfixes. Added tests for get_subset.

parent 1ec5e10c
Pipeline #3087 passed with stages
in 1 minute and 24 seconds
......@@ -1530,9 +1530,9 @@ class GeoArray(object):
bNs_out = list(self.bandnames)
_meta_out = self.meta
sub_gA._gt = sub_gt
sub_gA._metadata = _meta_out
sub_gA._bandnames = bNs_out
sub_gA.gt = sub_gt
sub_gA.metadata = _meta_out
sub_gA.bandnames = bNs_out
sub_gA.filePath = self.filePath
if xslicing or yslicing:
sub_gA._footprint_poly = None # reset footprint_poly -> has to be updated
......
......@@ -489,6 +489,24 @@ class Test_GeoarrayFunctions(unittest.TestCase):
reset_bandnames=True)
self.assertTrue(list(sub_gA.bandnames), ['B1'])
# test arrays are equal
sub_gA = self.testtiff.get_subset(xslice=slice(2, 5), yslice=slice(None, 3), zslice=slice(1, 2))
sub_testtiff_arr = self.testtiff[:3, 2:5, 1:2]
self.assertTrue(np.array_equal(sub_gA[:], sub_testtiff_arr))
# test deepcopied arrays (modification of sub_gA.arr must not affect self.testtiff.arr)
sub_gA[:2, :2] = 99
self.assertTrue(np.array_equal(sub_gA[:2, :2], np.full((2, 2, 1), 99, self.testtiff.dtype)))
self.assertNotEqual(np.mean(sub_testtiff_arr[:2, :2]), 99)
self.assertNotEqual(np.std(sub_testtiff_arr[:2, :2]), 0)
# test metadata
self.assertEqual(sub_gA.meta.bands, 1)
self.assertEqual(len(list(sub_gA.meta.band_meta.values())[0]), 1)
self.assertEqual(len(list(sub_gA.bandnames.keys())), 1)
self.assertNotEqual(sub_gA.gt, self.testtiff.gt)
self.assertEqual(sub_gA.prj, self.testtiff.prj)
# test not to return GeoArray
out = self.testtiff.get_subset(xslice=slice(2, 5), yslice=slice(None, 3), zslice=slice(1, 2),
return_GeoArray=False)
......
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