From a5278af7aa1dd0ea5d43741f61df5e9613a82f12 Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Fri, 30 May 2025 20:47:01 -0400 Subject: [PATCH 1/3] Wrap histogram self.vmin for eager objects --- fastplotlib/tools/_histogram_lut.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/fastplotlib/tools/_histogram_lut.py b/fastplotlib/tools/_histogram_lut.py index aeb8dd996..a9457f42c 100644 --- a/fastplotlib/tools/_histogram_lut.py +++ b/fastplotlib/tools/_histogram_lut.py @@ -173,18 +173,29 @@ def _make_colorbar(self, edges_flanked) -> ImageGraphic: return cbar def _get_vmin_vmax_str(self) -> tuple[str, str]: - if self.vmin < 0.001 or self.vmin > 99_999: - vmin_str = f"{self.vmin:.2e}" - else: - vmin_str = f"{self.vmin:.2f}" - if self.vmax < 0.001 or self.vmax > 99_999: - vmax_str = f"{self.vmax:.2e}" - else: - vmax_str = f"{self.vmax:.2f}" + # https://docs.dask.org/en/latest/generated/dask.array.Array.compute.html + # https://docs.pytorch.org/docs/stable/generated/torch.Tensor.item.html + lazy_callbacks = ("compute", "item") + + def as_float(x) -> float: + for name in lazy_callbacks: + meth = getattr(x, name, None) + if callable(meth): + x = meth() + break + return float(x) + + vmin = as_float(self.vmin) + vmax = as_float(self.vmax) + + vmin_str = f"{vmin:.2e}" if vmin < 1e-3 or vmin > 9.9999e4 else f"{vmin:.2f}" + vmax_str = f"{vmax:.2e}" if vmax < 1e-3 or vmax > 9.9999e4 else f"{vmax:.2f}" return vmin_str, vmax_str + + def _fpl_add_plot_area_hook(self, plot_area): self._plot_area = plot_area self._linear_region_selector._fpl_add_plot_area_hook(plot_area) From 9e147b1e0da6d174fdea6d8eb0d32212c312d270 Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Fri, 30 May 2025 21:02:31 -0400 Subject: [PATCH 2/3] remove the 'item' check from vmin str --- fastplotlib/tools/_histogram_lut.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fastplotlib/tools/_histogram_lut.py b/fastplotlib/tools/_histogram_lut.py index a9457f42c..3cdb6dadf 100644 --- a/fastplotlib/tools/_histogram_lut.py +++ b/fastplotlib/tools/_histogram_lut.py @@ -175,8 +175,7 @@ def _make_colorbar(self, edges_flanked) -> ImageGraphic: def _get_vmin_vmax_str(self) -> tuple[str, str]: # https://docs.dask.org/en/latest/generated/dask.array.Array.compute.html - # https://docs.pytorch.org/docs/stable/generated/torch.Tensor.item.html - lazy_callbacks = ("compute", "item") + lazy_callbacks = ("compute") def as_float(x) -> float: for name in lazy_callbacks: From 936fe32e5fdc627fb661908b8361844364335602 Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Fri, 30 May 2025 21:04:49 -0400 Subject: [PATCH 3/3] run black, change to list so black doens't burn the house down --- fastplotlib/tools/_histogram_lut.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fastplotlib/tools/_histogram_lut.py b/fastplotlib/tools/_histogram_lut.py index 3cdb6dadf..b68936b5e 100644 --- a/fastplotlib/tools/_histogram_lut.py +++ b/fastplotlib/tools/_histogram_lut.py @@ -175,7 +175,7 @@ def _make_colorbar(self, edges_flanked) -> ImageGraphic: def _get_vmin_vmax_str(self) -> tuple[str, str]: # https://docs.dask.org/en/latest/generated/dask.array.Array.compute.html - lazy_callbacks = ("compute") + lazy_callbacks = ["compute"] def as_float(x) -> float: for name in lazy_callbacks: @@ -193,8 +193,6 @@ def as_float(x) -> float: return vmin_str, vmax_str - - def _fpl_add_plot_area_hook(self, plot_area): self._plot_area = plot_area self._linear_region_selector._fpl_add_plot_area_hook(plot_area)