Repository navigation
Local FFT pseudo-4DSTEM for HRTEM images, with phase and in-plane orientation mapping - #314
Merged
Merged
Conversation
Resolve the diffraction/__init__.py export conflict by keeping the new StrainMapAutocorrelation and ModelDiffraction exports from dev and the SystematicRowMap export from this branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Crystal.from_cif dropped the Spacegroup object that ase's CIF reader puts in atoms.info, but Crystal.from_ase kept it, for example from ase.spacegroup.crystal. It cannot be saved, so saving a crystal or crystal map printed "Not saving non-JSON-serializable entries of atoms.info". The constructor now stores a copy of the atoms without it, so both paths drop it and the caller's structure is left as it was. Crystal finds the space group itself (Crystal.spacegroup). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ehrhardtkm
self-requested a review
November 19, 2026 01:15
ehrhardtkm
reviewed
Nov 23, 2026
ehrhardtkm
left a comment
Collaborator
There was a problem hiding this comment.
Did a first pass and think it mostly looks good! I left some comments on clarifying docstrings and asking a few questions about implementation details in the systematic row mapping
- LocalFFT: drop the amplitude option (the normalized noise of 1 holds only for the power spectrum) and use one variable name per meaning in _compute. - SystematicRowMap: document k_min, k_max and min_ring_intensity on the class; say that a row is one Friedel pair; an integer ring now indexes the rings of the given phase (it indexed the whole ring table); and num_directions counts only indexed, unambiguous rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OrientationMap.in_plane_angle_deg measured from the column axis toward the row axis, so a crystal rotated by t about the beam (quat_from_zone_axis in_plane_deg=t) read 90 - t. It now returns atan2(a_col, a_row), from the row axis toward the column axis, the sense of a right-handed rotation about the beam, as in the calibration, the orientation matching and SystematicRowMap. - ipf_color and plot_orientation_map: a numeric direction is an angle from the row axis toward the column axis (0 is "r", 90 is "c"); the title says so. - fold_in_plane uses the same angle, with the correction rotation sign flipped to match. - plot_cluster_pole_figure drew row horizontally and column upward, 90 degrees from plot_pole_figure. Both now use the image frame (column rightward, row downward) with the same scan-axes glyph. - test_in_plane_angle_auto_fold checks that the folded angle turns with the rotation about the beam. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The old assert required an unfolded angle above 60 degrees, which held only for the previous column-to-row convention and failed on CI after the switch (max 42.3). Check instead that mod_deg=None returns an angle in (-180, 180] that folds to the "auto" value modulo 60. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ehrhardtkm
approved these changes
Nov 24, 2026
ehrhardtkm
left a comment
Collaborator
There was a problem hiding this comment.
Looks good to me! Thanks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem this PR addresses
Lattice fringes in HRTEM images carry local phase and orientation information, but quantEM had no way to map them. This PR treats an HRTEM image as a pseudo-4DSTEM dataset: a tapered window moves across the image, and the local Fourier transform at each window position becomes a diffraction pattern. These patterns then go through the existing 4DSTEM workflow (Bragg disk detection and pixel size calibration), followed by phase and in-plane orientation mapping.
Left to right: HRTEM image with four positions of the moving window, the four tapered windows, their local Fourier transforms with the detected Bragg disks on the front pattern, and the phase map (LiF yellow, Li2O cyan) and LiF in-plane orientation map.
What's here
imaging/local_fft.py:LocalFFT.from_imagecuts a window ofwindow_sizepixels everysteppixels, applies a disk mask with a sin² taper over the full radius (window_mask), and stores the cropped power spectra as aDataset4dstemin Å and 1/Å. Each pattern is normalized by the azimuthal median of the scan-mean pattern asI / background - 1, so the background is 0 and the noise is close to 1 at every frequency, and the center disk is set to 0. The window centers are known exactly, soLocalFFT.originsgoes directly toBraggVectors.correct_peak_originsand we skip origin fitting and ellipse calibration.print(lfft)reports the window diameter and FWHM, which sets the spatial resolution.diffraction/systematic_row.py:SystematicRowMap. Most HRTEM windows show a single set of lattice fringes, which is a single systematic row: it determines the phase and the in-plane direction of g, but not the rotation of the crystal about g. Instead of full ACOM, we pair Friedel spots (+g and -g), assign |g| to the nearest reflection family of the candidate crystals, and map the phase and the in-plane angle of g (fiber texture). Plots:plot_rings,plot_phase,plot_orientationandplot_angle_distribution. Orientation colors use the same perceptually uniform hue as the rest of ACOM (array_to_rgba), with brightness from the row intensity, and angles follow the quantEM conventionatan2(g_col, g_row).Crystaldrops the aseSpacegroupobject that the ase CIF reader andase.spacegroup.crystalleave inatoms.info, whether it is built withfrom_ciforfrom_ase; the caller's structure is left as it was. Crystal finds the space group itself (Crystal.spacegroup), so it holds only native data, and saving a crystal or crystal map no longer warns "Not saving non-JSON-serializable entries of atoms.info".OrientationMap.in_plane_angle_degmeasured from the column axis toward the row axis, so a crystal rotated by t about the beam (quat_from_zone_axis(..., in_plane_deg=t)) read 90 - t. It now returnsatan2(a_col, a_row), from the row axis toward the column axis, the sense of a right-handed rotation about the beam and the convention of the calibration, the orientation matching andSystematicRowMap. A numericdirectioninipf_colorandplot_orientation_mapfollows the same convention (0 is "r", 90 is "c"), as doesfold_in_plane.plot_cluster_pole_figurewas drawn with the row axis horizontal and the column axis upward, 90 degrees fromplot_pole_figure; both now use the image frame (column rightward, row downward) with the same scan-axes glyph. Saved in-plane angle maps and cluster pole figures from earlier versions will change.LocalFFTandSystematicRowMap, and a rotation-sense check in the existing in-plane fold test.Validation (notebook, not in the repo)
HRTEM image of LiF and Li2O recorded by Guoliang Hu, 300 kV, 4096 x 4096 pixels of 0.355 Å. We used a resolution of 20 Å (112 pixel window, 40 Å diameter) and a step of 28 pixels, giving 143 x 143 windows.
What should the reviewer(s) do
Review the new
LocalFFTandSystematicRowMapclasses and merge.Written by Colin Ophus and Claude (Claude Code).