Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cosmicray_lacosmic does not return numpy.ndarray #796

Closed
ppmim opened this issue Oct 5, 2022 · 2 comments
Closed

cosmicray_lacosmic does not return numpy.ndarray #796

ppmim opened this issue Oct 5, 2022 · 2 comments

Comments

@ppmim
Copy link

ppmim commented Oct 5, 2022

I have found that cosmicray_lacosmic does not return numpy.ndarray, but a astropy.units.quantity.Quantity.
The problem comes from _astroscrappy_gain_apply_helper(), where the comparison with gain != 1 is always true, and I think it should be as 'gain.value != 1'.

So, when we run:

newdata, mask = cosmicray_lacosmic(data, sigclip=5)

newdata is a astropy.units.quantity.Quantity instead of numpy.ndarray.

The versions I am using are:

import astropy
print(astropy.__version__)
import ccdproc
print(ccdproc.__version__)
import numpy
print(numpy.__version__)

4.3.1
2.3.1
1.21.5

@mwcraig
Copy link
Member

mwcraig commented Oct 6, 2022

Thanks for reporting this @ppmim -- would you happen to have time to open a pull request to fix the issue?

@altair-above
Copy link
Contributor

I was having a related issue that seems to stem from the same thing! I noticed that _astroscrappy_gain_apply_helper()'s docstring says that gain should actually be a float, but cosmicray_lacosmic() is passing it a Quantity. This causes it to output a Quantity with incorrect units instead of a numpy array (although even with correct units, the Quantity still causes issues when using other functions that expect a numpy array).

I have more detailed example code showing the issue if needed, but here's the gist of it with a small test .fits file:

In [1]: ccd_orig = CCDData.read('new1.fits', unit=u.adu)

In [2]: ccd = ccdproc.cosmicray_lacosmic(ccd_orig)

In [3]: ccd.data
Out[3]:
<Quantity [[ 1.,  2.,  3.,  4.],
           [ 2.,  3.,  5.,  7.],
           [ 1.,  4.,  9., 16.],
           [ 1.,  3.,  6., 10.]] electron / adu>

In [4]: ccd_subtracted = ccdproc.subtract_overscan(ccd, overscan=ccd[:, 0:1])

INFO: overwriting Quantity's current unit with specified unit. [astropy.nddata.nddata]
---------------------------------------------------------------------------
UnitConversionError                       Traceback (most recent call last)

^ I think subtract_overscan() expects ccd.data not to have units at all--it throws an error even if the units are corrected.

I've tested out passing the helper gain.value instead of gain, and it fixes both this issue and the earlier one as far as I can tell, so I'll send in a pull request shortly!

altair-above added a commit to altair-above/ccdproc that referenced this issue Jul 26, 2024
mwcraig added a commit that referenced this issue Jul 27, 2024
Fixes #796 - cosmicray_lacosmic data type return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants