Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ New Features
- Add option to use regular expression matching when filtering items in
``ImageFileCollection``. [#480, #595, #682]

- Added an option to disregard negative values passed to ``create_deviation``
and assume the error is represented by the read noise [#688]

Other Changes and Additions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -34,6 +37,9 @@ Other Changes and Additions
- When creating a new object in ``wcs_transform``, WCS keywords in the header
are removed so that they are only stored in the WCS object [#685]

- Improved warning for negative values in the array passed to
``create_deviation`` [#688]

- Removed support for initializing ``ImageFileCollection`` from a table instead
of files. [#680]

Expand Down
21 changes: 18 additions & 3 deletions ccdproc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def ccd_process(ccd, oscan=None, trim=None, error=False, master_bias=None,


@log_to_metadata
def create_deviation(ccd_data, gain=None, readnoise=None):
def create_deviation(ccd_data, gain=None, readnoise=None, disregard_nan=False):
"""
Create a uncertainty frame. The function will update the uncertainty
plane which gives the standard deviation for the data. Gain is used in
Expand All @@ -296,6 +296,10 @@ def create_deviation(ccd_data, gain=None, readnoise=None):
Read noise per pixel.
Default is ``None``.

disregard_nan: boolean
If ``True``, any value of nan in the output array will be replaced by
the readnoise.

{log}

Raises
Expand Down Expand Up @@ -331,9 +335,20 @@ def create_deviation(ccd_data, gain=None, readnoise=None):
gain_value = float(gain / gain.unit)
readnoise_value = float(readnoise / readnoise.unit)

var = (gain_value * ccd_data.data + readnoise_value ** 2) ** 0.5
ccd = ccd_data.copy()
# remove values that might be negative or treat as nan
data = gain_value * ccd_data.data
mask = (data < 0)
if disregard_nan:
data[mask] = 0
else:
data[mask] = np.nan
logging.warning('Negative values in array will be replaced with nan')

# calculate the deviation
var = (data + readnoise_value ** 2) ** 0.5

# ensure uncertainty and image data have same unit
ccd = ccd_data.copy()
var /= gain_value
ccd.uncertainty = StdDevUncertainty(var)
return ccd
Expand Down
26 changes: 26 additions & 0 deletions ccdproc/tests/test_ccdproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
(u.adu, u.photon / u.adu, u.electron, False),
])
@pytest.mark.data_size(10)
@pytest.mark.data_mean(100)
def test_create_deviation(ccd_data, u_image, u_gain, u_readnoise,
expect_success):
ccd_data.unit = u_image
Expand Down Expand Up @@ -69,6 +70,31 @@ def test_create_deviation(ccd_data, u_image, u_gain, u_readnoise,
ccd_var = create_deviation(ccd_data, gain=gain, readnoise=readnoise)


@pytest.mark.data_mean(0)
@pytest.mark.data_scale(10)
def test_create_deviation_from_negative(ccd_data):
ccd_data.unit = u.electron
readnoise = 5 * u.electron
ccd_var = create_deviation(ccd_data, gain=None, readnoise=readnoise,
disregard_nan=False)
np.testing.assert_array_equal(ccd_data.data < 0,
np.isnan(ccd_var.uncertainty.array))


@pytest.mark.data_mean(0)
@pytest.mark.data_scale(10)
def test_create_deviation_from_negative(ccd_data):
ccd_data.unit = u.electron
readnoise = 5 * u.electron
ccd_var = create_deviation(ccd_data, gain=None, readnoise=readnoise,
disregard_nan=True)
mask = (ccd_data.data < 0)
ccd_data.data[mask] = 0
expected_var = np.sqrt(ccd_data.data + readnoise.value**2)
np.testing.assert_array_equal(ccd_var.uncertainty.array,
expected_var)


def test_create_deviation_keywords_must_have_unit(ccd_data):
# gain must have units if provided
with pytest.raises(TypeError):
Expand Down