From 7532ba6e2751e30ef2caf555a64235f7f490f70e Mon Sep 17 00:00:00 2001 From: wtclarke Date: Thu, 2 Nov 2023 16:26:06 +0000 Subject: [PATCH] Minor bug fixes in sequence to allow plotting to work with show_blocks = True. Allow all uses for gauss pulse. Tests for both. --- pypulseq/Sequence/sequence.py | 2 +- pypulseq/make_gauss_pulse.py | 10 +++++----- pypulseq/tests/test_make_gauss_pulse.py | 22 ++++++++++++++++++++++ pypulseq/tests/test_sequence.py | 23 +++++++++++++++++++++++ 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 pypulseq/tests/test_make_gauss_pulse.py create mode 100644 pypulseq/tests/test_sequence.py diff --git a/pypulseq/Sequence/sequence.py b/pypulseq/Sequence/sequence.py index 5ba0654..645a0eb 100755 --- a/pypulseq/Sequence/sequence.py +++ b/pypulseq/Sequence/sequence.py @@ -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) diff --git a/pypulseq/make_gauss_pulse.py b/pypulseq/make_gauss_pulse.py index fe58fa4..ec1b7b6 100755 --- a/pypulseq/make_gauss_pulse.py +++ b/pypulseq/make_gauss_pulse.py @@ -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( @@ -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 ------- @@ -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: diff --git a/pypulseq/tests/test_make_gauss_pulse.py b/pypulseq/tests/test_make_gauss_pulse.py new file mode 100644 index 0000000..4313a14 --- /dev/null +++ b/pypulseq/tests/test_make_gauss_pulse.py @@ -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) diff --git a/pypulseq/tests/test_sequence.py b/pypulseq/tests/test_sequence.py new file mode 100644 index 0000000..bdbfd55 --- /dev/null +++ b/pypulseq/tests/test_sequence.py @@ -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