Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/console/interfaces/acquisition_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def save_ismrmrd(
header=header,
sequence=self.sequence,
dataset_path=dataset_path,
channel_assignment=self.acquisition_parameters.channel_assignment,
)

log.warning("Invalid MRD header, could not write MRD file.")
Expand Down
32 changes: 29 additions & 3 deletions src/console/utilities/data/write_acquisition_to_mrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
from pypulseq.Sequence.sequence import Sequence

from console.interfaces.dimensions import Dimensions
from console.interfaces.rx_data import RxData
from console.utilities.data import get_logger, mrd_helper

Expand All @@ -17,6 +18,7 @@ def write_acquisition_to_mrd(
header: ismrmrd.xsd.ismrmrdHeader,
sequence: Sequence,
dataset_path: Path,
channel_assignment: Dimensions,
) -> Path:
"""Write imaging data to ISMRMRD."""
with ismrmrd.Dataset(dataset_path) as dataset:
Expand All @@ -25,9 +27,33 @@ def write_acquisition_to_mrd(
# Create acquisition
acq = ismrmrd.Acquisition()
acq.version = int(version("ismrmrd")[0])
acq.read_dir[0] = 1.0
acq.phase_dir[1] = 1.0
acq.slice_dir[2] = 1.0

# Set raw data orientation directions in LPS coordinates, assuming patient is lying supine, head first.
# This information is shared for all acquisitions
# The assumption is that the console output channels to physical gradient orientations are as follows
# ch output1 -> gradient from front to back (Patient: I to S)
# ch output2 -> gradient from top to bottom (Patient: P to A)
# ch output3 -> gradient from left to right (Patient: R to L)
# For LPS coordinates the direction P to A needs to be inverted, i.e., read_dir = [0,-1,0]

# Map logical gradient axes to physical directions in LPS coordinates
direction_map = {
1: (2, 1.0), # I to S -> [0, 0, 1]
2: (1, -1.0), # P to A -> [0, -1, 0] (inverted for LPS)
3: (0, 1.0), # R to L -> [1, 0, 0]
}

# Set readout direction
idx, val = direction_map[int(channel_assignment.x)]
acq.read_dir[idx] = val

# Set phase encoding direction
idx, val = direction_map[int(channel_assignment.y)]
acq.phase_dir[idx] = val

# Set slice direction
idx, val = direction_map[int(channel_assignment.z)]
acq.slice_dir[idx] = val

trajectory_position = 0
none_counter = 0
Expand Down
Loading