Skip to content

Commit 5c81f63

Browse files
committed
Fix several array API issues in lacosmic
1 parent 59690f7 commit 5c81f63

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

ccdproc/core.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,11 @@ def cosmicray_lacosmic(
18131813
gain = gain.value * u.one
18141814
# Check unit consistency before taking the time to check for
18151815
# cosmic rays.
1816-
if not (gain * ccd).unit.is_equivalent(readnoise.unit):
1816+
# Check this using the units, not the data, to avoid both an unnecessary
1817+
# array multiplication and a possible change of array namespace.
1818+
if not ((1.0 * gain.unit) * (1.0 * ccd.unit)).unit.is_equivalent(
1819+
readnoise.unit
1820+
):
18171821
raise ValueError(
18181822
f"Inconsistent units for gain ({gain.unit}) "
18191823
+ f" ccd ({ccd.unit}) and readnoise ({readnoise.unit})."
@@ -1842,22 +1846,28 @@ def cosmicray_lacosmic(
18421846
)
18431847

18441848
# create the new ccd data object
1845-
nccd = ccd.copy()
1849+
# Wrap the CCDData object to ensure it is compatible with array API
1850+
_ccd = _wrap_ccddata_for_array_api(ccd)
1851+
nccd = _ccd.copy()
18461852

18471853
cleanarr = cleanarr - data_offset
18481854
cleanarr = _astroscrappy_gain_apply_helper(
18491855
cleanarr, gain.value, gain_apply, old_astroscrappy_interface
18501856
)
18511857

18521858
# Fix the units if the gain is being applied.
1853-
nccd.unit = ccd.unit * gain.unit
1859+
nccd.unit = _ccd.unit * gain.unit
1860+
1861+
xp = array_api_compat.array_namespace(_ccd.data)
18541862

1855-
nccd.data = cleanarr
1863+
nccd.data = xp.asarray(cleanarr)
18561864
if nccd.mask is None:
18571865
nccd.mask = crmask
18581866
else:
18591867
nccd.mask = nccd.mask + crmask
18601868

1869+
# Unwrap the CCDData object to ensure it is compatible with array API
1870+
nccd = _unwrap_ccddata_for_array_api(nccd)
18611871
return nccd
18621872
elif _is_array(ccd):
18631873
data = ccd

0 commit comments

Comments
 (0)