code: def test_save_load_endian():
      shape = (2, 4, 6)
      affine = np.diag([1, 2, 3, 1])
      data = np.arange(np.prod(shape), dtype="f4").reshape(shape)
      # Native endian image
      img = Nifti1Image(data, affine)
      assert img.header.endianness == native_code
      img2 = round_trip(img)
      assert img2.header.endianness == native_code
      assert_array_equal(img2.get_fdata(), data)
      assert_array_equal(np.asanyarray(img2.dataobj), data)
      # byte swapped endian image
      bs_hdr = img.header.as_byteswapped()
      bs_img = Nifti1Image(data, affine, bs_hdr)
      assert bs_img.header.endianness == swapped_code
      # of course the data is the same because it's not written to disk
      assert_array_equal(bs_img.get_fdata(), data)
      assert_array_equal(np.asanyarray(bs_img.dataobj), data)
      # Check converting to another image
      cbs_img = AnalyzeImage.from_image(bs_img)
      # this will make the header native by doing the header conversion
      cbs_hdr = cbs_img.header
      assert cbs_hdr.endianness == native_code
      # and the byte order follows it back into another image
      cbs_img2 = Nifti1Image.from_image(cbs_img)
      cbs_hdr2 = cbs_img2.header
      assert cbs_hdr2.endianness == native_code
      # Try byteswapped round trip
      bs_img2 = round_trip(bs_img)
      bs_data2 = np.asanyarray(bs_img2.dataobj)
      bs_fdata2 = bs_img2.get_fdata()
      # now the data dtype was swapped endian, so the read data is too
      assert bs_data2.dtype.byteorder == swapped_code
      assert bs_img2.header.endianness == swapped_code
      assert_array_equal(bs_data2, data)
      # but get_fdata uses native endian
      assert bs_fdata2.dtype.byteorder != swapped_code
      assert_array_equal(bs_fdata2, data)
      # Now mix up byteswapped data and non-byteswapped header
      mixed_img = Nifti1Image(bs_data2, affine)
      assert mixed_img.header.endianness == native_code
      m_img2 = round_trip(mixed_img)
      assert m_img2.header.endianness == native_code
      assert_array_equal(m_img2.get_fdata(), data)
  
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 3 for calling a global function with example usage: test_save_load_endian() without return types