def test_cosmicray_lacosmic_does_not_change_input(): ccd_data = ccd_data_func() original = ccd_data.copy() error = np.zeros_like(ccd_data) ccd = cosmicray_lacosmic(ccd_data) np.testing.assert_array_equal(original.data, ccd_data.data) assert original.unit == ccd_data.unit
def test_cosmicray_lacosmic_ccddata(): 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 nccd_data = cosmicray_lacosmic(ccd_data, sigclip=5)
def test_cosmicray_lacosmic_detects_inconsistent_units(): # This is intended to detect cases like a ccd with units # of adu, a readnoise in electrons and a gain in adu / electron. # That is not internally inconsistent. ccd_data = ccd_data_func(data_scale=DATA_SCALE) ccd_data.unit = 'adu' threshold = 5 add_cosmicrays(ccd_data, DATA_SCALE, threshold, ncrays=NCRAYS) noise = DATA_SCALE * np.ones_like(ccd_data.data) ccd_data.uncertainty = noise readnoise = 6.5 * u.electron # The units below are deliberately incorrect. gain = 2.0 * u.adu / u.electron with pytest.raises(ValueError) as e: cosmicray_lacosmic(ccd_data, gain=gain, gain_apply=True, readnoise=readnoise) assert 'Inconsistent units' in str(e.value)
def test_cosmicray_lacosmic_accepts_quantity_gain(): 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 # The units below are the point of the test gain = 2.0 * u.electron / u.adu # Since gain and ccd_data have units, the readnoise should too. readnoise = 6.5 * u.electron new_ccd = cosmicray_lacosmic(ccd_data, gain=gain, gain_apply=True)
def test_cosmicray_gain_correct(array_input, gain_correct_data): # Add regression check for #705 and for the new gain_correct # argument. # The issue is that cosmicray_lacosmic gain-corrects the # data and returns that gain 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 # No units here on purpose. gain = 2.0 # Don't really need to set this (6.5 is the default value) but want to # make lack of units explicit. readnoise = 6.5 if array_input: new_data, cr_mask = cosmicray_lacosmic(ccd_data.data, gain=gain, gain_apply=gain_correct_data) else: new_ccd = cosmicray_lacosmic(ccd_data, gain=gain, gain_apply=gain_correct_data) 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.data, mask=cr_mask).filled(0) if gain_correct_data: gain_for_test = gain else: gain_for_test = 1.0 np.testing.assert_allclose(gain_for_test * orig_data, new_data)
def test_cosmicray_lacosmic_warns_on_ccd_in_electrons(recwarn): # Check that an input ccd in electrons raises a warning. ccd_data = ccd_data_func(data_scale=DATA_SCALE) # The unit below is important for the test; this unit on # input is supposed to raise an error. ccd_data.unit = u.electron threshold = 5 add_cosmicrays(ccd_data, DATA_SCALE, threshold, ncrays=NCRAYS) noise = DATA_SCALE * np.ones_like(ccd_data.data) ccd_data.uncertainty = noise # No units here on purpose. gain = 2.0 # Don't really need to set this (6.5 is the default value) but want to # make lack of units explicit. readnoise = 6.5 new_ccd = cosmicray_lacosmic(ccd_data, gain=gain, gain_apply=True, readnoise=readnoise) assert len(recwarn) == 1 assert "Image unit is electron" in str(recwarn.pop())
def test_cosmicray_lacosmic_check_data(): ccd_data = ccd_data_func(data_scale=DATA_SCALE) with pytest.raises(TypeError): noise = DATA_SCALE * np.ones_like(ccd_data.data) cosmicray_lacosmic(10, noise)
def test_cosmicray_lacosmic(): 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) data, crarr = cosmicray_lacosmic(ccd_data.data, sigclip=5)