def test_flat_correct_norm_value_bad_value(): ccd_data = ccd_data_func() # Test that flat_correct raises the appropriate error if # it is given a bad norm_value. Bad means <=0. # Create the flat, with some scatter data = np.random.normal(loc=1.0, scale=0.05, size=ccd_data.shape) flat = CCDData(data, meta=fits.Header(), unit=ccd_data.unit) with pytest.raises(ValueError) as e: flat_correct(ccd_data, flat, add_keyword=None, norm_value=-7) assert "norm_value must be" in str(e.value)
def test_flat_correct_min_value(data_scale=1, data_mean=5): ccd_data = ccd_data_func() size = ccd_data.shape[0] # Create the flat data = 2 * np.random.normal(loc=1.0, scale=0.05, size=(size, size)) flat = CCDData(data, meta=fits.header.Header(), unit=ccd_data.unit) flat_orig_data = flat.data.copy() min_value = 2.1 # Should replace some, but not all, values flat_corrected_data = flat_correct(ccd_data, flat, min_value=min_value) flat_with_min = flat.copy() flat_with_min.data[flat_with_min.data < min_value] = min_value # Check that the flat was normalized. The asserts below, which look a # little odd, are correctly testing that # flat_corrected_data = ccd_data / (flat_with_min / mean(flat_with_min)) np.testing.assert_almost_equal( (flat_corrected_data.data * flat_with_min.data).mean(), (ccd_data.data * flat_with_min.data.mean()).mean()) np.testing.assert_allclose(ccd_data.data / flat_corrected_data.data, flat_with_min.data / flat_with_min.data.mean()) # Test that flat is not modified. assert (flat_orig_data == flat.data).all() assert flat_orig_data is not flat.data
def test_flat_correct_does_not_change_input(): ccd_data = ccd_data_func() original = ccd_data.copy() flat = CCDData(np.zeros_like(ccd_data), unit=ccd_data.unit) ccd = flat_correct(ccd_data, flat=flat) np.testing.assert_array_equal(original.data, ccd_data.data) assert original.unit == ccd_data.unit
def test_flat_correct_data_uncertainty(): # Regression test for #345 dat = CCDData(np.ones([100, 100]), unit='adu', uncertainty=np.ones([100, 100])) # Note flat is set to 10, error, if present, is set to one. flat = CCDData(10 * np.ones([100, 100]), unit='adu') res = flat_correct(dat, flat) assert (res.data == dat.data).all() assert (res.uncertainty.array == dat.uncertainty.array).all()
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)
def test_flat_correct(): ccd_data = ccd_data_func(data_scale=10) # Add metadata to header for a test below... ccd_data.header['my_key'] = 42 size = ccd_data.shape[0] # create the flat, with some scatter data = 2 * np.random.normal(loc=1.0, scale=0.05, size=(size, size)) flat = CCDData(data, meta=fits.header.Header(), unit=ccd_data.unit) flat_data = flat_correct(ccd_data, flat, add_keyword=None) # Check that the flat was normalized # Should be the case that flat * flat_data = ccd_data * flat.data.mean # if the normalization was done correctly. np.testing.assert_almost_equal((flat_data.data * flat.data).mean(), ccd_data.data.mean() * flat.data.mean()) np.testing.assert_allclose(ccd_data.data / flat_data.data, flat.data / flat.data.mean()) # Check that metadata is unchanged (since logging is turned off) assert flat_data.header == ccd_data.header
def test_flat_correct_norm_value(): ccd_data = ccd_data_func(data_scale=10) # Test flat correction with mean value that is different than # the mean of the flat frame. # Create the flat, with some scatter # Note that mean value of flat is set below and is different than # the mean of the flat data. flat_mean = 5.0 data = np.random.normal(loc=1.0, scale=0.05, size=ccd_data.shape) flat = CCDData(data, meta=fits.Header(), unit=ccd_data.unit) flat_data = flat_correct(ccd_data, flat, add_keyword=None, norm_value=flat_mean) # Check that the flat was normalized # Should be the case that flat * flat_data = ccd_data * flat_mean # if the normalization was done correctly. np.testing.assert_almost_equal((flat_data.data * flat.data).mean(), ccd_data.data.mean() * flat_mean) np.testing.assert_allclose(ccd_data.data / flat_data.data, flat.data / flat_mean)