Skip to content

Commit

Permalink
Make start positioners more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
mspito committed Nov 26, 2024
1 parent 70753a5 commit bc2f0d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
31 changes: 30 additions & 1 deletion src/PyMca5/PyMcaCore/NexusTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,11 @@ def getStartingPositionersGroup(h5file, path):
Retrieve the start positioners group associated to a path
retrieving them from the same entry.
This method assumes the positioner group is NXentry/NXinstrument/positioners_start.
It assumes they are either in:
- NXentry/NXinstrument/positioners_start or
- NXentry/NXinstrument/positioners or
- NXentry/measurement/pre_scan_snapshot
"""
entry_path = getEntryName(path, h5file=h5file)
Expand All @@ -528,8 +532,33 @@ def getStartingPositionersGroup(h5file, path):
positioners = instrument[key]
if not isGroup(positioners):
positioners = None
if positioners is None:
positioners = getPositionersGroup(h5file, path)
return positioners

def getStartingPositionerValues(h5file, path):
"""
Retrieve the start positioners names, values and units associated to a path
retrieving them from the same entry.
It assumes they are either in:
- NXentry/NXinstrument/positioners_start or
- NXentry/NXinstrument/positioners or
- NXentry/measurement/pre_scan_snapshot
"""
nxpositioners = getStartingPositionersGroup(h5file, path)
positions = list()
if nxpositioners is None:
return positions
for name, dset in nxpositioners.items():
if not isinstance(dset, h5py.Dataset):
continue
idx = (0,) * dset.ndim
positions.append((name, dset[idx], dset.attrs.get("units", "")))
return positions

def getMeasurementGroup(h5file, path):
"""
Retrieve the measurement group associated to a path
Expand Down
13 changes: 2 additions & 11 deletions src/PyMca5/PyMcaGui/io/hdf5/NexusInfo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import h5py

from PyMca5.PyMcaGui import PyMcaQt as qt
from PyMca5.PyMcaCore.NexusTools import getStartingPositionersGroup
from PyMca5.PyMcaCore.NexusTools import getStartingPositionerValues

from . import HDF5Info

Expand Down Expand Up @@ -96,15 +96,6 @@ def get_motor_positions(hdf5File, node):
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
]
positions = getStartingPositionerValues(hdf5File, nxentry_name)
column_names = "Name", "Value", "Units"

return dict(zip(column_names, zip(*positions)))

0 comments on commit bc2f0d2

Please sign in to comment.