コード例 #1
0
def test_sample_Gaussian():
    """
    Test SampleImage 'Gaussian'.
    """
    # SampleImage options, recon tolerance
    param = [(dict(), 4e-4), (dict(n=501), 5e-4), (dict(n=501,
                                                        sigma=50), 3e-9)]

    # test transform using Daun with cubic splines (the most accurate)
    for kwargs, tol in param:
        test = SampleImage(name='Gaussian', **kwargs)
        recon = Transform(test.abel,
                          method='daun',
                          symmetry_axis=(0, 1),
                          transform_options={
                              'degree': 3,
                              'verbose': False
                          }).transform
        assert_allclose(recon,
                        test.func,
                        atol=tol,
                        err_msg='-> abel, {}'.format(kwargs))

    # test even size
    n = 10
    r_max = 4.5  # (n - 1) / 2
    sigma = 2
    x = np.arange(n) - r_max
    ref = np.exp(-(x**2 + x[:, None]**2) / sigma**2)

    test = SampleImage(n=n, name='Gaussian', sigma=sigma)
    assert test.r_max == r_max
    assert_allclose(test.r, x)
    assert_allclose(test.func, ref)
    assert_allclose(test.abel, np.sqrt(np.pi) * sigma * ref)
コード例 #2
0
def test_sample_Ominus():
    """
    Test SampleImage 'Ominus'.
    """
    # SampleImage options, recon tolerance
    param = [(dict(), 0.2), (dict(n=501), 0.073), (dict(sigma=3), 0.056),
             (dict(n=501, sigma=3), 0.14), (dict(temperature=100), 0.2)]

    # test transform using Daun with cubic splines (the most accurate)
    for kwargs, tol in param:
        test = SampleImage(name='Ominus', **kwargs)
        recon = Transform(test.abel,
                          method='daun',
                          symmetry_axis=(0, 1),
                          transform_options={
                              'degree': 3,
                              'verbose': False
                          }).transform
        assert_allclose(recon,
                        test.func,
                        atol=tol,
                        err_msg='-> abel, {}'.format(kwargs))

    # test transform tol
    test = SampleImage(name='Ominus')
    abel = test.abel.copy()  # default, ≲5e-3
    abel4 = test.transform(1e-4)
    abel5 = test.transform(1e-5)
    ampl = np.max(abel5)
    assert_allclose(abel, abel5, atol=3e-3 * ampl)
    assert_allclose(abel4, abel5, atol=0.3e-4 * ampl)
コード例 #3
0
def test_sample_Dribinski():
    """
    Test SampleImage 'Dribinski'.
    """
    # test deprecated attribute
    test = SampleImage(name='dribinski')  # (test lower-case)
    with catch_warnings():
        simplefilter('ignore', category=DeprecationWarning)
        assert_equal(test.image, test.func)

    # .abel is difficult to test reliably due to the huge dynamic range

    # test scaling
    n = 501
    test1 = SampleImage(n=n, name='Dribinski', sigma=2)
    test2 = SampleImage(n=n // 2 + 1, name='Dribinski', sigma=1)  # halved
    assert test2.r_max == test1.r_max / 2
    assert_allclose(test2.func, test1.func[::2, ::2])
    assert_allclose(test2.abel, test1.abel[::2, ::2] / 2, atol=2e-6)
コード例 #4
0
def plot(method, strength=None):
    # test distribution
    source = SampleImage(n=2 * rmax - 1).image / scale
    Isrc, _ = Ibeta(source)
    Inorm = (Isrc**2).sum()

    # simulated projection fith Poissonian noise
    proj, _ = rbasex_transform(source, direction='forward')
    proj[proj < 0] = 0
    proj = np.random.RandomState(0).poisson(proj)  # (reproducible, see NEP 19)

    # reconstructed image and intensity
    if strength is None:
        reg = method
    else:
        reg = (method, strength)
    im, distr = rbasex_transform(proj, reg=reg)
    I, _ = distr.Ibeta()

    # plot...
    fig = plt.figure(figsize=(7, 3.5), frameon=False)

    # image
    plt.subplot(121)

    fig = plt.imshow(rescaleI(im), vmin=-vlim, vmax=vlim, cmap='bwr')

    plt.axis('off')
    plt.text(0, 2 * rmax, method, va='top')

    # intensity
    ax = plt.subplot2grid((3, 2), (0, 1), rowspan=2)

    ax.plot(Isrc, c='r', lw=1)
    ax.plot(I, c='k', lw=1)

    ax.set_xlim((0, rmax))
    ax.set_ylim(Ilim)

    # error
    plt.subplot(326)

    plt.axhline(c='r', lw=1)
    plt.plot(I - Isrc, c='b', lw=1)

    plt.xlim((0, rmax))
    plt.ylim(dIlim)

    # finish
    plt.subplots_adjust(left=0,
                        right=0.97,
                        wspace=0.1,
                        bottom=0.08,
                        top=0.98,
                        hspace=0.5)
コード例 #5
0
def test_sample_Gerber():
    """
    Test SampleImage 'Gerber'.
    """
    # test transform with forward Daun with cubic splines (the most accurate)
    test = SampleImage(n=513, name='Gerber')  # original resolution, rmax = 256
    proj = Transform(test.func,
                     method='daun',
                     direction='forward',
                     symmetry_axis=(0, 1),
                     transform_options={
                         'degree': 3,
                         'verbose': False
                     }).transform
    assert_allclose(proj, test.abel, atol=6e-3 * np.max(proj))

    # test sigma-independence of total intensity
    test1 = SampleImage(name='Gerber', sigma=1)
    test2 = SampleImage(name='Gerber', sigma=2)
    assert_allclose(test1.abel.sum(), test2.abel.sum(), rtol=1e-3)
コード例 #6
0
def test_sample_O2():
    """
    Test SampleImage 'O2'.
    """
    # test transform with forward Daun with cubic splines (the most accurate)
    test = SampleImage(n=1001, name='O2')  # ~high resolution
    proj = Transform(test.func,
                     method='daun',
                     direction='forward',
                     symmetry_axis=(0, 1),
                     transform_options={
                         'degree': 3,
                         'verbose': False
                     }).transform
    assert_allclose(proj, test.abel, atol=9e-4 * np.max(proj))
コード例 #7
0
def test_radial_integration():
    """
    Basic test of radial integration.
    """
    # test image (not projected)
    IM = SampleImage(name='dribinski').func

    Beta, Amplitude, Rmidpt, _, _ = \
        vmi.radial_integration(IM, radial_ranges=([(65, 75), (80, 90), (95, 105)]))

    assert_equal(Rmidpt, [70, 85, 100], err_msg='Rmidpt')
    assert_allclose([b[0] for b in Beta], [0, 1.58, -0.85], atol=0.01,
                    err_msg='Beta')
    assert_allclose([a[0] for a in Amplitude], [880, 600, 560], rtol=0.01,
                    err_msg='Amplitude')
コード例 #8
0
def test_toPES():
    """
    Basic test of toPES conversion.
    """
    # test image (not projected)
    IM = SampleImage(name='Ominus').func

    eBE, PES = vmi.toPES(*vmi.angular_integration_3D(IM),
                         energy_cal_factor=1.2e-5,
                         photon_energy=1.0e7/808.6, Vrep=-100,
                         zoom=IM.shape[-1]/2048)

    assert_allclose(eBE[PES.argmax()], 11780, rtol=0.001,
                    err_msg='-> eBE @ max PES')
    assert_allclose(PES.max(), 16620, rtol=0.001,
                    err_msg='-> max PES')
コード例 #9
0
from __future__ import division, print_function

import numpy as np
import matplotlib.pyplot as plt

from abel.tools.analytical import SampleImage
from abel.tools.vmi import Ibeta
from abel.rbasex import rbasex_transform

# test distribution
rmax = 200
scale = 10000
source = SampleImage(n=2 * rmax - 1).image / scale
Isrc, _ = Ibeta(source)
Inorm = (Isrc**2).sum()

# simulated projection fith Poissonian noise
proj, _ = rbasex_transform(source, direction='forward')
proj[proj < 0] = 0
proj = np.random.RandomState(0).poisson(proj)  # (reproducible, see NEP 19)


# calculate relative RMS error for given regularization parameters
def rmse(method, strengths=None):
    if strengths is None:
        _, distr = rbasex_transform(proj, reg=method, out=None)
        I, _ = distr.Ibeta()
        return ((I - Isrc)**2).sum() / Inorm

    err = np.empty_like(strengths, dtype=float)
    for n, strength in enumerate(strengths):
コード例 #10
0
# but with its artifacts masked, showing good agreement with the actual
# distributions.
# Third, the rBasex method is used to transform the initial damaged image with
# the experimental artifacts masked, yielding a correct and cleaner
# reconstructed image and correct reconstructed distributions.

R = 150  # image radius
N = 2 * R + 1  # full image width and height
block_r = 20  # beam-block disk radius
block_w = 5  # beam-block holder width

vlim = 3.6  # intensity limits for images
ylim = (-1.3, 2.7)  # limits for plots

# create source distribution and its profiles for reference
source = SampleImage(N).func / 100
r_src, P0_src, P2_src = rharmonics(source)

# simulate experimental image:
# projection
im, _ = rbasex_transform(source, direction='forward')
# Poissonian noise
im[im < 0] = 0
im = np.random.RandomState(0).poisson(im)
# image coordinates
im_x = np.arange(float(N)) - R
im_y = R - np.arange(float(N))[:, None]
im_r = np.sqrt(im_x**2 + im_y**2)
# simulate beam-block shadow
im = im / (1 + np.exp(-(im_r - block_r)))
im[:R] *= 1 / (1 + np.exp(-(np.abs(im_x) - block_w)))
コード例 #11
0
# but with its artifacts masked, showing good agreement with the actual
# distributions.
# Third, the rBasex method is used to transform the initial damaged image with
# the experimental artifacts masked, yielding a correct and cleaner
# reconstructed image and correct reconstructed distributions.

R = 150  # image radius
N = 2 * R + 1  # full image width and height
block_r = 20  # beam-block disk radius
block_w = 5  # beam-block holder width

vlim = 3.6  # intensity limits for images
ylim = (-1.3, 2.7)  # limits for plots

# create source distribution and its profiles for reference
source = SampleImage(N).image / 100
r_src, P0_src, P2_src = rharmonics(source)

# simulate experimental image:
# projection
im, _ = rbasex_transform(source, direction='forward')
# Poissonian noise
im[im < 0] = 0
im = np.random.RandomState(0).poisson(im)
# image coordinates
im_x = np.arange(float(N)) - R
im_y = R - np.arange(float(N))[:, None]
im_r = np.sqrt(im_x**2 + im_y**2)
# simulate beam-block shadow
im = im / (1 + np.exp(-(im_r - block_r)))
im[:R] *= 1 / (1 + np.exp(-(np.abs(im_x) - block_w)))
コード例 #12
0
from __future__ import division, print_function

import numpy as np
import matplotlib.pyplot as plt

from abel.tools.analytical import SampleImage
from abel.tools.vmi import Ibeta
from abel.rbasex import rbasex_transform

# test distribution
rmax = 200
scale = 10000
source = SampleImage(n=2 * rmax - 1).func / scale
Isrc, _ = Ibeta(source)
Inorm = (Isrc**2).sum()

# simulated projection fith Poissonian noise
proj, _ = rbasex_transform(source, direction='forward')
proj[proj < 0] = 0
proj = np.random.RandomState(0).poisson(proj)  # (reproducible, see NEP 19)


# calculate relative RMS error for given regularization parameters
def rmse(method, strengths=None):
    if strengths is None:
        _, distr = rbasex_transform(proj, reg=method, out=None)
        I, _ = distr.Ibeta()
        return ((I - Isrc)**2).sum() / Inorm

    err = np.empty_like(strengths, dtype=float)
    for n, strength in enumerate(strengths):