Skip to content
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

Display 3D trajectories, with a grid interface #193

Open
wants to merge 67 commits into
base: master
Choose a base branch
from

Conversation

chaithyagr
Copy link
Member

No description provided.

chaithyagr and others added 30 commits April 26, 2024 14:45
This add "get_interpolators_from_fieldmap", supporting both real (B0 map only) and complex (Zmap = R2* + 1j * B0map) fields
in arbitrary dimension (2D and 3D). The routine supports both numpy / cupy arrays and torch tensors on CPU and GPU,
the latter requiring cupy due to limitations in torch.histogram / torch.histogramdd (pytorch/pytorch#69519).

Calculation uses time segmentation with uniform time samples and LS coefficients (using histogram).

Based on MIRT (https://github.com/JeffFessler/mirt/blob/main/mri/mri_exp_approx.m)
and its Python porting from MIRTORCH (https://github.com/guanhuaw/MIRTorch/blob/master/mirtorch/linear/mri.py)
and SigPy (https://github.com/mikgroup/sigpy/blob/main/sigpy/mri/util.py).
Avoid torch cuda test case if cupy is not available.
remove deprecated get_grad

Co-authored-by: Chaithya G R <[email protected]>
@paquiteau
Copy link
Member

Please base yourself from master :)

@chaithyagr
Copy link
Member Author

Naa, ill wait for #180 to go in :P

@chaithyagr chaithyagr marked this pull request as ready for review September 17, 2024 13:30
@chaithyagr
Copy link
Member Author

I will get a CLI also :P

@paquiteau paquiteau linked an issue Sep 22, 2024 that may be closed by this pull request
4 tasks
@chaithyagr chaithyagr self-assigned this Nov 8, 2024
@chaithyagr chaithyagr requested a review from Daval-G November 8, 2024 15:40
@chaithyagr
Copy link
Member Author

I seemed to have forgotten to add the example. Added it now. @Daval-G you are good to go for review whenever you get time.

@Daval-G
Copy link
Collaborator

Daval-G commented Nov 13, 2024

@chaithyagr I will have a look over the week-end

Copy link
Collaborator

@Daval-G Daval-G left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bunch of useful features that will make a great addition, but please try to make their use cases clearer to the readers.

Also remember to update the __init__.py files

@@ -0,0 +1,99 @@
"""
======================
3D Trajectory Display
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3D Trajectory Display
3D Trajectory display

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why is it a GPU example ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chaithyagr Sorry I misplaced this comment, but could you answer it ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason why it's a GPU example is cause we use spread and interpolate kernels which currently is only supported on GPU backends. I'll add support for it in finufft soon

examples/GPU/example_3d_trajectory_display.py Outdated Show resolved Hide resolved
examples/GPU/example_3d_trajectory_display.py Outdated Show resolved Hide resolved
examples/GPU/example_3d_trajectory_display.py Outdated Show resolved Hide resolved
Comment on lines 42 to 51
def create_grid(grid_type, title="", **kwargs):
fig, axs = plt.subplots(3, 3, figsize=(10, 10))
for i, (name, traj) in enumerate(trajectories.items()):
grid = get_gridded_trajectory(
traj, (64, 64, 64), grid_type=grid_type, traj_params=traj_params, **kwargs
)
plot_slices(axs[:, i], grid, title=name)
plt.tight_layout()
plt.suptitle(title)
plt.show()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not provide trajectories and traj_params as arguments but keep grid_type and title ? It makes it a bit of a pain to read here and below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved title below. But I dont know if I understand you?

Comment on lines +78 to +82
data = grid_op.raw_op.adj_op(
np.tile(np.linspace(1, 10, shots.shape[1]), (shots.shape[0],)),
None,
True,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to provide actual time values ? It should be more explicit in the documentation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the output shape doesn't correspond to shape as expected when reading the documentation. I don't understand why this is part of that function since it doesn't relate to a grid

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 1 to 10 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just relative to get an understanding. Given that adjoint is not inverse, even if we give exact values, we cant expect it to be reflected the same way on image domain.
The shape would still be same as expected as we use grid_op which is set based on shape, right? Am I missing something?


Parameters
----------
shots : ndarray
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shots name isn't conventional in that part of the package

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you recommend? traj ?

Comment on lines +15 to +25
def get_gridded_trajectory(
shots: np.ndarray,
shape: Tuple,
grid_type: str = "density",
osf: int = 1,
backend: str = "gpunufft",
traj_params: dict = None,
turbo_factor: int = 176,
elliptical_samp: bool = True,
threshold: float = 1e-3,
):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, why have all of those features gathered into only one function ? Some of them are not related to grids.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please add more comments to your code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, all the features are related to gridding and how you want to "color" the trajectories on the grid.

Comment on lines +84 to +90
data = grid_op.raw_op.adj_op(
np.repeat(
np.linspace(1, 10, turbo_factor), samples.shape[0] // turbo_factor + 1
)[: samples.shape[0]],
None,
True,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem here, the output shape doesn't seem to match the documented output

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, isnt data.shape same as shape we give as input?

Comment on lines 93 to 102
if elliptical_samp:
data[
np.linalg.norm(
np.meshgrid(
*[np.linspace(-1, 1, sh) for sh in shape], indexing="ij"
),
axis=0,
)
> 1
] = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments

@@ -0,0 +1,99 @@
"""
======================
3D Trajectory Display
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why is it a GPU example ?

@chaithyagr chaithyagr requested a review from Daval-G January 13, 2025 08:36
@chaithyagr
Copy link
Member Author

@Daval-G is there something else remaining or am I missing something here?

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.

Add trajectory plotting functions from SPARKLING
4 participants