From b92d06e88b3dab12c16bf87a3509660a6d9127e9 Mon Sep 17 00:00:00 2001 From: Rimma Bondarenko <119871740+rbondare@users.noreply.github.com> Date: Thu, 5 Mar 2026 22:21:10 +0100 Subject: [PATCH] Refactor return value and update mask_window calculation Modified return value to return an array instead of a single item. Updated mask_window calculation to handle float conversion and adjusted logging for spatial scale. --- suite2p/detection/sparsedetect.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/suite2p/detection/sparsedetect.py b/suite2p/detection/sparsedetect.py index 794ffc89..a99a72f0 100644 --- a/suite2p/detection/sparsedetect.py +++ b/suite2p/detection/sparsedetect.py @@ -452,7 +452,7 @@ def estimate_spatial_scale(I): ipk = np.abs(I0 - maximum_filter(I0, size=(11, 11))).flatten() < 1e-4 isort = np.argsort(I0.flatten()[ipk])[::-1] im, _ = mode(imap[ipk][isort[:50]], keepdims=True) - return im.item() + return im def find_best_scale(I, spatial_scale): @@ -565,12 +565,13 @@ def sparsery(mov, sdmov, highpass_neuropil, scale, estimate_mode = find_best_scale(I=I, spatial_scale=spatial_scale) spatscale_pix = 3 * 2**scale - mask_window = int(((spatscale_pix * 1.5) // 2) * 2) + print(np.size(spatscale_pix)) + mask_window = int(((float(np.asarray(spatscale_pix).item()) * 1.5) // 2) * 2) Th2 = threshold_scaling * 5 * max( 1, scale) # threshold for accepted peaks (scale it by spatial scale) vmultiplier = max(1, mov.shape[0] / 1200) logger.info("NOTE: %s spatial scale ~%d pixels, time epochs %2.2f, threshold %2.2f " % - (estimate_mode.value, spatscale_pix, vmultiplier, vmultiplier * Th2)) + (estimate_mode.value, np.asarray(spatscale_pix).item(), vmultiplier, vmultiplier * Th2)) # get standard deviation for pixels for all values > Th2 v_map = [threshold_reduce(movu0, Th2) for movu0 in movu]