Skip to content

Commit 86140df

Browse files
committed
feat: add pypulseq reader
1 parent 79dcf6c commit 86140df

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pynufft = ["pynufft"]
2727
pynufft-cpu = ["pynufft"]
2828
pynufft-gpu = ["pynufft"]
2929

30-
io = ["pymapvbvd"]
30+
io = ["pymapvbvd", "pypulseq"]
3131
smaps = ["scikit-image"]
3232
extra = ["pymapvbvd", "scikit-image", "scikit-learn", "pywavelets"]
3333
autodiff = ["torch"]

src/mrinufft/io/pulseq.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Pulseq Trajectory Reader and writers.
2+
3+
Reads Pulseq `.seq` files to extract k-space trajectory and other parameters. It also provides functionality to create pulseq block and shape objects to
4+
facilitate the integration of arbitrary k-space trajectories into Pulseq
5+
sequences. Requires the `pypulseq` package to be installed.
6+
"""
7+
8+
import numpy as np
9+
import pypulseq as pp
10+
11+
12+
def read_pulseq_traj(filename):
13+
"""Extract k-space trajectory from a Pulseq sequence file.
14+
15+
The sequence should be a valid Pulseq `.seq` file, with arbitrary gradient
16+
waveforms, which all have the same length.
17+
18+
Unlike `Sequence.calculate_kspace`, this function returns the k-space
19+
trajectory segmented in shots ("blocks" from Pulseq), and works directly
20+
from the gradients waveforms stored in the `.seq` file.
21+
22+
Parameters
23+
----------
24+
filename : str
25+
Path to the Pulseq `.seq` file.
26+
27+
Returns
28+
-------
29+
description : dict
30+
the [DESCRIPTION] block from the sequence file.
31+
np.ndarray
32+
The k-space trajectory as a numpy array of shape (n_shots, n_samples, 3),
33+
where the last dimension corresponds to the x, y, and z coordinates in k-space.
34+
35+
"""
36+
37+
seq = pp.Sequence()
38+
seq.read(filename)
39+
40+
41+
gradient_waveforms = seq.waveforms()

0 commit comments

Comments
 (0)