-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Density compensation #66
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c5cbf2a
feat: refactor density compensation to a module.
paquiteau 67979eb
feat: add decorator to flatten trajectories.
paquiteau 5f324a9
feat: add ultra fast cell counting method.
paquiteau 21c1082
refactor: use the flat_traj decorator.
paquiteau 7481b63
refactor: make pipe a classmethod.
paquiteau ab99858
fix: special case for 2d trajectories.
paquiteau 9d4e060
feat: enforce common api for density compensation functions.
paquiteau 6ab996e
feat: move density module up.
paquiteau c4d3369
feat(density): add test.
paquiteau 47b1a39
feat(cufinufft)!: drop pipe implementation and follow upstream.
paquiteau 1a794dd
fix: update module level for density.
paquiteau 0eb2293
fix: cleanup
paquiteau 784a45c
feat(ci): Install most recent cufinufft
paquiteau 50848d8
fix(ci): copy libcufinufft.so at the right place.
paquiteau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no
pip install
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the development of cufinufft is very active, I prefer to track directly the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might also need to test against the latest release version as that's what users use.