Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_template_match_results(structure, pattern_list, edc, rot_list, mask=None):
dp_library = get_template_library(structure, pattern_list, edc)
for key in dp_library['A']:
pattern = (dp_library['A'][key]['Sim'].as_signal(2 * half_side_length, 0.025, 1).data)
dp = pxm.ElectronDiffraction([[pattern, pattern], [pattern, pattern]])
library = get_template_library(structure, rot_list, edc)
indexer = IndexationGenerator(dp, library)
return indexer.correlate(mask=mask)
def create_single_peak(background):
background[:,:,40:43,40:43] = 2
return pxm.ElectronDiffraction(background)
def test_marker_placement_correct_alpha():
dps = []
dp_cord_list = generate_dp_cord_list()
for coords in dp_cord_list:
back = np.zeros((144, 144))
x = coords.astype(int)[0, 0]
y = coords.astype(int)[0, 1]
back[x, y] = 1
dps.append(back.T) # stores a numpy array of pattern, This is dangerous (T everywhere)
dp = pxm.ElectronDiffraction(np.array([dps[0:2], dps[2:]]))
local_plotter(dp, dp_cord_list)
# This is human assessed, if you see this comment, you should check it
assert True
def test_marker_placement_correct_beta():
dps = []
dp_cord_list = np.divide(generate_dp_cord_list(), 80)
max_r = np.max(dp_cord_list) + 0.1
for coords in dp_cord_list:
dp_sim = DiffractionSimulation(coordinates=coords,
intensities=np.ones_like(coords[:, 0]))
dps.append(dp_sim.as_signal(144, 0.025, max_r).data) # stores a numpy array of pattern
dp = pxm.ElectronDiffraction(np.array([dps[0:2], dps[2:]])) # now from a 2x2 array of patterns
dp.set_diffraction_calibration(2 * max_r / (144))
local_plotter(dp, dp_cord_list)
# This is human assessed, if you see this comment, you should check it
assert True
for alpha in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
coords = (np.random.rand(5, 2) - 0.5) * 2 # zero mean, range from -1 to +1
dp_sim = DiffractionSimulation(coordinates=coords,
intensities=np.ones_like(coords[:, 0]),
calibration=1 / half_side_length)
if alpha < 4:
dps.append(
dp_sim.as_signal(
2 * half_side_length,
0.075,
1).data) # stores a numpy array of pattern
# add a new entry to the library
library = create_library_entry(library, (alpha, alpha, alpha), dp_sim)
dp = pxm.ElectronDiffraction([dps[0:2], dps[2:]]) # now from a 2x2 array of patterns
indexer = IndexationGenerator(dp, library)
match_results = indexer.correlate()
def test_match_results():
# Note the random number generator may give a different assertion failure
# This should always work regardless of the RNG.
assert match_results.inav[0, 0].data[0][1][0] == 0
assert match_results.inav[1, 0].data[0][1][0] == 1
assert match_results.inav[0, 1].data[0][1][0] == 2
assert match_results.inav[1, 1].data[0][1][0] == 3
def test_visuals():
# This functions will need to abuse globals.