Skip to content

Commit

Permalink
Merge ac8061b into 070360a
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcraig committed Dec 10, 2019
2 parents 070360a + ac8061b commit 10182f3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
@@ -1,4 +1,4 @@
2.1.0 (Unreleased)
2.0.2 (Unreleased)
------------------

New Features
Expand All @@ -10,6 +10,8 @@ Other Changes and Additions
Bug Fixes
^^^^^^^^^

- Do not apply gain when using LACOSMIC to detect cosmic rays. [#712, #705]

2.0.1 (2019-09-05)
------------------

Expand Down
4 changes: 2 additions & 2 deletions ccdproc/core.py
Expand Up @@ -1472,7 +1472,7 @@ def cosmicray_lacosmic(ccd, sigclip=4.5, sigfrac=0.3,
psfsize=psfsize, psfk=psfk, psfbeta=psfbeta,
verbose=verbose)

return cleanarr, crmask
return cleanarr / gain, crmask

elif isinstance(ccd, CCDData):

Expand All @@ -1486,7 +1486,7 @@ def cosmicray_lacosmic(ccd, sigclip=4.5, sigfrac=0.3,

# create the new ccd data object
nccd = ccd.copy()
nccd.data = cleanarr
nccd.data = cleanarr / gain
if nccd.mask is None:
nccd.mask = crmask
else:
Expand Down
25 changes: 25 additions & 0 deletions ccdproc/tests/test_cosmicray.py
Expand Up @@ -64,6 +64,31 @@ def test_cosmicray_lacosmic_check_data():
cosmicray_lacosmic(10, noise)


@pytest.mark.parametrize('array_input', [True, False])
def test_cosmicray_does_not_gain_correct_ndarray_input(array_input):
# Add regression check for #705.
# The issue is that cosmicray_lacosmic gain-corrects the
# data and returns that corrected data. That is not the
# intent...
ccd_data = ccd_data_func(data_scale=DATA_SCALE)
threshold = 5
add_cosmicrays(ccd_data, DATA_SCALE, threshold, ncrays=NCRAYS)
noise = DATA_SCALE * np.ones_like(ccd_data.data)
ccd_data.uncertainty = noise
gain = 2.0
if array_input:
new_data, cr_mask = cosmicray_lacosmic(ccd_data.data, gain=gain)
else:
new_ccd = cosmicray_lacosmic(ccd_data, gain=gain)
new_data = new_ccd.data
cr_mask = new_ccd.mask
# Fill masked locations with 0 since there is no simple relationship
# between the original value and the corrected value.
orig_data = np.ma.array(ccd_data.data, mask=cr_mask).filled(0)
new_data = np.ma.array(new_data, mask=cr_mask).filled(0)
np.testing.assert_allclose(orig_data, new_data)


def test_cosmicray_median_check_data():
with pytest.raises(TypeError):
ndata, crarr = cosmicray_median(10, thresh=5, mbox=11,
Expand Down

0 comments on commit 10182f3

Please sign in to comment.