Skip to content

Image widget window_funcs with 4D lazy array #832

Open
@FlynnOConnell

Description

@FlynnOConnell

I have a 4D lazy array, I want to use ImageWidget with a window_func on only the time dimension.

When I apply the window function:

self.window_size = 3
self.proj = "mean"
self.image_widget.window_funcs = {"t": (getattr(np, self.proj), self.window_size)}

This works fine if my input is 3D. But if its 4D, I see the following, where increasing the index of "t" from 0->1 causes my Z dimension to be indexed (the z-plane changes here):

2025-05-20.10-32-04.mp4

I found this to be a result of _process_indices, which first sets indexer properly:

>>> `[range(0, 2), 0, slice(None), slice(None)]`

But then when trying to apply the window_func, it sets _indexer:

# 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]

        # 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)]

Each loop calls a[tuple(_indexer)], which for my 4D array:

# curr_ndim=4, i=0
_indexer = [slice(None)] * (curr_ndim - i)
_indexer[dim] = indexer[dim + i]

>>> indexer
Out[4]: [range(0, 2), 0, slice(None, None, None), slice(None, None, None)]
>>> _indexer
Out[5]: 
[range(0, 2),
 slice(None, None, None),
 slice(None, None, None),
 slice(None, None, None)]

So now my TZXY array is being indexed with arr[:2, :, :, :], where it should be arr[:2, 0, :, :].

Shouldn't the entire _indexer be filled before being called? So move a = func(window, axis=dim) outside of the for loop?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      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