### Example output of pyTEMlib version check Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/installation Example output from the version check command, showing the installed pyTEMlib version. ```text pyTEMlib version 0.2025.12.0 ``` -------------------------------- ### Metadata output example Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i1-adaptive-fourier-filter Example metadata output showing filename and experiment details. ```text {'filename': 'C:\\Users\\gduscher\\Documents\\Github\\pyTEMlib\\example_data\\p1-3-hr3.dm3', 'experiment': {'acceleration_voltage': 199990.28125, 'exposure_time': 1.0, 'microscope': 'Libra 200 MC'}} ``` -------------------------------- ### Initialize pyTEMlib environment Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/usefull-equations Imports necessary libraries and checks the installed version of pyTEMlib. ```python %matplotlib widget import matplotlib.pylab as plt import numpy as np import scipy import pyTEMlib pyTEMlib.__version__ ``` -------------------------------- ### Import libraries and setup Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Imports necessary libraries, enables widget manager for Google Colab, mounts drive if in Colab, and prints pyTEMlib version. ```python %matplotlib widget import numpy as np import matplotlib.pylab as plt import sys if 'google.colab' in sys.modules: from google.colab import output output.enable_custom_widget_manager() from google.colab import drive import sys sys.path.insert(0, '../../') import sidpy %load_ext autoreload %autoreload 2 if 'google.colab' in sys.modules: drive.mount("/content/drive") import pyTEMlib # For archiving reasons it is a good idea to print the version numbers out at this point print('pyTEM version: ', pyTEMlib.__version__) ## Do all of registration notebook_tags= {'notebook': 'Image_Registration', 'notebook_version': '2025_03_13', 'pyTEM version': pyTEMlib.__version__} ``` -------------------------------- ### Import pyTEMlib and print version Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/installation Import pyTEMlib and print its version to verify the installation. Use this minimal command in every notebook or Python instance after installation. ```python import pyTEMlib print('pyTEMlib version', pyTEMlib.__version__) ``` -------------------------------- ### Install or upgrade pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Checks the installed pyTEMlib version and upgrades it if below 0.2026.1.0. The output 'done' confirms the installation step completed. ```python import sys import importlib.metadata def test_package(package_name): """Test if package exists and returns version or -1""" try: version = importlib.metadata.version(package_name) except importlib.metadata.PackageNotFoundError: version = '-1' return version if test_package('pyTEMlib') < '0.2026.1.0': print('installing pyTEMlib') !{sys.executable} -m pip install --upgrade pyTEMlib -q print('done') ``` ```text done ``` -------------------------------- ### Complete registration start output Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Output message from the complete registration indicating the start of rigid registration and the stack dimensions. ```text Rigid_Registration Stack contains 10 images, each with 1024 pixels in x-direction and 1024 pixels in y-direction ``` -------------------------------- ### Load Example Data and Plot Diffraction Pattern Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d1-diffraction-rings Loads the example dataset GOLD-NP-DIFF.dm3 if load_your_own_data is False, otherwise uses the selected dataset from the file widget. Plots the main dataset with vmax=20000. ```python if load_your_own_data: datasets = fileWidget.datasets main_dataset = fileWidget.selected_dataset else: # load example datasets = pyTEMlib.file_tools.open_file(os.path.join("../../example_data", "GOLD-NP-DIFF.dm3")) main_dataset = datasets['Channel_000'] view = main_dataset.plot(vmax=20000) ``` -------------------------------- ### Check and Install pyTEMlib Package Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d1-diffraction-rings Tests whether pyTEMlib is installed and meets the minimum version requirement. If not, it installs the latest version from the GitHub repository. The version check uses importlib.metadata and the installation uses pip with the --upgrade flag. ```python import sys import importlib.metadata def test_package(package_name): """Test whether package exists and returns version or -1""" try: version = importlib.metadata.version(package_name) except importlib.metadata.PackageNotFoundError: version = '-1' return version if test_package('pyTEMlib') < '0.2026.06.0': print('installing pyTEMlib') !{sys.executable} -m pip install git+https://github.com/pycroscopy/pyTEMlib.git@main -q --upgrade print('done') ``` -------------------------------- ### Install pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Checks if pyTEMlib is installed and upgrades it if the version is below 0.2025.2.0. ```python import sys import importlib.metadata def test_package(package_name): """Test if package exists and returns version or -1""" try: version = importlib.metadata.version(package_name) except importlib.metadata.PackageNotFoundError: version = '-1' return version if test_package('pyTEMlib') < '0.2025.2.0': print('installing pyTEMlib') !{sys.executable} -m pip install --upgrade pyTEMlib -q print('done') ``` -------------------------------- ### Load Diffraction Pattern with Optional Google Drive Mount Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d1-diffraction-rings Sets up data loading: if load_your_own_data is True, mounts Google Drive and opens a file widget; otherwise, loads the example file GOLD-NP-DIFF.dm3. Requires sys and pyTEMlib imports. ```python # ------Input ------------- load_your_own_data = False # ------------------------- if 'google.colab' in sys.modules: drive.mount("/content/drive") if load_your_own_data: fileWidget = pyTEMlib.file_tools.FileWidget() ``` -------------------------------- ### Load necessary packages and show pyTEMlib version Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/open-files Sets up the notebook environment: enables interactive matplotlib widgets, imports numpy and matplotlib, and prints the installed pyTEMlib version. ```python %matplotlib widget import matplotlib.pyplot as plt import numpy as np import pyTEMlib print('pyTEMlib version', pyTEMlib.__version__) ``` -------------------------------- ### Install and upgrade pyTEMlib with version check Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/installation Install or upgrade pyTEMlib if the installed version is older than 0.2026.06.0. Run this cell in every notebook, especially in Google Colab where the environment resets each session. The cell uses the current Python executable to run pip and prints 'done' after installation. ```python import sys import importlib.metadata def test_package(package_name): """Test if package exists and returns version or -1""" try: version = importlib.metadata.version(package_name) except importlib.metadata.PackageNotFoundError: version = '-1' return version if test_package('pyTEMlib') < '0.2026.06.0': print('installing pyTEMlib') !{sys.executable} -m pip install --upgrade pyTEMlib -q print('done') ``` -------------------------------- ### Install and verify pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i1-adaptive-fourier-filter Checks for the existence of the pyTEMlib package and upgrades it if the version is older than 0.2025.3.0. ```python import sys import importlib.metadata def test_package(package_name): """Test if package exists and returns version or -1""" try: version = importlib.metadata.version(package_name) except importlib.metadata.PackageNotFoundError: version = '-1' return version if test_package('pyTEMlib') < '0.2025.3.0': print('installing pyTEMlib') !{sys.executable} -m pip install --upgrade pyTEMlib -q print('done') ``` ```text installing pyTEMlib done ``` -------------------------------- ### Check and install pyTEMlib package Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d2-diffraction-spots This snippet checks if pyTEMlib is installed and has a version at least 0.2024.1.0. If not, it installs the latest version from GitHub. It also installs numpy 1.24.4 if running in Google Colab. ```python import sys import importlib.metadata def test_package(package_name): """Test if package exists and returns version or -1""" try: version = importlib.metadata.version(package_name) except importlib.metadata.PackageNotFoundError: version = '-1' return version if test_package('pyTEMlib') < '0.2024.1.0': print('installing pyTEMlib') !{sys.executable} -m pip install git+https://github.com/pycroscopy/pyTEMlib.git@main -q --upgrade if 'google.colab' in sys.modules: !{sys.executable} -m pip install numpy==1.24.4 print('done') ``` ```text done ``` -------------------------------- ### Output of Center Extraction Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d1-diffraction-rings Example output showing the radius and center coordinates in pixels after selection. ```text radius = 559 pixels center = 1059.5, 1099.4 [pixels] ``` -------------------------------- ### Joblib parallel execution output Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Output from the joblib context manager example: shows backend selection and completion message. ```output [Parallel(n_jobs=2)]: Using backend LokyBackend with 2 concurrent workers. [Parallel(n_jobs=2)]: Done 20 out of 20 | elapsed: 0.3s finished ``` -------------------------------- ### Output of pyTEMlib version check Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/open-files Example output of the pyTEMlib version print statement from the previous cell. ```text pyTEMlib version 0.2025.12.0 ``` -------------------------------- ### Output of np.nditer iteration Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Output of the np.nditer example: shows the iterated element, the array slice at the multi_index, and the multi_index tuple. ```output 0 [0 1 2] (0, 0) 3 [3 4 5] (0, 1) 6 [6 7 8] (1, 0) 9 [ 9 10 11] (1, 1) ``` -------------------------------- ### Get all reflections and g-vectors with pyTEMlib.diffraction_tools Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Calls pyTEMlib.diffraction_tools.get_all_reflections and get_all_g_vectors to compute reciprocal lattice vectors and Miller indices for a given atom structure. The displayed output shows the first five entries of each result. ```python hkl2, g2= pyTEMlib.diffraction_tools.get_all_reflections(atoms, 1) g, hkl = pyTEMlib.diffraction_tools.get_all_g_vectors(1, atoms) g[:5], g2[:5], hkl2[:5], hkl[:5] ``` ```output (array([[-0.24520622, -0.24520622, -0.24520622], [-0.24520622, -0.24520622, 0. ], [-0.24520622, -0.24520622, 0.24520622], [-0.24520622, 0. , -0.24520622], [-0.24520622, 0. , 0. ]]), array([[ 0. , 0. , -0.24520622], [ 0. , 0.24520622, 0. ], [-0.24520622, 0. , 0. ], [ 0. , 0. , 0.24520622], [ 0.24520622, 0. , 0. ]]), array([[ 0., 0., -1.], [ 0., 1., 0.], [-1., 0., 0.], [ 0., 0., 1.], [ 1., 0., 0.]]), array([[-1., -1., -1.], [-1., -1., 0.], [-1., -1., 1.], [-1., 0., -1.], [-1., 0., 0.]])) ``` -------------------------------- ### Progress Bar Output Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Progress bar output from the refinement process, showing 0% completion at the start. A Jupyter kernel connection is required to fully display this output. ```text 0%| | 0/1183 [00:00 ``` -------------------------------- ### Get structure factors with pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Calls pyTEMlib.diffraction_tools.get_structure_factors with atoms and g_non_rot, then prints the shape, atomic positions, and a list of rounded structure factors with corresponding hkl indices. The output shows the shape (1330,), the atomic positions array, and a list of tuples. ```python s = pyTEMlib.diffraction_tools.get_structure_factors(atoms, g_non_rot) s.shape, atoms.positions, list(zip(np.round(s[200:210],3), hkl_all[200:210])) ``` ```text ((1330,), array([[0. , 0. , 0. ], [1.35772, 1.35772, 1.35772], [2.71544, 2.71544, 0. ], [4.07316, 4.07316, 1.35772], [2.71544, 0. , 2.71544], [4.07316, 1.35772, 4.07316], [0. , 2.71544, 2.71544], [1.35772, 4.07316, 4.07316]]), [(np.float64(0.0), array([-4., 2., -3.])), (np.float64(6.863), array([-4., 2., -2.])), (np.float64(0.0), array([-4., 2., -1.])), (np.float64(0.0), array([-4., 2., 0.])), (np.float64(0.0), array([-4., 2., 1.])), (np.float64(6.863), array([-4., 2., 2.])), (np.float64(0.0), array([-4., 2., 3.])), (np.float64(0.0), array([-4., 2., 4.])), (np.float64(0.0), array([-4., 2., 5.])), (np.float64(0.0), array([-4., 3., -5.]))])` ``` -------------------------------- ### Rigid registration progress bar output Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Progress bar output from the rigid registration process, showing the start of the 25-image processing. Requires a Jupyter kernel connection to display fully. ```text 0%| | 0/25 [00:00 ``` -------------------------------- ### Import libraries and set up notebook Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Sets up the notebook environment: enables interactive matplotlib, imports libraries, mounts Google Drive in Colab, and loads pyTEMlib. The output shows the autoreload extension status and the pyTEMlib version. ```python # import matplotlib and numpy # use "inline" instead of "notebook" for non-interactive # use widget for jupyterlab needs ipympl to be installed # import matplotlib and numpy %matplotlib widget import matplotlib.pylab as plt import numpy as np import sys if 'google.colab' in sys.modules: from google.colab import output output.enable_custom_widget_manager() from google.colab import drive %load_ext autoreload %autoreload 2 sys.path.insert(0, '../../') import pyTEMlib # For archiving reasons it is a good idea to print the version numbers out at this point print('pyTEM version: ', pyTEMlib.__version__) if 'google.colab' in sys.modules: drive.mount("/content/drive") ## Do all of registration notebook_tags= {'notebook': 'Structure Analysis', 'notebook_version': '2025_03_16', 'pyTEM version': pyTEMlib.__version__} ``` ```text The autoreload extension is already loaded. To reload it, use: %reload_ext autoreload pyTEM version: 0.2026.1.2 ``` -------------------------------- ### Load libraries and configure environment Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i1-adaptive-fourier-filter Imports necessary scientific libraries, configures matplotlib for interactive widgets, and initializes the pyTEMlib environment. ```python %matplotlib widget import numpy as np import matplotlib.pylab as plt import sys import scipy if 'google.colab' in sys.modules: from google.colab import output output.enable_custom_widget_manager() from google.colab import drive import sys sys.path.insert(0, '../../') %load_ext autoreload %autoreload 2 import pyTEMlib if 'google.colab' in sys.modules: drive.mount("/content/drive") print('pyTEMlib version: ', pyTEMlib.__version__) note_book_version = '2025.05.19' note_book_name='pyTEMib/notebooks/Imaging/Adaptive_Fourier_Filter' ``` ```text pyTEMlib version: 0.2026.5.0 ``` -------------------------------- ### Check for Newest Versions of pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i3-probe Tests if pyTEMlib is installed and upgrades it if the version is older than 0.2024.2.3. Uses importlib.metadata to check the version and pip to install the upgrade. ```python import sys import importlib.metadata def test_package(package_name): """Test if package exists and returns version or -1""" try: version = importlib.metadata.version(package_name) except importlib.metadata.PackageNotFoundError: version = '-1' return version if test_package('pyTEMlib') < '0.2024.2.3': print('installing pyTEMlib') !{sys.executable} -m pip install --upgrade pyTEMlib -q print('done') ``` -------------------------------- ### Simulate new notebook and open file Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i1-adaptive-fourier-filter Reopens the file using the saved filename and creates a ChooseDataset widget to select a dataset. ```python new_dataset= pyTEMlib.file_tools.open_file(filename) choose_image = pyTEMlib.file_tools.ChooseDataset(new_dataset) ``` -------------------------------- ### Output of Package Loading Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d1-diffraction-rings Shows the expected output after loading the packages, displaying the pyTEMlib version and notebook version. ```text pyTEM version: 0.2026.3.0 notebook version: 2025.12.06 ``` -------------------------------- ### Open File with FileWidget Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i1-adaptive-fourier-filter Creates a FileWidget instance to select a file and dataset. Requires a Jupyter kernel connection for full display. ```python fileWidget = pyTEMlib.file_tools.FileWidget() ``` -------------------------------- ### Initialize Crystal Structure Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d2-diffraction-spots Initializes an aluminum crystal structure using pyTEMlib's crystal_tools and visualizes it with ASE. ```python #Initialize the dictionary with all the input atoms = pyTEMlib.crystal_tools.structure_by_name('aluminum') print(atoms) import ase.visualize ase.visualize.view(atoms*[4,4,1], viewer='x3d') ``` -------------------------------- ### Calculate and plot diffraction pattern with pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d2-diffraction-spots Sets up input parameters for a diffraction simulation (zone axis, hkl_max, Sg_max, mistilt angles, acceleration voltage), builds a tags dictionary, calls pyTEMlib.diffraction_tools.get_bragg_reflections to compute reflections, and plots the pattern with plot_diffraction_pattern. The output includes warnings about division by zero and missing legend labels, and a summary of allowed reflections. ```python # --------------- INPUT ------------------------ zone_hkl = np.array([1, 0, 0]) hkl_max = 25 # maximum allowed Miller index sg_max = 0.01 # 1/Ang maximum allowed excitation error mistilt_alpha = 1.5 # degrees mistilt_beta = 1 # degrees acceleration_voltage = 200.0 * 1000.0 #V rotation = np.radians(0) # rotation of diffraction pattern # ------------------------------------------- tags = {'zone_hkl': zone_hkl, 'hkl_max': hkl_max, 'Sg_max': sg_max, 'mistilt_alpha': np.radians(mistilt_alpha), 'mistilt_beta': np.radians(mistilt_beta), 'acceleration_voltage': acceleration_voltage} diff_dict ={} diff_dict = pyTEMlib.diffraction_tools.get_bragg_reflections(atoms, tags, verbose=True) diff_dict.setdefault('output',{})['plot_forbidden']=False diff_dict['output']['plot_dynamically_allowed']=True v = pyTEMlib.diffraction_tools.plot_diffraction_pattern(diff_dict, unit='1/nm') ``` ```text C:\Users\gduscher\OneDrive - University of Tennessee\GitHub\pyTEMlib\notebooks\Diffraction\../..\pyTEMlib\diffraction_tools\basic.py:375: RuntimeWarning: divide by zero encountered in scalar divide alpha = np.arctan(zone[0] / r) C:\Users\gduscher\OneDrive - University of Tennessee\GitHub\pyTEMlib\notebooks\Diffraction\../..\pyTEMlib\diffraction_tools\diffraction_plot.py:810: UserWarning: No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument. plt.legend() n ``` ```text mistilt Of the 334 possible reflection 56 are allowed. Of those, there are 17 in ZOLZ and 39 in HOLZ Of the 130 forbidden reflection in ZOLZ 0 can be dynamically activated. ``` -------------------------------- ### Load Necessary Packages for Probe Calculation Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i3-probe Sets up the environment for probe calculation, including matplotlib widget mode, numpy, and pyTEMlib. Also enables autoreload and handles Google Colab specifics. ```python %matplotlib widget import matplotlib.pyplot as plt import numpy as np import sys import os %load_ext autoreload %autoreload 2 sys.path.insert(0,'..//..//pyTEMlib//') if 'google.colab' in sys.modules: from google.colab import output from google.colab import drive output.enable_custom_widget_manager() from matplotlib.patches import Circle import pyTEMlib import pyTEMlib.probe_tools print('pyTEM version: ', pyTEMlib.__version__) ``` -------------------------------- ### Output of joblib parallel processing Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Output of the joblib example: a list of six sublists, each containing the squared value repeated 15 times. ```output [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9], [16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16], [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25], [36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36]] ``` -------------------------------- ### Calculate and plot Bragg reflections with pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Sets up the diffraction calculation with pyTEMlib.diffraction_tools.get_bragg_reflections, configures plotting options, and displays the resulting keys of the HOLZ dictionary. The output shows the number of allowed reflections and the keys of the HOLZ dictionary. ```python tags = {'acceleration_voltage': acceleration_voltage_V, 'zone_hkl': [1, 1, -0], 'hkl_max': 15, 'mistilt_alpha': np.radians(1), 'mistilt_beta': np.radians(0), 'Sg_max': 0.03} diff_dict = {} diff_dict = pyTEMlib.diffraction_tools.get_bragg_reflections(atoms, tags, verbose=True) diff_dict.setdefault('output',{})['plot_forbidden']=False diff_dict['output']['plot_dynamically_allowed']=True diff_dict['output']['plot_Kikuchi']=True diff_dict['output']['plot_HOLZ']=True diff_dict['convergence_angle'] = 3 pyTEMlib.diffraction_tools.plot_diffraction_pattern(diff_dict, unit='1/nm') diff_dict['HOLZ'].keys() ``` ```text mistilt Of the 457 possible reflection 101 are allowed. Of those, there are 82 in ZOLZ and 19 in HOLZ Of the 137 forbidden reflection in ZOLZ 27 can be dynamically activated. ``` ```text dict_keys(['g_deficient', 'g_excess', 'FOLZ', 'SOLZ', 'HOLZ_plus', 'Laue_zones', 'hkl', 'intensities', 'kg']) ``` -------------------------------- ### Calculate Ring Pattern with pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d1-diffraction-rings Sets up input parameters for ring pattern calculation, loads the structure by name, stores it in the main dataset, and calls pyTEMlib.diffraction_tools.ring_pattern_calculation. Requires pyTEMlib to be imported beforehand. ```python # -----Input for ring pattern calculation ---- structure = 'aluminum' hkl_max = 7 verbose = True # -------------------------------------------- atoms = pyTEMlib.crystal_tools.structure_by_name(structure) main_dataset.structures['Structure_000'] = atoms main_dataset.metadata['experiment']['hkl_max'] = hkl_max pyTEMlib.diffraction_tools.ring_pattern_calculation(main_dataset, verbose=verbose) ``` -------------------------------- ### Select dataset with ft.ChooseDataset Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Creates a widget to select a dataset from the current channel. Requires a Jupyter kernel connection to fully display the output. ```python image_choice = ft.ChooseDataset(current_channel) ``` -------------------------------- ### Display FileWidget Output (VBox) Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i1-adaptive-fourier-filter Shows the widget output as a VBox with a directory dropdown. Requires a Jupyter kernel connection. ```python VBox(children=(Dropdown(description='directory:', layout=Layout(width='90%'), options=('c:\Users\gduscher\O… ``` -------------------------------- ### Inspect get_wavelength function Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/usefull-equations Displays the help documentation for the get_wavelength function. ```python help (get_wavelength) ``` ```text Help on function get_wavelength in module __main__: get_wavelength(e0: float) -> float get deBroglie wavelength of electron accelerated by energy e0 (in eV) Parameters ---------- e0 : float acceleration voltage in eV Returns ------- float wavelength in meters ``` -------------------------------- ### Parallel processing with joblib.Parallel Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Parallelizes a data processing function using joblib.Parallel and delayed. The function process_data squares each element and repeats it 15 times; the example processes 6 data items with 6 jobs. The commented line shows the general pattern. ```python import joblib def process_data(data): # Simulate a time-consuming data processing step import time time.sleep(2) return [data ** 2]*15 data = [1, 2, 3, 4, 5, 6] # Parallel(n_jobs=workjob_num)(delayed(func_be_applied)(aug) for elem in array results = joblib.Parallel(n_jobs=6)(joblib.delayed(process_data)(data[d]) for d in range(6)) print(results) ``` -------------------------------- ### Create FileWidget for file selection Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/open-files Creates a file selection widget for choosing a file, even in Google Colab. After navigating to the file, select 'Select Main' to load it. ```python file_list = pyTEMlib.file_tools.FileWidget() ``` -------------------------------- ### Create ChooseDataset widget Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/open-files Creates a widget to choose a different dataset from the collection. ```python dataset_chooser = pyTEMlib.file_tools.ChooseDataset(dataset_collection) ``` -------------------------------- ### Configure and plot image stack dataset Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Sets the dataset data type to IMAGE_STACK and spatial dimensions, then plots the dataset and accesses the slope of the x dimension. Requires the selector widget from the previous step. ```python dataset = selector.dataset dataset.data_type = 'IMAGE_STACK' dataset.x.dimension_type = 'SPATIAL' dataset.y.dimension_type = 'SPATIAL' view = dataset.plot() dataset.x.slope ``` -------------------------------- ### Create FileWidget for image selection with pyTEMlib.file_tools Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Creates a FileWidget from pyTEMlib.file_tools to select an image file. The output is an ipywidgets VBox containing a directory dropdown; a Jupyter kernel connection is required to fully display it. ```python fileWidget = pyTEMlib.file_tools.FileWidget() ``` ```output VBox(children=(Dropdown(description='directory:', layout=Layout(width='90%'), options=('C:\\Users\\gduscher\\o… ``` -------------------------------- ### Output of a[1,0] Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Output of a[1,0] showing the resulting array. ```output array([6, 7, 8]) ``` -------------------------------- ### Print first five detected spots Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i1-adaptive-fourier-filter Prints the first five rows of the spots array. The spots are ordered from center to outside, and the third parameter of each spot is its angle. ```python print(spots[:5]) ``` ```text [[-2.62027028 2.21908057 -0.86811058] [ 2.62027028 -2.21908057 2.27348207] [-3.4226497 0.43880124 -1.44328677] [ 3.4226497 -0.43880124 1.69830589] [-3.22205484 -1.25371784 -1.94187537]] ``` -------------------------------- ### Set center and plot ring pattern with pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/diffraction/d1-diffraction-rings Sets the scale from the image dimensions and calls pyTEMlib.diffraction_tools.set_center with a 7% larger scale, then plots the ring pattern using pyTEMlib.diffraction_tools.plot_ring_pattern. This produces the publication-quality figure. ```python scale = main_dataset.get_image_dims(return_axis=True)[0].slope pyTEMlib.diffraction_tools.set_center(main_dataset, center, scale=scale*1.07) v = pyTEMlib.diffraction_tools.plot_ring_pattern(main_dataset.metadata['diffraction'], main_dataset) ``` -------------------------------- ### Simulate atomic-resolution image with ASE and pyTEMlib Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i3-probe Builds an Al fcc(100) slab with ASE, sets the field of view from the cell, and generates a simulated atomic-resolution image by placing Gaussian peaks at atomic positions and convolving with a probe. The printed value is the field of view in Å, used to scale the image. ```python from ase import build sizeX = 512 slab = build.fcc100('Al', size=(20, 20, 1), orthogonal=True) ab['FOV'] = slab.cell[0,0] print(ab['FOV'] len(slab.positions)) scale = sizeX/ab['FOV'] FOV = ab['FOV'] img = np.zeros([sizeX,sizeX]) for pos in slab.positions: img += pyTEMlib.probe_tools.make_gauss(sizeX, sizeX, width=0.05*scale, x0=pos[0]*scale-sizeX/2, y0=pos[1]*scale-sizeX/2, intensity=13**2) import scipy img2 = scipy.signal.fftconvolve(img, probe, mode='same') img2.shape plt.figure() plt.imshow(img2) plt.show() ``` ```text 57.27564927611035 ``` -------------------------------- ### Complete registration with pyTEMlib.image_tools.complete_registration Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Performs complete registration (rigid and non-rigid) in one step using pyTEMlib.image_tools.complete_registration. The result is set to an image stack and plotted. ```python demon_registered, rigid_registered = pyTEMlib.image_tools.complete_registration(dataset) demon_registered.data_type = 'image_stack' view2 = demon_registered.plot() ``` -------------------------------- ### Compute form factor for silicon with pyTEMlib.diffraction_tools.form_factor Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Calls pyTEMlib.diffraction_tools.form_factor for silicon with the full g_norm array and with a single g vector, also printing g_norm[0]. The output shows the form factor values for all g vectors, the value at the first g, and the magnitude of that first reciprocal lattice vector. ```python pyTEMlib.diffraction_tools.form_factor('Si', g_norm), form_factor('Si', g_norm[0]), g_norm[0] ``` -------------------------------- ### Create dataset chooser widget with pyTEMlib.file_tools.ChooseDataset Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i1-adaptive-fourier-filter Creates a chooser widget for selecting a dataset from the datasets dictionary for further processing or visualization. ```python chooser = pyTEMlib.file_tools.ChooseDataset(datasets) ``` -------------------------------- ### Detect spots in power spectrum with diffractogram_spots Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i1-adaptive-fourier-filter Sets spot_threshold to 0.05 (lower values yield more spots), calls pyTEMlib.image_tools.diffractogram_spots on power_spectrum, filters spots by radial distance (between 0.5 and 7), plots the power spectrum with red spot markers, and prints the number of found spots. The output shows 22 spots. ```python # ------Input---------- spot_threshold=0.05 # --------------------- spots, _ = pyTEMlib.image_tools.diffractogram_spots(power_spectrum, spot_threshold=spot_threshold) spots = spots[np.linalg.norm(spots[:,:2],axis=1)<7,:] spots = spots[np.linalg.norm(spots[:,:2],axis=1)>0.5,:] power_spectrum.plot() plt.gca().scatter(spots[:,0],spots[:,1], color='red', alpha=0.4); print(f"found {len(spots)}") ``` ```text found 22 ``` -------------------------------- ### Select and plot dataset Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Selects the chosen dataset and plots it. The plot is displayed as a figure. ```python dataset = fileWidget.selected_dataset v = dataset.plot() ``` -------------------------------- ### Compute FFT and create sidpy.Dataset with reciprocal dimensions Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i2-image-registration Computes the FFT of the image and creates a sidpy.Dataset with reciprocal-space dimensions. The first block prepares the image and computes the FFT; the second block builds the FFT dataset with proper units and dimension types. ```python new_image = np.array(image) new_image = new_image - new_image.min() fft_transform = (np.fft.fftshift(np.fft.fft2(np.array(new_image)))) dset = image ``` ```python image_dims = dset.get_image_dims(return_axis=True) units_x = '1/' + image_dims[0].units units_y = '1/' + image_dims[1].units fft_dset = sidpy.Dataset.from_array(fft_transform) fft_dset.quantity = dset.quantity fft_dset.units = 'a.u.' fft_dset.data_type = 'IMAGE' fft_dset.source = dset.title fft_dset.modality = 'fft' fft_dset.set_dimension(0, sidpy.Dimension(np.fft.fftshift(np.fft.fftfreq(new_image.shape[0], d=dset.x[1]-dset.x[0])), name='u', units=units_x, dimension_type='RECIPROCAL', quantity='reciprocal_length')) fft_dset.set_dimension(1, sidpy.Dimension(np.fft.fftshift(np.fft.fftfreq(new_image.shape[1], d=dset.y[1]- dset.y[0])), name='v', units=units_y, dimension_type='RECIPROCAL', quantity='reciprocal_length')) ``` -------------------------------- ### Rigid registration with pyTEMlib.image_tools Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Applies rigid registration to the loaded image using pyTEMlib.image_tools.rigid_registration and plots the result. The output is an ipywidgets HBox with a play button and slider; a Jupyter kernel connection is required to fully display it. ```python rigid_registered = pyTEMlib.image_tools.rigid_registration(image) v= rigid_registered.plot() ``` ```output HBox(children=(Play(value=0, description='Press play', interval=500, max=20), IntSlider(value=0, continuous_up… ``` -------------------------------- ### Open EDS file and create dataset selector Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Opens a file using pyTEMlib's file_tools with EDS stream enabled and creates a dataset selector with sidpy. The first line retrieves the file name from a file widget. ```python fileWidget.file_name datasets = pyTEMlib.file_tools.open_file(fileWidget.file_name, eds_stream=True) selector = sidpy.ChooseDataset(datasets) ``` -------------------------------- ### Heading: Select a different dataset Source: https://pycroscopy.github.io/pyTEMlib/notebooks/introduction/open-files Heading for the section on selecting a different dataset. ```markdown ### Select a different dataset ``` -------------------------------- ### Select Dataset with sidpy.ChooseDataset Source: https://pycroscopy.github.io/pyTEMlib/notebooks/imaging/i4-structure-analysis Creates an interactive dataset selector using sidpy.ChooseDataset. This widget requires a Jupyter kernel connection to fully display its output. ```python image_choice = sidpy.ChooseDataset(datasets) ```