Beispiel #1
0
 def setup(self):
     self.p = np.array([0.0, 0.0, 1.0])
     self.s = np.array([1.0, 0.0, 0.0])
     self.f = np.array([0.0, 2.0, 0.0])
     self.shape = (10, 10)
     self.grid_list = [(self.p, self.s, self.f, self.shape)]
     self.bg = xray.BasisGrid(self.grid_list)
Beispiel #2
0
    def test_compute_intersect(self):

        # build a simple grid and turn it into a detector
        bg = xray.BasisGrid()
        p = np.array([0.0, 0.0, 1.0])
        s = np.array([1.0, 0.0, 0.0])
        f = np.array([0.0, 1.0, 0.0])
        shape = (10, 10)
        bg.add_grid(p, s, f, shape)
        d = xray.Detector(bg, 2.0 * np.pi / 1.4)

        # compute a set of q-vectors corresponding to a slightly offset grid
        xyz_grid = bg.to_explicit()
        xyz_off = xyz_grid.copy()
        xyz_off[:, 0] += 0.5
        xyz_off[:, 1] += 0.5
        q_vectors = d._real_to_reciprocal(xyz_off)

        # b/c s/f vectors are unit vectors, where they intersect s/f is simply
        # their coordinates. The last row and column will miss, however
        intersect_ref = np.logical_and((xyz_off[:, 0] <= 9.0),
                                       (xyz_off[:, 1] <= 9.0))

        pix_ref = xyz_off[intersect_ref, :2]

        # compute the intersection from code
        pix, intersect = d._compute_intersections(q_vectors,
                                                  0)  # 0 --> grid_index
        print pix, intersect

        assert_array_almost_equal(intersect_ref, intersect)
        assert_array_almost_equal(pix_ref, pix)
Beispiel #3
0
 def test_array_typechecking(self):
     bad_p = np.array([0.0, 0.0])
     grid_list = [(bad_p, self.s, self.f, self.shape)]
     try:
         bg = xray.BasisGrid(grid_list)
     except:
         pass
     else:
         raise Exception('should have failed : bad typecheck')
Beispiel #4
0
    def as_shotset(self):
        """
        Convert the CBF file to an ODIN shotset representation.
        
        Returns
        -------
        cbf : odin.xray.Shotset
            The CBF file as an ODIN shotset.
        """

        p = np.array(list(self.corner) + [self.path_length])
        f = np.array([self.pixel_size[0], 0.0, 0.0])  # fast is x
        s = np.array([0.0, self.pixel_size[1], 0.0])  # slow is y

        bg = xray.BasisGrid()
        bg.add_grid(p, s, f, self.intensities_shape)

        # todo better value for photons
        b = xray.Beam(1e4, wavelength=self.wavelength)
        d = xray.Detector(bg, b.k)
        s = xray.Shotset(self.intensities.flatten().astype(np.float64), d,
                         self.mask)

        return s
Beispiel #5
0
 def test_add_using_center(self):
     center = np.array([4.5, 9, 1.0])
     nbg = xray.BasisGrid()
     nbg.add_grid_using_center(center, self.s, self.f, self.shape)
     assert_array_almost_equal(nbg.to_explicit(), self.bg.to_explicit())
Beispiel #6
0
 def test_add_grid(self):
     nbg = xray.BasisGrid()
     nbg.add_grid(*self.grid_list[0])
     assert_array_almost_equal(nbg.to_explicit(), self.bg.to_explicit())