Skip to content

Commit

Permalink
Implement NanoMax DiffractionEndStation File Readers (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehenke authored Dec 21, 2023
1 parent afeee0e commit d8c2c32
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
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)',
)

0 comments on commit d8c2c32

Please sign in to comment.