Skip to content

Array API: wcs_project mixes numpy output from reproject with xp operations #930

Description

@mwcraig

Problem

In wcs_project, reproject_interp returns numpy arrays regardless of the input library, but the subsequent mask handling uses the input's namespace:

ccdproc/ccdproc/core.py

Lines 1163 to 1180 in 9d25eee

projected_image_raw, _ = reproject_interp(
(ccd.data, ccd.wcs), target_wcs, shape_out=target_shape, order=order
)
reprojected_mask = None
if ccd.mask is not None:
reprojected_mask, _ = reproject_interp(
(ccd.mask, ccd.wcs), target_wcs, shape_out=target_shape, order=order
)
# Make the mask 1 if the reprojected mask pixel value is non-zero.
# A small threshold is included to allow for some rounding in
# reproject_interp.
reprojected_mask = reprojected_mask > 1e-8
# The reprojection will contain nan for any pixels for which the source
# was outside the original image. Those should be masked also.
output_mask = xp.isnan(projected_image_raw)

With xp = cupy, xp.isnan(projected_image_raw) receives a numpy array — CuPy functions reject numpy input (TypeError: 'a' must be a cupy.ndarray). Even where it happens to work, the returned CCDData holds numpy data while the caller supplied another library's array, silently switching namespaces mid-pipeline. Likely contributes to the WCS-related failures in #910.

Suggested direction

reproject is CPU-only, so this falls under the general policy decision for CPU-only operations (#935): either convert explicitly to host, reproject, and convert the result (data and mask) back to the input namespace — or document wcs_project as numpy-only and raise an informative error.


Found during a review of the array API implementation from #885; follow-up to #909 / #910.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions