diff --git a/docs/index.html b/docs/index.html
index 5f7bf29..e15b6cb 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -418,7 +418,7 @@
Frequently asked questions
self.tile_shape = np.atleast_1d(np.asarray(tile_shape, dtype=np.int64))
# Append ones to match data_shape size
- if self.tile_shape.size <= self.data_shape.size:
+ if self.tile_shape.size < self.data_shape.size:
size_difference = self.data_shape.size - self.tile_shape.size
self.tile_shape = np.insert(
arr=self.tile_shape, obj=0, values=np.ones(size_difference), axis=0
@@ -1111,7 +1111,7 @@ Args
self.tile_shape = np.atleast_1d(np.asarray(tile_shape, dtype=np.int64))
# Append ones to match data_shape size
- if self.tile_shape.size <= self.data_shape.size:
+ if self.tile_shape.size < self.data_shape.size:
size_difference = self.data_shape.size - self.tile_shape.size
self.tile_shape = np.insert(
arr=self.tile_shape, obj=0, values=np.ones(size_difference), axis=0
@@ -2290,7 +2290,7 @@ Return
extra_padding: Optional[List[Tuple[int, int]]] = None,
argmax: bool = False,
normalize_by_weights: bool = True,
- dtype: np.dtype = np.float64,
+ dtype: Optional[npt.DTypeLike] = None,
) -> np.ndarray:
"""Returns merged data array obtained from added tiles.
@@ -2302,11 +2302,16 @@ Return
((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis.
Default is None.
- argmax (bool): If argmax is True, the first dimension will be argmaxed. Default is False.
+ argmax (bool): If argmax is True, the first dimension will be argmaxed.
+ Useful when merger is initialized with `logits=True`.
+ Default is False.
- normalize_by_weights (bool): If normalize is True, the accumulated data will be divided by weights. Default is True.
+ normalize_by_weights (bool): If normalize is True, the accumulated data will be divided by weights.
+ Default is True.
- dtype (np.dtype): Specify dtype for the final . Default is `np.float64`.
+ dtype (np.dtype, optional): Specify dtype for the final merged output.
+ If None, uses `data_dtype` specified when Merger was initialized.
+ Default is None.
Returns:
np.ndarray: Final merged data array obtained from added tiles.
@@ -2330,7 +2335,10 @@ Return
if argmax:
data = np.argmax(data, 0)
- return data.astype(dtype)
+ if dtype is not None:
+ return data.astype(dtype)
+ else:
+ return data.astype(self.data_dtype)
@@ -2802,7 +2810,7 @@ Returns
extra_padding: Union[List[Tuple[int, int]], NoneType] = None,
argmax: bool = False,
normalize_by_weights: bool = True,
- dtype: numpy.dtype = <class 'numpy.float64'>
+ dtype: Union[numpy.dtype, NoneType, type, numpy._dtype_like._SupportsDType, str, Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]], List[Any], numpy._dtype_like._DTypeDict, Tuple[Any, Any]] = None
) -> numpy.ndarray:
@@ -2814,7 +2822,7 @@ Returns
extra_padding: Optional[List[Tuple[int, int]]] = None,
argmax: bool = False,
normalize_by_weights: bool = True,
- dtype: np.dtype = np.float64,
+ dtype: Optional[npt.DTypeLike] = None,
) -> np.ndarray:
"""Returns merged data array obtained from added tiles.
@@ -2826,11 +2834,16 @@ Returns
((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis.
Default is None.
- argmax (bool): If argmax is True, the first dimension will be argmaxed. Default is False.
+ argmax (bool): If argmax is True, the first dimension will be argmaxed.
+ Useful when merger is initialized with `logits=True`.
+ Default is False.
- normalize_by_weights (bool): If normalize is True, the accumulated data will be divided by weights. Default is True.
+ normalize_by_weights (bool): If normalize is True, the accumulated data will be divided by weights.
+ Default is True.
- dtype (np.dtype): Specify dtype for the final . Default is `np.float64`.
+ dtype (np.dtype, optional): Specify dtype for the final merged output.
+ If None, uses `data_dtype` specified when Merger was initialized.
+ Default is None.
Returns:
np.ndarray: Final merged data array obtained from added tiles.
@@ -2854,7 +2867,10 @@ Returns
if argmax:
data = np.argmax(data, 0)
- return data.astype(dtype)
+ if dtype is not None:
+ return data.astype(dtype)
+ else:
+ return data.astype(self.data_dtype)
@@ -2869,9 +2885,14 @@ Args
Number of values padded to the edges of each axis.
((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis.
Default is None.
-argmax (bool): If argmax is True, the first dimension will be argmaxed. Default is False.
-normalize_by_weights (bool): If normalize is True, the accumulated data will be divided by weights. Default is True.
-dtype (np.dtype): Specify dtype for the final . Default is np.float64
.
+argmax (bool): If argmax is True, the first dimension will be argmaxed.
+Useful when merger is initialized with logits=True
.
+Default is False.
+normalize_by_weights (bool): If normalize is True, the accumulated data will be divided by weights.
+Default is True.
+dtype (np.dtype, optional): Specify dtype for the final merged output.
+If None, uses data_dtype
specified when Merger was initialized.
+Default is None.
Returns
diff --git a/setup.cfg b/setup.cfg
index 9af0e6d..7fa8aaf 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -22,7 +22,8 @@ project_urls =
Issues = https://github.com/the-lay/tiler/issues
[options]
-packages = find:
+packages =
+ tiler
platforms = any
python_requires = >= 3.6
install_requires =
diff --git a/tests/test_merger.py b/tests/test_merger.py
index 49ada9d..1aa012c 100644
--- a/tests/test_merger.py
+++ b/tests/test_merger.py
@@ -24,9 +24,9 @@ def test_init(self):
# Check save_visits
merger3 = Merger(tiler=tiler, save_visits=False)
- self.assert_(merger3.data_visits is None)
+ self.assertTrue(merger3.data_visits is None)
merger3 = Merger(tiler=tiler, save_visits=True)
- self.assert_(merger3.data_visits is not None)
+ self.assertTrue(merger3.data_visits is not None)
# Check data and weights dtypes
merger4 = Merger(
diff --git a/tests/test_tiler.py b/tests/test_tiler.py
index dfa54ea..4218145 100644
--- a/tests/test_tiler.py
+++ b/tests/test_tiler.py
@@ -36,7 +36,8 @@ def test_init(self):
)
# test tile shape broadcasting
- tiler = Tiler(data_shape=(300, 300), tile_shape=(10,))
+ with self.assertWarns(UserWarning):
+ tiler = Tiler(data_shape=(300, 300), tile_shape=(10,))
assert np.allclose(tiler.tile_shape, (1, 10))
def test_repr(self):
diff --git a/tiler/merger.py b/tiler/merger.py
index 675eb34..c8e24ea 100644
--- a/tiler/merger.py
+++ b/tiler/merger.py
@@ -355,7 +355,7 @@ def merge(
extra_padding: Optional[List[Tuple[int, int]]] = None,
argmax: bool = False,
normalize_by_weights: bool = True,
- dtype: np.dtype = np.float64,
+ dtype: Optional[npt.DTypeLike] = None,
) -> np.ndarray:
"""Returns merged data array obtained from added tiles.
@@ -367,11 +367,16 @@ def merge(
((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis.
Default is None.
- argmax (bool): If argmax is True, the first dimension will be argmaxed. Default is False.
+ argmax (bool): If argmax is True, the first dimension will be argmaxed.
+ Useful when merger is initialized with `logits=True`.
+ Default is False.
- normalize_by_weights (bool): If normalize is True, the accumulated data will be divided by weights. Default is True.
+ normalize_by_weights (bool): If normalize is True, the accumulated data will be divided by weights.
+ Default is True.
- dtype (np.dtype): Specify dtype for the final . Default is `np.float64`.
+ dtype (np.dtype, optional): Specify dtype for the final merged output.
+ If None, uses `data_dtype` specified when Merger was initialized.
+ Default is None.
Returns:
np.ndarray: Final merged data array obtained from added tiles.
@@ -395,4 +400,7 @@ def merge(
if argmax:
data = np.argmax(data, 0)
- return data.astype(dtype)
+ if dtype is not None:
+ return data.astype(dtype)
+ else:
+ return data.astype(self.data_dtype)
diff --git a/tiler/tiler.py b/tiler/tiler.py
index f51cbbe..c1d1272 100644
--- a/tiler/tiler.py
+++ b/tiler/tiler.py
@@ -52,7 +52,7 @@ def __init__(
overlap (int, float, tuple, list or np.ndarray): Specifies overlap between tiles.
If integer, the same overlap of overlap pixels applied in each dimension, except channel_dimension.
- If float, percentage of a tile_shape to overlap (from 0.0 to 1.0), except channel_dimension.
+ If float, percentage of a tile_shape to overlap [0.0, 1.0), i.e. from 0% to 100% non-inclusive, except channel_dimension.
If tuple, list or np.ndarray, explicit size of the overlap (must be smaller than tile_shape in each dimension).
Default is `0`.
@@ -99,7 +99,7 @@ def recalculate(
self.tile_shape = np.atleast_1d(np.asarray(tile_shape, dtype=np.int64))
# Append ones to match data_shape size
- if self.tile_shape.size <= self.data_shape.size:
+ if self.tile_shape.size < self.data_shape.size:
size_difference = self.data_shape.size - self.tile_shape.size
self.tile_shape = np.insert(
arr=self.tile_shape, obj=0, values=np.ones(size_difference), axis=0
@@ -151,9 +151,9 @@ def recalculate(
if overlap is not None:
self.overlap = overlap
if isinstance(self.overlap, float):
- if self.overlap < 0 or self.overlap > 1.0:
+ if self.overlap < 0 or self.overlap >= 1.0:
raise ValueError(
- "Float overlap must be in range of 0.0 (0%) to 1.0 (100%)."
+ "Float overlap must be in range of [0.0, 1.0) i.e. [0%, 100%)."
)
self._tile_overlap: np.ndarray = np.ceil(