Example #1
0
def test_tv_rw_sdmm():
    from numpy.linalg import norm
    from numpy.testing import assert_allclose
    from numpy import sqrt
    from purify.tests.random import reset
    from purify import SDMM
    from purify.tests.image_fixtures import image_and_visibilities, \
                               expected_images, dirty_measurements
    image, visibility = image_and_visibilities()
    expected = expected_images('30dor', 'tvrw')

    reset()
    wavelets = ['DB%i' % i for i in range(1, 9)] + ['Dirac']
    rwsdmm = SDMM(image_size=image.shape,
                  nblevels=4,
                  wavelets=wavelets,
                  reweighted=True,
                  tv_norm=True)
    visibility['y'] = dirty_measurements(image, visibility)

    sigma = norm(visibility['y0']) * 10.0**(-1.5) / sqrt(len(visibility))
    radius = sqrt(1e0 + 2.0 / sqrt(len(visibility))) * sigma               \
              * sqrt(image.size)
    rwsdmm.rw.sigma = sigma * sqrt(len(visibility)) \
                      / sqrt(len(rwsdmm) * image.size)
    rwsdmm.rw.max_iter = 2
    rwsdmm.relative_variation = 1e-3
    rwsdmm.rw.relative_variation = 1e-3
    rwsdmm.rw.warm_start = False
    actual = rwsdmm(visibility, radius=radius, max_iter=3)

    assert_allclose(actual.real, expected)
Example #2
0
def test_tv_sdmm():
    from numpy.linalg import norm
    from numpy.testing import assert_allclose
    from numpy import sqrt
    from purify.tests.random import reset
    from purify import SDMM
    from purify.tests.image_fixtures import image_and_visibilities, \
                               expected_images, dirty_measurements
    image, visibility = image_and_visibilities()
    expected = expected_images('30dor', 'tv')

    reset()
    sdmm = SDMM(image_size=image.shape)

    visibility['y'] = dirty_measurements(image, visibility)

    sigma = norm(visibility['y0']) * 10.0**(-1.5) / sqrt(len(visibility))
    radius = sqrt(1e0 + 2.0 / sqrt(len(visibility))) * sigma               \
              * sqrt(image.size)
    actual = sdmm(visibility,
                  radius=radius,
                  max_iter=6,
                  tv_norm=True,
                  relative_variation=1e-3)

    assert_allclose(actual.real, expected)
Example #3
0
def test_harden_random():
    """ Checks that random numbers are fixed by seed

        These numbers are used to generate fake dirty images from cleaned
        images in both C and python code. They should remain the same.
    """
    from numpy.testing import assert_allclose
    from purify.tests.random import reset

    image, visibility = image_and_visibilities()

    reset()
    actual = make_some_noise(visibility, 5)
    expected = [
        -0.0004048868413905625 + 0.0004998856543791353j,
         0.0010252113233472518 + 0.0006731309681747155j,
        -0.0006402841370415399 - 0.000710428273313625j,
        -0.0015624288645055503 - 0.0016640991757716221j,
         0.0015712341522236288 + 0.0008254357025121923j
    ]
    assert_allclose(actual, expected)
Example #4
0
def test_l1_sdmm():
    from numpy.linalg import norm
    from numpy.testing import assert_allclose
    from numpy import sqrt
    from purify.tests.random import reset
    from purify import SDMM
    from purify.tests.image_fixtures import image_and_visibilities, \
                               expected_images, dirty_measurements
    image, visibility = image_and_visibilities()
    expected = expected_images('30dor')

    reset()
    wavelets = ['DB%i' % i for i in range(1, 9)] + ['Dirac']
    sdmm = SDMM(image_size=image.shape, nblevels=4, wavelets=wavelets)
    visibility['y'] = dirty_measurements(image, visibility)

    sigma = norm(visibility['y0']) * 10.0**(-1.5) / sqrt(len(visibility))
    radius = sqrt(1e0 + 2.0 / sqrt(len(visibility))) * sigma               \
              * sqrt(image.size)
    actual = sdmm(visibility, radius=radius, max_iter=5)

    assert_allclose(actual.real, expected)
Example #5
0
def test_harden_dirty_image():
    """ Make sure dirty image stays what it is. """
    from numpy.testing import assert_allclose
    from numpy import sqrt
    from purify.tests.random import reset
    image, visibility = image_and_visibilities()

    reset()
    actual = dirty_measurements(image, visibility)[:10]
    expected = [
         (-0.0025779629409+0.000750385437798j),
          (0.00114034979371-0.00100676562853j),
         (-0.00136686865551-0.00159946686582j),
         (-0.00198922875103+0.00733872190704j),
         (-0.0060053359212-0.000512419375827j),
          (0.00266958514619-0.00375981242741j),
          (0.00690335501097-0.00766305939611j),
        (-0.000400339081838+0.00084899489691j),
            (0.0034246920022-0.0124356716948j),
          (0.000650022911397+0.0005080970237j),
    ]
    scale = sqrt(image.size) / sqrt(len(visibility))
    assert_allclose(actual, expected / scale)