class_docstr: Class for basic analyze header
  
  Implements zoom-only setting of affine transform, and no image
  scaling
class_docstr_tok: ["Class","for","basic","analyze","header","Implements","zoom-only","setting","of","affine","transform",",","and","no","image","scaling"]
docstr: Guess intended endianness from mapping-like ``hdr``
  
  Parameters
  ----------
  hdr : mapping-like
     hdr for which to guess endianness
  
  Returns
  -------
  endianness : {'<', '>'}
     Guessed endianness of header
  
  Examples
  --------
  Zeros header, no information, guess native
  
  >>> hdr = AnalyzeHeader()
  >>> hdr_data = np.zeros((), dtype=header_dtype)
  >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
  True
  
  A valid native header is guessed native
  
  >>> hdr_data = hdr.structarr.copy()
  >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
  True
  
  And, when swapped, is guessed as swapped
  
  >>> sw_hdr_data = hdr_data.byteswap(swapped_code)
  >>> AnalyzeHeader.guessed_endian(sw_hdr_data) == swapped_code
  True
  
  The algorithm is as follows:
  
  First, look at the first value in the ``dim`` field; this
  should be between 0 and 7.  If it is between 1 and 7, then
  this must be a native endian header.
  
  >>> hdr_data = np.zeros((), dtype=header_dtype) # blank binary data
  >>> hdr_data['dim'][0] = 1
  >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
  True
  >>> hdr_data['dim'][0] = 6
  >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
  True
  >>> hdr_data['dim'][0] = -1
  >>> AnalyzeHeader.guessed_endian(hdr_data) == swapped_code
  True
  
  If the first ``dim`` value is zeros, we need a tie breaker.
  In that case we check the ``sizeof_hdr`` field.  This should
  be 348.  If it looks like the byteswapped value of 348,
  assumed swapped.  Otherwise assume native.
  
  >>> hdr_data = np.zeros((), dtype=header_dtype) # blank binary data
  >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
  True
  >>> hdr_data['sizeof_hdr'] = 1543569408
  >>> AnalyzeHeader.guessed_endian(hdr_data) == swapped_code
  True
  >>> hdr_data['sizeof_hdr'] = -1
  >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
  True
  
  This is overridden by the ``dim[0]`` value though:
  
  >>> hdr_data['sizeof_hdr'] = 1543569408
  >>> hdr_data['dim'][0] = 1
  >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
  True
docstr_tok: ["Guess","intended","endianness","from","mapping-like","``","hdr","``","Parameters","--","--","--","--","--","hdr",":","mapping-like","hdr","for","which","to","guess","endianness","Returns","--","--","--","-","endianness",":","{","'","<","'",",","'",">","'","}","Guessed","endianness","of","header","Examples","--","--","--","--","Zeros","header",",","no","information",",","guess","native",">",">",">","hdr","=","AnalyzeHeader","(",")",">",">",">","hdr_data","=","np.zeros","(","(",")",",","dtype=header_dtype",")",">",">",">","AnalyzeHeader.guessed_endian","(","hdr_data",")","==","native_code","True","A","valid","native","header","is","guessed","native",">",">",">","hdr_data","=","hdr.structarr.copy","(",")",">",">",">","AnalyzeHeader.guessed_endian","(","hdr_data",")","==","native_code","True","And",",","when","swapped",",","is","guessed","as","swapped",">",">",">","sw_hdr_data","=","hdr_data.byteswap","(","swapped_code",")",">",">",">","AnalyzeHeader.guessed_endian","(","sw_hdr_data",")","==","swapped_code","True","The","algorithm","is","as","follows",":","First",",","look","at","the","first","value","in","the","``","dim","``","field",";","this","should","be","between","0","and","7",".","If","it","is","between","1","and","7",",","then","this","must","be","a","native","endian","header",".",">",">",">","hdr_data","=","np.zeros","(","(",")",",","dtype=header_dtype",")","#","blank","binary","data",">",">",">","hdr_data","[","'dim","'","]","[","0","]","=","1",">",">",">","AnalyzeHeader.guessed_endian","(","hdr_data",")","==","native_code","True",">",">",">","hdr_data","[","'dim","'","]","[","0","]","=","6",">",">",">","AnalyzeHeader.guessed_endian","(","hdr_data",")","==","native_code","True",">",">",">","hdr_data","[","'dim","'","]","[","0","]","=","-1",">",">",">","AnalyzeHeader.guessed_endian","(","hdr_data",")","==","swapped_code","True","If","the","first","``","dim","``","value","is","zeros",",","we","need","a","tie","breaker",".","In","that","case","we","check","the","``","sizeof_hdr","``","field",".","This","should","be","348",".","If","it","looks","like","the","byteswapped","value","of","348",",","assumed","swapped",".","Otherwise","assume","native",".",">",">",">","hdr_data","=","np.zeros","(","(",")",",","dtype=header_dtype",")","#","blank","binary","data",">",">",">","AnalyzeHeader.guessed_endian","(","hdr_data",")","==","native_code","True",">",">",">","hdr_data","[","'sizeof_hdr","'","]","=","1543569408",">",">",">","AnalyzeHeader.guessed_endian","(","hdr_data",")","==","swapped_code","True",">",">",">","hdr_data","[","'sizeof_hdr","'","]","=","-1",">",">",">","AnalyzeHeader.guessed_endian","(","hdr_data",")","==","native_code","True","This","is","overridden","by","the","``","dim","[","0","]","``","value","though",":",">",">",">","hdr_data","[","'sizeof_hdr","'","]","=","1543569408",">",">",">","hdr_data","[","'dim","'","]","[","0","]","=","1",">",">",">","AnalyzeHeader.guessed_endian","(","hdr_data",")","==","native_code","True"]
code: def guessed_endian(klass, hdr):
      """Guess intended endianness from mapping-like ``hdr``
  
      Parameters
      ----------
      hdr : mapping-like
         hdr for which to guess endianness
  
      Returns
      -------
      endianness : {'<', '>'}
         Guessed endianness of header
  
      Examples
      --------
      Zeros header, no information, guess native
  
      >>> hdr = AnalyzeHeader()
      >>> hdr_data = np.zeros((), dtype=header_dtype)
      >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
      True
  
      A valid native header is guessed native
  
      >>> hdr_data = hdr.structarr.copy()
      >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
      True
  
      And, when swapped, is guessed as swapped
  
      >>> sw_hdr_data = hdr_data.byteswap(swapped_code)
      >>> AnalyzeHeader.guessed_endian(sw_hdr_data) == swapped_code
      True
  
      The algorithm is as follows:
  
      First, look at the first value in the ``dim`` field; this
      should be between 0 and 7.  If it is between 1 and 7, then
      this must be a native endian header.
  
      >>> hdr_data = np.zeros((), dtype=header_dtype) # blank binary data
      >>> hdr_data['dim'][0] = 1
      >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
      True
      >>> hdr_data['dim'][0] = 6
      >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
      True
      >>> hdr_data['dim'][0] = -1
      >>> AnalyzeHeader.guessed_endian(hdr_data) == swapped_code
      True
  
      If the first ``dim`` value is zeros, we need a tie breaker.
      In that case we check the ``sizeof_hdr`` field.  This should
      be 348.  If it looks like the byteswapped value of 348,
      assumed swapped.  Otherwise assume native.
  
      >>> hdr_data = np.zeros((), dtype=header_dtype) # blank binary data
      >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
      True
      >>> hdr_data['sizeof_hdr'] = 1543569408
      >>> AnalyzeHeader.guessed_endian(hdr_data) == swapped_code
      True
      >>> hdr_data['sizeof_hdr'] = -1
      >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
      True
  
      This is overridden by the ``dim[0]`` value though:
  
      >>> hdr_data['sizeof_hdr'] = 1543569408
      >>> hdr_data['dim'][0] = 1
      >>> AnalyzeHeader.guessed_endian(hdr_data) == native_code
      True
      """
      dim0 = int(hdr["dim"][0])
      if dim0 == 0:
          if hdr["sizeof_hdr"].byteswap() == klass.sizeof_hdr:
              return swapped_code
          return native_code
      elif 1 <= dim0 <= 7:
          return native_code
      return swapped_code
  
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 2 for calling the AnalyzeHeader obj's underlying member method code with example usage: obj.guessed_endian(klass, hdr) and returns: swapped_code, native_code, swapped_code, native_code