Esempio n. 1
0
 def setUp(self):
     syris.init(device_index=0)
     wavelengths = np.arange(10) * q.nm
     qe = np.ones(len(wavelengths))
     self.camera = Camera(1e-3 * q.um,
                          1.0,
                          10.0,
                          0,
                          10, (64, 64),
                          wavelengths=wavelengths,
                          quantum_efficiencies=qe,
                          exp_time=1 * q.s,
                          fps=1 / q.s)
Esempio n. 2
0
 def setUp(self):
     default_syris_init()
     lens = Lens(3.0, f_number=1.4, focal_length=100.0 * q.mm)
     camera = Camera(1 * q.um, 0.1, 10, 1.0, 12, (64, 64))
     detector = Detector(None, lens, camera)
     ps = detector.pixel_size
     t = np.linspace(0, 1, 10) * q.mm
     x = t
     y = np.zeros(len(t))
     z = np.zeros(len(t))
     points = list(zip(x, y, z)) * q.mm
     mb_0 = MetaBall(
         Trajectory(points,
                    pixel_size=ps,
                    furthest_point=1 * q.um,
                    velocity=1 * q.mm / q.s),
         1 * q.um,
     )
     mb_1 = MetaBall(
         Trajectory(points,
                    pixel_size=ps,
                    furthest_point=1 * q.um,
                    velocity=2 * q.mm / q.s),
         1 * q.um,
     )
     self.experiment = Experiment([mb_0, mb_1], None, detector, 0 * q.m,
                                  None)
Esempio n. 3
0
 def setUp(self):
     syris.init(device_index=0)
     wavelengths = np.arange(10) * q.nm
     qe = np.ones(len(wavelengths))
     self.camera = Camera(1e-3 * q.um,
                          1.0,
                          10.0,
                          0,
                          10,
                          (64, 64),
                          wavelengths=wavelengths,
                          quantum_efficiencies=qe,
                          exp_time=1 * q.s,
                          fps=1 / q.s)
Esempio n. 4
0
    def test_constructor(self):
        Camera(1 * q.um, 0.1, 10, 1, 12, None)
        Camera(1 * q.um, 0.1, 10, 1, 12, (64, 64))
        # Exposure time priority
        cam = Camera(1 * q.um,
                     0.1,
                     10,
                     1,
                     12,
                     None, (64, 64),
                     exp_time=1 * q.ms,
                     fps=10000 / q.s)
        self.assertEqual(cam.fps.simplified, 1000 / q.s)

        # Shorter exposure time than 1 / FPS
        cam = Camera(1 * q.um,
                     0.1,
                     10,
                     1,
                     12, (64, 64),
                     exp_time=0.5 * q.s,
                     fps=1 / q.s)
        self.assertEqual(cam.exp_time, .5 * q.s)
        self.assertEqual(cam.fps, 1 / q.s)
Esempio n. 5
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()
Esempio n. 6
0
class TestCamera(SyrisTest):

    def setUp(self):
        syris.init(device_index=0)
        wavelengths = np.arange(10) * q.nm
        qe = np.ones(len(wavelengths))
        self.camera = Camera(1e-3 * q.um,
                             1.0,
                             10.0,
                             0,
                             10,
                             (64, 64),
                             wavelengths=wavelengths,
                             quantum_efficiencies=qe,
                             exp_time=1 * q.s,
                             fps=1 / q.s)

    def test_constructor(self):
        Camera(1 * q.um, 0.1, 10, 1, 12, None)
        Camera(1 * q.um, 0.1, 10, 1, 12, (64, 64))
        # Exposure time priority
        cam = Camera(1 * q.um, 0.1, 10, 1, 12, None, (64, 64), exp_time=1 * q.ms, fps=10000 / q.s)
        self.assertEqual(cam.fps.simplified, 1000 / q.s)

        # Shorter exposure time than 1 / FPS
        cam = Camera(1 * q.um, 0.1, 10, 1, 12, (64, 64), exp_time = 0.5 * q.s, fps=1 / q.s)
        self.assertEqual(cam.exp_time, .5 * q.s)
        self.assertEqual(cam.fps, 1 / q.s)

    def test_is_fps_feasible(self):
        self.assertTrue(is_fps_feasible(1000 / q.s, 1 * q.ms))
        self.assertTrue(is_fps_feasible(1000 / q.s, 0.5 * q.ms))
        self.assertFalse(is_fps_feasible(1000 / q.s, 2 * q.ms))

    def test_fps_setting(self):
        self.camera.fps = 1000 / q.s
        self.assertAlmostEqual(1e-3, self.camera.exp_time.simplified.magnitude)

    def test_exp_time_setting(self):
        self.camera.exp_time = 10 * q.s
        self.assertAlmostEqual(.1, self.camera.fps.simplified.magnitude)

    def test_bpp(self):
        self.assertEqual(self.camera.max_grey_value, 2 ** self.camera.bpp - 1)

    def test_dark(self):
        photons = np.zeros(self.camera.shape, dtype=cfg.PRECISION.np_float)
        res = self.camera.get_image(photons, shot_noise=True, psf=False)

        self.assertNotEqual(np.var(res), 0.0)
        self.assertNotEqual(np.sum(res), 0.0)

    def test_saturation(self):
        photons = np.ones(self.camera.shape, dtype=cfg.PRECISION.np_float) * 10 * \
                self.camera.max_grey_value
        res = self.camera.get_image(photons.astype(np.float32), shot_noise=False, psf=False)

        self.assertEqual(np.var(res), 0)

        diff = np.ones(self.camera.shape) * self.camera.max_grey_value - res
        self.assertEqual(np.sum(diff), 0)
Esempio n. 7
0
 def setUp(self):
     self.lens = Lens(3., f_number=1.4, focal_length=100.0 * q.mm)
     self.camera = Camera(10 * q.um, 0.1, 10, 1, 12, None)
     self.detector = Detector(None, self.lens, self.camera)
Esempio n. 8
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
Esempio n. 9
0
class TestCamera(SyrisTest):
    def setUp(self):
        syris.init(device_index=0)
        wavelengths = np.arange(10) * q.nm
        qe = np.ones(len(wavelengths))
        self.camera = Camera(1e-3 * q.um,
                             1.0,
                             10.0,
                             0,
                             10, (64, 64),
                             wavelengths=wavelengths,
                             quantum_efficiencies=qe,
                             exp_time=1 * q.s,
                             fps=1 / q.s)

    def test_constructor(self):
        Camera(1 * q.um, 0.1, 10, 1, 12, None)
        Camera(1 * q.um, 0.1, 10, 1, 12, (64, 64))
        # Exposure time priority
        cam = Camera(1 * q.um,
                     0.1,
                     10,
                     1,
                     12,
                     None, (64, 64),
                     exp_time=1 * q.ms,
                     fps=10000 / q.s)
        self.assertEqual(cam.fps.simplified, 1000 / q.s)

        # Shorter exposure time than 1 / FPS
        cam = Camera(1 * q.um,
                     0.1,
                     10,
                     1,
                     12, (64, 64),
                     exp_time=0.5 * q.s,
                     fps=1 / q.s)
        self.assertEqual(cam.exp_time, .5 * q.s)
        self.assertEqual(cam.fps, 1 / q.s)

    def test_is_fps_feasible(self):
        self.assertTrue(is_fps_feasible(1000 / q.s, 1 * q.ms))
        self.assertTrue(is_fps_feasible(1000 / q.s, 0.5 * q.ms))
        self.assertFalse(is_fps_feasible(1000 / q.s, 2 * q.ms))

    def test_fps_setting(self):
        self.camera.fps = 1000 / q.s
        self.assertAlmostEqual(1e-3, self.camera.exp_time.simplified.magnitude)

    def test_exp_time_setting(self):
        self.camera.exp_time = 10 * q.s
        self.assertAlmostEqual(.1, self.camera.fps.simplified.magnitude)

    def test_bpp(self):
        self.assertEqual(self.camera.max_grey_value, 2**self.camera.bpp - 1)

    def test_dark(self):
        photons = np.zeros(self.camera.shape, dtype=cfg.PRECISION.np_float)
        res = self.camera.get_image(photons, shot_noise=True, psf=False)

        self.assertNotEqual(np.var(res), 0.0)
        self.assertNotEqual(np.sum(res), 0.0)

    def test_saturation(self):
        photons = np.ones(self.camera.shape, dtype=cfg.PRECISION.np_float) * 10 * \
                self.camera.max_grey_value
        res = self.camera.get_image(photons.astype(np.float32),
                                    shot_noise=False,
                                    psf=False)

        self.assertEqual(np.var(res), 0)

        diff = np.ones(self.camera.shape) * self.camera.max_grey_value - res
        self.assertEqual(np.sum(diff), 0)