Skip to content

Fix ImageWidget_process_indices calling full z-dim #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 21 additions & 43 deletions fastplotlib/widgets/image_widget/_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,60 +696,38 @@ def _process_indices(
array-like, 2D slice

"""

data_ix = None
for i in range(len(self.data)):
if self.data[i] is array:
data_ix = i
break

numerical_dims = list()
# Find which entry in self.data this array corresponds to
data_ix = next(i for i, arr in enumerate(self.data) if arr is array)

# Totally number of dimensions for this specific array
curr_ndim = self.data[data_ix].ndim
curr_ndim = array.ndim

# Initialize slices for each dimension of array
indexer = [slice(None)] * curr_ndim
indexer: list[Union[int, slice, range]] = [slice(None)] * curr_ndim

# Maps from n_scrollable_dims to one of "", "t", "tz", etc.
# crollable_dims to one of "", "t", "tz", etc.
curr_scrollable_format = SCROLLABLE_DIMS_ORDER[self.n_scrollable_dims[data_ix]]
for dim in list(slice_indices.keys()):
if dim not in curr_scrollable_format:
for dim_str, idx in slice_indices.items():
if dim_str not in curr_scrollable_format:
continue
# get axes order for that specific array
numerical_dim = curr_scrollable_format.index(dim)

indices_dim = slice_indices[dim]

# takes care of index selection (window slicing) for this specific axis
indices_dim = self._get_window_indices(data_ix, numerical_dim, indices_dim)
axis = curr_scrollable_format.index(dim_str)

# set the indices for this dimension
indexer[numerical_dim] = indices_dim
# use the helper to get either a single index or a range for that axis
indices_dim = self._get_window_indices(data_ix, axis, idx)
indexer[axis] = indices_dim

numerical_dims.append(numerical_dim)
# apply basic slicing first
arr_window = array[tuple(indexer)]

# apply indexing to the array
# use window function is given for this dimension
if self.window_funcs is not None:
a = array
for i, dim in enumerate(sorted(numerical_dims)):
dim_str = curr_scrollable_format[dim]
dim = dim - i # since we loose a dimension every iteration
_indexer = [slice(None)] * (curr_ndim - i)
_indexer[dim] = indexer[dim + i]
# apply window functions to the resulting sub-array
if self.window_funcs:
for dim_str, cfg in self.window_funcs.items():
if not cfg or not cfg.window_size:
continue
axis = curr_scrollable_format.index(dim_str)
arr_window = cfg.func(arr_window, axis=axis)

# if the indexer is an int, this dim has no window func
if isinstance(_indexer[dim], int):
a = a[tuple(_indexer)]
else:
# if the indices are from `self._get_window_indices`
func = self.window_funcs[dim_str].func
window = a[tuple(_indexer)]
a = func(window, axis=dim)
return a
else:
return array[tuple(indexer)]
return arr_window

def _get_window_indices(self, data_ix, dim, indices_dim):
if self.window_funcs is None:
Expand Down
Loading