-
Notifications
You must be signed in to change notification settings - Fork 1
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
A couple of enhancements for MPRAGE #3
Open
chaithyagr
wants to merge
3
commits into
INFN-MRI:main
Choose a base branch
from
chaithyagr:new_mprage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,8 @@ def set_sequence( | |
flip: float, | ||
TRspgr: float, | ||
nshots: int | npt.ArrayLike, | ||
TRmprage: float = None, | ||
num_inversions: int = 1, | ||
): | ||
""" | ||
Set sequence parameters for the SPGR model. | ||
|
@@ -88,13 +90,15 @@ def set_sequence( | |
Flip angle train in degrees. | ||
TRspgr : float | ||
Repetition time in milliseconds for each SPGR readout. | ||
TRmprage : float | ||
TRmprage : float default is None | ||
Repetition time in milliseconds for the whole inversion block. | ||
nshots : int | npt.ArrayLike | ||
Number of SPGR readout within the inversion block of shape ``(npre, npost)`` | ||
If scalar, assume ``npre == npost == 0.5 * nshots``. Usually, this | ||
is the number of slice encoding lines ``(nshots = nz / Rz)``, | ||
i.e., the number of slices divided by the total acceleration factor along ``z``. | ||
num_inversions : int, optional | ||
Number of inversion pulses, default is ``1``. | ||
|
||
""" | ||
self.sequence.nshots = nshots | ||
|
@@ -104,6 +108,10 @@ def set_sequence( | |
if nshots.numel() == 1: | ||
nshots = torch.repeat_interleave(nshots // 2, 2) | ||
self.sequence.nshots = nshots | ||
self.sequence.TRmprage = TRmprage * 1e-3 # ms -> s | ||
if TRmprage is None and num_inversions > 1: | ||
raise ValueError("TRmprage must be provided for multiple inversions") | ||
self.sequence.num_inversions = num_inversions | ||
|
||
@staticmethod | ||
def _engine( | ||
|
@@ -115,6 +123,7 @@ def _engine( | |
nshots: int | npt.ArrayLike, | ||
M0: float | npt.ArrayLike = 1.0, | ||
inv_efficiency: float | npt.ArrayLike = 1.0, | ||
num_inversions: int = 1, | ||
): | ||
R1 = 1e3 / T1 | ||
|
||
|
@@ -135,21 +144,26 @@ def _engine( | |
|
||
# Prepare relaxation operator for sequence loop | ||
E1, rE1 = epg.longitudinal_relaxation_op(R1, TRspgr) | ||
if TRmprage is not None: | ||
mprageE1, mpragerE1 = epg.longitudinal_relaxation_op(R1, TRmprage) | ||
|
||
# Apply inversion | ||
states = epg.adiabatic_inversion(states, inv_efficiency) | ||
states = epg.longitudinal_relaxation(states, E1inv, rE1inv) | ||
states = epg.spoil(states) | ||
|
||
signal = [] | ||
# Scan loop | ||
for p in range(nshots_bef): | ||
|
||
# Apply RF pulse | ||
states = epg.rf_pulse(states, RF) | ||
|
||
# Evolve | ||
states = epg.longitudinal_relaxation(states, E1, rE1) | ||
for i in range(num_inversions): | ||
# Apply inversion | ||
states = epg.adiabatic_inversion(states, inv_efficiency) | ||
states = epg.longitudinal_relaxation(states, E1inv, rE1inv) | ||
states = epg.spoil(states) | ||
|
||
|
||
for p in range(nshots_bef*2): | ||
|
||
# Apply RF pulse | ||
states = epg.rf_pulse(states, RF) | ||
# Evolve | ||
states = epg.longitudinal_relaxation(states, E1, rE1) | ||
signal.append(M0 * 1j * epg.get_signal(states)) | ||
states = epg.spoil(states) | ||
if TRmprage is not None: | ||
epg.longitudinal_relaxation(states, mprageE1, mpragerE1) | ||
# Record signal | ||
return M0 * 1j * epg.get_signal(states) | ||
return torch.stack(signal) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe move |
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.
If we want to store magnetization for each spgr shot (e.g., to study signal modulation in k-space or for contrast-resolved reconstruction), it is better to use torchsim.models.MPnRAGEModel.