Beispiel #1
0
def make_motion(args):
    syris.init()
    n = 256
    shape = (n, n)
    energies = np.arange(5, 30, 1) * q.keV
    bm, detector = make_devices(n, energies)
    mb = create_sample(n, detector.pixel_size, velocity=20 * q.mm / q.s)
    mb_2 = create_sample(n, detector.pixel_size, velocity=10 * q.mm / q.s)
    mb.material = get_material('pmma_5_30_kev.mat')
    mb_2.material = mb.material

    cube = make_cube() / q.m * 30 * detector.pixel_size + 0.1 * detector.pixel_size
    fov = detector.pixel_size * n
    circle = make_circle().magnitude * fov / 30000 + fov / 2
    tr = Trajectory(circle, velocity=10 * q.um / q.s)
    glass = get_material('glass.mat')
    mesh = Mesh(cube, tr, material=glass)
    ex = Experiment([bm, mb, mb_2, mesh], bm, detector, 0 * q.m, energies)

    for sample in ex.samples:
        if sample != bm:
            sample.trajectory.bind(detector.pixel_size)

    if args.show_flat:
        show(get_flat(shape, energies, detector, bm), title='Counts')
        plt.show()

    if args.conduct:
        if args.output is not None and not os.path.exists(args.output):
            os.makedirs(args.output, mode=0o755)

        t_0 = 0 * q.s
        if args.num_images:
            t_1 = args.num_images / detector.camera.fps
        else:
            t_1 = ex.time

        st = time.time()
        mpl_im = None
        for i, proj in enumerate(ex.make_sequence(t_0, t_1)):
            image = get_host(proj)

            if args.show:
                if mpl_im is None:
                    plt.figure()
                    mpl_im = plt.imshow(image)
                    plt.show(False)
                else:
                    mpl_im.set_data(image)
                    plt.draw()

            if args.output:
                path = os.path.join(args.output, 'projection_{:>05}.png').format(i)
                scipy.misc.imsave(path, image)

        print 'Maximum intensity:', image.max()
        print 'Duration: {} s'.format(time.time() - st)

    plt.show()
Beispiel #2
0
def make_devices(n, energies, camera=None, highspeed=True, scintillator=None):
    """Create devices with image shape (*n*, *n*), X-ray *energies*, *camera* and use the high speed
    setup if *highspeed* is True.
    """
    shape = (n, n)
    dE = energies[1] - energies[0]

    if not camera:
        vis_wavelengths = np.arange(500, 700) * q.nm
        camera = Camera(11 * q.um, .1, 500, 23, 32, shape, exp_time=1 * q.ms, fps=1000 / q.s,
                        quantum_efficiencies=0.5 * np.ones(len(vis_wavelengths)),
                        wavelengths=vis_wavelengths, dtype=np.float32)
    else:
        vis_wavelengths = camera.wavelengths.rescale(q.nm)

    x = vis_wavelengths.rescale(q.nm).magnitude
    dx = x[1] - x[0]
    if scintillator == 'lso' or not (scintillator or highspeed):
        sigma = fwnm_to_sigma(50)
        emission = np.exp(-(x - 545) ** 2 / (2 * sigma ** 2)) / (sigma * np.sqrt(2 * np.pi))
        lso = get_material('lso_5_30_kev.mat')
        scintillator = Scintillator(13 * q.um,
                                    lso,
                                    36 * np.ones(len(energies)) / q.keV,
                                    energies,
                                    emission / q.nm,
                                    vis_wavelengths,
                                    1.82)
    elif scintillator == 'luag' or (not scintillator and highspeed):
        sigma = fwnm_to_sigma(50)
        emission = np.exp(-(x - 450) ** 2 / (2 * sigma ** 2)) / (sigma * np.sqrt(2 * np.pi))
        luag = get_material('luag.mat')
        scintillator = Scintillator(50 * q.um,
                                    luag,
                                    14 * np.ones(len(energies)) / q.keV,
                                    energies,
                                    emission / q.nm,
                                    vis_wavelengths,
                                    1.84)

    if highspeed:
        # High speed setup
        lens = Lens(3, f_number=1.4, focal_length=50 * q.mm, transmission_eff=0.7, sigma=None)
    else:
        # High resolution setup
        lens = Lens(9, na=0.28, sigma=None)

    detector = Detector(scintillator, lens, camera)
    source_trajectory = Trajectory([(n / 2, n / 2, 0)] * detector.pixel_size)
    bm = make_topotomo(dE=dE, trajectory=source_trajectory, pixel_size=detector.pixel_size)

    return bm, detector
Beispiel #3
0
def main():
    args = parse_args()
    syris.init()
    n = 1024
    d = args.propagation_distance * q.m
    shape = (n, n)
    ps = 1 * q.um
    energy = 20 * q.keV
    tr = Trajectory([(n / 2, n / 2, 0)] * ps, pixel_size=ps)
    sample = make_sphere(n,
                         n / 30 * ps,
                         pixel_size=ps,
                         material=get_material('air_5_30_kev.mat'))

    bm = make_topotomo(pixel_size=ps, trajectory=tr)
    print 'Source size FWHM (height x width): {}'.format(bm.size.rescale(q.um))

    u = bm.transfer(shape, ps, energy, t=0 * q.s)
    u = sample.transfer(shape, ps, energy)
    intensity = propagate([sample], shape, [energy], d, ps).get()
    incoh = bm.apply_blur(intensity, d, ps).get()

    region = (n / 4, n / 4, n / 2, n / 2)
    intensity = ip.crop(intensity, region).get()
    incoh = ip.crop(incoh, region).get()

    show(intensity, title='Coherent')
    show(incoh, title='Applied source blur')
    plt.show()
Beispiel #4
0
def make_topo_tomo_flat(args, highspeed=True, scintillator=None):
    syris.init(device_index=0, loglevel='INFO')
    dimax = make_pco_dimax()
    n = dimax.shape[0]
    energies = np.arange(5, 30) * q.keV

    bm, detector = make_devices(n, energies, camera=dimax, highspeed=highspeed,
                                scintillator=scintillator)

    # Customize the setup for the 2013_03_07-08 experiment
    air = MaterialFilter(1 * q.m, get_material('air_5_30_kev.mat'))
    filters = [air]
    dimax.bpp = 32
    dimax.dtype = np.float32
    dimax.fps = 450 / q.s
    detector.lens.f_number = 2.8
    bm.el_current = 130 * q.mA

    # Compte the flat field
    flat = get_flat(dimax.shape, energies, detector, bm, filters=filters, shot_noise=True,
                    amplifier_noise=True)
    fmt = 'min: {}, max: {}, mean: {}, middle row std: {}'
    print fmt.format(flat.min(), flat.max(), flat.mean(), flat[n / 2].std())

    show(flat)
    plt.show()

    return flat
Beispiel #5
0
def main():
    args = parse_args()
    syris.init()
    n = 1024
    d = args.propagation_distance * q.m
    shape = (n, n)
    ps = 1 * q.um
    energy = 20 * q.keV
    tr = Trajectory([(n / 2, n / 2, 0)] * ps, pixel_size=ps)
    sample = make_sphere(n, n / 30 * ps, pixel_size=ps, material=get_material('air_5_30_kev.mat'))

    bm = make_topotomo(pixel_size=ps, trajectory=tr)
    print 'Source size FWHM (height x width): {}'.format(bm.size.rescale(q.um))

    u = bm.transfer(shape, ps, energy, t=0 * q.s)
    u = sample.transfer(shape, ps, energy)
    intensity = propagate([sample], shape, [energy], d, ps).get()
    incoh = bm.apply_blur(intensity, d, ps).get()

    region = (n / 4, n / 4, n / 2, n / 2)
    intensity = ip.crop(intensity, region).get()
    incoh = ip.crop(incoh, region).get()

    show(intensity, title='Coherent')
    show(incoh, title='Applied source blur')
    plt.show()
Beispiel #6
0
def main():
    args = parse_args()
    syris.init()
    # Propagate to 20 cm
    d = 5 * q.cm
    # Compute grid
    n_camera = 256
    n = n_camera * args.supersampling
    shape = (n, n)
    material = get_material('pmma_5_30_kev.mat')
    energy = 15 * q.keV
    ps = 1 * q.um
    ps_hd = ps / args.supersampling
    radius = n / 4. * ps_hd

    fmt = '                     Wavelength: {}'
    print fmt.format(energy_to_wavelength(energy))
    fmt = 'Pixel size used for propagation: {}'
    print fmt.format(ps_hd.rescale(q.um))
    print '                  Field of view: {}'.format(n * ps_hd.rescale(q.um))
    fmt = '                Sphere diameter: {}'
    print fmt.format(2 * radius)

    sample = make_sphere(n, radius, pixel_size=ps_hd, material=material)
    projection = sample.project((n, n), ps_hd).get() * 1e6
    projection = decimate(projection, (n_camera, n_camera), average=True).get()
    # Propagation with a monochromatic plane incident wave
    hd = propagate([sample], shape, [energy], d, ps_hd).get()
    ld = decimate(hd, (n_camera, n_camera), average=True).get()

    kernel = compute_tie_kernel(n_camera, ps, d, material, energy)
    mju = material.get_attenuation_coefficient(energy).rescale(1 /
                                                               q.m).magnitude
    f_ld = fft_2(ld)
    f_ld *= get_array(kernel.astype(cfg.PRECISION.np_float))
    retrieved = ifft_2(f_ld).get().real
    retrieved = -1 / mju * np.log(retrieved) * 1e6

    show(hd, title='High resolution')
    show(ld, title='Low resolution (detector)')
    show(retrieved, title='Retrieved [um]')
    show(projection, title='Projection [um]')
    show(projection - retrieved, title='Projection - retrieved')
    plt.show()
Beispiel #7
0
def make_topo_tomo_flat(args, highspeed=True, scintillator=None):
    syris.init(device_index=0, loglevel='INFO')
    dimax = make_pco_dimax()
    n = dimax.shape[0]
    energies = np.arange(5, 30) * q.keV

    bm, detector = make_devices(n,
                                energies,
                                camera=dimax,
                                highspeed=highspeed,
                                scintillator=scintillator)

    # Customize the setup for the 2013_03_07-08 experiment
    air = MaterialFilter(1 * q.m, get_material('air_5_30_kev.mat'))
    filters = [air]
    dimax.bpp = 32
    dimax.dtype = np.float32
    dimax.fps = 450 / q.s
    detector.lens.f_number = 2.8
    bm.el_current = 130 * q.mA

    # Compte the flat field
    flat = get_flat(dimax.shape,
                    energies,
                    detector,
                    bm,
                    filters=filters,
                    shot_noise=True,
                    amplifier_noise=True)
    fmt = 'min: {}, max: {}, mean: {}, middle row std: {}'
    print fmt.format(flat.min(), flat.max(), flat.mean(), flat[n / 2].std())

    show(flat)
    plt.show()

    return flat
Beispiel #8
0
def main():
    args = parse_args()
    syris.init()
    # Propagate to 20 cm
    d = 20 * q.cm
    # Compute grid
    n_camera = 256
    n = n_camera * args.supersampling
    shape = (n, n)
    material = get_material('pmma_5_30_kev.mat')
    energies = material.energies
    dE = energies[1] - energies[0]
    # Lens with magnification 5 and numerical aperture 0.25
    lens = Lens(5, na=0.25)
    # Considered visible light wavelengths
    vis_wavelengths = np.arange(500, 700) * q.nm
    # Simple camera quantum efficiencies
    cam_qe = 0.1 * np.ones(len(vis_wavelengths))
    camera = Camera(10 * q.um, 0.1, 500, 23, 32, (256, 256), exp_time=args.exposure * q.ms,
                    fps=1 / q.s, quantum_efficiencies=cam_qe, wavelengths=vis_wavelengths,
                    dtype=np.float32)
    # Scintillator emits visible light into a region given by a Gaussian distribution
    x = camera.wavelengths.rescale(q.nm).magnitude
    sigma = fwnm_to_sigma(50)
    emission = np.exp(-(x - 600) ** 2 / (2 * sigma ** 2)) / (sigma * np.sqrt(2 * np.pi))
    # Scintillator 50 um thick, light yield 14 and refractive index 1.84
    luag = get_material('luag.mat')
    scintillator = Scintillator(50 * q.um,
                                luag,
                                14 * np.ones(len(energies)) / q.keV,
                                energies,
                                emission / q.nm,
                                camera.wavelengths,
                                1.84)
    detector = Detector(scintillator, lens, camera)
    # Pixel size used for propagation
    ps = detector.pixel_size / args.supersampling

    fmt = 'Pixel size used for propagation: {}'
    print fmt.format(ps.rescale(q.um))
    fmt = '  Effective detector pixel size: {}'
    print fmt.format(detector.pixel_size.rescale(q.um))
    print '                  Field of view: {}'.format(n * ps.rescale(q.um))

    # Bending magnet source
    trajectory = Trajectory([(n / 2, n / 2, 0)] * ps)
    source = make_topotomo(dE=dE, trajectory=trajectory, pixel_size=ps)

    sample = make_sphere(n, n / 4. * ps, pixel_size=ps, material=material)
    # Propagation with a monochromatic plane incident wave
    coherent = propagate([source, sample], shape, [15 * q.keV], d, ps, t=0 * q.s,
                         detector=detector).get()
    coherent *= camera.exp_time.simplified.magnitude
    # Decimate to fit the effective pixel size of the detector system
    coherent_ld = camera.get_image(coherent, shot_noise=False, amplifier_noise=False)

    # Propagation which takes into account polychromaticity
    poly = propagate([source, sample], shape, range(10, 30) * q.keV, d, ps, t=0 * q.s,
                     detector=detector).get()
    poly *= camera.exp_time.simplified.magnitude
    poly_ld = camera.get_image(poly, shot_noise=args.noise, amplifier_noise=args.noise)

    # Compute and show some of the used propagators
    propagator_10 = get_propagator_psf(n, d, ps, 10 * q.keV)
    propagator_30 = get_propagator_psf(n, d, ps, 30 * q.keV)

    show(coherent, title='Coherent Supersampled')
    show(coherent_ld, title='Coherent Detector')
    show(propagator_10.real, title='Propagator PSF for 10 keV (real part)')
    show(propagator_30.real, title='Propagator PSF for 30 keV (real part)')
    show(poly, title='Polychromatic Supersampled')
    show(poly_ld, title='Polychromatic Detector')
    plt.show()
Beispiel #9
0
def make_devices(n, energies, camera=None, highspeed=True, scintillator=None):
    """Create devices with image shape (*n*, *n*), X-ray *energies*, *camera* and use the high speed
    setup if *highspeed* is True.
    """
    shape = (n, n)
    dE = energies[1] - energies[0]

    if not camera:
        vis_wavelengths = np.arange(500, 700) * q.nm
        camera = Camera(11 * q.um,
                        .1,
                        500,
                        23,
                        32,
                        shape,
                        exp_time=1 * q.ms,
                        fps=1000 / q.s,
                        quantum_efficiencies=0.5 *
                        np.ones(len(vis_wavelengths)),
                        wavelengths=vis_wavelengths,
                        dtype=np.float32)
    else:
        vis_wavelengths = camera.wavelengths.rescale(q.nm)

    x = vis_wavelengths.rescale(q.nm).magnitude
    dx = x[1] - x[0]
    if scintillator == 'lso' or not (scintillator or highspeed):
        sigma = fwnm_to_sigma(50)
        emission = np.exp(-(x - 545)**2 /
                          (2 * sigma**2)) / (sigma * np.sqrt(2 * np.pi))
        lso = get_material('lso_5_30_kev.mat')
        scintillator = Scintillator(13 * q.um, lso,
                                    36 * np.ones(len(energies)) / q.keV,
                                    energies, emission / q.nm, vis_wavelengths,
                                    1.82)
    elif scintillator == 'luag' or (not scintillator and highspeed):
        sigma = fwnm_to_sigma(50)
        emission = np.exp(-(x - 450)**2 /
                          (2 * sigma**2)) / (sigma * np.sqrt(2 * np.pi))
        luag = get_material('luag.mat')
        scintillator = Scintillator(50 * q.um, luag,
                                    14 * np.ones(len(energies)) / q.keV,
                                    energies, emission / q.nm, vis_wavelengths,
                                    1.84)

    if highspeed:
        # High speed setup
        lens = Lens(3,
                    f_number=1.4,
                    focal_length=50 * q.mm,
                    transmission_eff=0.7,
                    sigma=None)
    else:
        # High resolution setup
        lens = Lens(9, na=0.28, sigma=None)

    detector = Detector(scintillator, lens, camera)
    source_trajectory = Trajectory([(n / 2, n / 2, 0)] * detector.pixel_size)
    bm = make_topotomo(dE=dE,
                       trajectory=source_trajectory,
                       pixel_size=detector.pixel_size)

    return bm, detector
Beispiel #10
0
def make_motion(args):
    syris.init()
    n = 256
    shape = (n, n)
    energies = np.arange(5, 30, 1) * q.keV
    bm, detector = make_devices(n, energies)
    mb = create_sample(n, detector.pixel_size, velocity=20 * q.mm / q.s)
    mb_2 = create_sample(n, detector.pixel_size, velocity=10 * q.mm / q.s)
    mb.material = get_material('pmma_5_30_kev.mat')
    mb_2.material = mb.material

    cube = make_cube(
    ) / q.m * 30 * detector.pixel_size + 0.1 * detector.pixel_size
    fov = detector.pixel_size * n
    circle = make_circle().magnitude * fov / 30000 + fov / 2
    tr = Trajectory(circle, velocity=10 * q.um / q.s)
    glass = get_material('glass.mat')
    mesh = Mesh(cube, tr, material=glass)
    ex = Experiment([bm, mb, mb_2, mesh], bm, detector, 0 * q.m, energies)

    for sample in ex.samples:
        if sample != bm:
            sample.trajectory.bind(detector.pixel_size)

    if args.show_flat:
        show(get_flat(shape, energies, detector, bm), title='Counts')
        plt.show()

    if args.conduct:
        if args.output is not None and not os.path.exists(args.output):
            os.makedirs(args.output, mode=0o755)

        t_0 = 0 * q.s
        if args.num_images:
            t_1 = args.num_images / detector.camera.fps
        else:
            t_1 = ex.time

        st = time.time()
        mpl_im = None
        for i, proj in enumerate(ex.make_sequence(t_0, t_1)):
            image = get_host(proj)

            if args.show:
                if mpl_im is None:
                    plt.figure()
                    mpl_im = plt.imshow(image)
                    plt.show(False)
                else:
                    mpl_im.set_data(image)
                    plt.draw()

            if args.output:
                path = os.path.join(args.output,
                                    'projection_{:>05}.png').format(i)
                scipy.misc.imsave(path, image)

        print 'Maximum intensity:', image.max()
        print 'Duration: {} s'.format(time.time() - st)

    plt.show()
Beispiel #11
0
## == GAUSIAN FILTER (MONOCHROMATOR APPROX) ==
fwhm = dE_mono * energy * q.eV
sigma = smath.fwnm_to_sigma(fwhm, n=2)
fltr = GaussianFilter(energies, energy * q.eV, sigma)

# == SAMPLE ===
meshes = read_collada(OBJ_PATH, [(n / 2, n / 2, 0)] * detector.pixel_size,
                      iterations=1)

tr = Trajectory([(0 / 2, 0 / 2, 0)] * detector.pixel_size)

cb = CompositeBody(tr, bodies=meshes)
cb.bind_trajectory(detector.pixel_size)

airm = get_material('air_dry.mat')
cu = get_material('cu.mat')
air_gap = MaterialFilter(3 * q.m, airm)
abs_fltr = MaterialFilter(100 * q.um, cu)
# === MAKE EXPERIMENT ===
ex = Tomography([undu, fltr, abs_fltr, air_gap, cb], cb, undu, detector,
                [53.455, 0, 0, 32.477, 0.15] * q.m, energies)

# == CONDUCT EXPERIMENT
if OUTPUT is not None and not os.path.exists(OUTPUT):
    os.makedirs(OUTPUT, mode=0o755)

t_0 = 0 * q.s

t_1 = NO_OF_IMAGES / detector.camera.fps
st = time.time()