Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def diffraction_pattern_one_dimension(request):
"""
1D (in navigation space) diffraction pattern <1|8,8>
"""
return ElectronDiffraction(request.param)
def test_remove_dead_pixels(self, diffraction_pattern, method):
dpr = diffraction_pattern.remove_deadpixels([[1, 2], [5, 6]], method,
inplace=False)
assert isinstance(dpr, ElectronDiffraction)
def test_plot_best_matching_results_on_signal_vector(structure, rot_list, edc):
# Just test that the code runs
library, match_results = get_vector_match_results(structure, rot_list, edc)
# Hyperspy can only add markers to square signals
match_results.data = np.vstack((match_results.data, match_results.data))
dp = ElectronDiffraction(2 * [2 * [np.zeros((144, 144))]])
match_results.plot_best_matching_results_on_signal(dp,
phase_names=["A"],
library=library,
diffraction_generator=edc,
reciprocal_radius=0.8)
def axes_test_dp(self):
dp_data = np.random.randint(0, 10, (2, 2, 10, 10))
dp = ElectronDiffraction(dp_data)
return dp
def test_as_signal_generation():
N = ElectronDiffraction([[np.array(1.)]])
C = ElectronDiffraction([[np.array(0.)]])
elements = ['Cu']
fracs = [1]
s_size = 10
s_scale = 0.1
types = ['lobato', 'xtables', 'not_implemented']
for type in types:
if type == 'lobato':
signal, normalisation = scattering_to_signal(elements, fracs, N, C,
s_size, s_scale, type)
expected_signal = np.array([[[31.371201, 21.08535486, 10.62320925,
5.89629809, 3.51507336, 2.15565751, 1.34986551,
0.8664032, 0.57201346, 0.38888391]]])
expected_normalisation = np.array([[[5.601, 4.59187923, 3.2593265,
2.42822942, 1.87485289, 1.46821576, 1.16183713,
def cal_generator_wt_data(self, cal_generator, generate_parameters):
x0 = generate_parameters
ring_data = cal_generator.generate_ring_pattern(mask=True,
mask_radius=10,
scale=x0[0],
amplitude=x0[1],
spread=x0[2],
direct_beam_amplitude=x0[3],
asymmetry=x0[4],
rotation=x0[5])
dp = ElectronDiffraction(ring_data)
return CalibrationGenerator(dp)
def pattern_for_fit_ring(self, input_parameters):
dp = ElectronDiffraction(np.zeros((256, 256)))
x0 = input_parameters
dp.data = dp.generate_ring_pattern(mask=True, mask_radius=10,
scale=x0[0], amplitude=x0[1],
spread=x0[2],
direct_beam_amplitude=x0[3],
asymmetry=x0[4],
rotation=x0[5])
return dp
diffuse_scatter.A.value = 0
diffuse_scatter.A.bmin = 0
diffuse_scatter.tau.value = 0
diffuse_scatter.tau.bmin = 0
model.append(diffuse_scatter)
linear_decay = Polynomial(1)
model.append(linear_decay)
model.fit(bounded=True)
x_axis = self.axes_manager.signal_axes[0].axis
y_axis = self.axes_manager.signal_axes[1].axis
xs, ys = np.meshgrid(x_axis, y_axis)
rs = (xs ** 2 + ys ** 2) ** 0.5
bg = ElectronDiffraction(
diffuse_scatter.function(rs) + linear_decay.function(rs))
for i in (0, 1):
bg.axes_manager.signal_axes[i].update_from(
self.axes_manager.signal_axes[i])
return bg
scattering = np.zeros_like(gs_sq)
if illumination == 'plane_wave':
for r in atomic_coordinates:
scattering = scattering + (fs * np.exp(np.dot(k.T, r) * np.pi * 2j))
elif illumination == 'gaussian_probe':
for r in atomic_coordinates:
probe = (1 / (np.sqrt(2 * np.pi) * sigma)) * \
np.exp((-np.abs(((r[0]**2) - (r[1]**2)))) / (4 * sigma**2))
scattering = scattering + (probe * fs * np.exp(np.dot(k.T, r) * np.pi * 2j))
else:
raise ValueError("User specified illumination '{}' not defined.".format(illumination))
# Calculate intensity
intensity = (scattering * scattering.conjugate()).real
return ElectronDiffraction(intensity)
"""
if method == 'h-dome':
scale = self.data.max()
self.data = self.data / scale
bg_subtracted = self.map(regional_filter,
inplace=False, *args, **kwargs)
bg_subtracted.map(filters.rank.mean, selem=square(3))
bg_subtracted.data = bg_subtracted.data / bg_subtracted.data.max()
elif method == 'model':
bg = self.get_background_model(*args, **kwargs)
bg_removed = np.clip(self - bg, self.min(), self.max())
h = max(bg.data.min(), 1e-6)
bg_subtracted = ElectronDiffraction(
bg_removed.map(regional_flattener, h=h, inplace=False))
bg_subtracted.axes_manager.update_axes_attributes_from(
self.axes_manager.navigation_axes)
bg_subtracted.axes_manager.update_axes_attributes_from(
self.axes_manager.signal_axes)
elif method == 'gaussian_difference':
bg_subtracted = self.map(subtract_background_dog,
inplace=False, *args, **kwargs)
elif method == 'median':
bg_subtracted = self.map(subtract_background_median,
inplace=False, *args, **kwargs)
elif method == 'reference_pattern':
bg_subtracted = self.map(subtract_reference, *args, **kwargs)