make_traversal_order

make_traversal_order#

pypulseqpp.make_traversal_order()[source]#

Return the order in which a loop visits n positions.

The result is a permutation p of range(n): the loop visits position p[0] first, p[1] second, and so on. The positions are abstract indices, typically slices, or the entries of a list of selected lines or partitions; [items[i] for i in p] reorders such a list.

Parameters:
  • n (int) – Number of positions.

  • order ({'sequential', 'reverse', 'interleaved', 'center_out', 'outside_in', 'random'}, default='sequential') – Traversal scheme. 'interleaved' visits the even positions and then the odd ones, the conventional multi-slice order. 'center_out' starts at the middle position and alternates outward, the lower position first on a tie; 'outside_in' is its reverse. 'random' is a seeded random permutation.

  • seed (int, default=0) – Seed for order='random'.

Returns:

Integer permutation of range(n), in visiting order.

Return type:

numpy.ndarray

Raises:

ValueError – If n is negative or order is unknown.

See also

make_cartesian_axis_sampling

selection of the views on one axis.

make_centric_order

assignment of views to echo trains.

Examples

>>> import pypulseqpp as pp
>>> pp.make_traversal_order(6, "interleaved").tolist()
[0, 2, 4, 1, 3, 5]

The permutation reorders an existing list, here the partitions of a stack-of-stars acquisition:

>>> partitions = [10, 11, 12, 13, 14]
>>> order = pp.make_traversal_order(len(partitions), "center_out")
>>> order.tolist()
[2, 1, 3, 0, 4]
>>> [partitions[i] for i in order]
[12, 11, 13, 10, 14]