code: def test_save_load():
      shape = (2, 4, 6)
      npt = np.float32
      data = np.arange(np.prod(shape), dtype=npt).reshape(shape)
      affine = np.diag([1, 2, 3, 1])
      affine[:3, 3] = [3, 2, 1]
      img = ni1.Nifti1Image(data, affine)
      img.set_data_dtype(npt)
      with InTemporaryDirectory() as pth:
          nifn = "an_image.nii"
          sifn = "another_image.img"
          ni1.save(img, nifn)
          re_img = nils.load(nifn)
          assert isinstance(re_img, ni1.Nifti1Image)
          assert_array_equal(re_img.get_fdata(), data)
          assert_array_equal(re_img.affine, affine)
          # These and subsequent del statements are to prevent confusing
          # windows errors when trying to open files or delete the
          # temporary directory.
          del re_img
          if have_scipy:  # skip we we cannot read .mat files
              spm2.save(img, sifn)
              re_img2 = nils.load(sifn)
              assert isinstance(re_img2, spm2.Spm2AnalyzeImage)
              assert_array_equal(re_img2.get_fdata(), data)
              assert_array_equal(re_img2.affine, affine)
              del re_img2
              spm99.save(img, sifn)
              re_img3 = nils.load(sifn)
              assert isinstance(re_img3, spm99.Spm99AnalyzeImage)
              assert_array_equal(re_img3.get_fdata(), data)
              assert_array_equal(re_img3.affine, affine)
              ni1.save(re_img3, nifn)
              del re_img3
          re_img = nils.load(nifn)
          assert isinstance(re_img, ni1.Nifti1Image)
          assert_array_equal(re_img.get_fdata(), data)
          assert_array_equal(re_img.affine, affine)
          del re_img
  
imports: import logging
  import pathlib
  import shutil
  from io import BytesIO
  from os.path import dirname
  from os.path import join
  from tempfile import mkdtemp
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from ..None import AnalyzeImage, MGHImage, Minc1Image, Minc2Image, Nifti1Header, Nifti1Image, Nifti1Pair, Nifti2Image, Nifti2Pair, Spm2AnalyzeImage, Spm99AnalyzeImage, all_image_classes
  from ..None import analyze
  from ..None import loadsave
  from ..None import nifti1
  from ..None import spm2analyze
  from ..None import spm99analyze
  from ..optpkg import optional_package
  from ..spatialimages import SpatialImage
  from ..testing import expires
  from ..tmpdirs import InTemporaryDirectory
  from ..volumeutils import native_code, swapped_code
label_desc: Use image node_id 4 for calling a global function with example usage: test_save_load() without return types