`BSplineFieldTransform.to_field()` reuses the weights of its first reference
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
Direzione di ricerca
The bug is in BSplineFieldTransform.to_field() in nitransforms/nonlinear.py, which caches B-spline weights on the first call and reuses them. Start by reading that method and its cache, then run the reproduction script from the issue to confirm the stale deltas and the broadcast ValueError on the smaller reference. Done when to_field() recomputes weights for each reference and both the shifted and smaller-grid cases produce correct fields.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
to_field() computes the B-spline weights for its reference on the first call and caches them. Later calls reuse those weights whatever reference they are given.
Reproduction
import nibabel as nb
import numpy as np
from nitransforms.base import ImageGrid
from nitransforms.nonlinear import BSplineFieldTransform
def centered_grid(linear, shape):
"""Affine for a grid of given shape, centered at the origin, with given linear part"""
affine = nb.affines.from_matvec(linear, -linear @ (np.array(shape) - 1) / 2)
return nb.Nifti1Image(np.zeros(shape), affine)
# A 10 mm lattice of 10 x 10 x 10 knots, centered at the origin
knots = ImageGrid(centered_grid(np.eye(3) * 10, (10, 10, 10)))
# Set coefficient to RAS position, which is linear and so exactly representable
coeffs = knots.ndcoords.reshape(10, 10, 10, 3).astype("float32")
xfm = BSplineFieldTransform(nb.Nifti1Image(coeffs, knots.affine))
first = centered_grid(np.eye(3) * 3, (11, 11, 11))
shifted = nb.Nifti1Image(first.dataobj, nb.affines.from_matvec(np.eye(3) * 3, [-10, -12, -14]))
xfm.to_field(reference=first)
field = xfm.to_field(reference=shifted)
assert np.allclose(field._deltas.reshape(-1, 3), ImageGrid(shifted).ndcoords, atol=1e-3)
A smaller reference fails outright:
xfm.to_field(reference=centered_grid(np.eye(3) * 3, (5, 5, 5)))
ValueError: could not broadcast input array from shape (1331,) into shape (125,)
- Lingua principale
- Python
- Stelle
- 36
- Fork
- 18
- Merge medio
- 1h 24m
- PR unite (30g)
- 1
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nipy/nitransforms
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nipy/nitransforms#307 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nipy/nitransforms#306 ·
-
DenseFieldTransform bugsAperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 25/100
nipy/nitransforms#305 ·
-
`BSplineFieldTransform` ignores `order`Forse già presa @effigies l’ha presa 1 giorno fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
nipy/nitransforms#302 ·
-
`BSplineFieldTransform.to_field()` ignores the orientation of the reference gridForse già presa @effigies l’ha presa 1 giorno fa. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 45/100
nipy/nitransforms#300 ·
Tutte le issue di nipy/nitransforms
Issue simili
-
eegprep-lean: set channel types from the Zarr group's channel_typeForse già presa @claude l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
sccn/eegprep#668 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Upgrade Django to 5.2.18Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
blacklanternsecurity/bbot#3679 ·
I maintainer di solito rispondono entro 2 giorni
-
Link Checker ReportApertaBot Type: Bug Type: Documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
speakeasy-api/speakeasy#2159 ·
I maintainer di solito rispondono entro 1 giorno