Пример #1
0
def run(n, ps, num_runs, queues):
    LOG.info('n: %d', n)
    shape = (n, n)
    distance = 5 * q.m
    material = make_fromfile(
        os.path.join('examples', 'data', 'pmma_5_30_kev.mat'))
    energies = np.linspace(material.energies[0].magnitude,
                           material.energies[-1].magnitude,
                           100,
                           endpoint=False) * material.energies.units
    spheres = {
        queue: make_sphere(n,
                           n / 4 * ps,
                           pixel_size=ps,
                           material=material,
                           queue=queue)
        for queue in queues
    }

    durations = []
    for i in range(num_runs):
        st = time.time()
        gutil.qmap(propagate_one,
                   range(len(queues)),
                   queues=queues,
                   args=(shape, energies, distance, ps, spheres))
        durations.append((time.time() - st) / len(queues))
        LOG.info('%d. run, duration: %.2f s', i + 1, durations[-1])

    mean = np.mean(durations)
    std = np.std(durations)
    LOG.info('Mean duration: %.2f s', mean)
    LOG.info('std: %.2f s', std)

    return mean, std
Пример #2
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()
Пример #3
0
def run(n, ps, num_runs, queues):
    LOG.info('n: %d', n)
    shape = (n, n)
    distance = 5 * q.m
    material = make_fromfile(os.path.join('examples', 'data', 'pmma_5_30_kev.mat'))
    energies = np.linspace(material.energies[0].magnitude,
                           material.energies[-1].magnitude,
                           100, endpoint=False) * material.energies.units
    spheres = {queue: make_sphere(n, n / 4 * ps, pixel_size=ps, material=material, queue=queue)
               for queue in queues}

    durations = []
    for i in range(num_runs):
        st = time.time()
        gutil.qmap(propagate_one, range(len(queues)), queues=queues,
                   args=(shape, energies, distance, ps, spheres))
        durations.append((time.time() - st) / len(queues))
        LOG.info('%d. run, duration: %.2f s', i + 1, durations[-1])

    mean = np.mean(durations)
    std = np.std(durations)
    LOG.info('Mean duration: %.2f s', mean)
    LOG.info('std: %.2f s', std)

    return mean, std
Пример #4
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()
Пример #5
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.0 * 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

    if args.output_thickness:
        imageio.imwrite(args.output_thickness, projection)
    if args.output_projection:
        imageio.imwrite(args.output_projection, ld)
    if args.output_retrieved:
        imageio.imwrite(args.output_retrieved, retrieved)

    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()
Пример #6
0
def main():
    syris.init()
    energies = np.arange(10, 30) * q.keV
    n = 1024
    pixel_size = 0.4 * q.um
    distance = 2 * q.m
    material = make_henke('PMMA', energies)

    sample = make_sphere(n, n / 4 * pixel_size, pixel_size, material=material)
    image = propagate([sample], (n, n), energies, distance, pixel_size).get()

    show(image)
    plt.show()
Пример #7
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()