From 52f6685873032c4ffc6eb98ef54c63fa41d6177e Mon Sep 17 00:00:00 2001 From: Steven Crawford Date: Tue, 20 May 2014 13:07:36 +0200 Subject: [PATCH 1/2] Fix bug in sigma_clip so it does it for each pixel --- ccdproc/combiner.py | 4 ++-- ccdproc/tests/test_combiner.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ccdproc/combiner.py b/ccdproc/combiner.py index 24453675..8f98f7b8 100644 --- a/ccdproc/combiner.py +++ b/ccdproc/combiner.py @@ -155,8 +155,8 @@ def sigma_clipping(self, low_thresh=3, high_thresh=3, #check for negative numbers in low_thresh #setup baseline values - baseline = func(self.data_arr) - dev = dev_func(self.data_arr) + baseline = func(self.data_arr, axis=0) + dev = dev_func(self.data_arr, axis=0) #reject values if low_thresh is not None: if low_thresh < 0: diff --git a/ccdproc/tests/test_combiner.py b/ccdproc/tests/test_combiner.py index c45feae7..a4d6850d 100644 --- a/ccdproc/tests/test_combiner.py +++ b/ccdproc/tests/test_combiner.py @@ -136,6 +136,24 @@ def test_combiner_sigmaclip_high(): dev_func=mad) assert c.data_arr[5].mask.all() +def test_combiner_sigmaclip_single_pix(): + ccd_list = [CCDData(np.zeros((10, 10)), unit=u.adu), + CCDData(np.zeros((10, 10)) - 10, unit=u.adu), + CCDData(np.zeros((10, 10)) + 10, unit=u.adu), + CCDData(np.zeros((10, 10)) - 10, unit=u.adu), + CCDData(np.zeros((10, 10)) + 10, unit=u.adu), + CCDData(np.zeros((10, 10)) - 10, unit=u.adu)] + c = Combiner(ccd_list) + #add a single pixel in another array to check that + #that one gets rejected + c.data_arr[0,5,5] = 0 + c.data_arr[1,5,5] = -5 + c.data_arr[2,5,5] = 5 + c.data_arr[3,5,5] = -5 + c.data_arr[4,5,5] = 25 + c.sigma_clipping(high_thresh=3, low_thresh=None, func=np.median, + dev_func=mad) + assert c.data_arr.mask[4,5,5] == True def test_combiner_sigmaclip_low(): ccd_list = [CCDData(np.zeros((10, 10)), unit=u.adu), From 77b8b79dc51e69f80cee6f68f665b185af421f49 Mon Sep 17 00:00:00 2001 From: Steven Crawford Date: Tue, 20 May 2014 13:29:20 +0200 Subject: [PATCH 2/2] Added min_value and tests for flat task --- ccdproc/ccdproc.py | 11 ++++++++++- ccdproc/tests/test_ccdproc.py | 20 +++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ccdproc/ccdproc.py b/ccdproc/ccdproc.py index cf65cb64..4876ba39 100644 --- a/ccdproc/ccdproc.py +++ b/ccdproc/ccdproc.py @@ -416,7 +416,7 @@ def gain_correct(ccd, gain, gain_unit=None): @log_to_metadata -def flat_correct(ccd, flat): +def flat_correct(ccd, flat, min_value=None): """Correct the image for flatfielding Parameters @@ -427,6 +427,11 @@ def flat_correct(ccd, flat): flat : CCDData object Flatfield to apply to the data + min_value : None or float + Minimum value for flat field. The value can either be None and no + minimum value is applied to the flat or specified by a float which + will replace all values in the flat by the min_value. + {log} Returns @@ -434,6 +439,10 @@ def flat_correct(ccd, flat): ccd : CCDData object CCDData object with flat corrected """ + #Use the min_value to replace any values in the flat + if min_value is not None: + flat.data[flat.data < min_value] = min_value + # normalize the flat flat.data = flat.data / flat.data.mean() if flat.uncertainty is not None: diff --git a/ccdproc/tests/test_ccdproc.py b/ccdproc/tests/test_ccdproc.py index 26aa16a8..814164b1 100644 --- a/ccdproc/tests/test_ccdproc.py +++ b/ccdproc/tests/test_ccdproc.py @@ -301,11 +301,29 @@ def test_subtract_dark_fails(ccd_data): @pytest.mark.data_scale(10) def test_flat_correct(ccd_data): size = ccd_data.shape[0] + orig_mean = ccd_data.data.mean() + # create the flat + data = 2 * np.ones((size, size)) + flat = CCDData(data, meta=fits.header.Header(), unit=ccd_data.unit) + flat_data = flat_correct(ccd_data, flat) + + #check that the flat was normalized + assert flat_data.data.mean() == ccd_data.data.mean() + assert (ccd_data.data / flat_data.data == flat.data).all() +# test for flat correction with min_value +@pytest.mark.data_scale(10) +def test_flat_correct_min_value(ccd_data): + size = ccd_data.shape[0] + orig_mean = ccd_data.data.mean() # create the flat data = 2 * np.ones((size, size)) flat = CCDData(data, meta=fits.header.Header(), unit=ccd_data.unit) - ccd_data = flat_correct(ccd_data, flat) + flat_data = flat_correct(ccd_data, flat, min_value = 4) + + #check that the flat was normalized + assert flat_data.data.mean() == ccd_data.data.mean() + assert (ccd_data.data / flat_data.data == flat.data).all() # test for variance and for flat correction