From 8c101c6ec4c5e91df9192cae7112a3ce6d1d8615 Mon Sep 17 00:00:00 2001 From: DEGERICJ Date: Tue, 15 Oct 2024 22:32:53 +0200 Subject: [PATCH] extend parameter check for kernel size --- src/worldcereal/parameters.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/worldcereal/parameters.py b/src/worldcereal/parameters.py index 69a1fa44..7b9b0e7e 100644 --- a/src/worldcereal/parameters.py +++ b/src/worldcereal/parameters.py @@ -167,7 +167,7 @@ class PostprocessParameters(BaseModel): method: str (default="smooth_probabilities") The method to use for postprocessing. Must be one of ["smooth_probabilities", "majority_vote"] kernel_size: int (default=5) - Used for majority vote postprocessing. Must be smaller than 25. + Used for majority vote postprocessing. Must be an odd number, larger than 1 and smaller than 25. save_intermediate: bool (default=False) Whether to save intermediate results (before applying the postprocessing). The intermediate results will be saved in the GeoTiff format. @@ -206,9 +206,17 @@ def check_parameters(self): ) if self.method == "majority_vote": + if self.kernel_size % 2 == 0: + raise ValueError( + f"Kernel size for majority filtering should be an odd number, got {self.kernel_size}" + ) if self.kernel_size > 25: raise ValueError( - f"Kernel size must be smaller than 25, got {self.kernel_size}" + f"Kernel size for majority filtering should be an odd number smaller than 25, got {self.kernel_size}" + ) + if self.kernel_size < 3: + raise ValueError( + f"Kernel size for majority filtering should be an odd number larger than 1, got {self.kernel_size}" ) return self