Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"been determined. Use get_elliptical_distortion "
"to determine this matrix.")
# Set name for experimental data pattern
dpeg = self.calibration_data.au_x_grating_dp
ringP = self.ring_params
size = dpeg.data.shape[0]
dpref = generate_ring_pattern(image_size=size,
mask=True, mask_radius=mask_radius,
scale=ringP[0],
amplitude=ringP[1],
spread=spread,
direct_beam_amplitude=ringP[3],
asymmetry=1, rotation=ringP[5])
# Apply distortion corrections to experimental data
dpegs = stack_method([dpeg, dpeg, dpeg, dpeg])
dpegs = ElectronDiffraction2D(dpegs.data.reshape((2, 2, size, size)))
dpegs.apply_affine_transformation(self.affine_matrix,
preserve_range=True,
inplace=True)
# Calculate residuals to be returned
diff_init = ElectronDiffraction2D(dpeg.data - dpref.data)
diff_end = ElectronDiffraction2D(dpegs.inav[0, 0].data - dpref.data)
residuals = stack_method([diff_init, diff_end])
return ElectronDiffraction2D(residuals)
size = dpeg.data.shape[0]
dpref = generate_ring_pattern(image_size=size,
mask=True, mask_radius=mask_radius,
scale=ringP[0],
amplitude=ringP[1],
spread=spread,
direct_beam_amplitude=ringP[3],
asymmetry=1, rotation=ringP[5])
# Apply distortion corrections to experimental data
dpegs = stack_method([dpeg, dpeg, dpeg, dpeg])
dpegs = ElectronDiffraction2D(dpegs.data.reshape((2, 2, size, size)))
dpegs.apply_affine_transformation(self.affine_matrix,
preserve_range=True,
inplace=True)
# Calculate residuals to be returned
diff_init = ElectronDiffraction2D(dpeg.data - dpref.data)
diff_end = ElectronDiffraction2D(dpegs.inav[0, 0].data - dpref.data)
residuals = stack_method([diff_init, diff_end])
return ElectronDiffraction2D(residuals)
inplace=True)
data = dpegs.mean((0, 1))
data.set_diffraction_calibration(self.diffraction_calibration)
# Plot the calibrated diffraction data
data.plot(*args, **kwargs)
elif data_to_plot == 'moo3_im':
data = self.calibration_data.moo3_im
# Plot the calibrated image data
data.plot(*args, **kwargs)
elif data_to_plot == 'rotation_overlay':
dpeg = self.calibration_data.moo3_dp
size = dpeg.data.shape[0]
if self.correction_matrix is None:
self.get_correction_matrix()
dpegs = stack_method([dpeg, dpeg, dpeg, dpeg])
dpegs = ElectronDiffraction2D(dpegs.data.reshape((2, 2, size, size)))
dpegs.apply_affine_transformation(self.correction_matrix,
preserve_range=True,
inplace=True)
dp = dpegs.mean((0, 1))
im = self.calibration_data.moo3_im.rebin(dp.data.shape)
stack1 = np.zeros((dp.data.shape[0], dp.data.shape[1], 3))
stack1[:, :, 0] = dp.data / (0.05 * dp.data.max())
stack1[:, :, 2] = im.data / im.data.max()
plt.figure(1)
plt.imshow(stack1)
if line:
line.add_widget(data, axes=data.axes_manager.signal_axes)
trace = line.interactive(data, navigation_signal='same')
trace.plot()
return trace
Diffraction calibration in reciprocal Angstroms per pixel.
"""
# Check that necessary calibration data is provided
if self.calibration_data.au_x_grating_dp is None:
raise ValueError("This method requires an Au X-grating diffraction "
"pattern to be provided. Please update the "
"CalibrationDataLibrary.")
if self.affine_matrix is None:
raise ValueError("This method requires a distortion matrix to have "
"been determined. Use get_elliptical_distortion "
"to determine this matrix.")
dpeg = self.calibration_data.au_x_grating_dp
size = dpeg.data.shape[0]
dpegs = stack_method([dpeg, dpeg, dpeg, dpeg])
dpegs = ElectronDiffraction2D(dpegs.data.reshape((2, 2, size, size)))
dpegs.apply_affine_transformation(self.affine_matrix,
preserve_range=True,
inplace=True)
dpegm = dpegs.mean((0, 1))
# Define line roi along which to take trace for calibration
line = Line2DROI(x1=5, y1=5, x2=250, y2=250, linewidth=linewidth)
# Obtain line trace
trace = line(dpegm)
trace = trace.as_signal1D(0)
# Find peaks in line trace either side of direct beam
db = (np.sqrt(2) * 128) - (5 * np.sqrt(2))
pka = trace.isig[db + mask_length:].find_peaks1D_ohaver()[0]['position']
pkb = trace.isig[:db - mask_length].find_peaks1D_ohaver()[0]['position']
# Determine predicted position of 022 peak of Au pattern d022=1.437
au_pre = db - (self.ring_params[0] / 1.437)
au_post = db + (self.ring_params[0] / 1.437)
from pyxem.signals.electron_diffraction1d import ElectronDiffraction1D
from pyxem.signals.electron_diffraction2d import ElectronDiffraction2D
from pyxem.signals.vdf_image import VDFImage
from pyxem.signals.crystallographic_map import CrystallographicMap
from pyxem.signals.diffraction_vectors import DiffractionVectors
from pyxem.signals.indexation_results import TemplateMatchingResults
from pyxem.signals.diffraction1d import LazyDiffraction1D
from pyxem.signals.diffraction2d import LazyDiffraction2D
from pyxem.signals.electron_diffraction1d import LazyElectronDiffraction1D
from pyxem.signals.electron_diffraction2d import LazyElectronDiffraction2D
signal_dictionary = {'diffraction1d': Diffraction1D,
'diffraction2d': Diffraction2D,
'electron_diffraction1d': ElectronDiffraction1D,
'electron_diffraction2d': ElectronDiffraction2D,
'vdf_image': VDFImage,
'template_matching': TemplateMatchingResults,
'diffraction_vectors': DiffractionVectors,
'crystallographic_map': CrystallographicMap}
lazy_signal_dictionary = {'diffraction1d': LazyDiffraction1D,
'diffraction2d': LazyDiffraction2D,
'electron_diffraction1d': LazyElectronDiffraction1D,
'electron_diffraction2d': LazyElectronDiffraction2D}
def load(filename, lazy=False):
"""Load data into pyxem objects.
Parameters
----------
dpref = generate_ring_pattern(image_size=size,
mask=True, mask_radius=mask_radius,
scale=ringP[0],
amplitude=ringP[1],
spread=spread,
direct_beam_amplitude=ringP[3],
asymmetry=1, rotation=ringP[5])
# Apply distortion corrections to experimental data
dpegs = stack_method([dpeg, dpeg, dpeg, dpeg])
dpegs = ElectronDiffraction2D(dpegs.data.reshape((2, 2, size, size)))
dpegs.apply_affine_transformation(self.affine_matrix,
preserve_range=True,
inplace=True)
# Calculate residuals to be returned
diff_init = ElectronDiffraction2D(dpeg.data - dpref.data)
diff_end = ElectronDiffraction2D(dpegs.inav[0, 0].data - dpref.data)
residuals = stack_method([diff_init, diff_end])
return ElectronDiffraction2D(residuals)
else:
intensities = self.intensities
# TODO: Refactor this to use the diffsims simulation to plot functionality
size_x, size_y = shape[0], shape[1]
cx, cy = -size_x / 2 * calibration, -size_y / 2 * calibration
x, y = np.indices((size_x, size_y))
x, y = x * calibration + cx, y * calibration + cy
virtual_ed = np.zeros((size_x, size_y, num_segments))
for i in range(num_segments):
virtual_ed[..., i] = sum(list(map(
lambda a, xo, yo: get_gaussian2d(
a, xo, yo, x=x, y=y, sigma=sigma),
intensities[i], vectors[i][..., 0], vectors[i][..., 1])))
virtual_ed = ElectronDiffraction2D(virtual_ed.T)
return virtual_ed
amplitude=ringP[1],
spread=spread,
direct_beam_amplitude=ringP[3],
asymmetry=1, rotation=ringP[5])
# Apply distortion corrections to experimental data
dpegs = stack_method([dpeg, dpeg, dpeg, dpeg])
dpegs = ElectronDiffraction2D(dpegs.data.reshape((2, 2, size, size)))
dpegs.apply_affine_transformation(self.affine_matrix,
preserve_range=True,
inplace=True)
# Calculate residuals to be returned
diff_init = ElectronDiffraction2D(dpeg.data - dpref.data)
diff_end = ElectronDiffraction2D(dpegs.inav[0, 0].data - dpref.data)
residuals = stack_method([diff_init, diff_end])
return ElectronDiffraction2D(residuals)
"""
# Check all required parameters are defined as attributes
if self.calibration_data.au_x_grating_dp is None:
raise ValueError("This method requires an Au X-grating diffraction "
"pattern to be provided. Please update the "
"CalibrationDataLibrary.")
if self.affine_matrix is None:
raise ValueError("This method requires a distortion matrix to have "
"been determined. Use get_elliptical_distortion "
"to determine this matrix.")
# Set name for experimental data pattern
dpeg = self.calibration_data.au_x_grating_dp
# Apply distortion corrections to experimental data
size = dpeg.data.shape[0]
dpegs = stack_method([dpeg, dpeg, dpeg, dpeg])
dpegs = ElectronDiffraction2D(dpegs.data.reshape((2, 2, size, size)))
dpegs.apply_affine_transformation(self.affine_matrix,
preserve_range=True,
inplace=True)
dpegm = dpegs.mean((0, 1))
# Plot distortion corrected data
dpegm.plot(*args, **kwargs)
# add reference circle if specified
if reference_circle is True:
circ = CircleROI(cx=128, cy=128, r=53.5, r_inner=0)
circ.add_widget(dpegm)