diff --git a/geoarray/baseclasses.py b/geoarray/baseclasses.py index 26e0f68b31f261d77dfd6e2c51ffe50e5581f4e2..69f3ca130e4bfc79c4737aea4e297305d07eb1c3 100644 --- a/geoarray/baseclasses.py +++ b/geoarray/baseclasses.py @@ -1471,6 +1471,9 @@ class GeoArray(object): 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 + # get array subset # + #################### + # get sub_arr if zslicing: # validation @@ -1484,25 +1487,26 @@ class GeoArray(object): if sub_arr is None: raise ValueError('Unable to return an array for the given slice parameters.') + # copy GeoArray instance # + ########################## + # get deepcopy of self (but without slowly copying the full-size self.arr) # -> cache self.arr, overwrite with subset, quickly create sub_gA and recreate self.arr # -> do the same with attributes 'mask_nodata' and 'mask_baddata' + from .masks import NoDataMask, BadDataMask full_arr = self.arr - self.arr = sub_arr + full_mask_nodata = self._mask_nodata + full_mask_baddata = self._mask_baddata - from .masks import NoDataMask, BadDataMask - full_mask_nodata = None + self.arr = sub_arr if isinstance(self._mask_nodata, NoDataMask): # avoid computing it here by using private - full_mask_nodata = self._mask_nodata self._mask_nodata = self._mask_nodata.get_subset(xslice=xslice, yslice=yslice) - full_mask_baddata = None if isinstance(self._mask_baddata, BadDataMask): # avoid computing it here by using private - full_mask_baddata = self._mask_baddata self._mask_baddata = self._mask_baddata.get_subset(xslice=xslice, yslice=yslice) sub_gA = deepcopy(self) # do not copy any references, otherwise numpy arrays would be copied as views - self.arr = full_arr + self._arr = full_arr if isinstance(self._mask_nodata, NoDataMask): self._mask_nodata = full_mask_nodata if isinstance(self._mask_baddata, BadDataMask): @@ -1511,6 +1515,9 @@ class GeoArray(object): # numpy array references need to be cleared separately (also called by self._mask_nodata.get_subset() above) sub_gA.deepcopy_array() + # handle metadata # + ################### + # adapt geotransform sub_ulXY = imXY2mapXY((xslice.start or 0, yslice.start or 0), self.gt) sub_gt = (sub_ulXY[0], self.gt[1], self.gt[2], sub_ulXY[1], self.gt[4], self.gt[5])