Skip to content

tools.igrog: non-Cartesian samples moved onto the grid by closed-form GRAPPA kernels (iGROG) - #170

Merged
mcencini merged 1 commit into
mainfrom
claude/project-thread-2eaqzo
Nov 4, 2026
Merged

mcencini merged 1 commit into
mainfrom
claude/project-thread-2eaqzo

Conversation

@mcencini

@mcencini mcencini commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Requested by Matteo · project thread

What changed

New bartorch.tools.igrog(kspace, traj, shape, calib, *, group=, sources=3, lam=1e-3, spacing=1.0, reach=4, upsample=8, batch=65536, device=None). It moves each non-Cartesian sample to its nearest grid point with a Wiener (closed-form) GRAPPA kernel over sources readout samples and all coils. The kernel comes from the calibration's coil cross-correlation, which is tabulated once and interpolated. There can be one calibration per group of shots, and the kernels are solved in batches on device. It returns the gridded values, their flat grid index, source shot/sample, the noise gain, and weights(), which whiten the values. The output feeds linop.CartesianSense(positions=), which is already released.

Why

mri2qmap-bartorch's default chain grids with iGROG. Until now that came from fast-encoding, which is unreleased and needs a locally built library. This PR ports fast-encoding's PyTorch path so the chain runs from wheels.

Validation

  • tests/test_igrog.py: on a 2-D smooth object with 6 coils, the gridded samples match the exact k-space at their grid points to 0.3 % relative error (asserted < 2 %). Leaving each sample where it is gives 21 %. A second test checks per-group calibrations and the scale invariance of the kernels.
  • I compared the output against fast-encoding's grid(..., backend="torch"): the index is identical, and the max values and noise differ by 0.0.
  • ruff check/ruff format --check, tests/test_docs.py and tests/test_docstrings.py pass against the 0.0.20 wheel with this module dropped in. These were CPU-only runs; there was no card in this container.

Documentation impact

docs/api/tools.md lists igrog under sampling.


Generated by Claude Code

… GRAPPA kernels (iGROG)

Wiener kernels from the calibration's coil cross-correlation, tabulated once and
interpolated; one calibration per group of shots; kernels solved in batches on a
given device. Its gridded samples feed CartesianSense(positions=). Ported from
fast-encoding's PyTorch path (identical output), so mri2qmap needs no locally built
library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MFB6QLjhTxFMFDEzathbEm
@mcencini mcencini self-assigned this Nov 4, 2026
@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.80000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/bartorch/tools/_igrog.py 96.77% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mcencini
mcencini merged commit cb66c41 into main Nov 4, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants