Skip to content
/ stempy Public
forked from OpenChemistry/stempy

Toolkit for 4D STEM processing on HPC using a Python interface and C++ engine

License

Notifications You must be signed in to change notification settings

ercius/stempy

This branch is 1 commit ahead of, 7 commits behind OpenChemistry/stempy:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

415f878 · Oct 3, 2024
Sep 13, 2024
Sep 12, 2024
Apr 25, 2024
Mar 16, 2022
Apr 23, 2024
Mar 16, 2022
Oct 3, 2024
Dec 12, 2023
Sep 16, 2024
Aug 17, 2023
Apr 10, 2019
Jun 2, 2023
Nov 12, 2020
Feb 10, 2021
Mar 2, 2021
Sep 13, 2024
Dec 3, 2018
Mar 15, 2022
Sep 13, 2024
Oct 26, 2023
Feb 26, 2021

Repository files navigation

Documentation Status

Toolkit for processing sparse 4D STEM image data.

Singularity instructions may be found here.

Build instructions may be found here.

Example usage

Electron counting raw 4d Camera data

from pathlib import Path
import stempy.io as stio
import stempy.image as stim
import matplotlib.pyplot as plt
import numpy as np
data_path = Path('/mnt/hdd1/2020.06.03')
files = sorted(data_path.glob('data_scan0*015_*.data'))  # raw data files
sReader = stio.reader(files, stio.FileVersion.VERSION5)
events = stim.electron_count(sReader, np.zeros((576,576),background_threshold_n_sigma=4.0))
stio.save_electron_counts('/mnt/hdd1/data_scan15_electrons.h5', events)
# Now create a bright field STEM image from the data by summing pixels 
# 0 to 110 radially
bf = stim.create_stem_images(events, 0, 35)
# Create a summed diffraction pattern of the entire dataset
dp = stim.calculate_sum_sparse(events.data,
                                   events.frame_dimensions)
fg, ax = plt.subplots(1,2)
ax[0].imshow(bf[0,:,:])
ax[1].imshow(dp)

Brightfield and diffraction pattern

Loading counted data

Data output after counting is in a stempy.io.sparse_array.SparseArray format. These can also be saved as an HDF5 file and loaded from a properly formatted HDF5 file. Here is an example of loading a sparse data set and summing all diffraction patterns. See the examples for more details.

import stempy.io as stio
import matplotlib.pyplot as plt
sa = stio.SparseArray.from_hdf5('data_scan5_electrons.h5')
dp = sa.sum(axis=(0, 1))
plt.figure()
plt.imshow(dp)

Advanced usage for raw data

Build repo and set PYTHONPATH:

export PYTHONPATH=<build dir>/lib/

Interact with raw data

import stempy.io as stio
r = stio.reader('/data/4dstem/smallScanningDiffraction/data0000.dat')
b = r.read()
print(b.header.images_in_block)
# 32
print(b.header.image_numbers)
# [1, 33, 65, 97, 129, 161, 193, 225, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993]
print(b.data)
# array([[   0,    0,    0, ...,    0,    0,    0],
#       [   0,    0,    0, ...,    0,    0,    0],
#       [   0,    0,    0, ...,    0,    0,    0],
#       ...,
#       [ 932, 1017,  976, ...,  984,  834, 1031],
#       [ 928, 1081, 1100, ..., 1020,  985,  969],
#       [ 989,  940, 1045, ..., 1010,  959,  887]], dtype=uint16)

About

Toolkit for 4D STEM processing on HPC using a Python interface and C++ engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 62.0%
  • Python 34.5%
  • CMake 2.8%
  • Other 0.7%