-
Notifications
You must be signed in to change notification settings - Fork 54
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 motor info to QNexuswidget #1088
Open
mspito
wants to merge
3
commits into
vasole:master
Choose a base branch
from
mspito:motor_info_h5
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import h5py | ||
|
||
from PyMca5.PyMcaGui import PyMcaQt as qt | ||
from PyMca5.PyMcaCore.NexusTools import getStartingPositionersGroup | ||
|
||
from . import HDF5Info | ||
|
||
|
||
class NexusMotorInfoWidget(qt.QWidget): | ||
def __init__(self, parent): | ||
super().__init__(parent) | ||
|
||
self.mainLayout = qt.QVBoxLayout(self) | ||
self.mainLayout.setContentsMargins(0, 0, 0, 0) | ||
self.mainLayout.setSpacing(2) | ||
|
||
self.label = qt.QLabel(self) | ||
self.label.setText("Number of motors: 0") | ||
|
||
column_names = ["Name", "Value", "Units"] | ||
self._column_names = column_names | ||
|
||
self.table = qt.QTableWidget(self) | ||
self.table.setColumnCount(len(column_names)) | ||
for i in range(len(column_names)): | ||
item = self.table.horizontalHeaderItem(i) | ||
if item is None: | ||
item = qt.QTableWidgetItem(column_names[i], qt.QTableWidgetItem.Type) | ||
item.setText(column_names[i]) | ||
self.table.setHorizontalHeaderItem(i, item) | ||
self.table.setSortingEnabled(True) | ||
|
||
self.mainLayout.addWidget(self.label) | ||
self.mainLayout.addWidget(self.table) | ||
|
||
def setInfoDict(self, ddict): | ||
if "motors" in ddict: | ||
self._setInfoDict(ddict["motors"]) | ||
else: | ||
self._setInfoDict(ddict) | ||
|
||
def _setInfoDict(self, ddict): | ||
nrows = len(ddict.get(self._column_names[0], [])) | ||
self.label.setText("Number of motors: %d" % nrows) | ||
self.table.setRowCount(nrows) | ||
|
||
if not nrows: | ||
self.hide() | ||
return | ||
|
||
for row in range(nrows): | ||
for col, label in enumerate(self._column_names): | ||
text = str(ddict[label][row]) | ||
item = self.table.item(row, col) | ||
if item is None: | ||
item = qt.QTableWidgetItem(text, qt.QTableWidgetItem.Type) | ||
item.setFlags(qt.Qt.ItemIsSelectable | qt.Qt.ItemIsEnabled) | ||
self.table.setItem(row, col, item) | ||
else: | ||
item.setText(text) | ||
|
||
for col in range(len(self._column_names)): | ||
self.table.resizeColumnToContents(col) | ||
|
||
|
||
class NexusInfoWidget(HDF5Info.HDF5InfoWidget): | ||
|
||
def _build(self): | ||
super()._build() | ||
self.motorInfoWidget = NexusMotorInfoWidget(self) | ||
self.addTab(self.motorInfoWidget, "Motors") | ||
|
||
def setInfoDict(self, ddict): | ||
super().setInfoDict(ddict) | ||
self.motorInfoWidget.setInfoDict(ddict) | ||
|
||
|
||
def getInfo(hdf5File, node): | ||
""" | ||
hdf5File is and HDF5 file-like insance | ||
node is the posix path to the node | ||
""" | ||
info = HDF5Info.getInfo(hdf5File, node) | ||
info["motors"] = get_motor_positions(hdf5File, node) | ||
return info | ||
|
||
|
||
def get_motor_positions(hdf5File, node): | ||
node = hdf5File[node] | ||
|
||
nxentry_name = node.name.split("/")[1] | ||
if not nxentry_name: | ||
return dict() | ||
|
||
nxentry = hdf5File[nxentry_name] | ||
if not isinstance(nxentry, h5py.Group): | ||
return dict() | ||
|
||
nxpositioners = getStartingPositionersGroup(hdf5File, nxentry_name) | ||
if nxpositioners is None or not isinstance(nxpositioners, h5py.Group): | ||
return dict() | ||
|
||
positions = [ | ||
(name, dset[()], dset.attrs.get("units", "")) | ||
for name, dset in nxpositioners.items() | ||
if isinstance(dset, h5py.Dataset) and dset.ndim == 0 | ||
] | ||
column_names = "Name", "Value", "Units" | ||
|
||
return dict(zip(column_names, zip(*positions))) |
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.