Skip to content

Commit

Permalink
Merge 77b8b79 into 1d5fcae
Browse files Browse the repository at this point in the history
  • Loading branch information
crawfordsm committed May 20, 2014
2 parents 1d5fcae + 77b8b79 commit a73ad03
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
11 changes: 10 additions & 1 deletion ccdproc/ccdproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -427,13 +427,22 @@ 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
-------
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:
Expand Down
4 changes: 2 additions & 2 deletions ccdproc/combiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 19 additions & 1 deletion ccdproc/tests/test_ccdproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions ccdproc/tests/test_combiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit a73ad03

Please sign in to comment.