Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Prerequisites

Chapter 1: Introduction


Prerequisites

Download

OpenInColab

part of

MSE672: Introduction to Transmission Electron Microscopy

Spring 2026
by Gerd Duscher

Microscopy Facilities
Institute of Advanced Materials & Manufacturing
Materials Science & Engineering
The University of Tennessee, Knoxville

Background and methods to analysis and quantification of data acquired with transmission electron microscopes.

Language

The notebooks are all in python 3.

At this point the common version is python 3.9

cd

Packages

The idea behind any python program is to make use of the highly efficient libraries that already exist.

I use anaconda3 (not miniconda) which is available for all major operating systems.

We use a few modules that come with every python installation, like:

  • math

  • sys

  • os

We use mostly the common packages for scientific computing in python (all included in anaconda3) The most important ones are:

  • Numpy - the numerical library

  • Scipy the scientific library

  • Matplotlib the interactive plotting library

These packages are expected to be installed on your computer to run the notebooks of this book. These packages are already installed in Google colab.

For specialist applications we do not reinvent the wheel and use those on an as needed basis.

Example is the library to register a stack of images:

  • SimpleITK integration of AI in image analysis and for high performing computer algorithms

  • pyNSID the atomistic simulation program is used for crystallographic data

  • ase together with a symmetry package

  • spglib

For dialogs, we use the capabilities of Jupyter Widgets provided by:

All routines that are introduced in the notebooks are also available (for analysis) in the provided package

If you install pyTEMlib with the code cell below all packages you need for this book will be installed.

Basic Installation of Python Environment

I recommend installing the free anaconda3 from this link.

If you have an old version of anaconda, please reinstall the new version. The lecture is based on fairly new packages of scipy and numpy, dask, and h5py, which will create problems in old anaconda versions.

Once you have installed anaconda type

pip install pyTEMlib

Alternatively you can just run the code cell below. Be aware that the installation process may take a while.

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

# pyTEMlib setup ------------------
if test_package('pyTEMlib') < '0.2026.1.0':
    print('installing pyTEMlib')
    !{sys.executable} -m pip install --upgrade pyTEMlib

# ------------------------------
print('done')
installing pyTEMlib
Requirement already satisfied: pyTEMlib in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (0.2025.12.0)
Collecting pyTEMlib
  Using cached pytemlib-0.2025.12.1-py3-none-any.whl.metadata (3.6 kB)
Requirement already satisfied: scipy in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (1.16.3)
Requirement already satisfied: numpy in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (2.3.5)
Requirement already satisfied: pillow in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (12.0.0)
Requirement already satisfied: ase in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (3.27.0)
Requirement already satisfied: tqdm in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (4.67.1)
Requirement already satisfied: plotly in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (6.5.0)
Requirement already satisfied: pandas in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (2.3.3)
Requirement already satisfied: requests in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (2.32.5)
Requirement already satisfied: lxml in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (5.3.0)
Requirement already satisfied: ipympl in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (0.9.8)
Requirement already satisfied: spglib in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (2.6.0)
Requirement already satisfied: simpleitk in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (2.5.2)
Requirement already satisfied: scikit-image in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (0.25.2)
Requirement already satisfied: scikit-learn in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (1.7.2)
Requirement already satisfied: pyNSID>=0.0.7 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (0.0.7.2)
Requirement already satisfied: sidpy>=0.12.7 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (0.12.7)
Requirement already satisfied: SciFiReaders>=0.12.4 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (0.12.4)
Requirement already satisfied: xraylib in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyTEMlib) (4.2.0)
Requirement already satisfied: toolz in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyNSID>=0.0.7->pyTEMlib) (1.1.0)
Requirement already satisfied: cytoolz in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyNSID>=0.0.7->pyTEMlib) (1.0.1)
Requirement already satisfied: dask>=0.10 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyNSID>=0.0.7->pyTEMlib) (2025.11.0)
Requirement already satisfied: h5py>=2.6.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyNSID>=0.0.7->pyTEMlib) (3.15.1)
Requirement already satisfied: six in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pyNSID>=0.0.7->pyTEMlib) (1.17.0)
Requirement already satisfied: click>=8.1 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from dask>=0.10->pyNSID>=0.0.7->pyTEMlib) (8.2.1)
Requirement already satisfied: cloudpickle>=3.0.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from dask>=0.10->pyNSID>=0.0.7->pyTEMlib) (3.1.2)
Requirement already satisfied: fsspec>=2021.09.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from dask>=0.10->pyNSID>=0.0.7->pyTEMlib) (2025.10.0)
Requirement already satisfied: packaging>=20.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from dask>=0.10->pyNSID>=0.0.7->pyTEMlib) (25.0)
Requirement already satisfied: partd>=1.4.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from dask>=0.10->pyNSID>=0.0.7->pyTEMlib) (1.4.2)
Requirement already satisfied: pyyaml>=5.3.1 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from dask>=0.10->pyNSID>=0.0.7->pyTEMlib) (6.0.3)
Requirement already satisfied: colorama in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from click>=8.1->dask>=0.10->pyNSID>=0.0.7->pyTEMlib) (0.4.6)
Requirement already satisfied: locket in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from partd>=1.4.0->dask>=0.10->pyNSID>=0.0.7->pyTEMlib) (1.0.0)
Requirement already satisfied: setuptools in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from SciFiReaders>=0.12.4->pyTEMlib) (80.9.0)
Requirement already satisfied: numba in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from SciFiReaders>=0.12.4->pyTEMlib) (0.62.1)
Requirement already satisfied: ipython>=7.1.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from SciFiReaders>=0.12.4->pyTEMlib) (9.7.0)
Requirement already satisfied: pyUSID in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from SciFiReaders>=0.12.4->pyTEMlib) (0.0.12)
Requirement already satisfied: gdown in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from SciFiReaders>=0.12.4->pyTEMlib) (5.2.0)
Requirement already satisfied: mrcfile in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from SciFiReaders>=0.12.4->pyTEMlib) (1.5.4)
Requirement already satisfied: pycroscopy-gwyfile in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from SciFiReaders>=0.12.4->pyTEMlib) (1.0.2)
Requirement already satisfied: decorator>=4.3.2 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (5.2.1)
Requirement already satisfied: ipython-pygments-lexers>=1.0.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (1.1.1)
Requirement already satisfied: jedi>=0.18.1 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (0.19.2)
Requirement already satisfied: matplotlib-inline>=0.1.5 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (0.2.1)
Requirement already satisfied: prompt_toolkit<3.1.0,>=3.0.41 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (3.0.52)
Requirement already satisfied: pygments>=2.11.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (2.19.2)
Requirement already satisfied: stack_data>=0.6.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (0.6.3)
Requirement already satisfied: traitlets>=5.13.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (5.14.3)
Requirement already satisfied: wcwidth in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from prompt_toolkit<3.1.0,>=3.0.41->ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (0.2.13)
Requirement already satisfied: parso<0.9.0,>=0.8.4 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from jedi>=0.18.1->ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (0.8.5)
Requirement already satisfied: matplotlib>=2.0.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from sidpy>=0.12.7->pyTEMlib) (3.10.7)
Requirement already satisfied: distributed>=2.0.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from sidpy>=0.12.7->pyTEMlib) (2025.11.0)
Requirement already satisfied: psutil in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from sidpy>=0.12.7->pyTEMlib) (7.0.0)
Requirement already satisfied: joblib>=0.11.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from sidpy>=0.12.7->pyTEMlib) (1.5.2)
Requirement already satisfied: ipywidgets in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from sidpy>=0.12.7->pyTEMlib) (8.1.7)
Requirement already satisfied: ipykernel in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from sidpy>=0.12.7->pyTEMlib) (6.31.0)
Requirement already satisfied: dill in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from sidpy>=0.12.7->pyTEMlib) (0.4.0)
Requirement already satisfied: jinja2>=2.10.3 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from distributed>=2.0.0->sidpy>=0.12.7->pyTEMlib) (3.1.6)
Requirement already satisfied: msgpack>=1.0.2 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from distributed>=2.0.0->sidpy>=0.12.7->pyTEMlib) (1.1.1)
Requirement already satisfied: sortedcontainers>=2.0.5 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from distributed>=2.0.0->sidpy>=0.12.7->pyTEMlib) (2.4.0)
Requirement already satisfied: tblib>=1.6.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from distributed>=2.0.0->sidpy>=0.12.7->pyTEMlib) (3.1.0)
Requirement already satisfied: tornado>=6.2.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from distributed>=2.0.0->sidpy>=0.12.7->pyTEMlib) (6.5.1)
Requirement already satisfied: urllib3>=1.26.5 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from distributed>=2.0.0->sidpy>=0.12.7->pyTEMlib) (2.6.1)
Requirement already satisfied: zict>=3.0.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from distributed>=2.0.0->sidpy>=0.12.7->pyTEMlib) (3.0.0)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from jinja2>=2.10.3->distributed>=2.0.0->sidpy>=0.12.7->pyTEMlib) (3.0.2)
Requirement already satisfied: contourpy>=1.0.1 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from matplotlib>=2.0.0->sidpy>=0.12.7->pyTEMlib) (1.3.3)
Requirement already satisfied: cycler>=0.10 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from matplotlib>=2.0.0->sidpy>=0.12.7->pyTEMlib) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from matplotlib>=2.0.0->sidpy>=0.12.7->pyTEMlib) (4.61.0)
Requirement already satisfied: kiwisolver>=1.3.1 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from matplotlib>=2.0.0->sidpy>=0.12.7->pyTEMlib) (1.4.9)
Requirement already satisfied: pyparsing>=3 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from matplotlib>=2.0.0->sidpy>=0.12.7->pyTEMlib) (3.2.5)
Requirement already satisfied: python-dateutil>=2.7 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from matplotlib>=2.0.0->sidpy>=0.12.7->pyTEMlib) (2.9.0.post0)
Requirement already satisfied: executing>=1.2.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from stack_data>=0.6.0->ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (2.2.1)
Requirement already satisfied: asttokens>=2.1.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from stack_data>=0.6.0->ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (3.0.0)
Requirement already satisfied: pure_eval in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from stack_data>=0.6.0->ipython>=7.1.0->SciFiReaders>=0.12.4->pyTEMlib) (0.2.3)
Requirement already satisfied: beautifulsoup4 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from gdown->SciFiReaders>=0.12.4->pyTEMlib) (4.14.2)
Requirement already satisfied: filelock in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from gdown->SciFiReaders>=0.12.4->pyTEMlib) (3.20.0)
Requirement already satisfied: soupsieve>1.2 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from beautifulsoup4->gdown->SciFiReaders>=0.12.4->pyTEMlib) (2.5)
Requirement already satisfied: typing-extensions>=4.0.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from beautifulsoup4->gdown->SciFiReaders>=0.12.4->pyTEMlib) (4.15.0)
Requirement already satisfied: comm>=0.1.1 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipykernel->sidpy>=0.12.7->pyTEMlib) (0.2.3)
Requirement already satisfied: debugpy>=1.6.5 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipykernel->sidpy>=0.12.7->pyTEMlib) (1.8.16)
Requirement already satisfied: jupyter-client>=8.0.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipykernel->sidpy>=0.12.7->pyTEMlib) (8.6.3)
Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipykernel->sidpy>=0.12.7->pyTEMlib) (5.9.1)
Requirement already satisfied: nest-asyncio>=1.4 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipykernel->sidpy>=0.12.7->pyTEMlib) (1.6.0)
Requirement already satisfied: pyzmq>=25 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipykernel->sidpy>=0.12.7->pyTEMlib) (27.1.0)
Requirement already satisfied: platformdirs>=2.5 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from jupyter-core!=5.0.*,>=4.12->ipykernel->sidpy>=0.12.7->pyTEMlib) (4.5.0)
Requirement already satisfied: widgetsnbextension~=4.0.14 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipywidgets->sidpy>=0.12.7->pyTEMlib) (4.0.14)
Requirement already satisfied: jupyterlab_widgets~=3.0.15 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from ipywidgets->sidpy>=0.12.7->pyTEMlib) (3.0.15)
Requirement already satisfied: llvmlite<0.46,>=0.45.0dev0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from numba->SciFiReaders>=0.12.4->pyTEMlib) (0.45.1)
Requirement already satisfied: pytz>=2020.1 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pandas->pyTEMlib) (2025.2)
Requirement already satisfied: tzdata>=2022.7 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from pandas->pyTEMlib) (2025.2)
Requirement already satisfied: narwhals>=1.15.1 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from plotly->pyTEMlib) (2.7.0)
Requirement already satisfied: charset_normalizer<4,>=2 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from requests->pyTEMlib) (3.4.4)
Requirement already satisfied: idna<4,>=2.5 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from requests->pyTEMlib) (3.11)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from requests->pyTEMlib) (2025.11.12)
Requirement already satisfied: PySocks!=1.5.7,>=1.5.6 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from requests[socks]->gdown->SciFiReaders>=0.12.4->pyTEMlib) (1.7.1)
Requirement already satisfied: networkx>=3.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from scikit-image->pyTEMlib) (3.6.1)
Requirement already satisfied: imageio!=2.35.0,>=2.33 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from scikit-image->pyTEMlib) (2.37.2)
Requirement already satisfied: tifffile>=2022.8.12 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from scikit-image->pyTEMlib) (2025.10.4)
Requirement already satisfied: lazy-loader>=0.4 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from scikit-image->pyTEMlib) (0.4)
Requirement already satisfied: threadpoolctl>=3.1.0 in c:\users\gduscher\appdata\local\anaconda3\lib\site-packages (from scikit-learn->pyTEMlib) (3.5.0)
Using cached pytemlib-0.2025.12.1-py3-none-any.whl (1.5 MB)
Installing collected packages: pyTEMlib
  Attempting uninstall: pyTEMlib
    Found existing installation: pyTEMlib 0.2025.12.0
    Uninstalling pyTEMlib-0.2025.12.0:
      Successfully uninstalled pyTEMlib-0.2025.12.0
Successfully installed pyTEMlib-0.2025.12.1
done
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pycrosgui 0.2.2 requires pyqt5, which is not installed.
pytemgui 0.2.2 requires pyqt5, which is not installed.

Data Format

All data in this course are stored in the data format of

which is based on

Notebook preamble

As a minimum Any notebook in this course has to have the following libraries loaded :

# import matplotlib and numpy 
# Define iteractivity with this **magic** command
#                       use "inline" instead of "widget" for non-interactive plots
%matplotlib widget

import matplotlib.pylab as plt
import numpy as np

Numpy

The calculations depend on Numpy and an installation of that package that is compiled to include BLAS and LAPACK libraries will be much faster than the standalone version. For example the numpy installed on ubuntu with > sudo apt-get install python3-numpy or at windows you can install the numpy package from Gohlke’s webpage which compiled against the MKL library of Intel. If you used anaconda3, everything is already optimized.

The command below lets you see what you have

## What is numpy compiled against
np.__config__.show()
print('numpy version: ',np.version.version)
import scipy as sp
print('scipy version: ',sp.__version__)
Build Dependencies:
  blas:
    detection method: pkgconfig
    found: true
    include directory: C:/Users/gduscher/AppData/Local/anaconda3/Library/include
    lib directory: C:/Users/gduscher/AppData/Local/anaconda3/Library/lib
    name: mkl-sdl
    openblas configuration: unknown
    pc file directory: C:\miniconda3\conda-bld\numpy_and_numpy_base_1763980694785\_h_env\Library\lib\pkgconfig
    version: '2025'
  lapack:
    detection method: pkgconfig
    found: true
    include directory: C:/Users/gduscher/AppData/Local/anaconda3/Library/include
    lib directory: C:/Users/gduscher/AppData/Local/anaconda3/Library/lib
    name: mkl-sdl
    openblas configuration: unknown
    pc file directory: C:\miniconda3\conda-bld\numpy_and_numpy_base_1763980694785\_h_env\Library\lib\pkgconfig
    version: '2025'
Compilers:
  c:
    commands: cl.exe
    linker: link
    name: msvc
    version: 19.29.30159
  c++:
    commands: cl.exe
    linker: link
    name: msvc
    version: 19.29.30159
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 3.1.4
Machine Information:
  build:
    cpu: x86_64
    endian: little
    family: x86_64
    system: windows
  host:
    cpu: x86_64
    endian: little
    family: x86_64
    system: windows
Python Information:
  path: C:\miniconda3\conda-bld\numpy_and_numpy_base_1763980694785\_h_env\python.exe
  version: '3.13'
SIMD Extensions:
  baseline:
  - SSE
  - SSE2
  - SSE3
  found:
  - SSSE3
  - SSE41
  - POPCNT
  - SSE42
  - AVX
  - F16C

numpy version:  2.3.5
scipy version:  1.16.3

TEM Library

You will have to run the code cell below at least once to install the library with the programs needed for the analysis of data.

The code cell below will install pyTEMlib directly from pypi

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

# pyTEMlib setup ------------------
if test_package('pyTEMlib') < '0.2026.1.0':
    print('installing pyTEMlib')
    !{sys.executable} -m pip install --upgrade pyTEMlib
print('done')
installing pyTEMlib
done

Now we load pyTEMlib to make it available for this notebook.

import pyTEMlib
print(f'pyTEM version: {pyTEMlib.__version__}')
pyTEM version: 0.2025.12.1

Test

Let’s test if the installation was successful and plot a unit cell. You can rotate the plot around, zoom and select. Try it!

# ---- Input ------------
crystal_name = 'Silicon'
# -----------------------

# make a structure dictionary with crystal_tools
atoms = pyTEMlib.crystal_tools.structure_by_name(crystal_name)
print(atoms)
import ase.visualize
ase.visualize.view(atoms*(4,4,1), viewer='x3d')
Lattice(symbols='Si8', pbc=True, cell=[5.43088, 5.43088, 5.43088])
Loading...

Get used to changing parameters and type silicon instead of Graphite in the code cell above.

Summary

We now have tested all tools to load data and save our analysis.

We are ready to go

Appendix

I am using some extensions to jupyter notebooks which can be installed with the following cells

I like mostly the table of content extension that shows where in the notebook I am and lets me jump to different parts easily.

# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m jupyter nbextension list
Known nbextensions:
  config dir: C:\Users\gdusc\anaconda3\etc\jupyter\nbconfig
    notebook section
      jupyter-jsmol/extension enabled 
      jupyterlab-plotly/extension enabled 
      jupyter-js-widgets/extension enabled 
      - Validating: ok
      - Validating: ok
      - Validating: ok

Use one of the following (uncomment pip and comment out the conda command line, if you are not in an anaconda environment)

import sys

#!{sys.executable} -m pip install jupyter_contrib_nbextensions
!conda install --yes --prefix {sys.prefix} jupyter_contrib_nbextensions
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - jupyter_contrib_nbextensions

Current channels:

  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.



!{sys.executable} -m  jupyter nbextension enable toc2
Enabling notebook extension toc2...
      - Validating: problems found:
        - require?  X toc2
%%javascript
$('<div id="toc"></div>').css({position: 'fixed', top: '120px', left: 0}).appendTo(document.body);
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js');
Loading...