From 396286b2b386fed2ed4f172ca56b422675e35fe2 Mon Sep 17 00:00:00 2001 From: Colin Ophus Date: Sun, 18 Oct 2026 14:04:46 -0700 Subject: [PATCH 1/2] tomo_6d: use intrinsic ZXZ Euler angles everywhere --- src/quantem/diffraction/full_diffraction_tomography.py | 7 ++++--- src/quantem/diffraction/show_diffraction_patterns.py | 2 +- src/quantem/diffraction/simulate_diffraction_tomography.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/quantem/diffraction/full_diffraction_tomography.py b/src/quantem/diffraction/full_diffraction_tomography.py index 6eb473850..e1f97d2cb 100644 --- a/src/quantem/diffraction/full_diffraction_tomography.py +++ b/src/quantem/diffraction/full_diffraction_tomography.py @@ -344,7 +344,7 @@ def _rotate_complex_volume_zxz( kx, ky, kz = cls._make_reciprocal_grids(shape, dk) k_grid = torch.stack(torch.broadcast_tensors(kx, ky, kz), axis=-1) - rot = Rotation.from_euler("zxz", zxz) + rot = Rotation.from_euler("ZXZ", zxz) k_source = rot.inv().apply(k_grid.reshape(-1, 3)).reshape(*volume.shape, 3) coords = torch.stack( [ @@ -1158,11 +1158,12 @@ def projection_axes( `u_proj` is the fast-scan direction, `v_proj` the slow-scan direction, and `w_proj` the beam direction. The sample is rotated by the given - ZXZ Euler angles relative to the (lab, beam-down-z) frame; the lab + intrinsic Z-X-Z (Bunge) Euler angles, scipy "ZXZ", relative to + the (lab, beam-down-z) frame; the lab axes (1,0,0), (0,1,0), (0,0,1) are then expressed in the sample frame. """ zxz_arr = self._resolve_zxz_deg(tilt_x_deg, zxz_deg) - rot = Rotation.from_euler("zxz", zxz_arr, degrees=True) + rot = Rotation.from_euler("ZXZ", zxz_arr, degrees=True) # Lab→sample mapping: apply the inverse rotation to lab basis vectors. u_proj = torch.tensor(rot.inv().apply([1.0, 0.0, 0.0])) v_proj = torch.tensor(rot.inv().apply([0.0, 1.0, 0.0])) diff --git a/src/quantem/diffraction/show_diffraction_patterns.py b/src/quantem/diffraction/show_diffraction_patterns.py index 915d0281c..37b714451 100644 --- a/src/quantem/diffraction/show_diffraction_patterns.py +++ b/src/quantem/diffraction/show_diffraction_patterns.py @@ -195,7 +195,7 @@ def show_view(tilt_idx, power, vmin, vmax): if disp_vmax <= disp_vmin: disp_vmax = disp_vmin + 1e-12 - R_sample = Rotation.from_euler("zxz", [0.0, tilt, 0.0], degrees=True) + R_sample = Rotation.from_euler("ZXZ", [0.0, tilt, 0.0], degrees=True) fs = figsize if figsize is not None else ((11, 5.5) if show_3d else (5.5, 5.5)) fig = plt.figure(figsize=fs, dpi=dpi) diff --git a/src/quantem/diffraction/simulate_diffraction_tomography.py b/src/quantem/diffraction/simulate_diffraction_tomography.py index 29df8221a..855531640 100644 --- a/src/quantem/diffraction/simulate_diffraction_tomography.py +++ b/src/quantem/diffraction/simulate_diffraction_tomography.py @@ -84,7 +84,7 @@ def _make_au_structure_factor( amp_scale = 1j * phase_scale rot = ( - Rotation.from_euler("zxz", torch.tensor(zxz_deg, dtype=torch.float32), degrees=True) + Rotation.from_euler("ZXZ", torch.tensor(zxz_deg, dtype=torch.float32), degrees=True) if zxz_deg is not None else None ) From 52bad7a925f8542d34d7de950adf60927741c624 Mon Sep 17 00:00:00 2001 From: Colin Ophus Date: Sun, 18 Oct 2026 14:19:51 -0700 Subject: [PATCH 2/2] Import the anywidget viewers lazily so quantem imports without the widgets extra --- src/quantem/diffraction/__init__.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/quantem/diffraction/__init__.py b/src/quantem/diffraction/__init__.py index 60d1e7e95..80a0e9651 100644 --- a/src/quantem/diffraction/__init__.py +++ b/src/quantem/diffraction/__init__.py @@ -1,9 +1,6 @@ from quantem.diffraction.diffraction_tomography import ( DiffractionTomography as DiffractionTomography, ) -from quantem.diffraction.show_diffraction_tomography import ( - show_diffraction_tomography as show_diffraction_tomography, -) from quantem.diffraction.show_diffraction_tilts import ( show_diffraction_tilts as show_diffraction_tilts, ) @@ -15,9 +12,23 @@ from quantem.diffraction.simulate_diffraction_tomography import ( SimDiffractionTomography as SimDiffractionTomography, ) -from quantem.diffraction.show_diffraction_tomography_6d import ( - DiffractionTomographyViewer as DiffractionTomographyViewer, -) from quantem.diffraction.show_diffraction_patterns import ( show_diffraction_patterns as show_diffraction_patterns, ) + +# the anywidget viewers need the optional "widgets" extra, so they are +# imported on first use rather than with the package +_LAZY = { + "show_diffraction_tomography": "quantem.diffraction.show_diffraction_tomography", + "DiffractionTomographyViewer": "quantem.diffraction.show_diffraction_tomography_6d", +} + + +def __getattr__(name): + if name in _LAZY: + import importlib + + value = getattr(importlib.import_module(_LAZY[name]), name) + globals()[name] = value + return value + raise AttributeError(f"module {__name__!r} has no attribute {name!r}")