Skip to content

Commit e4890cc

Browse files
timtreisclaude
andcommitted
Rename _ensure_f32_2d to _to_f32_2d for clarity
The function converts input to float32 contiguous 2D, not just validates it. The new name better communicates the transformation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1bcd264 commit e4890cc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/squidpy/experimental/im/_sharpness_metrics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55
from skimage.filters import laplace, sobel_h, sobel_v
66

77

8-
def _ensure_f32_2d(x: np.ndarray) -> np.ndarray:
8+
def _to_f32_2d(x: np.ndarray) -> np.ndarray:
99
if x.ndim != 2:
1010
raise ValueError("block must be 2D")
1111
return np.ascontiguousarray(x.astype(np.float32, copy=False))
1212

1313

1414
def _tenengrad_mean(block: np.ndarray) -> np.ndarray:
1515
"""Mean Tenengrad energy (sum of squared Sobel gradients)."""
16-
b = _ensure_f32_2d(block)
16+
b = _to_f32_2d(block)
1717
energy = sobel_h(b) ** 2 + sobel_v(b) ** 2
1818
return np.array([[float(energy.mean())]], dtype=np.float32)
1919

2020

2121
def _laplacian_variance(block: np.ndarray) -> np.ndarray:
2222
"""Population variance of Laplacian response."""
23-
b = _ensure_f32_2d(block)
23+
b = _to_f32_2d(block)
2424
lap = laplace(b)
2525
var_val = float(np.var(lap))
2626
return np.array([[max(var_val, 0.0)]], dtype=np.float32)
2727

2828

2929
def _pop_variance(block: np.ndarray) -> np.ndarray:
3030
"""Population variance of pixel intensities."""
31-
b = _ensure_f32_2d(block)
31+
b = _to_f32_2d(block)
3232
return np.array([[float(np.var(b))]], dtype=np.float32)
3333

3434

3535
def _fft_high_freq_energy(block: np.ndarray) -> np.ndarray:
36-
x = _ensure_f32_2d(block).astype(np.float64, copy=False)
36+
x = _to_f32_2d(block).astype(np.float64, copy=False)
3737
m = float(x.mean())
3838
s = float(x.std())
3939
x = (x - m) / s if s > 0.0 else (x - m)
@@ -63,7 +63,7 @@ def _fft_high_freq_energy(block: np.ndarray) -> np.ndarray:
6363

6464
def _haar_wavelet_energy(block: np.ndarray) -> np.ndarray:
6565
"""Detail-band (LH+HL+HH) energy ratio of a single-level Haar transform."""
66-
x = _ensure_f32_2d(block).astype(np.float64, copy=False)
66+
x = _to_f32_2d(block).astype(np.float64, copy=False)
6767
m = float(x.mean())
6868
s = float(x.std())
6969
x = (x - m) / s if s > 0.0 else (x - m)

0 commit comments

Comments
 (0)