Пример #1
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)
Пример #2
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()
Пример #3
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)