-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement NanoMax DiffractionEndStation File Readers (#68)
- Loading branch information
1 parent
afeee0e
commit d8c2c32
Showing
3 changed files
with
54 additions
and
5 deletions.
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,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)', | ||
) |