def within_footprint(img, wcsobj, x, y):
    """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.

    wcsobj : `~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

    """
    sky = wcsobj.pixel_to_world(x, y, 1)
    inmask = wcsobj.footprint_contains(sky)
    x = x[inmask]
    y = y[inmask]
    return x, y
