class_docstr: Class for basic Analyze format image
class_docstr_tok: ["Class","for","basic","Analyze","format","image"]
docstr: Write image to `file_map` or contained ``self.file_map``
  
  Parameters
  ----------
  file_map : None or mapping, optional
     files mapping.  If None (default) use object's ``file_map``
     attribute instead
  dtype : dtype-like, optional
     The on-disk data type to coerce the data array.
docstr_tok: ["Write","image","to","`","file_map","`","or","contained","``","self.file_map","``","Parameters","--","--","--","--","--","file_map",":","None","or","mapping",",","optional","files","mapping",".","If","None","(","default",")","use","object","'s","``","file_map","``","attribute","instead","dtype",":","dtype-like",",","optional","The","on-disk","data","type","to","coerce","the","data","array","."]
code: def to_file_map(self, file_map=None, dtype=None):
      """Write image to `file_map` or contained ``self.file_map``
  
      Parameters
      ----------
      file_map : None or mapping, optional
         files mapping.  If None (default) use object's ``file_map``
         attribute instead
      dtype : dtype-like, optional
         The on-disk data type to coerce the data array.
      """
      if file_map is None:
          file_map = self.file_map
      data = np.asanyarray(self.dataobj)
      self.update_header()
      hdr = self._header
      # Store consumable values for later restore
      offset = hdr.get_data_offset()
      data_dtype = hdr.get_data_dtype()
      # Override dtype conditionally
      if dtype is not None:
          hdr.set_data_dtype(dtype)
      out_dtype = hdr.get_data_dtype()
      # Scalars of slope, offset to get immutable values
      slope = hdr["scl_slope"].item() if hdr.has_data_slope else np.nan
      inter = (
          hdr["scl_inter"].item() if hdr.has_data_intercept else np.nan
      )
      # Check whether to calculate slope / inter
      scale_me = np.all(np.isnan((slope, inter)))
      try:
          if scale_me:
              arr_writer = make_array_writer(
                  data,
                  out_dtype,
                  hdr.has_data_slope,
                  hdr.has_data_intercept,
              )
          else:
              arr_writer = ArrayWriter(
                  data, out_dtype, check_scaling=False
              )
      except WriterError:
          # Restore any changed consumable values, in case caller catches
          # Should match cleanup at the end of the method
          hdr.set_data_offset(offset)
          hdr.set_data_dtype(data_dtype)
          if hdr.has_data_slope:
              hdr["scl_slope"] = slope
          if hdr.has_data_intercept:
              hdr["scl_inter"] = inter
          raise
      hdr_fh, img_fh = self._get_fileholders(file_map)
      # Check if hdr and img refer to same file; this can happen with odd
      # analyze images but most often this is because it's a single nifti
      # file
      hdr_img_same = hdr_fh.same_file_as(img_fh)
      hdrf = hdr_fh.get_prepare_fileobj(mode="wb")
      if hdr_img_same:
          imgf = hdrf
      else:
          imgf = img_fh.get_prepare_fileobj(mode="wb")
      # Rescale values if asked
      if scale_me:
          hdr.set_slope_inter(*get_slope_inter(arr_writer))
      # Write header
      hdr.write_to(hdrf)
      # Write image
      # Seek to writing position, get there by writing zeros if seek fails
      seek_tell(imgf, hdr.get_data_offset(), write0=True)
      # Write array data
      arr_writer.to_fileobj(imgf)
      hdrf.close_if_mine()
      if not hdr_img_same:
          imgf.close_if_mine()
      self._header = hdr
      self.file_map = file_map
      # Restore any changed consumable values
      hdr.set_data_offset(offset)
      hdr.set_data_dtype(data_dtype)
      if hdr.has_data_slope:
          hdr["scl_slope"] = slope
      if hdr.has_data_intercept:
          hdr["scl_inter"] = inter
  
imports: from __future__ import annotations
  import numpy
  from .arrayproxy import ArrayProxy
  from .arraywriters import ArrayWriter, WriterError, get_slope_inter, make_array_writer
  from .batteryrunners import Report
  from .fileholders import copy_file_map
  from .spatialimages import HeaderDataError, HeaderTypeError, SpatialHeader, SpatialImage
  from .volumeutils import apply_read_scaling, array_from_file, make_dt_codes, native_code, seek_tell, shape_zoom_affine, swapped_code
  from .wrapstruct import LabeledWrapStruct
label_desc: Use image node_id 6 for calling the AnalyzeImage obj's underlying member method code with example usage: obj.to_file_map(file_map, dtype) without return types