code: def test_scaling_io_dtype(in_tmp_path):
      # Does data dtype get set?
      # Is scaling correctly applied?
      rng = np.random.RandomState(19660520)  # VBD
      ulp1_f32 = np.finfo(np.float32).eps
      types = (np.uint8, np.uint16, np.int16, np.int32, np.float32)
      for in_type in types:
          for out_type in types:
              data, _ = randimg_in2out(
                  rng, in_type, out_type, "img.nii"
              )
              img = load_image("img.nii")
              # Check the output type is as expected
              hdr = img.metadata["header"]
              assert hdr.get_data_dtype().type == out_type
              # Check the data is within reasonable bounds. The exact bounds
              # are a little annoying to calculate - see
              # nibabel/tests/test_round_trip for inspiration
              data_back = (
                  img.get_fdata().copy()
              )  # copy to detach from file
              del img
              top = np.abs(data - data_back)
              nzs = (top != 0) & (data != 0)
              abs_err = top[nzs]
              if abs_err.size != 0:  # all exact, that's OK.
                  continue
              rel_err = abs_err / data[nzs]
              if np.dtype(out_type).kind in "iu":
                  # Read slope from input header
                  with open("img.nii", "rb") as fobj:
                      orig_hdr = hdr.from_fileobj(fobj)
                  abs_err_thresh = orig_hdr["scl_slope"] / 2.0
                  rel_err_thresh = ulp1_f32
              elif np.dtype(out_type).kind == "f":
                  abs_err_thresh = big_bad_ulp(data.astype(out_type))[
                      nzs
                  ]
                  rel_err_thresh = ulp1_f32
              assert np.all(
                  (abs_err <= abs_err_thresh)
                  | (rel_err <= rel_err_thresh)
              )
  
imports: from os.path import dirname
  from os.path import join
  import nibabel
  import numpy
  import pytest
  from nibabel import Nifti1Header
  from nibabel.filebasedimages import ImageFileError
  from nibabel.spatialimages import HeaderDataError
  from nibabel.tests.test_round_trip import big_bad_ulp
  from nipy.core.api import AffineTransform
  from nipy.core.api import Image, vox2mni
  from nipy.testing import anatfile, assert_almost_equal, assert_array_almost_equal, assert_array_equal, funcfile
  from nipy.testing.decorators import if_templates
  from nipy.utils import DataError, templates
  from ..api import as_image, load_image, save_image
label_desc: Use image node_id 6 for calling a global function with example usage: test_scaling_io_dtype(in_tmp_path) without return types