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

silx.gui: support imageaggregate in _plot2d #4174

Merged
merged 23 commits into from
Nov 26, 2024

Conversation

EdgarGF93
Copy link
Contributor

@EdgarGF93 EdgarGF93 commented Sep 19, 2024

Checklist:


This PR enables:

  • ImageAggregate filters on _plot2dview
  • ImageAggregate filters on Nexusimageview
  • ImageAggregate filters on StackView

@EdgarGF93 EdgarGF93 changed the title support imageaggregate in _plot2d silx.gui: support imageaggregate in _plot2d Sep 19, 2024
@EdgarGF93 EdgarGF93 marked this pull request as draft September 19, 2024 17:34
@EdgarGF93
Copy link
Contributor Author

EdgarGF93 commented Sep 19, 2024

Not sure if the slot _aggregationModeChanged and setAggregatedImage are well placed into into the class Plot2View

Copy link
Member

@t20100 t20100 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I left a first round of feedbacks that aims at hopefully simplifying the implementation.

src/silx/gui/plot/PlotWindow.py Outdated Show resolved Hide resolved
Comment on lines 25 to 32
:mod:`silx.gui.plot.actions.image` provides a set of QAction relative to data processing
and outputs for a :class:`.PlotWidget`.

The following QAction are available:

- :class:`CopyAction`
- :class:`PrintAction`
- :class:`SaveAction`
Copy link
Member

Choose a reason for hiding this comment

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

docstring in not consistent with the module content

src/silx/gui/plot/items/image_aggregated.py Outdated Show resolved Hide resolved
src/silx/gui/plot/actions/image.py Outdated Show resolved Hide resolved
src/silx/gui/plot/actions/image.py Show resolved Hide resolved
src/silx/gui/data/DataViews.py Outdated Show resolved Hide resolved
src/silx/gui/data/DataViews.py Outdated Show resolved Hide resolved
@EdgarGF93
Copy link
Contributor Author

EdgarGF93 commented Sep 26, 2024

how about this approach? If yes, I will use it for the rest of the classes

Copy link
Member

@t20100 t20100 left a comment

Choose a reason for hiding this comment

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

By avoiding calling addImage there is no need for setData **kwargs

src/silx/gui/plot/items/image_aggregated.py Outdated Show resolved Hide resolved
src/silx/gui/data/DataViews.py Outdated Show resolved Hide resolved
src/silx/gui/data/DataViews.py Outdated Show resolved Hide resolved
src/silx/gui/data/DataViews.py Outdated Show resolved Hide resolved
@EdgarGF93 EdgarGF93 marked this pull request as ready for review October 6, 2024 10:17
@EdgarGF93
Copy link
Contributor Author

EdgarGF93 commented Oct 6, 2024

About the _ComplexImageView class, the setData method updates the array and also the Complex mode, so I'm not sure how to implement the filter without changing the ImageComplexView class

@t20100 t20100 added this to the Next release milestone Oct 7, 2024
Copy link
Member

@t20100 t20100 left a comment

Choose a reason for hiding this comment

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

Let's keep the complex number for another PR!

I left a few more comments. The main point is to put the aggregation mode action in the widget that adds/updates the aggregated plot item rather in the widget that is using this widget.

src/silx/gui/data/DataViews.py Outdated Show resolved Hide resolved
Comment on lines 559 to 562
imageItem = ImageDataAggregated()
imageItem.setName(legend)
self._plot.addItem(imageItem)

Copy link
Member

Choose a reason for hiding this comment

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

it doesn't sounds to be the right place to add the image item since it can be a scatter that is added

Suggested change
imageItem = ImageDataAggregated()
imageItem.setName(legend)
self._plot.addItem(imageItem)

Comment on lines +573 to +576
imageItem.setData(image)
imageItem.setOrigin(origin)
imageItem.setScale(scale)
imageItem.setColormap(self._plot.getDefaultColormap())
Copy link
Member

Choose a reason for hiding this comment

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

It sounds this is where to create and add the image item:

Suggested change
imageItem.setData(image)
imageItem.setOrigin(origin)
imageItem.setScale(scale)
imageItem.setColormap(self._plot.getDefaultColormap())
imageItem = ImageDataAggregated()
imageItem.setName(legend)
imageItem.setData(image)
imageItem.setOrigin(origin)
imageItem.setScale(scale)
imageItem.setColormap(self._plot.getDefaultColormap())
self._plot.addItem(imageItem)

Comment on lines 1338 to 1358
self.__aggregationModeAction = AggregationModeAction(parent=widget)
widget.getPlotWidget().toolBar().addAction(self.__aggregationModeAction)
self.__aggregationModeAction.sigAggregationModeChanged.connect(self._aggregationModeChanged)
return widget

def getAggregationModeAction(self) -> AggregationModeAction:
"""Action toggling the aggregation mode action
"""
return self.__aggregationModeAction

def _aggregationModeChanged(self):
plot = self.getWidget().getPlotWidget()
item = plot._getItem("image")

if item is None:
return

if isinstance(item, ImageDataAggregated):
aggregationMode = self.getAggregationModeAction().getAggregationMode()
item.setAggregationMode(aggregationMode)

Copy link
Member

Choose a reason for hiding this comment

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

Let's add the AggregationModeAction in the widget which controls the item in the plot.

  • For _Plot2dView above, it is the widget that controls the plot item.
  • Here, the widget controlling the plot item is the StackView, so best to control it's plot item from this widget. Otherwise it adds implicit relations: When looking at the StackView code, one can wonder why an `ImageDataAggregated item is used there.

Comment on lines 1847 to 1865
self.__aggregationModeAction = AggregationModeAction(parent=widget)
widget.getPlot().toolBar().addAction(self.__aggregationModeAction)
self.__aggregationModeAction.sigAggregationModeChanged.connect(self._aggregationModeChanged)
return widget

def getAggregationModeAction(self) -> AggregationModeAction:
"""Action toggling the aggregation mode action
"""
return self.__aggregationModeAction

def _aggregationModeChanged(self):
plot = self.getWidget().getPlot()
item = plot._getItem("image")

if item is None:
return

if isinstance(item, ImageDataAggregated):
item.setAggregationMode(self.getAggregationModeAction().getAggregationMode())
Copy link
Member

Choose a reason for hiding this comment

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

Same here, the widget controlling the plot item is ArrayImagePlot, so the let it handle the aggregation mode as well (this would allow to enable/disable this action according to the displayed item image/scatter)

@EdgarGF93
Copy link
Contributor Author

EdgarGF93 commented Oct 27, 2024

Do you mean adding the Aggregation items in the class where the self._plot is? (StackView and ArrayImagePlot as you said)
In the case of _Plot2dView the plot is what is called widget, but yes, _Plot2dView is the class creating the plot anyway

Check it if I understood correctly

@t20100
Copy link
Member

t20100 commented Nov 4, 2024

Do you mean adding the Aggregation items in the class where the self._plot is? (StackView and ArrayImagePlot as you said)

Yes, StackView and ArrayImagePlot which are the widgets that create and add/remove the ImageAggregatedItem to the plot (there is not necessarily a self._plot in there). Doing so will make those widgets self-consistent.

@EdgarGF93 EdgarGF93 requested a review from t20100 November 4, 2024 14:20
@t20100
Copy link
Member

t20100 commented Nov 18, 2024

I made a PR on your branch with a few updates/fixes: EdgarGF93#3
I let you review it and merge if you agree with it, else let's discuss it.

Apart from that, this looks good to me! Thanks for the work and your patience !

@EdgarGF93
Copy link
Contributor Author

Looks good to me, thanks Thomas!

@t20100 t20100 merged commit a9eddc5 into silx-kit:main Nov 26, 2024
9 checks passed
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.

2 participants