class_docstr: Class returns a list of Ecat images, with one image(hdr/data) per frame
class_docstr_tok: ["Class","returns","a","list","of","Ecat","images",",","with","one","image","(","hdr\/data",")","per","frame"]
docstr: Write ECAT7 image to `file_map` or contained ``self.file_map``
  
  The format consist of:
  
  - A main header (512L) with dictionary entries in the form
      [numAvail, nextDir, previousDir, numUsed]
  - For every frame (3D volume in 4D data)
    - A subheader (size = frame_offset)
    - Frame data (3D volume)
docstr_tok: ["Write","ECAT7","image","to","`","file_map","`","or","contained","``","self.file_map","``","The","format","consist","of",":","-","A","main","header","(","512L",")","with","dictionary","entries","in","the","form","[","numAvail",",","nextDir",",","previousDir",",","numUsed","]","-","For","every","frame","(","3D","volume","in","4D","data",")","-","A","subheader","(","size","=","frame_offset",")","-","Frame","data","(","3D","volume",")"]
code: def to_file_map(self, file_map=None):
      """Write ECAT7 image to `file_map` or contained ``self.file_map``
  
      The format consist of:
  
      - A main header (512L) with dictionary entries in the form
          [numAvail, nextDir, previousDir, numUsed]
      - For every frame (3D volume in 4D data)
        - A subheader (size = frame_offset)
        - Frame data (3D volume)
      """
      if file_map is None:
          file_map = self.file_map
  
      # It appears to be necessary to load the data before saving even if the
      # data itself is not used.
      self.get_fdata()
      hdr = self.header
      mlist = self._mlist
      subheaders = self.get_subheaders()
      dir_pos = 512
      entry_pos = dir_pos + 16  # 528
      current_dir = self._get_empty_dir()
  
      hdr_fh, img_fh = self._get_fileholders(file_map)
      hdrf = hdr_fh.get_prepare_fileobj(mode="wb")
      imgf = hdrf
  
      # Write main header
      hdr.write_to(hdrf)
  
      # Write every frames
      for index in range(0, self.header["num_frames"]):
          # Move to subheader offset
          frame_offset = subheaders._get_frame_offset(index) - 512
          imgf.seek(frame_offset)
  
          # Write subheader
          subhdr = subheaders.subheaders[index]
          imgf.write(subhdr.tobytes())
  
          # Seek to the next image block
          pos = imgf.tell()
          imgf.seek(pos + 2)
  
          # Get frame
          image = self._subheader.raw_data_from_fileobj(index)
  
          # Write frame images
          self._write_data(image, imgf, pos + 2, endianness=">")
  
          # Move to dictionary offset and write dictionary entry
          self._write_data(
              mlist[index], imgf, entry_pos, endianness=">"
          )
  
          entry_pos = entry_pos + 16
  
          current_dir[0] = current_dir[0] - 1
          current_dir[3] = current_dir[3] + 1
  
          # Create a new directory is previous one is full
          if current_dir[0] == 0:
              # self._write_dir(current_dir, imgf, dir_pos)
              self._write_data(current_dir, imgf, dir_pos)
              current_dir = self._get_empty_dir()
              current_dir[3] = dir_pos / 512
              dir_pos = mlist[index][2] + 1
              entry_pos = dir_pos + 16
  
      tmp_avail = current_dir[0]
      tmp_used = current_dir[3]
  
      # Fill directory with empty data until directory is full
      while current_dir[0] > 0:
          entry_pos = dir_pos + 16 + (16 * current_dir[3])
          self._write_data(np.zeros(4, dtype=np.int32), imgf, entry_pos)
          current_dir[0] = current_dir[0] - 1
          current_dir[3] = current_dir[3] + 1
  
      current_dir[0] = tmp_avail
      current_dir[3] = tmp_used
  
      # Write directory index
      self._write_data(current_dir, imgf, dir_pos, endianness=">")
  
imports: import warnings
  from numbers import Integral
  import numpy
  from .arraywriters import make_array_writer
  from .fileslice import canonical_slicers, predict_shape, slice2outax
  from .spatialimages import SpatialHeader, SpatialImage
  from .volumeutils import array_from_file, make_dt_codes, native_code, swapped_code
  from .wrapstruct import WrapStruct
label_desc: Use image node_id 13 for calling the EcatImage obj's underlying member method code with example usage: obj.to_file_map(file_map) without return types