From 28e56d16158a3cfacc4a075ac12b0fb5eaa0e9a7 Mon Sep 17 00:00:00 2001 From: Flynn Date: Sun, 13 Apr 2025 16:29:18 -0400 Subject: [PATCH 1/2] add ignore_dims arg to subsample_array --- fastplotlib/utils/functions.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fastplotlib/utils/functions.py b/fastplotlib/utils/functions.py index e775288d..163e4370 100644 --- a/fastplotlib/utils/functions.py +++ b/fastplotlib/utils/functions.py @@ -406,7 +406,8 @@ def parse_cmap_values( return colors -def subsample_array(arr: np.ndarray, max_size: int = 1e6): +def subsample_array(arr: np.ndarray, max_size: int = 1e6, ignore_dims: Sequence[int] | None = None + ): """ Subsamples an input array while preserving its relative dimensional proportions. @@ -444,6 +445,10 @@ def subsample_array(arr: np.ndarray, max_size: int = 1e6): max_size: int, default 1e6 maximum number of elements in subsampled array + ignore_dims: Sequence[int], optional + List of dimension indices to exclude from subsampling (i.e. retain full resolution). + For example, `ignore_dims=[0]` will avoid subsampling along the first axis. + Returns ------- np.ndarray @@ -462,4 +467,12 @@ def subsample_array(arr: np.ndarray, max_size: int = 1e6): slices = tuple( slice(None, None, int(s)) for s in np.floor(arr.shape / ns).astype(int) ) + + # ignore dims e.g. RGB, which we don't want to downsample + if ignore_dims is not None: + for dim in ignore_dims: + slices[dim] = slice(None) + + slices = tuple(slices) + return np.asarray(arr[slices]) From 4e93317e0fd28f17d60643f027b29f4421b26726 Mon Sep 17 00:00:00 2001 From: Flynn Date: Sun, 13 Apr 2025 17:14:09 -0400 Subject: [PATCH 2/2] black --- fastplotlib/utils/functions.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fastplotlib/utils/functions.py b/fastplotlib/utils/functions.py index 163e4370..87d764e4 100644 --- a/fastplotlib/utils/functions.py +++ b/fastplotlib/utils/functions.py @@ -406,8 +406,9 @@ def parse_cmap_values( return colors -def subsample_array(arr: np.ndarray, max_size: int = 1e6, ignore_dims: Sequence[int] | None = None - ): +def subsample_array( + arr: np.ndarray, max_size: int = 1e6, ignore_dims: Sequence[int] | None = None +): """ Subsamples an input array while preserving its relative dimensional proportions. @@ -470,8 +471,8 @@ def subsample_array(arr: np.ndarray, max_size: int = 1e6, ignore_dims: Sequence[ # ignore dims e.g. RGB, which we don't want to downsample if ignore_dims is not None: - for dim in ignore_dims: - slices[dim] = slice(None) + for dim in ignore_dims: + slices[dim] = slice(None) slices = tuple(slices) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy