Commit d5b12896 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Revised get_array_tilebounds() and added tests.

parent 13bda83d
Pipeline #1463 passed with stages
in 59 seconds
......@@ -2,7 +2,7 @@
__author__ = "Daniel Scheffler"
import numpy as np
from typing import List # noqa F401 # flake8 issue
from typing import List, Iterable # noqa F401 # flake8 issue
def get_outFillZeroSaturated(dtype):
......@@ -21,7 +21,7 @@ def get_outFillZeroSaturated(dtype):
def get_array_tilebounds(array_shape, tile_shape):
# type: (tuple, tuple) -> List[List[tuple]]
# type: (Iterable, Iterable) -> List[List[tuple]]
"""Calculate row/col bounds for image tiles according to the given parameters.
:param array_shape: dimensions of array to be tiled: (rows, columns, bands) or (rows, columns)
......@@ -29,6 +29,7 @@ def get_array_tilebounds(array_shape, tile_shape):
"""
rows, cols = array_shape[:2]
tgt_rows, tgt_cols = tile_shape[:2]
tgt_rows, tgt_cols = tgt_rows or rows, tgt_cols or cols # return all rows/cols in case tile_shape contains None
row_bounds = [0]
while row_bounds[-1] + tgt_rows < rows:
......
......@@ -17,12 +17,23 @@ from py_tools_ds.numeric.array import get_array_tilebounds
class Test_get_array_tilebounds(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Testjob Landsat-8
cls.arr = np.random.randint(1, 10, (100, 100, 5))
def test_block_tile(self):
tile_shape = (10, 10)
def _run_and_validate(self, tile_shape):
tile_shape = tile_shape[0] or self.arr.shape[0], tile_shape[1] or self.arr.shape[1]
bounds = get_array_tilebounds(self.arr.shape, tile_shape)
(rS, rE), (cS, cE) = bounds[0]
self.assertEqual(self.arr[rS: rE + 1, cS: cE + 1].shape[:2], tile_shape)
def test_block_tile(self):
self._run_and_validate(tile_shape=(10, 10))
def test_row(self):
self._run_and_validate(tile_shape=(1, None))
def test_col(self):
self._run_and_validate(tile_shape=(None, 1))
def test_pixel(self):
self._run_and_validate(tile_shape=(1, 1))
Supports Markdown
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