Note
Go to the end to download the full example code.
Operations on Vectors#
This example shows how to perform some basic operations slicing and selecting vectors. This is designed to be very flexible and powerful. Many operations such as slicing with a boolean array are supported.
Additionally, lazy operations are supported and can be chained together. These are often faster
than their non-lazy counterparts as dask
very effectively prunes the computation graph.
import pyxem as pxm
import hyperspy.api as hs
hs.set_log_level("ERROR")
s = pxm.data.tilt_boundary_data()
temp = s.template_match_disk(disk_r=5, subtract_min=False)
vectors = s.get_diffraction_vectors(threshold_abs=0.4, min_distance=5)
0%| | 0/33 [00:00<?, ?it/s]
64%|██████▎ | 21/33 [00:00<00:00, 192.55it/s]
100%|██████████| 33/33 [00:00<00:00, 190.80it/s]
0%| | 0/33 [00:00<?, ?it/s]
45%|████▌ | 15/33 [00:00<00:00, 137.66it/s]
88%|████████▊ | 29/33 [00:00<00:00, 105.01it/s]
100%|██████████| 33/33 [00:00<00:00, 112.45it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 8459.88it/s]
Plotting all the vectors
s.plot()
all_vectors = vectors.to_markers(color="red", sizes=10, alpha=0.5)
s.add_marker(all_vectors)
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 11780.75it/s]
slic_vectors = (vectors.ivec[:, vectors.ivec[0] < 10]).to_markers(
color="green", sizes=5, alpha=0.5
)
s.plot()
s.add_marker([all_vectors, slic_vectors])
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 11945.46it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 12024.33it/s]
0%| | 0/49 [00:00<?, ?it/s]
100%|██████████| 49/49 [00:00<00:00, 11685.29it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 8858.37it/s]
slic_vectors = (
vectors.ivec[:, (vectors.ivec[0] > 0) * (vectors.ivec[0] < 10)]
).to_markers(color="w", sizes=5, alpha=0.5)
s.plot()
s.add_marker([all_vectors, slic_vectors])
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 11926.93it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 8326.04it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 12148.87it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 11847.30it/s]
0%| | 0/49 [00:00<?, ?it/s]
100%|██████████| 49/49 [00:00<00:00, 11744.05it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 12098.95it/s]
vect_magnitudes = (vectors.ivec[0] ** 2 + vectors.ivec[1] ** 2) ** 0.5
slic_vectors = vectors.ivec[:, vect_magnitudes < 20].to_markers(
color="w", sizes=5, alpha=0.5
)
s.plot()
s.add_marker([all_vectors, slic_vectors])
s.add_marker([all_vectors, slic_vectors])
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 7547.41it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 13338.35it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 11863.55it/s]
0%| | 0/49 [00:00<?, ?it/s]
100%|██████████| 49/49 [00:00<00:00, 11098.44it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 12449.36it/s]
slic_vectors = (vectors.ivec[:, vectors.ivec["intensity"] < 0.5]).to_markers(
color="w", sizes=5, alpha=0.5
)
s.plot()
s.add_marker([all_vectors, slic_vectors])
s.add_marker([all_vectors, slic_vectors])
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 12233.70it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 12071.52it/s]
0%| | 0/49 [00:00<?, ?it/s]
100%|██████████| 49/49 [00:00<00:00, 11656.79it/s]
0%| | 0/33 [00:00<?, ?it/s]
100%|██████████| 33/33 [00:00<00:00, 12344.99it/s]
sphinx_gallery_thumbnail_number = 8
Total running time of the script: (0 minutes 2.803 seconds)