From b80141febc17f1d561c2ec0842c577bffdab0459 Mon Sep 17 00:00:00 2001 From: Patrick Schuenke <37338697+schuenke@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:31:09 +0100 Subject: [PATCH] Fix trajectory scaling in KTrajectoryPulseq (#551) Co-authored-by: Felix F Zimmermann --- .../data/traj_calculators/KTrajectoryPulseq.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/mrpro/data/traj_calculators/KTrajectoryPulseq.py b/src/mrpro/data/traj_calculators/KTrajectoryPulseq.py index 7c843572d..598aa2184 100644 --- a/src/mrpro/data/traj_calculators/KTrajectoryPulseq.py +++ b/src/mrpro/data/traj_calculators/KTrajectoryPulseq.py @@ -54,13 +54,18 @@ def __call__(self, kheader: KHeader) -> KTrajectoryRawShape: raise ValueError('We currently only support constant number of samples') n_k0 = int(n_samples.item()) - def reshape_pulseq_traj(k_traj: torch.Tensor, encoding_size: int): - k_traj *= encoding_size / (2 * torch.max(torch.abs(k_traj))) + def rescale_and_reshape_traj(k_traj: torch.Tensor, encoding_size: int): + if encoding_size > 1 and torch.max(torch.abs(k_traj)) > 0: + k_traj = k_traj * encoding_size / (2 * torch.max(torch.abs(k_traj))) + else: + # We force k_traj to be 0 if encoding_size = 1. This is typically the case for kz in 2D sequences. + # However, it happens that seq.calculate_kspace() returns values != 0 (numerical noise) in such cases. + k_traj = torch.zeros_like(k_traj) return rearrange(k_traj, '(other k0) -> other k0', k0=n_k0) # rearrange k-space trajectory to match MRpro convention - kx = reshape_pulseq_traj(k_traj_adc[0], kheader.encoding_matrix.x) - ky = reshape_pulseq_traj(k_traj_adc[1], kheader.encoding_matrix.y) - kz = reshape_pulseq_traj(k_traj_adc[2], kheader.encoding_matrix.z) + kx = rescale_and_reshape_traj(k_traj_adc[0], kheader.encoding_matrix.x) + ky = rescale_and_reshape_traj(k_traj_adc[1], kheader.encoding_matrix.y) + kz = rescale_and_reshape_traj(k_traj_adc[2], kheader.encoding_matrix.z) return KTrajectoryRawShape(kz, ky, kx, self.repeat_detection_tolerance)