  This work presents the new template matching capabilities implemented in
Pyxem, an open source Python library for analyzing four-dimensional scanning
transmission electron microscopy (4D-STEM) data. Template matching is a brute
force approach for deriving local crystal orientations. It works by comparing a
library of simulated diffraction patterns to experimental patterns collected
with nano-beam and precession electron diffraction (NBED and PED). This is a
computationally demanding task, therefore the implementation combines
efficiency and scalability by utilizing multiple CPU cores or a graphical
processing unit (GPU). The code is built on top of the scientific python
ecosystem, and is designed to support custom and reproducible workflows that
combine the image processing, template library generation, indexation and
visualisation all in one environment. The tools are agnostic to file size and
format, which is significant in light of the increased adoption of pixelated
detectors from different manufacturers. This paper details the implementation,
validation, and benchmarking results of the method. The method is illustrated
by calculating orientation maps of nanocrystalline materials and precipitates
embedded in a crystalline matrix. The combination of speed and flexibility
opens the door for automated parameter studies and real-time on-line
orientation mapping inside the TEM.
