code: def _calculate_scale(data, out_dtype, allow_intercept):
      """Calculate scaling and optional intercept for data
  
      Copy of the deprecated volumeutils.calculate_scale, to preserve tests
  
      Parameters
      ----------
      data : array
      out_dtype : dtype
         output data type in some form understood by ``np.dtype``
      allow_intercept : bool
         If True allow non-zero intercept
  
      Returns
      -------
      scaling : None or float
         scalefactor to divide into data.  None if no valid data
      intercept : None or float
         intercept to subtract from data.  None if no valid data
      mn : None or float
         minimum of finite value in data or None if this will not
         be used to threshold data
      mx : None or float
         minimum of finite value in data, or None if this will not
         be used to threshold data
      """
      # Code here is a compatibility shell around arraywriters refactor
      in_dtype = data.dtype
      out_dtype = np.dtype(out_dtype)
      if np.can_cast(in_dtype, out_dtype):
          return 1.0, 0.0, None, None
      from ..arraywriters import (
          WriterError,
          get_slope_inter,
          make_array_writer,
      )
  
      try:
          writer = make_array_writer(
              data, out_dtype, True, allow_intercept
          )
      except WriterError as e:
          raise ValueError(str(e))
      if out_dtype.kind in "fc":
          return (1.0, 0.0, None, None)
      mn, mx = writer.finite_range()
      if (mn, mx) == (np.inf, -np.inf):  # No valid data
          return (None, None, None, None)
      if in_dtype.kind not in "fc":
          mn, mx = (None, None)
      return get_slope_inter(writer) + (mn, mx)
  
imports: import bz2
  import functools
  import gzip
  import itertools
  import os
  import tempfile
  import threading
  import time
  import warnings
  from io import BytesIO
  from os.path import exists
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from packaging.version import Version
  from nibabel.testing import assert_allclose_safely, assert_dt_equal, error_warnings, suppress_warnings
  from ..casting import OK_FLOATS, floor_log2, sctypes, shared_range, type_info
  from ..openers import BZ2File, ImageOpener, Opener
  from ..optpkg import optional_package
  from ..tmpdirs import InTemporaryDirectory
  from ..volumeutils import _dt_min_max, _ftype4scaled_finite, _is_compressed_fobj, _write_data, apply_read_scaling, array_from_file, array_to_file, best_write_scale_ftype, better_float_of, fname_ext_ul_case, int_scinter_ftype, make_dt_codes, native_code, rec2dict, seek_tell, shape_zoom_affine, working_type, write_zeros
label_desc: Use image node_id 43 for calling a global function with example usage: _calculate_scale(data, out_dtype, allow_intercept) and returns: unknown, int,  int,  None,  None, int,  int,  None,  None, None,  None,  None,  None