code: def _write_mef(self, key, extlist, outfile):
          
          channel = self.fv.get_channel(self.chname)
          with fits.open(outfile, mode='update') as pf:
              # Process each modified data extension
              for idx in extlist:
                  k = '{0}[{1}]'.format(key, self._format_extname(idx))
                  image = channel.datasrc[k]
  
                  # Insert data and header into output HDU
                  pf[idx].data = image.get_data()
                  self._write_header(image, pf[idx])
  
              # Write history to PRIMARY
              self._write_history(key, pf['PRIMARY'])
docs: Write out regular multi-extension FITS data.