class_docstr: Mixin to add scaling tests to header tests
  
  Needs to be a mixin so nifti tests can use this method without inheriting
  directly from the SPM header tests
class_docstr_tok: ["Mixin","to","add","scaling","tests","to","header","tests","Needs","to","be","a","mixin","so","nifti","tests","can","use","this","method","without","inheriting","directly","from","the","SPM","header","tests"]
code: def test_data_scaling(self):
      hdr = self.header_class()
      hdr.set_data_shape((1, 2, 3))
      hdr.set_data_dtype(np.int16)
      S3 = BytesIO()
      data = np.arange(6, dtype=np.float64).reshape((1, 2, 3))
      # This uses scaling
      hdr.data_to_fileobj(data, S3)
      data_back = hdr.data_from_fileobj(S3)
      # almost equal
      assert_array_almost_equal(data, data_back, 4)
      # But not quite
      assert not np.all(data == data_back)
      # This is exactly the same call, just testing it works twice
      data_back2 = hdr.data_from_fileobj(S3)
      assert_array_equal(data_back, data_back2, 4)
      # Rescaling is the default
      hdr.data_to_fileobj(data, S3, rescale=True)
      data_back = hdr.data_from_fileobj(S3)
      assert_array_almost_equal(data, data_back, 4)
      assert not np.all(data == data_back)
      # This doesn't use scaling, and so gets perfect precision
      with np.errstate(invalid="ignore"):
          hdr.data_to_fileobj(data, S3, rescale=False)
      data_back = hdr.data_from_fileobj(S3)
      assert np.all(data == data_back)
  
imports: import itertools
  import unittest
  from io import BytesIO
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from ..optpkg import optional_package
  from ..casting import sctypes_aliases, shared_range, type_info
  from ..spatialimages import HeaderDataError
  from ..spm99analyze import HeaderTypeError, Spm99AnalyzeHeader, Spm99AnalyzeImage
  from ..testing import assert_allclose_safely, bytesio_filemap, bytesio_round_trip, suppress_warnings
  from ..volumeutils import _dt_min_max, apply_read_scaling
  from .None import test_analyze
label_desc: Use image node_id 1 for calling the HeaderScalingMixin obj's underlying member method code with example usage: obj.test_data_scaling() without return types