Skip to content

Commit

Permalink
Minor bug fixes in sequence to allow plotting to work with show_block…
Browse files Browse the repository at this point in the history
…s = True. Allow all uses for gauss pulse. Tests for both.
  • Loading branch information
wtclarke authored and btasdelen committed Nov 14, 2023
1 parent 799b3eb commit 613c31d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pypulseq/Sequence/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def plot(
if show_blocks:
for sp in [sp11, sp12, sp13, *fig2_subplots]:
sp.set_xticks(t_factor * block_edges_in_range)
sp.set_xticklabels(rotation=90)
sp.set_xticklabels(sp.get_xticklabels(), rotation=90)

for block_counter in range(len(self.block_events)):
block = self.get_block(block_counter + 1)
Expand Down
10 changes: 5 additions & 5 deletions pypulseq/make_gauss_pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pypulseq.make_delay import make_delay
from pypulseq.make_trapezoid import make_trapezoid
from pypulseq.opts import Opts
from pypulseq.supported_labels_rf_use import get_supported_rf_uses


def make_gauss_pulse(
Expand Down Expand Up @@ -73,7 +74,7 @@ def make_gauss_pulse(
time_bw_product : int, default=4
Time-bandwidth product.
use : str, default=str()
Use of radio-frequency gauss pulse event. Must be one of 'excitation', 'refocusing' or 'inversion'.
Use of radio-frequency gauss pulse event. Must be one defined in pypulseq.supported_labels_rf_use.get_supported_rf_uses.
Returns
-------
Expand All @@ -89,13 +90,12 @@ def make_gauss_pulse(
Raises
------
ValueError
If invalid `use` is passed. Must be one of 'excitation', 'refocusing' or 'inversion'.
If invalid `use` is passed.
If `return_gz=True` and `slice_thickness` was not passed.
"""
valid_use_pulses = ["excitation", "refocusing", "inversion"]
if use != "" and use not in valid_use_pulses:
if use != "" and use not in get_supported_rf_uses():
raise ValueError(
f"Invalid use parameter. Must be one of 'excitation', 'refocusing' or 'inversion'. Passed: {use}"
f"Invalid use parameter. Must be one of {get_supported_rf_uses()}. Passed: {use}"
)

if dwell == 0:
Expand Down
22 changes: 22 additions & 0 deletions pypulseq/tests/test_make_gauss_pulse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Tests for the make_gauss_pulse module
Will Clarke, University of Oxford, 2023
"""

from types import SimpleNamespace

import pytest

from pypulseq import make_gauss_pulse
from pypulseq.supported_labels_rf_use import get_supported_rf_uses


def test_use():

with pytest.raises(
ValueError,
match=r"Invalid use parameter. Must be one of"):
make_gauss_pulse(flip_angle=1, use='invalid')

for use in get_supported_rf_uses():
assert isinstance(make_gauss_pulse(flip_angle=1, use=use), SimpleNamespace)
23 changes: 23 additions & 0 deletions pypulseq/tests/test_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Tests for the make_gauss_pulse module
Will Clarke, University of Oxford, 2023
"""


from types import SimpleNamespace

import pytest
from unittest.mock import patch

from pypulseq import Sequence
from pypulseq import make_gauss_pulse


@patch("matplotlib.pyplot.show")
def test_plot(mock_show):
seq = Sequence()
seq.add_block(
make_gauss_pulse(flip_angle=1))
assert seq.plot() is None

assert seq.plot(show_blocks=True) is None

0 comments on commit 613c31d

Please sign in to comment.