code: def isFits(input):
      
  
      isfits = False
      fitstype = None
      names = ['fits', 'fit', 'FITS', 'FIT']
      #determine if input is a fits file based on extension
      # Only check type of FITS file if filename ends in valid FITS string
      f = None
      fileclose = False
      if isinstance(input, fits.HDUList):
          isfits = True
          f = input
      else:
          isfits = True in [input.endswith(l) for l in names]
  
      # if input is a fits file determine what kind of fits it is
      #waiver fits len(shape) == 3
      if isfits:
          if f is None:
              try:
                  f = fits.open(input, mode='readonly')
                  fileclose = True
              except Exception:
                  if f is not None:
                      f.close()
                  raise
          data0 = f[0].data
          if data0 is not None:
              try:
                  if isinstance(f[1], fits.TableHDU):
                      fitstype = 'waiver'
              except IndexError:
                  fitstype = 'simple'
          else:
              fitstype = 'mef'
          if fileclose:
              f.close()
  
      return isfits, fitstype
docs: Returns
      --------
      isFits: tuple
          An ``(isfits, fitstype)`` tuple.  The values of ``isfits`` and
          ``fitstype`` are specified as:
  
           - ``isfits``: True|False
           - ``fitstype``: if True, one of 'waiver', 'mef', 'simple'; if False, None
  
      Notes
      -----
      Input images which do not have a valid FITS filename will automatically
      result in a return of (False, None).
  
      In the case that the input has a valid FITS filename but runs into some
      error upon opening, this routine will raise that exception for the calling
      routine/user to handle.