docs: def getnii(fim, nan_replace=None, output='image'):
      '''Get PET image from NIfTI file.
      fim: input file name for the nifty image
      nan_replace:    the value to be used for replacing the NaNs in the image.
                      by default no change (None).
      output: option for choosing output: image, affine matrix or a dictionary with all info.
      ----------
      Return:
          'image': outputs just an image (4D or 3D)
          'affine': outputs just the affine matrix
          'all': outputs all as a dictionary
      '''
  
      import numbers
  
      nim = nib.load(fim)
  
      dim = nim.header.get('dim')
      dimno = dim[0]
  
      if output=='image' or output=='all':
          imr = nim.get_data()
          # replace NaNs if requested
          if isinstance(nan_replace, numbers.Number): imr[np.isnan(imr)]
  
          imr = np.squeeze(imr)
          if dimno!=imr.ndim and dimno==4:
              dimno = imr.ndim
          
          #> get orientations from the affine
          ornt = nib.orientations.axcodes2ornt(nib.aff2axcodes(nim.affine))
          trnsp = tuple(np.int8(ornt[::-1,0]))
          flip  = tuple(np.int8(ornt[:,1]))
  
          #> flip y-axis and z-axis and then transpose.  Depends if dynamic (4 dimensions) or static (3 dimensions)
          if dimno==4:
              imr = np.transpose(imr[::-flip[0],::-flip[1],::-flip[2],:], (3,)+trnsp)
          elif  dimno==3:
              imr = np.transpose(imr[::-flip[0],::-flip[1],::-flip[2]], trnsp)
      
      if output=='affine' or output=='all':
          # A = nim.get_sform()
          # if not A[:3,:3].any():
          #     A = nim.get_qform()
          A = nim.affine
  
      if output=='all':
          out = { 'im':imr,
                  'affine':A,
                  'fim':fim,
                  'dtype':nim.get_data_dtype(),
                  'shape':imr.shape,
                  'hdr':nim.header,
                  'transpose':trnsp,
                  'flip':flip}
      elif output=='image':
          out = imr
      elif output=='affine':
          out = A
      else:
          raise NameError('Unrecognised output request!')
  
      return out