code: def within_footprint(img, wcs, x, y):
      
      # start with limits of WCS shape
      if hasattr(wcs, 'naxis1'):
          naxis1 = wcs.naxis1
          naxis2 = wcs.naxis2
      elif hasattr(wcs, 'pixel_shape'):
          naxis1, naxis2 = wcs.pixel_shape
      else:
          naxis1 = wcs._naxis1
          naxis2 = wcs._naxis2
      maskx = np.bitwise_or(x < 0, x > naxis1)
      masky = np.bitwise_or(y < 0, y > naxis2)
      mask = ~np.bitwise_or(maskx, masky)
      x = x[mask]
      y = y[mask]
  
      # Now, confirm that these points fall within actual science area of WCS
      img_mask = create_image_footprint(img, wcs, border=1.0)
      inmask = np.where(img_mask[y.astype(np.int32), x.astype(np.int32)])[0]
      x = x[inmask]
      y = y[inmask]
      return x, y
docs: Determine whether input x, y fall in the science area of the image.
  
      Parameters
      ----------
      img : ndarray
          ndarray of image where non-science areas are marked with value of NaN.
  
      wcs : `stwcs.wcsutil.HSTWCS`
          HSTWCS or WCS object with naxis terms defined.
  
      x, y : ndarray
          arrays of x, y positions for sources to be checked.
  
      Returns
      -------
      x, y : ndarray
          New arrays which have been trimmed of all sources that fall outside
          the science areas of the image