run

Contents

run#

pypulseqpp.cli.run()[source]#

Run a sequence script’s main from the command line.

Every keyword parameter of main annotated with a scalar becomes an option, described by what main’s own docstring says about it. Five names are answered here instead: plot, test_report, write_seq and seq_filename, which are the calling convention rather than the prescription, and system, which is built from the limit options.

Parameters:
  • main (callable) – The script’s entry point. Returns the sequence.

  • argv (list of str, default=None) – The arguments, without the program name. sys.argv[1:] when omitted.

  • description (str, default=None) – What --help says the script does. The first line of main’s docstring when omitted.

  • default_output (str, default='sequence.seq') – Where to write when --output is not given.

Returns:

The exit status: zero when the sequence was written.

Return type:

int

Notes

The sequence main returns is written to --output with pypulseqpp.io.write(), in binary form under --binary. The main of a SequenceApp subclass instead writes the application’s chain of prescan and main-sequence files through write().

Examples

>>> import pypulseqpp as pp
>>> from pypulseqpp.cli import run
>>> def main(write_seq: bool = False, seq_filename: str = "x.seq",
...          *, n_x: int = 128, tr: float | None = None) -> pp.Sequence:
...     '''One line.
...
...     Parameters
...     ----------
...     n_x : int, optional
...         Readout samples.
...     tr : float or None, optional
...         Repetition time, in seconds.
...     '''
...     return pp.Sequence()

The options are the function’s parameters, described by its docstring:

>>> import contextlib, io
>>> text = io.StringIO()
>>> with contextlib.redirect_stdout(text), contextlib.suppress(SystemExit):
...     run(main, ["--help"])
>>> "--n-x" in text.getvalue(), "Readout samples." in text.getvalue()
(True, True)