code: def test_scaling(self):
      # Test integer scaling from float
      # Analyze headers cannot do float-integer scaling
      hdr = self.header_class()
      assert hdr.default_x_flip
      shape = (1, 2, 3)
      hdr.set_data_shape(shape)
      hdr.set_data_dtype(np.float32)
      data = np.ones(shape, dtype=np.float64)
      S = BytesIO()
      # Writing to float datatype doesn't need scaling
      hdr.data_to_fileobj(data, S)
      rdata = hdr.data_from_fileobj(S)
      assert_array_almost_equal(data, rdata)
      # Now test writing to integers
      hdr.set_data_dtype(np.int32)
      # Writing to int needs scaling, and raises an error if we can't scale
      if not hdr.has_data_slope:
          with pytest.raises(HeaderTypeError):
              hdr.data_to_fileobj(data, BytesIO())
      # But if we aren't scaling, convert the floats to integers and write
      with np.errstate(invalid="ignore"):
          hdr.data_to_fileobj(data, S, rescale=False)
      rdata = hdr.data_from_fileobj(S)
      assert np.allclose(data, rdata)
      # This won't work for floats that aren't close to integers
      data_p5 = data + 0.5
      with np.errstate(invalid="ignore"):
          hdr.data_to_fileobj(data_p5, S, rescale=False)
      rdata = hdr.data_from_fileobj(S)
      assert not np.allclose(data_p5, rdata)
  
imports: import itertools
  import logging
  import os
  import pickle
  import re
  from io import BytesIO, StringIO
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from ..None import imageglobals
  from ..analyze import AnalyzeHeader, AnalyzeImage
  from ..arraywriters import WriterError
  from ..casting import sctypes_aliases
  from ..nifti1 import Nifti1Header
  from ..optpkg import optional_package
  from ..spatialimages import HeaderDataError, HeaderTypeError, supported_np_types
  from ..testing import assert_dt_equal, bytesio_filemap, bytesio_round_trip, data_path, suppress_warnings
  from ..tmpdirs import InTemporaryDirectory
  from .None import test_spatialimages
  from .None import test_wrapstruct
label_desc: Use image node_id 25 for calling the TestAnalyzeHeader obj's underlying member method code with example usage: obj.test_scaling() without return types