This release is a pre-release and may not be stable for production use.
torch-tiltxcorr
Cross correlation with image stretching for coarse alignment of cryo-EM tilt series data in PyTorch.
Overview
torch-tiltxcorr reimplements the IMOD program tiltxcorr in PyTorch.
Installation
pip install torch-tiltxcorr
Usage
import torch
from torch_fourier_shift import fourier_shift_image_2d
from torch_tiltxcorr import tiltxcorr
# Load or create your tilt series
# tilt_series shape: (batch, height, width) - batch is number of tilt images
# Example: tilt_series with shape (61, 512, 512) - 61 tilt images of 512x512 pixels
tilt_series = torch.randn(61, 512, 512)
# Define tilt angles (in degrees)
# Shape: (batch,) - one angle per tilt image
tilt_angles = torch.linspace(-60, 60, steps=61)
# Define tilt axis angle (in degrees)
tilt_axis_angle = 45
# Run tiltxcorr
# (for noisy cryo-EM data, apply a lowpass to ~4x pixel size as a starting point)
shifts = tiltxcorr(
tilt_series=tilt_series,
tilt_angles=tilt_angles,
tilt_axis_angle=tilt_axis_angle,
pixel_spacing_angstroms=10,
lowpass_angstroms=40,
)
# shifts shape: (batch, 2) - (dy, dx) shifts which center each tilt image
# Apply shifts to align the tilt series
aligned_tilt_series = fourier_shift_image_2d(tilt_series, shifts=shifts)
# aligned_tilt_series shape: (batch, height, width)
Use uv to run an example with simulated data and visualize the results.
uv run examples/tiltxcorr_example_simulated_data.py
How It Works
torch-tiltxcorr performs coarse tilt series alignment by:
- Sorting images by tilt angle
- Dividing the series into groups of positive and negative tilt angles
- For each adjacent pair of images in each group:
- Applying a stretch perpendicular to the tilt axis on the image with the larger tilt angle
- Calculating cross-correlation between the images
- Extracting the shift from the position of the correlation peak
- Transforming the shift to account for the stretch applied to the image
- Accumulating shifts to align the entire series
With Sample Tilt Estimation
If a sample is physically rotated +5° around the microscope stage tilt axis, then at nominal 0° stage tilt the beam sees the sample at +5°.
This offset affects the correlations measured by tiltxcorr. By finding the offset value that maximizes total correlation, we can estimate the true physical pre-tilt of the sample around the microscope tilt axis.
import torch
from torch_fourier_shift import fourier_shift_image_2d
from torch_tiltxcorr import tiltxcorr_with_sample_tilt_estimation
# Load or create your tilt series
tilt_series = torch.randn(61, 512, 512)
tilt_angles = torch.linspace(-60, 60, steps=61)
tilt_axis_angle = 45
# Run tiltxcorr with sample tilt estimation
# (for noisy cryo-EM data, apply a lowpass to ~4x pixel size as a starting point)
shifts, sample_tilt = tiltxcorr_with_sample_tilt_estimation(
tilt_series=tilt_series,
tilt_angles=tilt_angles,
tilt_axis_angle=tilt_axis_angle,
pixel_spacing_angstroms=10,
lowpass_angstroms=40,
sample_tilt_range=(-30.0, 30.0), # search range in degrees
)
# shifts shape: (batch, 2) tensor of (dy, dx) shifts which center each tilt image
# sample_tilt: float value for component of sample tilt about the stage in degrees
# Apply shifts to align the tilt series
aligned_tilt_series = fourier_shift_image_2d(tilt_series, shifts=shifts)
License
This package is distributed under the BSD 3-Clause License.
Metadata
Release files for torch-tiltxcorr 0.6.0rc2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torch_tiltxcorr-0.6.0rc2.tar.gz | 13.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torch_tiltxcorr-0.6.0rc2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.6 kB
Release files / torch_tiltxcorr-0.6.0rc2.tar.gz
| Download URL | torch_tiltxcorr-0.6.0rc2.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0580a0dc976ce29dfd96aa965050675b56fc1e81b6e583125dd72e6d69bd3a97
|
|
BLAKE2b-256 checksum How to use checksums |
66f7188bfbd185334e97306637a1a1ddd8e0dea3c16e408c5423f7c7bd2bb4c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.
Transparency logRelease files / torch_tiltxcorr-0.6.0rc2-py3-none-any.whl
| Download URL | torch_tiltxcorr-0.6.0rc2-py3-none-any.whl |
|---|---|
| Size | 13.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8f542a4ca58b64c2613703b14d1b5b8a8c181c46443421fb13ca394674ad9f5f
|
|
BLAKE2b-256 checksum How to use checksums |
c2340c933c994dba33fd121201d82ae09636d2ae5f2d8978cd02a5e7b45de635
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.
Transparency log