Skip to content

Commit

Permalink
Changed naming of classification method
Browse files Browse the repository at this point in the history
  • Loading branch information
benvanbasten-ns committed Oct 2, 2024
1 parent c9f7909 commit 03de0d3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tool_animation/map_animator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@


class MethodEnum(str, Enum):
PRETTY = "pretty"
PERCENTILE = "percentile"
PRETTY = "Pretty Breaks"
PERCENTILE = "Equal Count (Quantile)"


class MapAnimatorSettings(object):
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(self, parent, title: str, default_settings: MapAnimatorSettings):
break
settings_group.layout().addWidget(self.method_combo, 2, 1)

settings_group.layout().addWidget(QLabel("Number of classes:"), 3, 0)
settings_group.layout().addWidget(QLabel("Preferred number of classes:"), 3, 0)
self.nr_classes_lineedit = QLineEdit(str(default_settings.nr_classes), settings_group)
self.nr_classes_lineedit.setValidator(QIntValidator(2, 42, self.nr_classes_lineedit))
settings_group.layout().addWidget(self.nr_classes_lineedit, 3, 1)
Expand Down Expand Up @@ -171,7 +171,7 @@ def threedi_result_legend_class_bounds(
relative_to_t0: bool,
nr_classes: int,
simple=False,
method: str = "pretty",
method: str = "Pretty Breaks",
) -> List[float]:
"""
Calculate percentile values given variable in a 3Di results netcdf
Expand All @@ -189,7 +189,7 @@ def threedi_result_legend_class_bounds(
:param lower_threshold: ignore values below this threshold
:param relative_to_t0: calculate percentiles on difference w/ initial values (applied before absolute)
:param nodatavalue: ignore these values
:param method: 'pretty' (pretty breaks) or 'percentile' (equal count)
:param method: 'Pretty Breaks' or 'Equal Count (Quantile)'
"""

class_bounds_empty = [0] * nr_classes
Expand Down Expand Up @@ -273,17 +273,17 @@ def threedi_result_legend_class_bounds(
)
]

if method == "pretty":
if method == MethodEnum.PRETTY.value:
try:
result = pretty(values_cutoff, n=nr_classes)
except ValueError: # All values are the same
result = class_bounds_empty
elif method == "percentile":
elif method == MethodEnum.PERCENTILE.value:
result = np.nanpercentile(
values_cutoff, class_bounds_percentiles
).tolist()
else:
raise ValueError("'method' must be one of 'pretty', 'percentile'")
raise ValueError(f"'method' must be one of '{MethodEnum.PRETTY.value}', '{MethodEnum.PERCENTILE.value}'")

real_min = 0 if absolute else np.nanmin(values).item()
real_max = np.nanmax(values).item()
Expand Down

0 comments on commit 03de0d3

Please sign in to comment.