Example #1
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)
Example #2
0
    def _generate_shot_from_entry(self, entry):

        # loop over all the detector elements and piece them together
        xyz = []
        intensities = []
        metadatas = []
        for detector_group in self._get_groups('detector', root=entry):
            x, i, m = self._detector_group_to_array(detector_group)
            xyz.append(x)
            intensities.append(i)
            metadatas.append(m)

        xyz = np.concatenate(xyz)
        intensities = np.concatenate(intensities)

        # instantitate a detector
        # todo NEED: logic for path_length
        path_length = 1.0
        beam = self._extract_energy(entry)
        d = xray.Detector(xyz, path_length, beam.k)

        # generate a shot instance and add it to our list
        return xray.Shot(intensities, d)
Example #3
0
    def test_rotated_beam(self):
        # shift a detector up (in x) a bit and test to make sure there's no diff
        t = structure.load_coor(ref_file('gold1k.coor'))
        s = xray.Shotset.simulate(t, self.d, 5, 1)

        sh = 50.0  # the shift mag
        xyz = self.d.xyz.copy()
        shift = np.zeros_like(xyz)
        shift[:, 0] += sh
        beam_vector = np.array([sh / self.l, 0.0, 1.0])

        # note that the detector du is further from the interaction site
        du = xray.Detector(xyz + shift, self.d.k, beam_vector=beam_vector)
        su = xray.Shotset.simulate(t, du, 5, 1)

        p1 = s.intensity_profile(q_spacing=0.05)
        p2 = su.intensity_profile(q_spacing=0.05)

        p1 /= p1.max()
        p2 /= p2.max()
        p1 = p2[:10, :]
        p2 = p2[:p1.shape[0], :]

        assert_allclose(p1, p2, rtol=0.1)
Example #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