Skip to content

Commit 41e6da6

Browse files
authored
fix: get rid of unused clims cache (#248)
1 parent ccf74f3 commit 41e6da6

2 files changed

Lines changed: 1 addition & 13 deletions

File tree

src/ndv/controllers/_channel_controller.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def add_lut_view(self, view: LUTView) -> None:
3939
"""Add a LUT view to the controller."""
4040
view.model = self.lut_model
4141
self.lut_views.append(view)
42-
# TODO: Could probably reuse cached clims
4342
self._auto_scale()
4443

4544
def synchronize(self, *views: LUTView) -> None:
@@ -86,7 +85,7 @@ def get_value_at_index(self, idx: tuple[int, ...]) -> np.ndarray | float | None:
8685
def _auto_scale(self) -> None:
8786
if self.lut_model and len(self.handles):
8887
policy = self.lut_model.clims
89-
handle_clims = [policy.calc_clims(handle.data()) for handle in self.handles]
88+
handle_clims = [policy.get_limits(handle.data()) for handle in self.handles]
9089
mi, ma = handle_clims[0]
9190
for clims in handle_clims[1:]:
9291
mi = min(mi, clims[0])

src/ndv/models/_lut_model.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
BeforeValidator,
1212
ConfigDict,
1313
Field,
14-
PrivateAttr,
1514
model_validator,
1615
)
1716

@@ -26,21 +25,11 @@ class ClimPolicy(BaseModel, ABC):
2625
"""ABC for contrast limit policies."""
2726

2827
model_config = ConfigDict(frozen=True, extra="forbid")
29-
_cached_clims: tuple[float, float] | None = PrivateAttr(None)
3028

3129
@abstractmethod
3230
def get_limits(self, image: npt.NDArray) -> tuple[float, float]:
3331
"""Return the contrast limits for the given image."""
3432

35-
def calc_clims(self, image: npt.NDArray) -> tuple[float, float]:
36-
self._cached_clims = value = self.get_limits(image)
37-
return value
38-
39-
@property
40-
def cached_clims(self) -> tuple[float, float] | None:
41-
"""Return the last calculated clims."""
42-
return self._cached_clims
43-
4433
@property
4534
def is_manual(self) -> bool:
4635
return self.__class__ == ClimsManual

0 commit comments

Comments
 (0)