Skip to content

Commit 2d3942d

Browse files
committed
fix: make pypulseq an optional dependency.
fix: remove type annonation for optional deps. Otherwise, its a mess. Acquisition Configuration (#285) * feat!: acquisition Config. This is a breaking change! * fmt: black * feat(test): use acquisition fixture for tests. * feat: docstrings * refactor!: use acq in display functions as well * fmt:black * fix: correct field name. * feat: move adc setup to acquisition level. * fix: example use the acquisition object * feat: example use acquisition. * fix: style * use correct units * fix: enum meta has evolved in python 3.12 * feat: use better default for grad raster time. * feat: more SI units and acq use * fix: don't modify API for write/read_trajectory * fmt * fix examples * update * fix: acq and display * feat: add context manager for the acquisition * update context manager * fmt: PEP604 type union fixes UP045 * [docs] update docstring for acquisition config.
1 parent 4408e6e commit 2d3942d

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/mrinufft/io/nsp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from mrinufft.io.utils import prepare_trajectory_for_seq
1212
import numpy as np
13-
from typing import Optional
1413

1514
from mrinufft.trajectories.utils import (
1615
Acquisition,

src/mrinufft/io/pulseq.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88

99
import warnings
1010
from types import SimpleNamespace
11+
1112
import numpy as np
12-
import pypulseq as pp
1313
from numpy.typing import NDArray
14-
from .utils import prepare_trajectory_for_seq
14+
1515
from mrinufft.trajectories.utils import KMAX
1616

17+
from .utils import prepare_trajectory_for_seq
18+
19+
PULSEQ_AVAILABLE = True
20+
try:
21+
import pypulseq as pp
22+
except ImportError:
23+
PULSEQ_AVAILABLE = False
24+
1725

1826
def read_pulseq_traj(seq, trajectory_delay=0.0, gradient_offset=0.0):
1927
"""Extract k-space trajectory from a Pulseq sequence file.
@@ -39,6 +47,12 @@ def read_pulseq_traj(seq, trajectory_delay=0.0, gradient_offset=0.0):
3947
The k-space trajectory as a numpy array of shape (n_shots, n_samples, 3),
4048
where the last dimension corresponds to the x, y, and z coordinates in k-space.
4149
"""
50+
if not PULSEQ_AVAILABLE:
51+
raise ImportError(
52+
"The `pypulseq` package is required for this function. "
53+
"Please install it via `pip install pypulseq` or "
54+
"`pip install mri-nufft[io]`."
55+
)
4256
if not isinstance(seq, pp.Sequence):
4357
filename = seq
4458
seq = pp.Sequence()
@@ -95,9 +109,9 @@ def pulseq_gre(
95109
rf_pulse: SimpleNamespace | None = None,
96110
rf_spoiling_inc: float = 0.0,
97111
grad_spoil_factor: float = 2.0,
98-
system: pp.Opts | None = None,
112+
system = None,
99113
osf: int = 1,
100-
) -> pp.Sequence:
114+
):
101115
"""Create a Pulseq 3D-GRE sequence for arbitrary trajectories.
102116
103117
Parameters
@@ -159,6 +173,12 @@ def pulseq_gre(
159173
pp.Sequence
160174
A Pulseq sequence object with the specified arbitrary gradient waveform.
161175
"""
176+
if not PULSEQ_AVAILABLE:
177+
raise ImportError(
178+
"The `pypulseq` package is required for this function. "
179+
"Please install it via `pip install pypulseq` "
180+
"or `pip install mri-nufft[io]`."
181+
)
162182
TR = TR / 1000.0 # convert to seconds
163183
TE = TE / 1000.0 # convert to seconds
164184
if system is None:
@@ -275,7 +295,7 @@ def pulseq_gre(
275295

276296

277297
def _pulseq_gre_2D(
278-
seq: pp.Sequence,
298+
seq,
279299
full_grads: NDArray,
280300
rf_spoiling_inc: float,
281301
adc: SimpleNamespace,
@@ -284,7 +304,7 @@ def _pulseq_gre_2D(
284304
delay_end_TR: SimpleNamespace,
285305
thickness: float,
286306
slice_locs: NDArray,
287-
) -> pp.Sequence:
307+
):
288308
"""Create a Pulseq 2D-GRE sequence for arbitrary trajectories."""
289309
rf, gz, gzr = pp.make_sinc_pulse(
290310
flip_angle=float(seq.get_definition("FA")),

0 commit comments

Comments
 (0)