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

NanoMax DiffractionEndStation File Readers #68

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions ptychodus/plugins/h5DiffractionFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ class H5DiffractionFileTreeBuilder:
def _addAttributes(self, treeNode: SimpleTreeNode,
attributeManager: h5py.AttributeManager) -> None:
for name, value in attributeManager.items():
stringInfo = h5py.check_string_dtype(value.dtype)
itemDetails = f'STRING = "{value.decode(stringInfo.encoding)}"' if stringInfo \
else f'SCALAR {value.dtype} = {value}'
if isinstance(value, str):
itemDetails = f'STRING = "{value}"'
else:
stringInfo = h5py.check_string_dtype(value.dtype)
itemDetails = f'STRING = "{value.decode(stringInfo.encoding)}"' if stringInfo \
else f'SCALAR {value.dtype} = {value}'

treeNode.createChild([str(name), 'Attribute', itemDetails])

Expand Down Expand Up @@ -171,5 +174,10 @@ def registerPlugins(registry: PluginRegistry) -> None:
registry.diffractionFileReaders.registerPlugin(
H5DiffractionFileReader(dataPath='/dp'),
simpleName='PtychoShelves',
displayName='PtychoShelves Diffraction Data Files (*.h5 *.hdf5)',
displayName='PtychoShelves Diffraction Files (*.h5 *.hdf5)',
)
registry.diffractionFileReaders.registerPlugin(
H5DiffractionFileReader(dataPath='/entry/measurement/Eiger/data'),
simpleName='NanoMax',
displayName='NanoMax DiffractionEndStation Files (*.h5 *.hdf5)',
)
2 changes: 1 addition & 1 deletion ptychodus/plugins/lynxDiffractionFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ def registerPlugins(registry: PluginRegistry) -> None:
registry.diffractionFileReaders.registerPlugin(
LYNXDiffractionFileReader(),
simpleName='LYNX',
displayName='LYNX Diffraction Data Files (*.h5 *.hdf5)',
displayName='LYNX Diffraction Files (*.h5 *.hdf5)',
)
41 changes: 41 additions & 0 deletions ptychodus/plugins/nanoMaxScanFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from pathlib import Path
from typing import Final
import logging

import h5py

from ptychodus.api.plugins import PluginRegistry
from ptychodus.api.scan import Scan, ScanFileReader, ScanPoint, TabularScan

logger = logging.getLogger(__name__)


class NanoMaxScanFileReader(ScanFileReader):
MICRONS_TO_METERS: Final[float] = 1.e-6

def read(self, filePath: Path) -> Scan:
pointList = list()

with h5py.File(filePath, 'r') as h5File:
try:
xArray = h5File['/entry/measurement/pseudo/x'][()]
yArray = h5File['/entry/measurement/pseudo/y'][()]
except KeyError:
logger.exception('Unable to load scan.')
else:
for x, y in zip(xArray, yArray):
point = ScanPoint(
x=x * self.MICRONS_TO_METERS,
y=y * self.MICRONS_TO_METERS,
)
pointList.append(point)

return TabularScan.createFromPointIterable(pointList)


def registerPlugins(registry: PluginRegistry) -> None:
registry.scanFileReaders.registerPlugin(
NanoMaxScanFileReader(),
simpleName='NanoMax',
displayName='NanoMax DiffractionEndStation Scan Files (*.h5 *.hdf5)',
)