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

Do not gain correct data when identifying cosmic rays #712

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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