Skip to content

array-api-strict: subtract_overscan and cosmicray_lacosmic(gain_apply=True) fail on integer data #1034

Open

Description

@mwcraig

On array-api-strict, two ccdproc functions fail on integer data (uint16, int32 and so on). array-api-strict refuses the implicit integer → floating promotion that NumPy, dask and JAX do. The cause in both cases is ccdproc's own arithmetic, not a host round trip.

  1. subtract_overscan, with or without model=:
    • median=False calls xp.mean on the integer overscan: TypeError: Only floating-point dtypes are allowed in mean.
    • median=True gets a float64 median, then fails at ccd.data - oscan: TypeError: array_api_strict.uint16 and array_api_strict.float64 cannot be type promoted together.
  2. cosmicray_lacosmic with gain_apply=True, on an integer CCDData that has an uncertainty. The uncertainty is scaled with _ccd.multiply(gain_value), which multiplies the integer data by a floating 0-d array as well: TypeError: array_api_strict.uint16 and array_api_strict.float32 cannot be type promoted together (float64 in place of float32 on main before Keep the floating dtype of the input in the host round trips #1032).

Reproducer, run on array-api-strict device1 (the same happens on the default device):

import array_api_strict as xp
import numpy as np
import astropy.units as u
from astropy.nddata import CCDData, StdDevUncertainty
from ccdproc import subtract_overscan, cosmicray_lacosmic

dev = xp.Device("device1")
data = xp.asarray(
    np.random.default_rng(0).normal(1000, 10, (40, 40)).astype("uint16"), device=dev
)

for median in (False, True):
    subtract_overscan(
        CCDData(data, unit="adu"), overscan_axis=1, fits_section="[1:5,:]", median=median
    )  # TypeError

ccd = CCDData(
    data,
    unit="adu",
    uncertainty=StdDevUncertainty(xp.full((40, 40), 10.0, dtype=xp.float32, device=dev)),
)
cosmicray_lacosmic(ccd, gain=2 * u.electron / u.adu, gain_apply=True)  # TypeError

History: found while working on #1023 (PR #1032), and present on main. PR #1032 pins the subtract_overscan mean path and the cosmicray_lacosmic case with non-strict backend_xfail markers; the subtract_overscan median path has no test. #1013 (subtract_dark(scale=True) promoting float32 on NumPy) is a related dtype problem from the same kind of 0-d float64 operand, but it is a different bug. Summary noted on #971.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions