Skip to content

Commit

Permalink
extend parameter check for kernel size
Browse files Browse the repository at this point in the history
  • Loading branch information
jdegerickx committed Oct 15, 2024
1 parent d04b555 commit 8c101c6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/worldcereal/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit 8c101c6

Please sign in to comment.