Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

torch-2dtm

License PyPI Python Version CI codecov

Overview

torch-2dtm is a Python package for efficient templating matching of 2D projections of a 3D template with a 2D image in PyTorch.

This is implemented for cryo-EM applications, see Rickgauer et al. 2017 eLife for details.

Features

  • Fast 2D template matching using Fourier transforms
  • Batch processing over orientations
  • Batch processing over Fourier space filters (e.g. for defocus sweeps)
  • GPU acceleration through PyTorch

Projections are calculated on-the-fly using torch-fourier-slice.

Installation

pip install torch-2dtm

Basic Usage

import torch
import torch_2dtm
from scipy.stats import special_ortho_group

# Create random test data
# 1. Create a random image and compute its FFT
image_size = (128, 128)
image = torch.randn(*image_size, dtype=torch.float32)
image_dft = torch.fft.rfftn(image, dim=(0, 1))  # Shape: (128, 65)

# 2. Create a random 3D template and compute its FFT
template_size = (64, 64, 64)
template = torch.randn(*template_size, dtype=torch.float32)
template_dft = torch.fft.rfftn(template, dim=(0, 1, 2))  # Shape: (64, 64, 33)

# 3. Create a batch of random rotation matrices with shape (b, 3, 3)
num_orientations = 10
rotation_matrices = torch.tensor(special_ortho_group.rvs(size=num_orientations, dim=3), dtype=torch.float32)

# 4. Create an arbitrary stack of Fourier space filters (identity filter in this example)
# These filters operate on rffts of the 2D projection images
# Filter shape: (..., h, w // 2 + 1)
filters = torch.ones(template_size[0], template_size[1] // 2 + 1, dtype=torch.complex64)

# Perform template matching
cross_correlation = torch_2dtm.match_template_dft_2d(
    image_dft=image_dft,
    template_dft=template_dft,
    rotation_matrices=rotation_matrices,
    filters=filters
)
# The result has shape (..., num_orientations, image_height, image_width)

License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

Metadata

Release files for torch-2dtm 0.6.0rc2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torch-2dtm 0.6.0rc2
File Size Uploaded
torch_2dtm-0.6.0rc2.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for torch-2dtm 0.6.0rc2
File Interpreter ABI Platform
torch_2dtm-0.6.0rc2-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / torch_2dtm-0.6.0rc2.tar.gz

Download URL torch_2dtm-0.6.0rc2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0b764c4e430199ea7afc2bf71bf1d13baa0f392aa53cde14a7373fbfca2976b6
BLAKE2b-256 checksum
How to use checksums
12d35814ea56e8887819cbad419be48c41bdbb5e8a796a4e5f7271a03306a852
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

Release files / torch_2dtm-0.6.0rc2-py3-none-any.whl

Download URL torch_2dtm-0.6.0rc2-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a03a55b1864e4c9ec78960630761a8ab2f68cf0ea1073ea870bfd1be0c13969c
BLAKE2b-256 checksum
How to use checksums
6d53b22fc5004d63c17a238d420c8ad344c6ff011e8c86e1aca03328fbc515ae
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
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page