Skip to content

Refactor imwidget #459

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

Merged
merged 32 commits into from
Apr 12, 2024
Merged

Conversation

apasarkar
Copy link
Collaborator

@apasarkar apasarkar commented Mar 29, 2024

Closes #284

@apasarkar apasarkar marked this pull request as draft March 29, 2024 14:25
…e the function was only being applied to the first array
…e graphic now occurs outside of the for loop for running the window functions which is more efficient
… Z dimensions, also removes logic saying that window_funcs can be ints, they now have to be dictionaries or None
@kushalkolar
Copy link
Member

kushalkolar commented Apr 1, 2024

I think we can use the a[np.newaxis] method as you mentioned, it returns views of the array which makes sense: a[np.newaxis, np.newaxis].ctypes.data == a.ctypes.data

Currently ImageWidget uses the lowest "t" and/or "z" dimension sizes to set the max bounds "_dims_max_bounds" for the ImageWidget and the sliders. If we instead set _dims_max_bounds based on the largest sizes in each dimension by modifying this bit:

# get max bound for all data arrays for all dimensions
self._dims_max_bounds: Dict[str, int] = {k: np.inf for k in self.slider_dims}
for _dim in list(self._dims_max_bounds.keys()):
for array, order in zip(self.data, self.dims_order):
self._dims_max_bounds[_dim] = min(
self._dims_max_bounds[_dim], array.shape[order.index(_dim)]
)

and then in @current_index.setter

for i, (ig, data) in enumerate(zip(self.managed_graphics, self.data)):
frame = self._process_indices(data, self._current_index)
frame = self._process_frame_apply(frame, i)
ig.data = frame

when iterating through each individual data array, we do something like this to prevent out of bounds indices for the data arrays which have fewer "t" or "z" items (ex. corr images) than the other data arrays (ex. movies).

current_index = dict()
for k in self._current_index:
  dim_ix = dict(reversed(ALLOWED_SLIDER_DIMS))[k]
  current_index[k] = min(self._current_index[k], data.shape[dim_ix])

It'll be generally useful anytime the shapes are very different. Might want to raise a warning in the constructor and set_data() to just let the user know that the array shapes are different and to expect this type of behavior (ex. sliding through data using the "t" slider will only change the graphic data if data exists at that position along that dimension, else it is ignored and the other data arrays are updated).

@kushalkolar kushalkolar mentioned this pull request Apr 7, 2024
7 tasks
…num to n for readability, makes rgb init parameter a list of boolean values
…array so it can be applied in a modular fashion to each individual array
…ing the max length logic to reflect the mixed types and also adding explicit property for histogram_widget
@apasarkar
Copy link
Collaborator Author

@kushalkolar It seems the tests for pre-existing cells in image_widget_test.ipynb are failing. The rgba_to_rgb function seems to complain that the input has 2 indices but 3 indices are indexed etc. Let me know what you think, maybe we need to update the rgba_to_rgb function?

Once we have that fixed, I can re-run to generate + update new screenshots.

@kushalkolar kushalkolar marked this pull request as ready for review April 11, 2024 04:29
@kushalkolar
Copy link
Member

I've made this a full PR from the draft so the CI will run on GitHub actions, we can check the result tomorrow.

@kushalkolar kushalkolar changed the base branch from main to iw_refactor April 12, 2024 04:28
@kushalkolar kushalkolar merged commit 55e8b4e into fastplotlib:iw_refactor Apr 12, 2024
@kushalkolar kushalkolar mentioned this pull request Apr 12, 2024
kushalkolar added a commit that referenced this pull request Apr 12, 2024
* fefactor imwidget, restrict to tzxy, txy, xy, added RGB(A) support (#459)

* add new iw test screenshots

* update api docs

---------

Co-authored-by: Amol Pasarkar <amolpasarkar@gmail.com>
kushalkolar added a commit that referenced this pull request Apr 12, 2024
* figure refactor seems to work

* update nbs w.r.t. new figure

* update test util

* black

* remove lingering uses of gridplot

* update API doc generation

* update contributing

* typo

Co-authored-by: Caitlin Lewis <69729525+clewis7@users.noreply.github.com>

* Iw refactor (#482)

* fefactor imwidget, restrict to tzxy, txy, xy, added RGB(A) support (#459)

* add new iw test screenshots

* update api docs

---------

Co-authored-by: Amol Pasarkar <amolpasarkar@gmail.com>

* figure refactor seems to work

* update nbs w.r.t. new figure

* update test util

* black

* remove lingering uses of gridplot

* update API doc generation

* update contributing

* typos

* update iw with FIgure

* update api docs

* black

* update quickstart

* update iw examples

* update iw type annotations

* default cmap iw

* remove gp docs

* update readme

* forgot to delete more api docs

* I need to run nbs before committing them

* more docs

---------

Co-authored-by: Caitlin Lewis <69729525+clewis7@users.noreply.github.com>
Co-authored-by: Amol Pasarkar <amolpasarkar@gmail.com>
@apasarkar apasarkar deleted the refactor_imwidget branch July 15, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor ImageWidget
2 participants
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