예제 #1
0
def test_crosstalk(set_random_seed):
    tester = CrosstalkCorrector(None)
    nx = 101
    ny = 103

    image = FakeImage(nx=nx, ny=ny)
    # Add random pixels at 10000 to each of the extensions
    for amp in range(4):
        image.data = np.ones((4, ny, nx)) * 1000.0
        random_pixels_x = np.random.randint(0, nx - 1, size=int(0.05 * nx * ny))
        random_pixels_y = np.random.randint(0, ny - 1, size=int(0.05 * nx * ny))
        for i in zip(random_pixels_y, random_pixels_x):
            image.data[amp][i] = 10000

    expected_image_data = image.data.copy()

    # Simulate crosstalk
    original_data = image.data.copy()
    for j in range(4):
        for i in range(4):
            if i != j:
                crosstalk_coeff = np.random.uniform(0.0, 0.01)
                image.header['CRSTLK{i}{j}'.format(i=i+1, j=j+1)] = crosstalk_coeff
                image.data[j] += original_data[i] * crosstalk_coeff
    # Try to remove it
    image = tester.do_stage(image)
    # Assert that we got back the original image
    np.testing.assert_allclose(image.data, expected_image_data, atol=2.0, rtol=1e-5)
예제 #2
0
def test_pattern_noise_on_2d_image(set_random_seed):
    image = FakeImage()
    image.data = generate_data(has_pattern_noise=True)

    detector = pattern_noise.PatternNoiseDetector(None)
    logger.error = mock.MagicMock()
    detector.do_stage(image)
    assert logger.error.called
예제 #3
0
파일: test_image.py 프로젝트: baulml/banzai
def test_get_inner_quarter_default():
    test_image = FakeImage()
    test_image.data = np.random.randint(0, 1000, size=test_image.data.shape)
    # get inner quarter manually
    inner_nx = round(test_image.nx * 0.25)
    inner_ny = round(test_image.ny * 0.25)
    inner_quarter = test_image.data[inner_ny:-inner_ny, inner_nx:-inner_nx]
    np.testing.assert_array_equal(test_image.get_inner_image_section(), inner_quarter)
예제 #4
0
파일: test_image.py 프로젝트: LCOGT/banzai
def test_get_inner_quarter_default():
    test_image = FakeImage()
    test_image.data = np.random.randint(0, 1000, size=test_image.data.shape)
    # get inner quarter manually
    inner_nx = round(test_image.nx * 0.25)
    inner_ny = round(test_image.ny * 0.25)
    inner_quarter = test_image.data[inner_ny:-inner_ny, inner_nx:-inner_nx]
    np.testing.assert_array_equal(test_image.get_inner_image_section(), inner_quarter)
예제 #5
0
def test_pattern_noise_on_2d_image(set_random_seed):
    image = FakeImage()
    image.data = generate_data(has_pattern_noise=True)

    detector = pattern_noise.PatternNoiseDetector(None)
    logger.error = mock.MagicMock()
    detector.do_stage(image)
    assert logger.error.called
예제 #6
0
def test_pattern_noise_on_3d_image(mock_save_qc):
    data = 100.0 * np.sin(np.arange(1000000 * 4) / 0.1) + 1000.0 + np.random.normal(0.0, 10.0, size=1000000 * 4)
    data = data.reshape(4, 1000, 1000)

    image = FakeImage()
    image.data = data

    detector = pattern_noise.PatternNoiseDetector(None)
    _ = detector.do_stage([image])

    assert mock_save_qc.called
예제 #7
0
def test_bias_master_level_subtraction_is_reasonable(set_random_seed):
    input_bias = 2000.0
    read_noise = 15.0

    subtractor = BiasMasterLevelSubtractor(None)
    image = FakeImage()
    image.data = np.random.normal(input_bias, read_noise, size=(image.ny, image.nx))
    image = subtractor.do_stage(image)

    np.testing.assert_allclose(np.zeros(image.data.shape), image.data, atol=8 * read_noise)
    np.testing.assert_allclose(image.header.get('BIASLVL'), input_bias, atol=1.0)
예제 #8
0
def test_dark_normalization_is_reasonable(set_random_seed):
    nx = 101
    ny = 103

    normalizer = DarkNormalizer(None)
    data = np.random.normal(30.0, 10, size=(ny, nx))
    image = FakeImage()
    image.data = data.copy()

    image = normalizer.do_stage(image)
    np.testing.assert_allclose(image.data, data / image.exptime, 1e-5)
예제 #9
0
def test_pattern_noise_in_only_one_quadrant(mock_save_qc):
    data = np.random.normal(0.0, 10.0, size=1000000 * 4) + 1000.0
    data = data.reshape(4, 1000, 1000)
    data[3] += 100.0 * np.sin(np.arange(1e6) / 0.1).reshape(1000, 1000)

    image = FakeImage()
    image.data = data

    detector = pattern_noise.PatternNoiseDetector(None)
    _ = detector.do_stage([image])

    assert mock_save_qc.called
예제 #10
0
def test_does_not_reject_noisy_image(mock_cal, mock_frame, set_random_seed):
    mock_cal.return_value = 'test.fits'
    master_readnoise = 3.0
    nx = 101
    ny = 103

    context = make_context_with_master_bias(readnoise=master_readnoise, nx=nx, ny=ny)
    comparer = BiasComparer(context)
    image = FakeImage(image_multiplier=0.0)
    image.data = np.random.normal(0.0, image.readnoise, size=(ny, nx))

    image = comparer.do_stage(image)

    assert image.is_bad is False
예제 #11
0
def test_does_not_reject_noisy_image(mock_cal, mock_frame, set_random_seed):
    mock_cal.return_value = 'test.fits'
    master_readnoise = 3.0
    nx = 101
    ny = 103

    context = make_context_with_master_bias(readnoise=master_readnoise,
                                            nx=nx,
                                            ny=ny)
    comparer = BiasComparer(context)
    image = FakeImage(image_multiplier=0.0)
    image.data = np.random.normal(0.0, image.readnoise, size=(ny, nx))

    image = comparer.do_stage(image)

    assert image.is_bad is False
예제 #12
0
def test_flat_normalization_is_reasonable(set_random_seed):
    flat_variation = 0.05
    input_level = 10000.0
    nx = 101
    ny = 103

    normalizer = FlatNormalizer(None)
    image = FakeImage()
    flat_pattern = np.random.normal(1.0, flat_variation, size=(ny, nx))
    image.data = np.random.poisson(flat_pattern * input_level).astype(float)
    image = normalizer.do_stage(image)

    # For right now, we only use a quarter of the image to calculate the flat normalization
    # because real ccds have crazy stuff at the edges, so the S/N is cut down by a factor of 2
    # Assume 50% slop because the variation in the pattern does not decrease like sqrt(n)
    assert np.abs(image.header['FLATLVL'] - input_level) < (3.0 * flat_variation * input_level / (nx * ny) ** 0.5)
    assert np.abs(np.mean(image.data) - 1.0) <= 3.0 * flat_variation / (nx * ny) ** 0.5
예제 #13
0
def test_does_flag_bad_image(mock_cal, mock_frame, set_random_seed):
    mock_cal.return_value = 'test.fits'
    master_readnoise = 3.0
    nx = 101
    ny = 103

    context = make_context_with_master_bias(readnoise=master_readnoise, nx=nx, ny=ny)
    comparer = BiasComparer(context)
    image = FakeImage(image_multiplier=0.0)
    image.data = np.random.normal(0.0, image.readnoise, size=(ny, nx))

    x_indexes = np.random.choice(np.arange(nx), size=2000)
    y_indexes = np.random.choice(np.arange(ny), size=2000)
    for x, y in zip(x_indexes, y_indexes):
        image.data[y, x] = np.random.normal(100, image.readnoise)
    image = comparer.do_stage(image)

    assert image.is_bad
예제 #14
0
def test_does_flag_bad_image(mock_cal, mock_frame, set_random_seed):
    mock_cal.return_value = 'test.fits'
    master_readnoise = 3.0
    nx = 101
    ny = 103

    context = make_context_with_master_bias(readnoise=master_readnoise,
                                            nx=nx,
                                            ny=ny)
    comparer = BiasComparer(context)
    image = FakeImage(image_multiplier=0.0)
    image.data = np.random.normal(0.0, image.readnoise, size=(ny, nx))

    x_indexes = np.random.choice(np.arange(nx), size=2000)
    y_indexes = np.random.choice(np.arange(ny), size=2000)
    for x, y in zip(x_indexes, y_indexes):
        image.data[y, x] = np.random.normal(100, image.readnoise)
    image = comparer.do_stage(image)

    assert image.is_bad
예제 #15
0
def test_crosstalk(set_random_seed):
    tester = CrosstalkCorrector(None)
    nx = 101
    ny = 103

    image = FakeImage(nx=nx, ny=ny)
    # Add random pixels at 10000 to each of the extensions
    for amp in range(4):
        image.data = np.ones((4, ny, nx)) * 1000.0
        random_pixels_x = np.random.randint(0,
                                            nx - 1,
                                            size=int(0.05 * nx * ny))
        random_pixels_y = np.random.randint(0,
                                            ny - 1,
                                            size=int(0.05 * nx * ny))
        for i in zip(random_pixels_y, random_pixels_x):
            image.data[amp][i] = 10000

    expected_image_data = image.data.copy()

    # Simulate crosstalk
    original_data = image.data.copy()
    for j in range(4):
        for i in range(4):
            if i != j:
                crosstalk_coeff = np.random.uniform(0.0, 0.01)
                image.header['CRSTLK{i}{j}'.format(i=i + 1,
                                                   j=j + 1)] = crosstalk_coeff
                image.data[j] += original_data[i] * crosstalk_coeff
    # Try to remove it
    image = tester.do_stage(image)
    # Assert that we got back the original image
    np.testing.assert_allclose(image.data,
                               expected_image_data,
                               atol=2.0,
                               rtol=1e-5)