forked from mind-inria/mri-nufft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Density compensation (mind-inria#66)
* feat: refactor density compensation to a module. * feat: add decorator to flatten trajectories. * feat: add ultra fast cell counting method. * refactor: use the flat_traj decorator. * refactor: make pipe a classmethod. * fix: special case for 2d trajectories. * feat: enforce common api for density compensation functions. * feat: move density module up. * feat(density): add test. * feat(cufinufft)!: drop pipe implementation and follow upstream. * fix: update module level for density. * fix: cleanup * feat(ci): Install most recent cufinufft * fix(ci): copy libcufinufft.so at the right place.
- Loading branch information
1 parent
f4e0a1f
commit 0ee9976
Showing
13 changed files
with
274 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Density compensation methods.""" | ||
from .geometry_based import voronoi, voronoi_unique, cell_count | ||
from .nufft_based import pipe | ||
|
||
|
||
__all__ = ["voronoi", "voronoi_unique", "pipe", "cell_count"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Density compensation weights using the NUFFT-based methods.""" | ||
|
||
from mrinufft import get_operator | ||
from .utils import flat_traj | ||
|
||
|
||
@flat_traj | ||
def pipe(traj, shape, backend="cufinufft", **kwargs): | ||
"""Compute the density compensation weights using the pipe method. | ||
Parameters | ||
---------- | ||
traj: array_like | ||
array of shape (M, 2) or (M, 3) containing the coordinates of the points. | ||
shape: array_like | ||
array of shape (2,) or (3,) containing the size of the grid. | ||
backend: str | ||
backend to use for the computation. Either "cufinufft" or "tensorflow". | ||
""" | ||
nufft_class = get_operator(backend) | ||
if hasattr(nufft_class, "pipe"): | ||
return nufft_class.pipe(traj, shape, **kwargs) | ||
raise ValueError("backend does not have pipe iterations method.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Utilities for density compensation.""" | ||
from functools import wraps | ||
|
||
import numpy as np | ||
|
||
from mrinufft.operators import proper_trajectory | ||
|
||
|
||
def flat_traj(normalize="unit"): | ||
"""Decorate function to ensure that the trajectory is flatten before calling.""" | ||
|
||
def decorator(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
args = list(args) | ||
args[0] = proper_trajectory(args[0], normalize=normalize) | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
if callable(normalize): # call without argument | ||
func = normalize | ||
normalize = "unit" | ||
return decorator(func) | ||
else: | ||
return decorator | ||
|
||
|
||
def normalize_weights(weights): | ||
"""Normalize samples weights to reflect their importance. | ||
Higher weights have lower importance. | ||
""" | ||
inv_weights = np.sum(weights) / weights | ||
return inv_weights / (np.sum(inv_weights)) |
Oops, something went wrong.