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: Initialize array writer
  
  Parameters
  ----------
  array : array-like
      array-like object
  out_dtype : None or dtype
      dtype with which `array` will be written.  For this class,
      `out_dtype`` needs to be the same as the dtype of the input `array`
      or a swapped version of the same.
  calc_scale : {True, False}, optional
      Whether to calculate scaling for writing `array` on initialization.
      If False, then you can calculate this scaling with
      ``obj.calc_scale()`` - see examples
  scaler_dtype : dtype-like, optional
      specifier for numpy dtype for scaling
  \*\*kwargs : keyword arguments
      This class processes only:
  
      * nan2zero : bool, optional
        Whether to set NaN values to 0 when writing integer output.
        Defaults to True.  If False, NaNs get converted with numpy
        ``astype``, and the behavior is undefined.  Ignored for floating
        point output.
  
  Examples
  --------
  >>> arr = np.array([0, 254], np.uint8)
  >>> aw = SlopeArrayWriter(arr)
  >>> aw.slope
  1.0
  >>> aw = SlopeArrayWriter(arr, np.int8)
  >>> aw.slope
  2.0
  >>> aw = SlopeArrayWriter(arr, np.int8, calc_scale=False)
  >>> aw.slope
  1.0
  >>> aw.calc_scale()
  >>> aw.slope
  2.0
docstr_tok: ["Initialize","array","writer","Parameters","--","--","--","--","--","array",":","array-like","array-like","object","out_dtype",":","None","or","dtype","dtype","with","which","`","array","`","will","be","written",".","For","this","class",",","`","out_dtype","``","needs","to","be","the","same","as","the","dtype","of","the","input","`","array","`","or","a","swapped","version","of","the","same",".","calc_scale",":","{","True",",","False","}",",","optional","Whether","to","calculate","scaling","for","writing","`","array","`","on","initialization",".","If","False",",","then","you","can","calculate","this","scaling","with","``","obj.calc_scale","(",")","``","-","see","examples","scaler_dtype",":","dtype-like",",","optional","specifier","for","numpy","dtype","for","scaling","\\","*","\\","*","kwargs",":","keyword","arguments","This","class","processes","only",":","*","nan2zero",":","bool",",","optional","Whether","to","set","NaN","values","to","0","when","writing","integer","output",".","Defaults","to","True",".","If","False",",","NaNs","get","converted","with","numpy","``","astype","``",",","and","the","behavior","is","undefined",".","Ignored","for","floating","point","output",".","Examples","--","--","--","--",">",">",">","arr","=","np.array","(","[","0",",","254","]",",","np.uint8",")",">",">",">","aw","=","SlopeArrayWriter","(","arr",")",">",">",">","aw.slope","1.0",">",">",">","aw","=","SlopeArrayWriter","(","arr",",","np.int8",")",">",">",">","aw.slope","2.0",">",">",">","aw","=","SlopeArrayWriter","(","arr",",","np.int8",",","calc_scale=False",")",">",">",">","aw.slope","1.0",">",">",">","aw.calc_scale","(",")",">",">",">","aw.slope","2.0"]
code: def __init__(
      self,
      array,
      out_dtype=None,
      calc_scale=True,
      scaler_dtype=np.float32,
      **kwargs,
  ):
      r"""Initialize array writer
  
      Parameters
      ----------
      array : array-like
          array-like object
      out_dtype : None or dtype
          dtype with which `array` will be written.  For this class,
          `out_dtype`` needs to be the same as the dtype of the input `array`
          or a swapped version of the same.
      calc_scale : {True, False}, optional
          Whether to calculate scaling for writing `array` on initialization.
          If False, then you can calculate this scaling with
          ``obj.calc_scale()`` - see examples
      scaler_dtype : dtype-like, optional
          specifier for numpy dtype for scaling
      \*\*kwargs : keyword arguments
          This class processes only:
  
          * nan2zero : bool, optional
            Whether to set NaN values to 0 when writing integer output.
            Defaults to True.  If False, NaNs get converted with numpy
            ``astype``, and the behavior is undefined.  Ignored for floating
            point output.
  
      Examples
      --------
      >>> arr = np.array([0, 254], np.uint8)
      >>> aw = SlopeArrayWriter(arr)
      >>> aw.slope
      1.0
      >>> aw = SlopeArrayWriter(arr, np.int8)
      >>> aw.slope
      2.0
      >>> aw = SlopeArrayWriter(arr, np.int8, calc_scale=False)
      >>> aw.slope
      1.0
      >>> aw.calc_scale()
      >>> aw.slope
      2.0
      """
      nan2zero = kwargs.pop("nan2zero", True)
      self._array = np.asanyarray(array)
      arr_dtype = self._array.dtype
      if out_dtype is None:
          out_dtype = arr_dtype
      else:
          out_dtype = np.dtype(out_dtype)
      self._out_dtype = out_dtype
      self.scaler_dtype = np.dtype(scaler_dtype)
      self.reset()
      self._nan2zero = nan2zero
      self._has_nan = None
      if calc_scale:
          self.calc_scale()
  
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 1 to create a new SlopeArrayWriter object from inherited base classes: ArrayWriter with example: obj = SlopeArrayWriter(array, out_dtype, calc_scale, scaler_dtype)