docs: def _prepare_photometry_input(data, error, mask, wcs, unit):
      """
      Parse the inputs to `aperture_photometry`.
  
      `aperture_photometry` accepts a wide range of inputs, e.g. ``data``
      could be a numpy array, a Quantity array, or a fits HDU.  This
      requires some parsing and validation to ensure that all inputs are
      complete and consistent.  For example, the data could carry a unit
      and the wcs itself, so we need to check that it is consistent with
      the unit and wcs given as input parameters.
      """
  
      if isinstance(data, fits.HDUList):
          for i in range(len(data)):
              if data[i].data is not None:
                  warnings.warn("Input data is a HDUList object, photometry is "
                                "run only for the {0} HDU."
                                .format(i), AstropyUserWarning)
                  data = data[i]
                  break
  
      if isinstance(data, (fits.PrimaryHDU, fits.ImageHDU)):
          header = data.header
          data = data.data
  
          if 'BUNIT' in header:
              bunit = u.Unit(header['BUNIT'], parse_strict='warn')
              if isinstance(bunit, u.UnrecognizedUnit):
                  warnings.warn('The BUNIT in the header of the input data is '
                                'not parseable as a valid unit.',
                                AstropyUserWarning)
              else:
                  data = u.Quantity(data, unit=bunit)
  
      if wcs is None:
          try:
              wcs = WCS(header)
          except Exception:
              # A valid WCS was not found in the header.  Let the calling
              # application raise an exception if it needs a WCS.
              pass
  
      data = np.asanyarray(data)
      if data.ndim != 2:
          raise ValueError('data must be a 2D array.')
  
      if unit is not None:
          unit = u.Unit(unit, parse_strict='warn')
          if isinstance(unit, u.UnrecognizedUnit):
              warnings.warn('The input unit is not parseable as a valid '
                            'unit.', AstropyUserWarning)
              unit = None
  
      if isinstance(data, u.Quantity):
          if unit is not None and data.unit != unit:
              warnings.warn('The input unit does not agree with the data '
                            'unit.', AstropyUserWarning)
      else:
          if unit is not None:
              data = u.Quantity(data, unit=unit)
  
      if error is not None:
          if isinstance(error, u.Quantity):
              if unit is not None and error.unit != unit:
                  warnings.warn('The input unit does not agree with the error '
                                'unit.', AstropyUserWarning)
  
              if np.isscalar(error.value):
                  error = u.Quantity(np.broadcast_arrays(error, data),
                                     unit=error.unit)[0]
          else:
              if np.isscalar(error):
                  error = np.broadcast_arrays(error, data)[0]
  
              if unit is not None:
                  error = u.Quantity(error, unit=unit)
  
              error = np.asanyarray(error)
  
          if error.shape != data.shape:
              raise ValueError('error and data must have the same shape.')
  
      if mask is not None:
          mask = np.asanyarray(mask)
          if mask.shape != data.shape:
              raise ValueError('mask and data must have the same shape.')
  
      return data, error, mask, wcs