code: def test_sorting_multiple_echos_and_contrasts():
      # This .PAR file has 3 echos and 4 image types (real, imaginary, magnitude,
      # phase).
      # After sorting should be:
      #     Type 0, Echo 1, Slices 1-30
      #     Type 0, Echo 2, Slices 1-30
      #     Type 0, Echo 3, Slices 1-30
      #     Type 1, Echo 1, Slices 1-30
      #     ...
      #     Type 3, Echo 3, Slices 1-30
      t1_par = pjoin(DATA_PATH, "T1_3echo_mag_real_imag_phase.PAR")
      with open(t1_par) as fobj:
          t1_hdr = PARRECHeader.from_fileobj(fobj, strict_sort=True)
  
      # should get the correct order even if we randomly shuffle the order
      np.random.shuffle(t1_hdr.image_defs)
  
      sorted_indices = t1_hdr.get_sorted_slice_indices()
      sorted_slices = t1_hdr.image_defs["slice number"][sorted_indices]
      sorted_echos = t1_hdr.image_defs["echo number"][sorted_indices]
      sorted_types = t1_hdr.image_defs["image_type_mr"][sorted_indices]
  
      ntotal = len(t1_hdr.image_defs)
      nslices = sorted_slices.max()
      nechos = sorted_echos.max()
      for slice_offset in range(ntotal // nslices):
          istart = slice_offset * nslices
          iend = (slice_offset + 1) * nslices
          # innermost sort index is slices
          assert_array_equal(
              sorted_slices[istart:iend], np.arange(1, nslices + 1)
          )
          current_echo = slice_offset % nechos + 1
          # same echo for each slice in the group
          assert np.all(sorted_echos[istart:iend] == current_echo)
      # outermost sort index is image_type_mr
      assert np.all(sorted_types[: ntotal // 4] == 0)
      assert np.all(sorted_types[ntotal // 4 : ntotal // 2] == 1)
      assert np.all(sorted_types[ntotal // 2 : 3 * ntotal // 4] == 2)
      assert np.all(sorted_types[3 * ntotal // 4 : ntotal] == 3)
  
      # check volume labels
      vol_labels = t1_hdr.get_volume_labels()
      assert list(vol_labels.keys()) == ["echo number", "image_type_mr"]
      assert_array_equal(vol_labels["echo number"], [1, 2, 3] * 4)
      assert_array_equal(
          vol_labels["image_type_mr"],
          [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
      )
  
imports: from glob import glob
  from os.path import basename, dirname
  from os.path import join
  from warnings import simplefilter
  import numpy
  import pytest
  from numpy import array
  from numpy.testing import assert_almost_equal, assert_array_equal
  from ..None import load
  from ..None import parrec
  from ..fileholders import FileHolder
  from ..nifti1 import Nifti1Extension, Nifti1Header, Nifti1Image
  from ..openers import ImageOpener
  from ..parrec import PARRECArrayProxy, PARRECError, PARRECHeader, PARRECImage, exts2pars, parse_PAR_header, vol_is_full, vol_numbers
  from ..testing import assert_arr_dict_equal, clear_and_catch_warnings, suppress_warnings
  from ..volumeutils import array_from_file
  from .None import test_spatialimages
  from .test_arrayproxy import check_mmap
label_desc: Use image node_id 11 for calling a global function with example usage: test_sorting_multiple_echos_and_contrasts() without return types