From e2cc987d54823689806309d160ff1160a202dcee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Rodr=C3=ADguez-Guerra?= Date: Sat, 12 Feb 2022 13:16:15 +0100 Subject: [PATCH 1/6] Exclude tests from packaged distribution --- setup.cfg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup.cfg b/setup.cfg index 9af0e6d..544bbd8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,3 +39,8 @@ docs = all = %(docs)s %(test)s + +[options.packages.find] +exclude = + tests + tests.* From d84ca6f5fc4a16919e245928bbc82e8095417f86 Mon Sep 17 00:00:00 2001 From: the-lay Date: Sun, 13 Feb 2022 16:58:37 +0200 Subject: [PATCH 2/6] Updated merging dtype handling; fixed unnecessary warnings --- tiler/merger.py | 18 +++++++++++++----- tiler/tiler.py | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) 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..9fe41ea 100644 --- a/tiler/tiler.py +++ b/tiler/tiler.py @@ -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 From 62871d9453d76e151ea43ec2ca0c00eb797601b8 Mon Sep 17 00:00:00 2001 From: the-lay Date: Sun, 13 Feb 2022 17:00:02 +0200 Subject: [PATCH 3/6] Updated docs --- docs/index.html | 53 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) 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
    From 6965e0d6f4546778c6eff49779068ff9bb9027b7 Mon Sep 17 00:00:00 2001 From: the-lay Date: Sun, 13 Feb 2022 17:08:18 +0200 Subject: [PATCH 4/6] Fixing unit test warnings --- tests/test_merger.py | 4 ++-- tests/test_tiler.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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): From 73c541d35aae62409a285b04e8e77cb8e5a6e03c Mon Sep 17 00:00:00 2001 From: the-lay Date: Tue, 15 Feb 2022 18:55:18 +0200 Subject: [PATCH 5/6] Explicitly defining package, this should fix conda-forge builds --- setup.cfg | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/setup.cfg b/setup.cfg index 544bbd8..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 = @@ -39,8 +40,3 @@ docs = all = %(docs)s %(test)s - -[options.packages.find] -exclude = - tests - tests.* From 16633bb3713db2428e872592216212d94626d5f2 Mon Sep 17 00:00:00 2001 From: Ilja Gubins Date: Tue, 19 Apr 2022 00:26:04 +0200 Subject: [PATCH 6/6] Float overlap of 1.0 is not permitted anymore (100% overlap doesn't really make sense) --- tiler/tiler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tiler/tiler.py b/tiler/tiler.py index 9fe41ea..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`. @@ -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(