Metadata-Version: 2.5
Name: torch-ctf-estimation
Version: 0.6.0rc2
Summary: Contrast transfer function estimation for cryo-EM images in PyTorch
Project-URL: homepage, https://github.com/teamtomo/teamtomo
Project-URL: repository, https://github.com/teamtomo/teamtomo
Author-email: Alister Burt <alisterburt@gmail.com>, Josh Dickerson <jdickerson@berkeley.edu>
License: BSD-3-Clause
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: einops
Requires-Dist: numpy
Requires-Dist: pydantic<3,>=2.0
Requires-Dist: scipy
Requires-Dist: teamtomo-basemodel
Requires-Dist: torch
Requires-Dist: torch-ctf
Requires-Dist: torch-cubic-spline-grids
Requires-Dist: torch-fourier-filter
Requires-Dist: torch-fourier-rescale
Requires-Dist: torch-grid-utils
Requires-Dist: torch-image-interpolation
Requires-Dist: torchvision
Provides-Extra: plot
Requires-Dist: matplotlib; extra == 'plot'
Description-Content-Type: text/markdown

# torch-ctf-estimation

Contrast transfer function estimation for cryo-EM images in PyTorch.

## Overview

`torch-ctf-estimation` fits defocus, astigmatism, and (optionally) sample
thickness from a micrograph power spectrum.

- 1D defocus on the mean spectrum, then 2D defocus / astigmatism on patches
- Spatial defocus as a spline grid or a linear tilt model
- 1D thickness grid search against a thickness-modulated CTF, with optional
  joint defocus+thickness refinement (1D scalar or 2D field)
- Laser phase plate (LPP) CTF support via `torch-ctf`

This package is the algorithm: `estimate_ctf` (defocus only) and
`estimate_ctf_and_thickness` (defocus + thickness) are self-contained
compositions of the lower-level primitives, usable directly from notebooks,
tests, or another program. Downstream tools can chain these primitives
differently and add optics / metrics file I/O.

## Installation

This package is part of the [TeamTomo monorepo](https://github.com/teamtomo/teamtomo).
See the main repository README for development setup instructions.

## Usage

```python
import torch
from torch_ctf_estimation import estimate_ctf
from torch_ctf_estimation.models import CTFFittingParams, OpticalParams

image = torch.randn(1024, 1024)
optical = OpticalParams(
    pixel_spacing_angstroms=1.0,
    voltage_kev=300.0,
    spherical_aberration_mm=2.7,
    amplitude_contrast_fraction=0.07,
)
fitting = CTFFittingParams(
    defocus_grid_resolution=(1, 3, 3),
    frequency_fit_range_angstroms=(30.0, 5.0),
    defocus_range_microns=(0.5, 5.0),
    patch_sidelength=128,
)
mean_ps, result1d, result2d = estimate_ctf(image, optical, fitting)
```

To also estimate sample thickness, use `estimate_ctf_and_thickness` with a
`ThicknessParams`:

```python
from torch_ctf_estimation import estimate_ctf_and_thickness
from torch_ctf_estimation.models import ThicknessParams

thickness = ThicknessParams(refine_dim="2d")
result = estimate_ctf_and_thickness(image, optical, fitting, thickness)
result.result2d, result.thickness1d, result.thickness_joint
```
