class_docstr: ArrayWriter that can use scalefactor for writing arrays
  
  The scalefactor allows the array writer to write floats to int output
  types, and rescale larger ints to smaller.  It can therefore lose
  precision.
  
  It extends the ArrayWriter class with attribute:
  
  * slope
  
  and methods:
  
  * reset() - reset slope to default (not adapted to self.array)
  * calc_scale() - calculate slope to best write self.array
class_docstr_tok: ["ArrayWriter","that","can","use","scalefactor","for","writing","arrays","The","scalefactor","allows","the","array","writer","to","write","floats","to","int","output","types",",","and","rescale","larger","ints","to","smaller",".","It","can","therefore","lose","precision",".","It","extends","the","ArrayWriter","class","with","attribute",":","*","slope","and","methods",":","*","reset","(",")","-","reset","slope","to","default","(","not","adapted","to","self.array",")","*","calc_scale","(",")","-","calculate","slope","to","best","write","self.array"]
docstr: Calculate scaling based on data range and output type
docstr_tok: ["Calculate","scaling","based","on","data","range","and","output","type"]
code: def _range_scale(self, in_min, in_max):
      """Calculate scaling based on data range and output type"""
      out_dtype = self._out_dtype
      info = type_info(out_dtype)
      out_min, out_max = info["min"], info["max"]
      big_float = best_float()
      if out_dtype.kind == "f":
          # But we want maximum precision for the calculations. Casting will
          # not lose precision because min/max are of fp type.
          out_min, out_max = np.array(
              (out_min, out_max), dtype=big_float
          )
      else:  # (u)int
          out_min, out_max = (big_float(v) for v in (out_min, out_max))
      if self._out_dtype.kind == "u":
          if in_min < 0 and in_max > 0:
              raise WriterError(
                  "Cannot scale negative and positive numbers to uint without intercept"
              )
          if in_max <= 0:  # All input numbers <= 0
              self.slope = in_min / out_max
          else:  # All input numbers > 0
              self.slope = in_max / out_max
          return
      # Scaling to int. We need the bigger slope of (in_min/out_min) and
      # (in_max/out_max). If in_min or in_max is the wrong side of 0, that
      # will make these negative and so they won't worry us
      mx_slope = in_max / out_max
      mn_slope = in_min / out_min
      self.slope = np.max([mx_slope, mn_slope])
  
imports: import numpy
  from .casting import best_float, floor_exact, int_abs, shared_range, type_info
  from .volumeutils import array_to_file, finite_range
label_desc: Use image node_id 11 for calling the SlopeArrayWriter obj's underlying member method code with example usage: obj._range_scale(in_min, in_max) without return types