Ejemplo n.º 1
0
def test_create_deviation(u_image, u_gain, u_readnoise, expect_success):
    ccd_data = ccd_data_func(data_size=10, data_mean=100)
    ccd_data.unit = u_image
    if u_gain is not None:
        gain = 2.0 * u_gain
    else:
        gain = None
    readnoise = 5 * u_readnoise
    if expect_success:
        ccd_var = create_deviation(ccd_data, gain=gain, readnoise=readnoise)
        assert ccd_var.uncertainty.array.shape == (10, 10)
        assert ccd_var.uncertainty.array.size == 100
        assert ccd_var.uncertainty.array.dtype == np.dtype(float)
        if gain is not None:
            expected_var = np.sqrt(2 * ccd_data.data + 5**2) / 2
        else:
            expected_var = np.sqrt(ccd_data.data + 5**2)
        np.testing.assert_array_equal(ccd_var.uncertainty.array, expected_var)
        assert ccd_var.unit == ccd_data.unit
        # Uncertainty should *not* have any units -- does it?
        with pytest.raises(AttributeError):
            ccd_var.uncertainty.array.unit
    else:
        with pytest.raises(u.UnitsError):
            ccd_var = create_deviation(ccd_data,
                                       gain=gain,
                                       readnoise=readnoise)
Ejemplo n.º 2
0
def test_flat_correct_deviation():
    ccd_data = ccd_data_func(data_scale=10, data_mean=300)
    size = ccd_data.shape[0]
    ccd_data.unit = u.electron
    ccd_data = create_deviation(ccd_data, readnoise=5 * u.electron)
    # Create the flat
    data = 2 * np.ones((size, size))
    flat = CCDData(data, meta=fits.header.Header(), unit=ccd_data.unit)
    flat = create_deviation(flat, readnoise=0.5 * u.electron)
    ccd_data = flat_correct(ccd_data, flat)
Ejemplo n.º 3
0
def test_create_deviation_does_not_change_input():
    ccd_data = ccd_data_func()
    original = ccd_data.copy()
    ccd = create_deviation(ccd_data,
                           gain=5 * u.electron / u.adu,
                           readnoise=10 * u.electron)
    np.testing.assert_array_equal(original.data, ccd_data.data)
    assert original.unit == ccd_data.unit
Ejemplo n.º 4
0
def test_create_deviation_from_negative():
    ccd_data = ccd_data_func(data_mean=0, data_scale=10)
    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))
Ejemplo n.º 5
0
def test_create_deviation_from_negative():
    ccd_data = ccd_data_func(data_mean=0, data_scale=10)
    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)
Ejemplo n.º 6
0
def test_linear_gain_unit_keyword():
    ccd_data = ccd_data_func()
    # The data values should be positive, so the poisson noise calculation
    # works without throwing warnings
    ccd_data.data = np.absolute(ccd_data.data)

    ccd_data = create_deviation(ccd_data, readnoise=1.0 * u.adu)
    orig_data = ccd_data.data
    gain = 3.0
    gain_unit = u.electron / u.adu
    ccd = gain_correct(ccd_data, gain, gain_unit=gain_unit)
    np.testing.assert_array_almost_equal_nulp(ccd.data, gain * orig_data)
    np.testing.assert_array_almost_equal_nulp(
        ccd.uncertainty.array, gain * ccd_data.uncertainty.array)
    assert ccd.unit == ccd_data.unit * gain_unit
Ejemplo n.º 7
0
def test_create_deviation_keywords_must_have_unit():
    ccd_data = ccd_data_func()
    # Gain must have units if provided
    with pytest.raises(TypeError):
        create_deviation(ccd_data, gain=3)
    # Readnoise must have units
    with pytest.raises(TypeError):
        create_deviation(ccd_data, readnoise=5)
    # Readnoise must be provided
    with pytest.raises(ValueError):
        create_deviation(ccd_data)
Ejemplo n.º 8
0
def test_linear_gain_correct(gain):
    ccd_data = ccd_data_func()
    # The data values should be positive, so the poisson noise calculation
    # works without throwing warnings
    ccd_data.data = np.absolute(ccd_data.data)
    ccd_data = create_deviation(ccd_data, readnoise=1.0 * u.adu)
    ccd_data.meta['gainval'] = 3.0
    orig_data = ccd_data.data
    ccd = gain_correct(ccd_data, gain)
    if isinstance(gain, Keyword):
        gain = gain.value  # convert to Quantity...
    try:
        gain_value = gain.value
    except AttributeError:
        gain_value = gain

    np.testing.assert_array_almost_equal_nulp(ccd.data, gain_value * orig_data)
    np.testing.assert_array_almost_equal_nulp(
        ccd.uncertainty.array, gain_value * ccd_data.uncertainty.array)

    if isinstance(gain, u.Quantity):
        assert ccd.unit == ccd_data.unit * gain.unit
    else:
        assert ccd.unit == ccd_data.unit