@@ -1813,7 +1813,11 @@ def cosmicray_lacosmic(
1813
1813
gain = gain .value * u .one
1814
1814
# Check unit consistency before taking the time to check for
1815
1815
# 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
+ ):
1817
1821
raise ValueError (
1818
1822
f"Inconsistent units for gain ({ gain .unit } ) "
1819
1823
+ f" ccd ({ ccd .unit } ) and readnoise ({ readnoise .unit } )."
@@ -1842,22 +1846,28 @@ def cosmicray_lacosmic(
1842
1846
)
1843
1847
1844
1848
# 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 ()
1846
1852
1847
1853
cleanarr = cleanarr - data_offset
1848
1854
cleanarr = _astroscrappy_gain_apply_helper (
1849
1855
cleanarr , gain .value , gain_apply , old_astroscrappy_interface
1850
1856
)
1851
1857
1852
1858
# 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 )
1854
1862
1855
- nccd .data = cleanarr
1863
+ nccd .data = xp . asarray ( cleanarr )
1856
1864
if nccd .mask is None :
1857
1865
nccd .mask = crmask
1858
1866
else :
1859
1867
nccd .mask = nccd .mask + crmask
1860
1868
1869
+ # Unwrap the CCDData object to ensure it is compatible with array API
1870
+ nccd = _unwrap_ccddata_for_array_api (nccd )
1861
1871
return nccd
1862
1872
elif _is_array (ccd ):
1863
1873
data = ccd
0 commit comments