astropy/ccdproc

ccdproc.cosmicray_lacosmic has undocumented side effect of gain correcting CCDData

Closed this issue · 2 comments

Calling ccdproc.cosmicray_lacosmic() on a CCDData object that has not been gain corrected (i.e. units of ADU) has the side effect of scaling the image data by the gain value passed to ccdproc.cosmicray_lacosmic. The units of the returned CCDData do not get changed, however, and remain as ADU even though the data is now in electrons.

The fact that the data has been gain corrected during the cosmic ray removal does not get logged in the header either, but then neither does the cosmic ray removal itself.

This side effect is undocumented and probably unintended? My expectation was that when calling cosmicray_lacosmic on a non-gain corrected CCDData and passing in a gain value the data would be converted to electrons for the cosmic ray removal (which happens), and then be converted back to ADU for the returned CCDData (which doesn't happen).

Minimal example:

In [1]: import numpy as np                                                                                                             

In [2]: import ccdproc                                                                                                                 

In [3]: c1 = ccdproc.CCDData(np.arange(1,10).reshape((3, 3)), unit='adu')                                                              

In [4]: c1                                                                                                                             
Out[4]: 
CCDData([[1, 2, 3],
         [4, 5, 6],
         [7, 8, 9]])

In [5]: c1.unit                                                                                                                        
Out[5]: Unit("adu")

In [6]: c2 = ccdproc.cosmicray_lacosmic(c1, gain=2.0)                                                                                  

In [7]: c2                                                                                                                             
Out[7]: 
CCDData([[ 2.,  4.,  6.],
         [ 8., 10., 12.],
         [14., 16., 18.]])

In [8]: c2.unit                                                                                                                        
Out[8]: Unit("adu")

If the gain correction is intended behaviour then it needs to also change the units, needs to log to the header, and needs to be documented.

astropy 3.2.3
ccdproc 2.0.1
numpy 1.17.3

Thanks for reporting this with the short example; we should do a bug fix release for this fairly quickly. I will try to get to it this weekend.

I think the correct behavior here should be to not modify the data.

Closed by #716