-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add new analysis node for creating histogram of data #241
Merged
astafan8
merged 33 commits into
toolsforexperiments:master
from
wpfff:feature/histogram-node
Dec 20, 2021
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
cd4147b
started developing central dimension selection widgets.
wpfff b9a7bc9
Merge branch 'master' into feature/histogram-node
wpfff 5bd67fe
Merge branch 'master' into feature/histogram-node
wpfff fba3aa2
allow multiple widgets in the dialog.
wpfff 31705ba
added a signal for changed dependents.
wpfff f89f9b1
generic widgets for dimension selection, for use in node widgets.
wpfff 51065f2
new testdata functions that produce complex data that looks like a ty…
wpfff 0e50878
completed list widget that allows selection of data fields.
wpfff 4509507
better organization of testdata files.
wpfff 3470e88
allow running as standalone script.
wpfff eb1bd6c
example script illustrating how to use MultiDimensionSelector.
wpfff 3a76a8e
Create histogram.py
wpfff 1ee636a
Merge branch 'master' into feature/histogram-node
wpfff 1a1dcae
bugfix: prevent old reductions from lingering (they lead to crashes).
wpfff a884fea
fix: should not add ax for deletion multiple times.
wpfff 77b1649
fix: logic in determining whether data has changed was incomplete.
wpfff 8e3fac9
added missing requirements
wpfff 0b35a04
added missing requirements
wpfff ccc6742
added a note for potential todo.
wpfff 245adf9
finished v1 of the histogramming node.
wpfff 19551c3
added testscript for histogramming node.
wpfff e9f646a
added additional test data
wpfff 1510431
added histogram by default to ddh5 plot
wpfff 21df34c
fixed mypy issue.
wpfff 781612f
unsupported data will simply result in error rather than flawed checks.
wpfff 13aef80
fixed test to use only supported data.
wpfff 005e90a
bugfix: wrong computation of the histogram axes in the complex case.
wpfff b839702
Merge branch 'master' into feature/histogram-node
wpfff 4f16b52
fix docs.
wpfff 97d8dfd
Merge branch 'master' into feature/histogram-node
wpfff 863fbd0
added pytest for histogrammer node.
wpfff 136cfc2
Merge remote-tracking branch 'origin/feature/histogram-node' into fea…
wpfff d88af9f
Merge branch 'master' into feature/histogram-node
wpfff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
"""A simple script that illustrates how to use the :class:`.MultiDimensionSelector` widget | ||
in a node to select axes in a dataset. | ||
|
||
This example does the following: | ||
* create a flowchart with one node, that has a node widget. | ||
* selected axes in the node widget will be deleted from the data when the | ||
selection is changed, and the remaining data is printed to stdout. | ||
""" | ||
|
||
from typing import List, Optional | ||
from pprint import pprint | ||
|
||
import numpy as np | ||
|
||
from plottr import QtCore, QtWidgets, Signal, Slot | ||
from plottr.data import DataDict | ||
from plottr.node.node import Node, NodeWidget, updateOption, updateGuiQuietly | ||
from plottr.node.tools import linearFlowchart | ||
from plottr.gui.widgets import MultiDimensionSelector | ||
from plottr.gui.tools import widgetDialog | ||
from plottr.utils import testdata | ||
|
||
|
||
class DummyNodeWidget(NodeWidget): | ||
"""Node widget for this dummy node""" | ||
|
||
def __init__(self, node: Node): | ||
|
||
super().__init__(embedWidgetClass=MultiDimensionSelector) | ||
assert isinstance(self.widget, MultiDimensionSelector) # this is for mypy | ||
|
||
# allow selection of axis dimensions. See :class:`.MultiDimensionSelector`. | ||
self.widget.dimensionType = 'axes' | ||
|
||
# specify the functions that link node property to GUI elements | ||
self.optSetters = { | ||
'selectedAxes': self.setSelected, | ||
} | ||
self.optGetters = { | ||
'selectedAxes': self.getSelected, | ||
} | ||
|
||
# make sure the widget is populated with the right dimensions | ||
self.widget.connectNode(node) | ||
|
||
# when the user selects an option, notify the node | ||
self.widget.dimensionSelectionMade.connect(lambda x: self.signalOption('selectedAxes')) | ||
|
||
@updateGuiQuietly | ||
def setSelected(self, selected: List[str]) -> None: | ||
self.widget.setSelected(selected) | ||
|
||
def getSelected(self) -> List[str]: | ||
return self.widget.getSelected() | ||
|
||
|
||
class DummyNode(Node): | ||
useUi = True | ||
uiClass = DummyNodeWidget | ||
|
||
def __init__(self, name: str): | ||
super().__init__(name) | ||
self._selectedAxes: List[str] = [] | ||
|
||
@property | ||
def selectedAxes(self): | ||
return self._selectedAxes | ||
|
||
@selectedAxes.setter | ||
@updateOption('selectedAxes') | ||
def selectedAxes(self, value: List[str]): | ||
self._selectedAxes = value | ||
|
||
def process(self, dataIn = None) -> Dict[str, Optional[DataDict]]: | ||
if super().process(dataIn) is None: | ||
return None | ||
data = dataIn.copy() | ||
for k, v in data.items(): | ||
for s in self.selectedAxes: | ||
if s in v.get('axes', []): | ||
idx = v['axes'].index(s) | ||
v['axes'].pop(idx) | ||
|
||
for a in self.selectedAxes: | ||
if a in data: | ||
del data[a] | ||
|
||
pprint(data) | ||
return dict(dataOut=data) | ||
|
||
|
||
def main(): | ||
fc = linearFlowchart(('dummy', DummyNode)) | ||
node = fc.nodes()['dummy'] | ||
dialog = widgetDialog(node.ui, title='dummy node') | ||
data = testdata.get_2d_scalar_cos_data(2, 2, 1) | ||
fc.setInput(dataIn=data) | ||
return dialog, fc | ||
|
||
|
||
if __name__ == '__main__': | ||
app = QtWidgets.QApplication([]) | ||
dialog, fc = main() | ||
dialog.show() | ||
app.exec_() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this actually change self.entries and call addItem on elements of that? or is self.entries actually unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.entries
contains currently only one element,None
, to give the user the option to not select any item.And that entry should be stored somewhere other than the actual item list, because it would be cleared when we set a new list of dimensions.
So there will in any case always at least be the
None
in the dropdown. It looks maybe a bit weird, but i wanted to have that information not in the function but rather in the constructor, and was thinking of cases where more than just theNone
could be useful to fall under that category.