code: def test_write_mgh():
      # write our data to a tmp file
      v = np.arange(120)
      v = v.reshape((5, 4, 3, 2)).astype(np.float32)
      # form a MGHImage object using data and vox2ras matrix
      img = MGHImage(v, v2r)
      with InTemporaryDirectory():
          save(img, "tmpsave.mgz")
          # read from the tmp file and see if it checks out
          mgz = load("tmpsave.mgz")
          h = mgz.header
          dat = mgz.get_fdata()
          # Delete loaded image to allow file deletion by windows
          del mgz
      # header
      assert h["version"] == 1
      assert h["type"] == 3
      assert h["dof"] == 0
      assert h["goodRASFlag"] == 1
      assert np.array_equal(h["dims"], [5, 4, 3, 2])
      assert_almost_equal(h["tr"], 0.0)
      assert_almost_equal(h["flip_angle"], 0.0)
      assert_almost_equal(h["te"], 0.0)
      assert_almost_equal(h["ti"], 0.0)
      assert_almost_equal(h["fov"], 0.0)
      assert_array_almost_equal(h.get_vox2ras(), v2r)
      # data
      assert_almost_equal(dat, v, 7)
  
imports: import io
  import os
  import pathlib
  import numpy
  import pytest
  from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal
  from ...None import imageglobals
  from ...fileholders import FileHolder
  from ...openers import ImageOpener
  from ...spatialimages import HeaderDataError
  from ...testing import data_path
  from ...tests import test_spatialimages
  from ...tests import test_wrapstruct
  from ...tmpdirs import InTemporaryDirectory
  from ...volumeutils import sys_is_le
  from ...wrapstruct import WrapStructError
  from ..None import load, save
  from ..mghformat import MGHError, MGHHeader, MGHImage
label_desc: Use image node_id 2 for calling a global function with example usage: test_write_mgh() without return types