Skip to content
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

feat: v2 histogram (simplified alternative) #65

Merged
merged 31 commits into from
Dec 11, 2024

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Dec 10, 2024

hey @gselzer. this is what I came up with after rearranging #55

Screen.Recording.2024-12-10.at.8.26.39.AM.mov

note: cursor changes actually do work... but apparently not in the screen recorder

it's hooked up to the view and shows up in the main viewer now if you want to run mvc.py as an entry point

sharp bits that still need to be considered:

  • the main frontend ViewerView object now accepts a histogram widget (just like it accepts a canvas widget) and can place it wherever it wants in the view. For now that breaks pygfx, which doesn't have a histogram... so we probably need to come up with a slightly "lazier" pattern using something like add_histogram to the view, rather than passing in init.
  • similarly, we need a way to turn the computation for the histogram off when not needed
  • as mentioned elsewhere, we need to figure out how to deal with multiple lookup tables on the same histogram widget. Currently it's just showing the "last" channel that was updated. so, in composite mode, it's only showing the last channel

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

Attention: Patch coverage is 20.66929% with 403 lines in your changes missing coverage. Please review.

Please upload report for BASE (v2-mvc@f339e31). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/ndv/views/_vispy/_histogram.py 0.00% 229 Missing ⚠️
src/ndv/views/_vispy/_plot_widget.py 0.00% 100 Missing ⚠️
src/ndv/controller/_controller.py 38.23% 21 Missing ⚠️
src/ndv/controller/_channel_controller.py 62.22% 17 Missing ⚠️
src/ndv/views/_qt/qt_view.py 68.29% 13 Missing ⚠️
src/ndv/views/_app.py 31.25% 11 Missing ⚠️
src/ndv/views/_jupyter/jupyter_view.py 0.00% 6 Missing ⚠️
src/ndv/views/_pygfx/_pygfx.py 66.66% 2 Missing ⚠️
src/ndv/views/_vispy/_vispy.py 71.42% 2 Missing ⚠️
src/ndv/views/protocols.py 90.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             v2-mvc      #65   +/-   ##
=========================================
  Coverage          ?   66.41%           
=========================================
  Files             ?       33           
  Lines             ?     3490           
  Branches          ?        0           
=========================================
  Hits              ?     2318           
  Misses            ?     1172           
  Partials          ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@gselzer gselzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's hooked up to the view and shows up in the main viewer now if you want to run mvc.py as an entry point

Looks nice! For some reason it suffers from pretty poor performance on my machine, though - but I think it has nothing to do with this rework, as I saw the same things on #55.

  • the main frontend ViewerView object now accepts a histogram widget (just like it accepts a canvas widget) and can place it wherever it wants in the view. For now that breaks pygfx, which doesn't have a histogram... so we probably need to come up with a slightly "lazier" pattern using something like add_histogram to the view, rather than passing in init.
  • as mentioned elsewhere, we need to figure out how to deal with multiple lookup tables on the same histogram widget. Currently it's just showing the "last" channel that was updated. so, in composite mode, it's only showing the last channel

I was thinking that, instead of accepting a histogram widget, the histograms should be created (on demand?) by/along with the LUT widgets. I had some other ideas on implementation here, too, but was going to wait for #55 to be merged before I tried.

  • similarly, we need a way to turn the computation for the histogram off when not needed

Yes, good point. This was one thing I liked about the Stats dataclass I had in #55, which computed all of these statistics lazily. If we had that, then this would be as simple as adding some visibility check within the histogram.

Also looks like the Jupyter frontend isn't quite working yet?

Comment on lines 243 to 247
# TODO: once data comes in in chunks, we'll need a proper stateful
# stats object that calculates the histogram incrementally
counts, bin_edges = _calc_hist_bins(data)
self._histogram.set_data(counts, bin_edges)
# self._histogram.set_range()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stats object would also be nice for sharing computational results, right? For example, it's probably helpful in autoscaling done by lut_ctrl.

Curious as to why you removed the Stats dataclass given the reasons that we will likely want it...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i removed it because, at the moment, it's not necessary. Once we start seeing what will actually consume it then it will be clearer what roles it needs to fill. So, basically: need-based design rather than thinking ahead about what might be useful in the future.

@tlambert03
Copy link
Member Author

, the histograms should be created (on demand?)

yeah that's what I meant by "so we probably need to come up with a slightly "lazier" pattern using something like add_histogram to the view,"

was going to wait for #55 to be merged

we could go back and merge #55, that would be fine with me ... but i think it needs to have the qtview jupyter view and stats objects removed... they're too much for now

@tlambert03
Copy link
Member Author

For some reason it suffers from pretty poor performance on my machine,

would be good to run a profiler on your machine to see which functions are eating the most time

@gselzer
Copy link
Collaborator

gselzer commented Dec 10, 2024

but i think it needs to have the qtview jupyter view and stats objects removed... they're too much for now

That's fair, and it's easy enough to iterate on these things later. LGTM so we can continue iterating on more things!

@tlambert03
Copy link
Member Author

I was thinking that, instead of accepting a histogram widget, the histograms should be created (on demand?) by/along with the LUT widgets.

implemented now

Also looks like the Jupyter frontend isn't quite working yet?

working again now, but doesn't yet show histogram

@tlambert03
Copy link
Member Author

Yes, good point. This was one thing I liked about the Stats dataclass I had in #55, which computed all of these statistics lazily. If we had that, then this would be as simple as adding some visibility check within the histogram.

it's also as easy as just doing if we have a histogram before calculating the stats... which I now have here.
This can and should be revisited.

@tlambert03
Copy link
Member Author

ok, I'm going to merge this after tests pass. We need to just have the vispy histogram in the main v2 branch so we can both move on and continue to play with it. Thanks for all your work, ideas, and patience on this!

@tlambert03 tlambert03 merged commit ff37483 into pyapp-kit:v2-mvc Dec 11, 2024
15 checks passed
@tlambert03 tlambert03 deleted the v2-histogram-simple branch December 11, 2024 00:18
@tlambert03 tlambert03 added the enhancement New feature or request label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants