Created
March 17, 2018 13:30
-
-
Save thomasaarholt/4107bd3a28940ed314dda7e20d7d779b to your computer and use it in GitHub Desktop.
Pyprismatic function that saves to the hyperspy format
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
def prism(file, path=None, focus=0, FP=20, alpha=20.0e-3): | |
import gc | |
gc.collect() | |
import os | |
import pyprismatic as pr | |
file = os.path.abspath(file) | |
save_path = path | |
path, filename = os.path.split(file) | |
name, _ = os.path.splitext(filename) | |
name += '_FP{0}'.format(FP) | |
#name = name + '_focus_' + str(focus) | |
if save_path == None: | |
save_path = path | |
output = os.path.join(save_path, name + '.mrc') | |
probestep = 0.1 # Å | |
potential_spacing = 0.05 # Å | |
include_thermal_effects = bool(FP) | |
meta = pr.Metadata( | |
filenameAtoms=file, | |
E0=300e3, | |
potBound = 2.0, | |
probeSemiangle=alpha, | |
alphaBeamMax = alpha+4e-3, | |
interpolationFactorX=4, | |
interpolationFactorY=4, | |
filenameOutput=output, | |
probeStepX = probestep, | |
probeStepY = probestep, | |
realspacePixelSizeX = potential_spacing, | |
realspacePixelSizeY = potential_spacing, | |
detectorAngleStep = 0.001, | |
sliceThickness = 1.625, | |
scanWindowXMin = 0.38, | |
scanWindowXMax = 0.58, | |
scanWindowYMin = 0.39, | |
scanWindowYMax = 0.61, | |
#scanWindowXMin = 0.14, | |
#scanWindowXMax = 0.855, | |
#scanWindowYMin = 0.1666, | |
#scanWindowYMax = 0.8333, | |
numFP = FP, | |
probeDefocus = focus, | |
numGPUs=1, | |
numThreads=10, | |
includeThermalEffects=include_thermal_effects, | |
tileX=1, | |
tileY=1, | |
) | |
from time import time | |
t1 = time() | |
meta.go() | |
t2 = time() | |
print('It took',(t2 - t1)/60, 'min') | |
import hyperspy.api as hs | |
s = hs.signals.Signal2D(pr.fileio.readMRC(output)).as_signal2D((0,2)) | |
s.metadata.add_node('Simulation') | |
s.metadata.Simulation.Software = 'Prismatic' | |
for field in meta.fields: | |
s.metadata.Simulation[field] = getattr(meta, field) | |
metadata = s.metadata.Simulation | |
s.axes_manager[0].name = 'Acceptance Angle' | |
s.axes_manager[0].scale = metadata.detectorAngleStep*1000 | |
s.axes_manager[0].units = 'mrad' | |
s.axes_manager[1].name = 'x' | |
s.axes_manager[2].name = 'y' | |
s.axes_manager[1].units = s.axes_manager[2].units = 'Å' | |
s.axes_manager[1].scale = metadata.probeStepX | |
s.axes_manager[2].scale = metadata.probeStepY | |
s.save(os.path.join(save_path, name + '.hspy'), overwrite=True) | |
print('Saved in ' + os.path.join(save_path, name + '.hspy')) | |
return s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment